use of org.gbif.dwc.record.Record in project eol-globi-data by jhpoelen.
the class DwCAUtilTest method assertHasRecords.
private void assertHasRecords(Archive dwcArchive) {
// Loop over core core records and display id, basis of record and scientific name
boolean hasRecords = false;
for (Record rec : dwcArchive.getCore()) {
hasRecords = true;
break;
}
assertThat(hasRecords, is(true));
}
use of org.gbif.dwc.record.Record in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method importTaxaExtension.
private static void importTaxaExtension(InteractionListener interactionListener, ArchiveFile extension, ArchiveFile core, BTreeMap<String, Map<String, String>> associationsMap) {
for (Record record : extension) {
Map<String, String> props = new TreeMap<>();
termsToMap(record, props);
associationsMap.put(record.id(), props);
}
for (Record coreRecord : core) {
String id = coreRecord.id();
if (contains(associationsMap, id)) {
try {
Map<String, String> targetProperties = associationsMap.get(id);
TreeMap<String, String> interaction = new TreeMap<>();
mapAssociationProperties(targetProperties, interaction);
mapCoreProperties(coreRecord, interaction);
interaction.put(RESOURCE_TYPES, StringUtils.join(Arrays.asList(core.getRowType().qualifiedName(), extension.getRowType().qualifiedName()), CharsetConstant.SEPARATOR));
interactionListener.on(interaction);
} catch (StudyImporterException e) {
//
}
}
}
}
use of org.gbif.dwc.record.Record in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method importCore.
private int importCore(Archive archive, InteractionListener interactionListener) throws StudyImporterException {
AtomicInteger recordCounter = new AtomicInteger(0);
ClosableIterator<Record> iterator = archive.getCore().iterator();
while (true) {
try {
if (!iterator.hasNext()) {
break;
}
Record rec = iterator.next();
handleRecord(interactionListener, rec);
recordCounter.incrementAndGet();
} catch (IllegalStateException ex) {
LogUtil.logError(getLogger(), "failed to handle dwc record", ex);
}
}
return recordCounter.get();
}
use of org.gbif.dwc.record.Record in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method collectRelatedResourceIds.
private static void collectRelatedResourceIds(ArchiveFile resourceExtension, Set<String> referencedSourceIds, Set<String> referencedTargetIds) {
for (Record record : resourceExtension) {
String targetId = record.value(DwcTerm.relatedResourceID);
String sourceId = record.value(DwcTerm.resourceID);
String relationshipRemarks = record.value(DwcTerm.relationshipRemarks);
if (StringUtils.isNotBlank(sourceId)) {
if (StringUtils.isNotBlank(targetId)) {
referencedSourceIds.add(sourceId);
referencedTargetIds.add(targetId);
} else if (StringUtils.contains(relationshipRemarks, "scientificName:")) {
referencedSourceIds.add(sourceId);
}
}
}
}
use of org.gbif.dwc.record.Record 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