Search in sources :

Example 46 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForDwCATest method hasAssociatedTaxa.

@Test
public void hasAssociatedTaxa() throws IOException, URISyntaxException {
    URI sampleArchive = getClass().getResource("AEC-DBCNet_DwC-A20160308-sample.zip").toURI();
    Archive archive = DwCAUtil.archiveFor(sampleArchive, "target/tmp");
    AtomicBoolean foundLink = new AtomicBoolean(false);
    importAssociatedTaxaExtension(archive, new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            assertThat(interaction.get(SOURCE_TAXON_NAME), is("Andrena wilkella"));
            assertThat(interaction.get(DatasetImporterForTSV.SOURCE_SEX_NAME), is("Female"));
            assertThat(interaction.get(SOURCE_LIFE_STAGE_NAME), is("Adult"));
            assertThat(interaction.get(TaxonUtil.TARGET_TAXON_NAME), is("Melilotus officinalis"));
            assertThat(interaction.get(INTERACTION_TYPE_NAME), is("associated with"));
            assertThat(interaction.get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002437"));
            assertThat(interaction.get(DatasetImporterForTSV.BASIS_OF_RECORD_NAME), is("LabelObservation"));
            assertThat(interaction.get(DatasetImporterForTSV.DECIMAL_LATITUDE), is("42.40000"));
            assertThat(interaction.get(DatasetImporterForTSV.DECIMAL_LONGITUDE), is("-76.50000"));
            assertThat(interaction.get(DatasetImporterForTSV.LOCALITY_NAME), is("Tompkins County"));
            assertThat(interaction.get(SOURCE_OCCURRENCE_ID), is("urn:uuid:859e1708-d8e1-11e2-99a2-0026552be7ea"));
            assertThat(interaction.get(DatasetImporterForTSV.SOURCE_COLLECTION_CODE), is(nullValue()));
            assertThat(interaction.get(DatasetImporterForTSV.SOURCE_COLLECTION_ID), is(nullValue()));
            assertThat(interaction.get(DatasetImporterForTSV.SOURCE_INSTITUTION_CODE), is("CUIC"));
            assertThat(interaction.get(DatasetImporterForTSV.SOURCE_CATALOG_NUMBER), is("CUIC_ENT 00014070"));
            assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), is("Digital Bee Collections Network, 2014 (and updates). Version: 2016-03-08. National Science Foundation grant DBI 0956388"));
            assertThat(interaction.get(DatasetImporterForTSV.RESOURCE_TYPES), is("http://rs.tdwg.org/dwc/terms/Occurrence | http://purl.org/NET/aec/associatedTaxa"));
            foundLink.set(true);
        }
    });
    assertTrue(foundLink.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InteractionListener(org.eol.globi.process.InteractionListener) Archive(org.gbif.dwc.Archive) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URI(java.net.URI) Test(org.junit.Test)

Example 47 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForZOVERTest method importDataset.

@Test
public void importDataset() throws StudyImporterException {
    List<Map<String, String>> interactions = new ArrayList<>();
    DatasetImporterForZOVER importer = new DatasetImporterForZOVER(null, null);
    importer.setDatabases(Collections.singletonList(DatasetImporterForZOVER.ZOVER_CHIROPTERA));
    importer.setInteractionListener(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            interactions.add(interaction);
        }
    });
    DatasetImpl dataset = new DatasetImpl("some/namespace", new ResourceService() {

        @Override
        public InputStream retrieve(URI resourceName) throws IOException {
            InputStream is = null;
            if (StringUtils.equals("http://www.mgc.ac.cn/cgi-bin/ZOVER/lineage2json1.pl?type=viruses&host=chiroptera", resourceName.toString())) {
                is = getClass().getResourceAsStream("zover/chiroptera_chopped.json");
            } else if (StringUtils.equals("http://www.mgc.ac.cn/ZOVER/json/chiroptera_viruses_363628.json", resourceName.toString())) {
                is = getClass().getResourceAsStream("zover/chiroptera_viruses_363628.json");
            }
            return is;
        }
    }, URI.create("some:uri")) {
    };
    importer.setDataset(dataset);
    importer.importStudy();
    assertThat(interactions.size(), is(1));
    Map<String, String> interaction = interactions.get(0);
    assertThat(interaction.get(SOURCE_TAXON_NAME), is("Torque teno Tadarida brasiliensis virus"));
    assertThat(interaction.get(SOURCE_TAXON_ID), is("NCBI:1543419"));
    assertThat(interaction.get(TARGET_TAXON_NAME), is("Tadarida brasiliensis"));
    assertThat(interaction.get(TARGET_TAXON_ID), is("NCBI:9438"));
    assertThat(interaction.get(INTERACTION_TYPE_NAME), is("pathogenOf"));
    assertThat(interaction.get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002556"));
    assertThat(interaction.get(REFERENCE_CITATION), is(nullValue()));
    assertThat(interaction.get(REFERENCE_URL), is("https://www.ncbi.nlm.nih.gov/nuccore/KM434181"));
    assertThat(interaction.get(REFERENCE_DOI), is(nullValue()));
    assertThat(interaction.get(REFERENCE_ID), is("urn:lsid:cn.ac.mgc:tick:363628"));
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ResourceService(org.eol.globi.service.ResourceService) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) IOException(java.io.IOException) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) Map(java.util.Map) Test(org.junit.Test)

Example 48 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForZenodoMetadataTest method assertInteractionOfExamplePub.

public static void assertInteractionOfExamplePub(InputStream searchResultStream) throws IOException, StudyImporterException {
    List<Map<String, String>> links = new ArrayList<>();
    final InteractionListener interactionListener = new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            links.add(interaction);
        }
    };
    DatasetImporterForZenodoMetadata.parseSearchResults(searchResultStream, interactionListener);
    assertThat(links.size(), Is.is(12));
    final Map<String, String> first = links.get(0);
    assertRefenceAndInteractionType(first);
    assertThat(first, hasEntry(TaxonUtil.SOURCE_TAXON_NAME, "Rhinolophus"));
    assertThat(first, hasEntry(TaxonUtil.TARGET_TAXON_NAME, "Severe acute respiratory syndrome coronavirus"));
    final Map<String, String> last = links.get(11);
    assertThat(last, hasEntry(TaxonUtil.SOURCE_TAXON_NAME, "Rhinolophus ferrumequinum"));
    assertThat(last, hasEntry(TaxonUtil.TARGET_TAXON_NAME, "SL-CoV Rp3"));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 49 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class TableInteractionListenerProxyTest method interactionListenerTest.

@Test
public void interactionListenerTest() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    JsonNode config = new ObjectMapper().readTree("{ \"dcterms:bibliographicCitation\":\"some citation\", \"url\":\"https://example.org/someResource\" }");
    DatasetImpl dataset = new DatasetImpl(null, URI.create("http://someurl"), inStream -> inStream);
    dataset.setConfig(config);
    final TableInteractionListenerProxy listener = new TableInteractionListenerProxy(dataset, new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            links.add(interaction);
        }
    });
    listener.on(new HashMap<>());
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(DatasetImporterForTSV.DATASET_CITATION), startsWith("some citation. Accessed at <https://example.org/someResource> on "));
    assertThat(links.get(0).get(DatasetImporterForTSV.REFERENCE_CITATION), startsWith("some citation. Accessed at <https://example.org/someResource> on "));
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) InteractionListener(org.eol.globi.process.InteractionListener) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 50 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class TableInteractionListenerProxyTest method interactionListener2Test.

@Test
public void interactionListener2Test() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    JsonNode config = new ObjectMapper().readTree("{ \"dcterms:bibliographicCitation\":\"some citation\", \"url\":\"https://example.org/someResource\" }");
    DatasetImpl dataset = new DatasetImpl(null, URI.create("http://someurl"), inStream -> inStream);
    dataset.setConfig(config);
    final TableInteractionListenerProxy listener = new TableInteractionListenerProxy(dataset, new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            links.add(interaction);
        }
    });
    listener.on(new HashMap<String, String>() {

        {
            put(DatasetImporterForTSV.REFERENCE_CITATION, "some ref");
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(DatasetImporterForTSV.DATASET_CITATION), startsWith("some citation. Accessed at <https://example.org/someResource> on "));
    assertThat(links.get(0).get(DatasetImporterForTSV.REFERENCE_CITATION), startsWith("some ref"));
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) InteractionListener(org.eol.globi.process.InteractionListener) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

InteractionListener (org.eol.globi.process.InteractionListener)58 Test (org.junit.Test)51 Map (java.util.Map)46 ArrayList (java.util.ArrayList)36 TreeMap (java.util.TreeMap)26 URI (java.net.URI)24 IOException (java.io.IOException)22 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 URL (java.net.URL)15 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)14 InputStream (java.io.InputStream)13 List (java.util.List)13 TaxonUtil (org.eol.globi.service.TaxonUtil)13 Archive (org.gbif.dwc.Archive)13 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)13 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10