use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method importRecordsFromMCZ.
@Test
public void importRecordsFromMCZ() throws StudyImporterException, URISyntaxException {
StringBuilder actualMessage = new StringBuilder();
URL resource = getClass().getResource("/org/globalbioticinteractions/dataset/mcz/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 severe(LogContext ctx, String message) {
actualMessage.append(message);
}
});
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 : new String[] {}) {
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(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));
assertThat(actualMessage.toString(), startsWith("[failed to handle dwc record]"));
}
use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method importRecords.
@Test
public void importRecords() throws StudyImporterException, URISyntaxException, IOException {
URL resource = getClass().getResource("/org/globalbioticinteractions/dataset/dwca.zip");
DatasetImporterForDwCA studyImporterForDwCA = new DatasetImporterForDwCA(null, null);
DatasetImpl dataset = new DatasetImpl("some/namespace", resource.toURI(), inStream -> inStream);
dataset.setConfig(new ObjectMapper().readTree("{ \"citation\": \"some citation\" }"));
studyImporterForDwCA.setDataset(dataset);
AtomicBoolean someRecords = new AtomicBoolean(false);
Set<String> resourceTypes = new TreeSet<>();
studyImporterForDwCA.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
String associatedTaxa = interaction.get("http://rs.tdwg.org/dwc/terms/associatedTaxa");
String dynamicProperties = interaction.get("http://rs.tdwg.org/dwc/terms/dynamicProperties");
assertThat(StringUtils.isNotBlank(associatedTaxa) || StringUtils.isNotBlank(dynamicProperties), is(true));
assertThat(interaction.get(SOURCE_TAXON_NAME), is(not(nullValue())));
assertThat(interaction.get(TaxonUtil.TARGET_TAXON_NAME), is(not(nullValue())));
assertThat(interaction.get(INTERACTION_TYPE_NAME), is(not(nullValue())));
assertThat(interaction.get(DatasetImporterForTSV.DATASET_CITATION), containsString("some citation"));
assertThat(interaction.get(DatasetImporterForTSV.DATASET_CITATION), containsString("Accessed at"));
assertThat(interaction.get(DatasetImporterForTSV.DATASET_CITATION), containsString("dataset/dwca.zip"));
assertThat(interaction.get(REFERENCE_ID), is(not(nullValue())));
assertThat(interaction.get(DatasetImporterForTSV.REFERENCE_CITATION), is(not(nullValue())));
assertThat(interaction.get(REFERENCE_URL), is(not(nullValue())));
resourceTypes.addAll(Arrays.asList(splitByPipes(interaction.get(RESOURCE_TYPES))));
someRecords.set(true);
}
});
studyImporterForDwCA.importStudy();
assertThat(someRecords.get(), is(true));
assertThat(resourceTypes, containsInAnyOrder("http://rs.tdwg.org/dwc/terms/dynamicProperties", "http://rs.tdwg.org/dwc/terms/Occurrence", "http://rs.tdwg.org/dwc/terms/associatedTaxa"));
}
use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForZenodoMetadataIT method importStudy.
@Test
public void importStudy() throws IOException, StudyImporterException {
List<Map<String, String>> links = new ArrayList<>();
final DatasetImporterForZenodoMetadata importer = new DatasetImporterForZenodoMetadata(null, null);
importer.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
links.add(interaction);
}
});
final DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("some:archive"), in -> in) {
@Override
public String getOrDefault(String key, String defaultValue) {
return "https://sandbox.zenodo.org/api/records/?custom=%5Bobo%3ARO_0002453%5D%3A%5B%3A%5D";
}
};
importer.setDataset(dataset);
importer.importStudy();
assertThat(links.size() > 0, Is.is(true));
}
use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class InteractionListenerIndexingTest method indexOnSourceOccurrenceIdOnly.
@Test
public void indexOnSourceOccurrenceIdOnly() throws StudyImporterException {
TreeMap<Pair<String, String>, Map<String, String>> interactionsWithUnresolvedOccurrenceIds = new TreeMap<>();
InteractionListener listener = new InteractionListenerIndexing(interactionsWithUnresolvedOccurrenceIds);
listener.on(new TreeMap<String, String>() {
{
put(DatasetImporterForTSV.SOURCE_OCCURRENCE_ID, "target123");
put(TaxonUtil.SOURCE_TAXON_NAME, "sourceName123");
}
});
assertThat(interactionsWithUnresolvedOccurrenceIds.size(), Is.is(0));
}
use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForMetaTable method importStudy.
@Override
public void importStudy() throws StudyImporterException {
try {
for (JsonNode tableConfig : collectTables(dataset)) {
Dataset datasetProxy = new DatasetProxy(dataset);
datasetProxy.setConfig(tableConfig);
InteractionListener interactionListener = getInteractionListener();
final InteractionListener listener = new TableInteractionListenerProxy(datasetProxy, interactionListener);
importTable(listener, new TableParserFactoryImpl(), tableConfig, datasetProxy, getLogger());
}
} catch (IOException | NodeFactoryException e) {
String msg = "problem importing from [" + getBaseUrl() + "]";
LogUtil.logError(getLogger(), msg, e);
throw new StudyImporterException(msg, e);
}
}
Aggregations