use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForGlobalWebDb method importStudy.
@Override
public void importStudy() throws StudyImporterException {
InteractionListener interactionListener = getInteractionListener();
importDietMatrices(URI.create("https://www.globalwebdb.com/Service/DownloadArchive"), dietMatrixString -> {
try {
parseDietMatrix(interactionListener, dietMatrixString, getSourceCitation());
} catch (IOException e) {
throw new StudyImporterException(e);
}
});
}
use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method assertImportsSomethingOfType.
private void assertImportsSomethingOfType(URI archiveRoot, AtomicInteger recordCounter, String defaultResourceType, String... expectedProperties) throws StudyImporterException {
final Set<String> resourceTypes = new TreeSet<>();
DatasetImporterForDwCA studyImporterForDwCA = new DatasetImporterForDwCA(null, null);
studyImporterForDwCA.setDataset(new DatasetImpl("some/namespace", archiveRoot, inStream -> inStream));
studyImporterForDwCA.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
for (String expectedProperty : expectedProperties) {
assertThat("no [" + expectedProperty + "] found in " + interaction, interaction.containsKey(expectedProperty), is(true));
assertThat("no value of [" + expectedProperty + "] found in " + interaction, interaction.get(expectedProperty), is(notNullValue()));
}
assertThat(interaction.get(RESOURCE_TYPES), is(notNullValue()));
String[] types = splitByPipes(interaction.get(RESOURCE_TYPES));
resourceTypes.addAll(Arrays.asList(types));
recordCounter.incrementAndGet();
}
});
studyImporterForDwCA.importStudy();
assertThat(recordCounter.get(), greaterThan(0));
String[] items = splitByPipes(defaultResourceType);
assertThat(resourceTypes, containsInAnyOrder(items));
assertThat(recordCounter.get(), greaterThan(0));
}
use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method hasResourceRelationshipsOccurrenceToOccurrenceMissingTargetReference.
@Test
public void hasResourceRelationshipsOccurrenceToOccurrenceMissingTargetReference() throws IOException, URISyntaxException {
URI sampleArchive = getClass().getResource("fmnh-rr-unresolved-targetid-test.zip").toURI();
Archive archive = DwCAUtil.archiveFor(sampleArchive, "target/tmp");
AtomicInteger numberOfFoundLinks = new AtomicInteger(0);
importResourceRelationshipExtension(archive, new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
numberOfFoundLinks.incrementAndGet();
assertThat(interaction.get(relatedResourceID.qualifiedName()), is("http://n2t.net/ark:/65665/37d63a454-d948-4b1d-89db-89809887ef41"));
assertThat(interaction.get(SOURCE_TAXON_NAME), is("Trichobius parasparsus Wenzel, 1976"));
assertThat(interaction.get(SOURCE_OCCURRENCE_ID), is("8afec7db-7b19-44f7-8ac8-8d98614e71d2"));
assertThat(interaction.get(INTERACTION_TYPE_NAME), is("Ectoparasite of"));
assertThat(interaction.get(INTERACTION_TYPE_ID), is(nullValue()));
assertThat(interaction.get(DatasetImporterForTSV.BASIS_OF_RECORD_NAME), is("PreservedSpecimen"));
assertThat(interaction.get(TaxonUtil.TARGET_TAXON_NAME), is(nullValue()));
assertThat(interaction.get(DatasetImporterForTSV.TARGET_OCCURRENCE_ID), is("http://n2t.net/ark:/65665/37d63a454-d948-4b1d-89db-89809887ef41"));
assertThat(interaction.get(DatasetImporterForTSV.TARGET_CATALOG_NUMBER), is(nullValue()));
assertThat(interaction.get(DatasetImporterForTSV.TARGET_COLLECTION_CODE), is(nullValue()));
assertThat(interaction.get(DatasetImporterForTSV.TARGET_INSTITUTION_CODE), is(nullValue()));
assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), is("A. L. Tuttle | M. D. Tuttle"));
assertThat(interaction.get(DatasetImporterForTSV.RESOURCE_TYPES), is("http://rs.tdwg.org/dwc/terms/ResourceRelationship | http://rs.tdwg.org/dwc/terms/Occurrence"));
}
});
assertThat(numberOfFoundLinks.get(), is(1));
}
use of org.eol.globi.process.InteractionListener 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)"));
}
use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method importTaxonDescriptionsFromDirNoInteractionType.
@Test
public void importTaxonDescriptionsFromDirNoInteractionType() throws StudyImporterException, URISyntaxException {
URL resource = getClass().getResource("/org/globalbioticinteractions/dataset/coetzer-no-interaction-type/meta.xml");
URI archiveRoot = new File(resource.toURI()).getParentFile().toURI();
List<Map<String, String>> links = new ArrayList<>();
DatasetImporterForDwCA studyImporterForDwCA = new DatasetImporterForDwCA(null, null);
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"));
links.add(interaction);
}
});
studyImporterForDwCA.importStudy();
assertThat(links.size(), is(0));
}
Aggregations