use of org.eol.globi.data.DatasetImporterForTSV.INTERACTION_TYPE_ID 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