Search in sources :

Example 11 with NullImportLogger

use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.

the class DatasetImporterForDwCATest method nonInteractionRecordMessage.

@Test
public void nonInteractionRecordMessage() throws StudyImporterException, URISyntaxException {
    List<String> msgs = new ArrayList<>();
    URL resource = getClass().getResource("/org/globalbioticinteractions/dataset/mcz-adjusted/meta.xml");
    URI archiveRoot = new File(resource.toURI()).getParentFile().toURI();
    AtomicInteger recordCounter = new AtomicInteger(0);
    DatasetImporterForDwCA studyImporterForDwCA = new DatasetImporterForDwCA(null, null);
    studyImporterForDwCA.setLogger(new NullImportLogger() {

        @Override
        public void info(LogContext ctx, String message) {
            msgs.add(message);
        }
    });
    studyImporterForDwCA.setDataset(new DatasetImpl("some/namespace", archiveRoot, inStream -> inStream));
    studyImporterForDwCA.setInteractionListener(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            assertThat(interaction.get(DatasetImporterForTSV.RESOURCE_TYPES), is("http://rs.tdwg.org/dwc/terms/ResourceRelationship | http://rs.tdwg.org/dwc/terms/Occurrence"));
            recordCounter.incrementAndGet();
        }
    });
    studyImporterForDwCA.importStudy();
    assertThat(recordCounter.get(), is(0));
    String joinedMsgs = StringUtils.join(msgs, "\n");
    assertThat(joinedMsgs, containsString("]: indexing interaction records"));
    assertThat(joinedMsgs, containsString("]: scanned [1] record(s)"));
}
Also used : NullImportLogger(org.eol.globi.tool.NullImportLogger) TaxonUtil(org.eol.globi.service.TaxonUtil) Arrays(java.util.Arrays) INTERACTION_TYPE_NAME(org.eol.globi.data.DatasetImporterForTSV.INTERACTION_TYPE_NAME) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) INTERACTION_TYPE_ID(org.eol.globi.data.DatasetImporterForTSV.INTERACTION_TYPE_ID) InteractionListener(org.eol.globi.process.InteractionListener) StringUtils(org.apache.commons.lang3.StringUtils) NullImportLogger(org.eol.globi.tool.NullImportLogger) InteractType(org.eol.globi.domain.InteractType) Is(org.hamcrest.core.Is) REFERENCE_URL(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_URL) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) SOURCE_LIFE_STAGE_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) DatasetImporterForDwCA.parseAssociatedSequences(org.eol.globi.data.DatasetImporterForDwCA.parseAssociatedSequences) DatasetImporterForDwCA.importAssociatedTaxaExtension(org.eol.globi.data.DatasetImporterForDwCA.importAssociatedTaxaExtension) DatasetImporterForDwCA.mapReferenceInfo(org.eol.globi.data.DatasetImporterForDwCA.mapReferenceInfo) TARGET_OCCURRENCE_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_OCCURRENCE_ID) EXTENSION_RESOURCE_RELATIONSHIP(org.eol.globi.data.DatasetImporterForDwCA.EXTENSION_RESOURCE_RELATIONSHIP) SOURCE_TAXON_NAME(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_NAME) DwcTerm(org.gbif.dwc.terms.DwcTerm) IsNot.not(org.hamcrest.core.IsNot.not) TARGET_FIELD_NUMBER(org.eol.globi.data.DatasetImporterForTSV.TARGET_FIELD_NUMBER) DatasetImporterForDwCA.importResourceRelationshipExtension(org.eol.globi.data.DatasetImporterForDwCA.importResourceRelationshipExtension) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) REFERENCE_ID(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_ID) Record(org.gbif.dwc.record.Record) Set(java.util.Set) TestCase.assertNull(junit.framework.TestCase.assertNull) Matchers.startsWith(org.hamcrest.Matchers.startsWith) DatasetImporterForDwCA.parseDynamicPropertiesForInteractionsOnly(org.eol.globi.data.DatasetImporterForDwCA.parseDynamicPropertiesForInteractionsOnly) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) EXTENSION_ASSOCIATED_TAXA(org.eol.globi.data.DatasetImporterForDwCA.EXTENSION_ASSOCIATED_TAXA) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) TARGET_BODY_PART_NAME(org.eol.globi.data.DatasetImporterForTSV.TARGET_BODY_PART_NAME) DATASET_CITATION(org.eol.globi.data.DatasetImporterForTSV.DATASET_CITATION) CoreMatchers.anyOf(org.hamcrest.CoreMatchers.anyOf) LogContext(org.eol.globi.domain.LogContext) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) TARGET_CATALOG_NUMBER(org.eol.globi.data.DatasetImporterForTSV.TARGET_CATALOG_NUMBER) DwcTerm.relatedResourceID(org.gbif.dwc.terms.DwcTerm.relatedResourceID) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SOURCE_TAXON_FAMILY(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_FAMILY) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) RESOURCE_TYPES(org.eol.globi.data.DatasetImporterForTSV.RESOURCE_TYPES) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SOURCE_OCCURRENCE_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_OCCURRENCE_ID) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Term(org.gbif.dwc.terms.Term) MapUtils(org.apache.commons.collections4.MapUtils) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Archive(org.gbif.dwc.Archive) DwCAUtil(org.globalbioticinteractions.dataset.DwCAUtil) Test(org.junit.Test) IOException(java.io.IOException) TARGET_TAXON_NAME(org.eol.globi.service.TaxonUtil.TARGET_TAXON_NAME) File(java.io.File) DatasetImporterForDwCA.parseAssociatedOccurrences(org.eol.globi.data.DatasetImporterForDwCA.parseAssociatedOccurrences) TARGET_SEX_NAME(org.eol.globi.data.DatasetImporterForTSV.TARGET_SEX_NAME) TreeMap(java.util.TreeMap) DcTerm(org.gbif.dwc.terms.DcTerm) REFERENCE_CITATION(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_CITATION) ArrayList(java.util.ArrayList) LogContext(org.eol.globi.domain.LogContext) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) URI(java.net.URI) URL(java.net.URL) REFERENCE_URL(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_URL) InteractionListener(org.eol.globi.process.InteractionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) Test(org.junit.Test)

Example 12 with NullImportLogger

use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.

the class InteractionListenerWithInteractionTypeMappingTest method withVerbatimInteractionType.

@Test
public void withVerbatimInteractionType() throws StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<>();
    InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {

        @Override
        public boolean shouldIgnoreInteractionType(String nameOrId) {
            return false;
        }

        @Override
        public InteractType getInteractType(String nameOrId) {
            return InteractType.ATE;
        }
    }, new NullImportLogger());
    listener.on(new HashMap<String, String>() {

        {
            put(INTERACTION_TYPE_NAME, "Donald");
            put(INTERACTION_TYPE_ID, "duck");
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID_VERBATIM), is("duck"));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME_VERBATIM), is("Donald"));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is("eats"));
}
Also used : InteractType(org.eol.globi.domain.InteractType) NullImportLogger(org.eol.globi.tool.NullImportLogger) ArrayList(java.util.ArrayList) InteractTypeMapper(org.eol.globi.util.InteractTypeMapper) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with NullImportLogger

use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.

the class InteractionListenerWithInteractionTypeMappingTest method withBlankInteractionType.

@Test
public void withBlankInteractionType() throws StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<>();
    InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {

        @Override
        public boolean shouldIgnoreInteractionType(String nameOrId) {
            return false;
        }

        @Override
        public InteractType getInteractType(String nameOrId) {
            return InteractType.ATE;
        }
    }, new NullImportLogger());
    listener.on(new HashMap<String, String>() {

        {
            put(INTERACTION_TYPE_NAME, "");
            put(INTERACTION_TYPE_ID, "");
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is("eats"));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID_VERBATIM), is(""));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME_VERBATIM), is(""));
}
Also used : InteractType(org.eol.globi.domain.InteractType) NullImportLogger(org.eol.globi.tool.NullImportLogger) ArrayList(java.util.ArrayList) InteractTypeMapper(org.eol.globi.util.InteractTypeMapper) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 14 with NullImportLogger

use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.

the class InteractionListenerWithInteractionTypeMappingTest method withNullInteractionType.

@Test
public void withNullInteractionType() throws StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<>();
    InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {

        @Override
        public boolean shouldIgnoreInteractionType(String nameOrId) {
            return false;
        }

        @Override
        public InteractType getInteractType(String nameOrId) {
            return InteractType.ATE;
        }
    }, new NullImportLogger());
    listener.on(new HashMap<String, String>() {

        {
            put(INTERACTION_TYPE_NAME, null);
            put(INTERACTION_TYPE_ID, null);
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID), is(nullValue()));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is(nullValue()));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID_VERBATIM), is(nullValue()));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME_VERBATIM), is(nullValue()));
}
Also used : InteractType(org.eol.globi.domain.InteractType) NullImportLogger(org.eol.globi.tool.NullImportLogger) ArrayList(java.util.ArrayList) InteractTypeMapper(org.eol.globi.util.InteractTypeMapper) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 15 with NullImportLogger

use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.

the class TaxonNameEnricherTest method importWithMissingTargetTaxonButAvailableInstitutionCollectionCatalogTriple.

@Test
public void importWithMissingTargetTaxonButAvailableInstitutionCollectionCatalogTriple() throws StudyImporterException {
    List<String> msgs = new ArrayList<>();
    List<Map<String, String>> received = new ArrayList<>();
    final InteractionListener listener = new TaxonNameEnricher(interaction -> received.add(interaction), new NullImportLogger() {

        @Override
        public void info(LogContext ctx, String message) {
            msgs.add(message);
        }

        @Override
        public void warn(LogContext ctx, String message) {
            msgs.add(message);
        }

        @Override
        public void severe(LogContext ctx, String message) {
            msgs.add(message);
        }
    });
    final TreeMap<String, String> link = new TreeMap<>();
    link.put(SOURCE_TAXON_NAME, "Donald duck");
    link.put(SOURCE_TAXON_PATH, "Aves | Donald | Donald duck");
    link.put(SOURCE_TAXON_PATH_NAMES, "class | genus | species");
    link.put(SOURCE_TAXON_SPECIFIC_EPITHET, "duck");
    link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, InteractType.ATE.getIRI());
    link.put(TARGET_OCCURRENCE_ID, "occurrenceId123");
    link.put(TARGET_INSTITUTION_CODE, "institutionCode123");
    link.put(TARGET_COLLECTION_CODE, "collectionCode123");
    link.put(TARGET_COLLECTION_ID, "collectionId123");
    link.put(TARGET_CATALOG_NUMBER, "catalogNumber123");
    link.put(DATASET_CITATION, "some source ref");
    link.put(REFERENCE_ID, "123");
    link.put(REFERENCE_CITATION, "");
    listener.on(link);
    assertThat(msgs, hasItem("target taxon name missing: using institutionCode/collectionCode/collectionId/catalogNumber/occurrenceId as placeholder"));
    assertThat(received.size(), is(1));
    Map<String, String> receivedInteraction = received.get(0);
    assertThat(receivedInteraction.get(TARGET_TAXON_NAME), is("institutionCode123 | collectionCode123 | collectionId123 | catalogNumber123 | occurrenceId123"));
}
Also used : NullImportLogger(org.eol.globi.tool.NullImportLogger) ArrayList(java.util.ArrayList) LogContext(org.eol.globi.domain.LogContext) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Aggregations

NullImportLogger (org.eol.globi.tool.NullImportLogger)16 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)13 Map (java.util.Map)11 LogContext (org.eol.globi.domain.LogContext)11 TreeMap (java.util.TreeMap)8 HashMap (java.util.HashMap)6 InteractType (org.eol.globi.domain.InteractType)6 IOException (java.io.IOException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 StudyImporterException (org.eol.globi.data.StudyImporterException)3 LatLng (org.eol.globi.geo.LatLng)3 InteractionListener (org.eol.globi.process.InteractionListener)3 GeoNamesService (org.eol.globi.service.GeoNamesService)3 InteractTypeMapper (org.eol.globi.util.InteractTypeMapper)3 File (java.io.File)2 URI (java.net.URI)2