use of org.eol.globi.data.DatasetImporterForTSV.INTERACTION_TYPE_NAME in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method importTaxonDescriptionsFromDir.
@Test
public void importTaxonDescriptionsFromDir() throws StudyImporterException, URISyntaxException {
URL resource = getClass().getResource("/org/globalbioticinteractions/dataset/coetzer/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 {
links.add(interaction);
}
});
studyImporterForDwCA.importStudy();
assertThat(links.size() > 0, is(true));
assertThat(links.get(0).get(DATASET_CITATION), containsString("org/globalbioticinteractions/dataset/coetzer/"));
assertThat(links.get(0).get(REFERENCE_CITATION), is("Cockerell, T.D.A. 1937. African bees of the genera Ceratina, Halictus and Megachile. 254 pp. William Clowes and Sons, London"));
assertThat(links.get(0).get(TARGET_TAXON_NAME), is("Chaetodactylus leleupi"));
assertThat(links.get(0).get(SOURCE_TAXON_NAME), is("Ceratina ruwenzorica Cockerell, 1937"));
assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is("Parasite"));
assertThat(links.get(0).get(RESOURCE_TYPES), is("http://rs.gbif.org/terms/1.0/Reference"));
}
use of org.eol.globi.data.DatasetImporterForTSV.INTERACTION_TYPE_NAME in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method importInteractionsFromResourceRelationships.
private static void importInteractionsFromResourceRelationships(InteractionListener interactionListener, ArchiveFile resourceExtension, Map<String, Map<String, Map<String, String>>> termTypeIdPropMap, List<DwcTerm> termTypes) {
for (Record record : resourceExtension) {
Map<String, String> props = new TreeMap<>();
appendResourceType(props, resourceExtension.getRowType());
String sourceId = record.value(DwcTerm.resourceID);
String relationship = record.value(DwcTerm.relationshipOfResource);
Optional<Term> relationshipOfResourceIDTerm = record.terms().stream().filter(x -> StringUtils.equals(x.simpleName(), "relationshipOfResourceID")).findFirst();
String relationshipTypeIdValue = relationshipOfResourceIDTerm.map(record::value).orElse(null);
String targetId = record.value(DwcTerm.relatedResourceID);
if (StringUtils.isNotBlank(sourceId)) {
appendVerbatimResourceRelationsValues(record, props);
String relationshipAccordingTo = record.value(DwcTerm.relationshipAccordingTo);
if (StringUtils.isNotBlank(relationshipAccordingTo)) {
props.putIfAbsent(REFERENCE_CITATION, relationshipAccordingTo);
}
putIfAbsentAndNotBlank(props, INTERACTION_TYPE_NAME, relationship);
putIfAbsentAndNotBlank(props, INTERACTION_TYPE_ID, relationshipTypeIdValue);
putIfAbsentAndNotBlank(props, DatasetImporterForMetaTable.EVENT_DATE, record.value(DwcTerm.relationshipEstablishedDate));
for (DwcTerm termType : termTypes) {
String key = termType.qualifiedName();
if (StringUtils.isNoneBlank(key) && termTypeIdPropMap.containsKey(key)) {
Map<String, Map<String, String>> propMap = termTypeIdPropMap.get(termType.qualifiedName());
populatePropertiesAssociatedWithId(props, sourceId, true, propMap.get(sourceId), labelPairFor(termType));
extractNameFromRelationshipRemarks(record).ifPresent(name -> props.put(TARGET_TAXON_NAME, name));
populatePropertiesAssociatedWithId(props, targetId, false, propMap.get(targetId), labelPairFor(termType));
}
}
try {
interactionListener.on(props);
} catch (StudyImporterException e) {
//
}
}
}
}
Aggregations