Search in sources :

Example 6 with NullImportLogger

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

the class InteractionImporterTest method malformedDateRange.

@Test
public void malformedDateRange() {
    final List<String> msgs = new ArrayList<>();
    InteractionListener interactionListener = new InteractionImporter(nodeFactory, new GeoNamesService() {

        @Override
        public boolean hasTermForLocale(String locality) {
            return true;
        }

        @Override
        public LatLng findLatLng(String locality) throws IOException {
            throw new IOException("kaboom!");
        }
    }, new NullImportLogger() {

        @Override
        public void warn(LogContext ctx, String message) {
            msgs.add(message);
        }
    });
    final TreeMap<String, String> link = new TreeMap<>();
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
    link.put(TARGET_TAXON_NAME, "mini");
    link.put(REFERENCE_ID, "123");
    link.put(DATASET_CITATION, "some source ref");
    link.put(REFERENCE_CITATION, "");
    link.put(REFERENCE_DOI, "10.12/123");
    link.put(DatasetImporterForMetaTable.EVENT_DATE, "2009-09/2003-09");
    try {
        interactionListener.on(link);
        assertThat(msgs.size(), is(2));
        assertThat(msgs.get(0), startsWith("issue handling date range [2009-09/2003-09]: The end instant must be greater than the start instant"));
        assertThat(msgs.get(1), startsWith("issue handling date range [2009-09/2003-09]: The end instant must be greater than the start instant"));
    } catch (StudyImporterException ex) {
        fail("should not throw on failing geoname lookup");
    }
}
Also used : NullImportLogger(org.eol.globi.tool.NullImportLogger) GeoNamesService(org.eol.globi.service.GeoNamesService) ArrayList(java.util.ArrayList) LogContext(org.eol.globi.domain.LogContext) IOException(java.io.IOException) TreeMap(java.util.TreeMap) StudyImporterException(org.eol.globi.data.StudyImporterException) LatLng(org.eol.globi.geo.LatLng) Test(org.junit.Test)

Example 7 with NullImportLogger

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

the class InteractionImporterTest method throwingGeoNamesService.

@Test
public void throwingGeoNamesService() {
    final List<String> msgs = new ArrayList<>();
    InteractionListener interactionListener = new InteractionImporter(nodeFactory, new GeoNamesService() {

        @Override
        public boolean hasTermForLocale(String locality) {
            return true;
        }

        @Override
        public LatLng findLatLng(String locality) throws IOException {
            throw new IOException("kaboom!");
        }
    }, new NullImportLogger() {

        @Override
        public void warn(LogContext ctx, String message) {
            msgs.add(message);
        }
    });
    final TreeMap<String, String> link = new TreeMap<>();
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
    link.put(TARGET_TAXON_NAME, "mini");
    link.put(LOCALITY_ID, "bla:123");
    link.put(LOCALITY_NAME, "my back yard");
    link.put(REFERENCE_ID, "123");
    link.put(DATASET_CITATION, "some source ref");
    link.put(REFERENCE_CITATION, "");
    try {
        interactionListener.on(link);
        assertThat(msgs.size(), is(1));
        assertThat(msgs.get(0), startsWith("failed to lookup [bla:123]"));
    } catch (StudyImporterException ex) {
        fail("should not throw on failing geoname lookup");
    }
}
Also used : NullImportLogger(org.eol.globi.tool.NullImportLogger) GeoNamesService(org.eol.globi.service.GeoNamesService) ArrayList(java.util.ArrayList) LogContext(org.eol.globi.domain.LogContext) IOException(java.io.IOException) TreeMap(java.util.TreeMap) StudyImporterException(org.eol.globi.data.StudyImporterException) LatLng(org.eol.globi.geo.LatLng) Test(org.junit.Test)

Example 8 with NullImportLogger

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

the class DatasetImporterForPlanqueIT method importAll.

@Test
public void importAll() throws StudyImporterException, IOException {
    final List<String> errorMessages = new ArrayList<String>();
    BaseDatasetImporter importer = new DatasetImporterForPlanque(new ParserFactoryLocal(), nodeFactory);
    JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Benjamin Planque, Raul Primicerio, Kathrine Michalsen, Michaela Aschan, Grégoire Certain, Padmini Dalpadado, Harald Gjøsæater, Cecilie Hansen, Edda Johannesen, Lis Lindal Jørgensen, Ina Kolsum, Susanne Kortsch, Lise-Marie Leclerc, Lena Omli, Mette Skern-Mauritzen, and Magnus Wiedmann 2014. Who eats whom in the Barents Sea: a food web topology from plankton to whales. Ecology 95:1430–1430. https://doi.org/10.1890/13-1062.1\",\n" + "  \"doi\": \"https://doi.org/10.1890/13-1062.1\",\n" + "  \"format\": \"planque\",\n" + "  \"resources\": {\n" + "    \"links\": \"http://www.esapubs.org/archive/ecol/E095/124/revised/PairwiseList.txt\",\n" + "    \"references\": \"http://www.esapubs.org/archive/ecol/E095/124/revised/References.txt\",\n" + "    \"referencesForLinks\": \"http://www.esapubs.org/archive/ecol/E095/124/revised/PairWise2References.txt\"\n" + "  }\n" + "}");
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"), inStream -> inStream);
    dataset.setConfig(config);
    importer.setDataset(dataset);
    importer.setLogger(new NullImportLogger() {

        @Override
        public void warn(LogContext ctx, String message) {
            errorMessages.add(message);
        }
    });
    importStudy(importer);
    int interactionCount = 0;
    List<StudyNode> studies = NodeUtil.findAllStudies(getGraphDb());
    for (StudyNode study : studies) {
        interactionCount += getSpecimenCount(study);
    }
    assertThat(interactionCount, is(4900));
    int uniqueReference = 236;
    // note that the +1 is for all links that had no reference associated to it
    assertThat(studies.size(), is(uniqueReference + 1));
    assertThat(taxonIndex.findTaxonByName("Trisopterus esmarkii"), is(notNullValue()));
    assertThat(errorMessages.size(), is(0));
}
Also used : NullImportLogger(org.eol.globi.tool.NullImportLogger) ArrayList(java.util.ArrayList) LogContext(org.eol.globi.domain.LogContext) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) StudyNode(org.eol.globi.domain.StudyNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 9 with NullImportLogger

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

the class DatasetImporterForMangalIT method importAll.

@Test
public void importAll() throws StudyImporterException {
    AtomicInteger counter = new AtomicInteger(0);
    DatasetImporterForMangal importer = new DatasetImporterForMangal(null, null);
    importer.setDataset(new DatasetLocal(inStream -> inStream));
    importer.setInteractionListener(new InteractionValidator(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            counter.incrementAndGet();
        }
    }, new NullImportLogger() {

        @Override
        public void warn(LogContext ctx, String message) {
            fail("unexpected warning: [" + message + "]");
        }
    }));
    importer.importStudy();
    assertThat(counter.get() > 0, Is.is(true));
}
Also used : LogContext(org.eol.globi.domain.LogContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) InteractionValidator(org.eol.globi.process.InteractionValidator) InteractionListener(org.eol.globi.process.InteractionListener) Test(org.junit.Test) Assert.fail(org.junit.Assert.fail) InteractionListenerImpl(org.eol.globi.process.InteractionListenerImpl) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NullImportLogger(org.eol.globi.tool.NullImportLogger) DatasetLocal(org.eol.globi.service.DatasetLocal) Is(org.hamcrest.core.Is) NullImportLogger(org.eol.globi.tool.NullImportLogger) InteractionListener(org.eol.globi.process.InteractionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InteractionValidator(org.eol.globi.process.InteractionValidator) LogContext(org.eol.globi.domain.LogContext) DatasetLocal(org.eol.globi.service.DatasetLocal) Map(java.util.Map) Test(org.junit.Test)

Example 10 with NullImportLogger

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

the class DatasetImporterForBatBaseIT method importAll.

@Test
public void importAll() throws StudyImporterException {
    AtomicInteger counter = new AtomicInteger(0);
    DatasetImporterForBatBase importer = new DatasetImporterForBatBase(null, null);
    DatasetImpl dataset = new DatasetImpl("test/batplant", URI.create("classpath:/org/eol/globi/data/batplant/"), is -> is);
    importer.setDataset(dataset);
    importer.setInteractionListener(new InteractionValidator(new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            counter.incrementAndGet();
        }
    }, new NullImportLogger() {

        @Override
        public void warn(LogContext ctx, String message) {
            fail("unexpected warning: [" + message + "]");
        }
    }));
    importer.importStudy();
    assertThat(counter.get() > 0, Is.is(true));
}
Also used : NullImportLogger(org.eol.globi.tool.NullImportLogger) InteractionListener(org.eol.globi.process.InteractionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InteractionValidator(org.eol.globi.process.InteractionValidator) LogContext(org.eol.globi.domain.LogContext) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Map(java.util.Map) 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