use of org.gbif.dwc.terms.Term in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method termsToMap.
private static void termsToMap(Record record, Map<String, String> props) {
for (Term term : record.terms()) {
String value = record.value(term);
if (StringUtils.isNotBlank(value)) {
props.put(term.qualifiedName(), value);
}
appendResourceType(props, record.rowType());
}
}
use of org.gbif.dwc.terms.Term in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method handleRecord.
private void handleRecord(InteractionListener interactionListener, Record rec) throws StudyImporterException {
List<Map<String, String>> interactionCandidates = new ArrayList<>();
appendInteractionCandidatesIfAvailable(rec, interactionCandidates, DwcTerm.associatedTaxa, "");
appendInteractionCandidatesIfAvailable(rec, interactionCandidates, DwcTerm.habitat, null);
appendAssociatedOccurrencesIfAvailable(rec, interactionCandidates);
// see https://github.com/globalbioticinteractions/globalbioticinteractions/issues/755#issuecomment-1029509362
appendAssociatedSequencesIfAvailable(rec, interactionCandidates);
String occurrenceRemarks = rec.value(DwcTerm.occurrenceRemarks);
try {
addCandidatesFromRemarks(interactionCandidates, occurrenceRemarks);
} catch (IOException e) {
if (getLogger() != null) {
Map<String, String> interactionProperties = new HashMap<>();
mapCoreProperties(rec, interactionProperties);
getLogger().warn(LogUtil.contextFor(interactionProperties), e.getMessage());
}
}
String dynamicProperties = rec.value(DwcTerm.dynamicProperties);
if (StringUtils.isNotBlank(dynamicProperties)) {
Map<String, String> parsedDynamicProperties = parseDynamicPropertiesForInteractionsOnly(dynamicProperties);
if (!parsedDynamicProperties.isEmpty()) {
interactionCandidates.add(parsedDynamicProperties);
}
}
Map<String, String> interaction = new HashMap<>(rec.terms().size());
for (Term term : rec.terms()) {
interaction.put(term.qualifiedName(), rec.value(term));
}
if (interactionCandidates.isEmpty() && isDependency()) {
// If no candidates are found,
// add empty candidate to allow interaction listeners to do indexing/enriching
interactionCandidates.add(new TreeMap<>());
}
for (Map<String, String> interactionProperties : interactionCandidates) {
interactionProperties.putAll(interaction);
interactionProperties.put(DWC_COREID, rec.id());
mapIfAvailable(rec, interactionProperties, BASIS_OF_RECORD_NAME, DwcTerm.basisOfRecord);
mapCoreProperties(rec, interactionProperties);
appendResourceType(interactionProperties, rec.rowType());
interactionListener.on(interactionProperties);
}
}
use of org.gbif.dwc.terms.Term 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