use of org.gbif.dwc.ArchiveFile in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method findResourceExtension.
static ArchiveFile findResourceExtension(Archive archive, String extensionType) {
ArchiveFile resourceRelationExtension = null;
Set<ArchiveFile> extensions = archive.getExtensions();
for (ArchiveFile extension : extensions) {
if (StringUtils.equals(extension.getRowType().qualifiedName(), extensionType)) {
resourceRelationExtension = extension;
break;
}
}
return resourceRelationExtension;
}
use of org.gbif.dwc.ArchiveFile in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method importDescriptionExtension.
private static void importDescriptionExtension(Archive archive, InteractionListener interactionListener, ImportLogger logger) {
ArchiveFile extension = findResourceExtension(archive, EXTENSION_DESCRIPTION);
if (extension != null) {
final BTreeMap<String, Map<String, String>> associationsMap = MapDBUtil.createBigMap();
try {
ArchiveFile core = archive.getCore();
importDescriptionExtension(interactionListener, logger, extension, core, associationsMap);
} finally {
if (associationsMap != null) {
associationsMap.close();
}
}
}
}
use of org.gbif.dwc.ArchiveFile in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method createReferenceEnricher.
private static InteractionListenerClosable createReferenceEnricher(Archive archive, final InteractionListener interactionListener) {
return new InteractionListenerClosable() {
private BTreeMap<String, Map<String, String>> referenceMap = null;
@Override
public void close() {
if (referenceMap != null) {
referenceMap.close();
referenceMap = null;
}
}
private void initIfNeeded() {
if (referenceMap == null) {
referenceMap = MapDBUtil.createBigMap();
ArchiveFile extension = findResourceExtension(archive, EXTENSION_REFERENCE);
if (extension != null) {
for (Record record : extension) {
Map<String, String> props = new TreeMap<>();
termsToMap(record, props);
props.put(REFERENCE_CITATION, CitationUtil.citationFor(props));
appendResourceType(props, extension.getRowType());
referenceMap.put(record.id(), props);
}
}
}
}
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
initIfNeeded();
String s = interaction.get(DWC_COREID);
Map<String, String> enrichedLink = contains(referenceMap, s) ? new TreeMap<String, String>(interaction) {
{
putAll(referenceMap.get(s));
}
} : interaction;
interactionListener.on(enrichedLink);
}
};
}
use of org.gbif.dwc.ArchiveFile in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method importResourceRelationshipExtension.
static void importResourceRelationshipExtension(Archive archive, InteractionListener interactionListener) {
ArchiveFile resourceExtension = findResourceRelationshipExtension(archive);
if (resourceExtension != null) {
final BTreeMap<String, Map<String, Map<String, String>>> termTypeIdPropertyMap = MapDBUtil.createBigMap();
final DB sourceIdDb = MapDBUtil.tmpDB();
final DB targetIdDb = MapDBUtil.tmpDB();
try {
importResourceRelationshipExtension(archive, interactionListener, resourceExtension, termTypeIdPropertyMap, sourceIdDb, targetIdDb);
} finally {
sourceIdDb.close();
targetIdDb.close();
if (termTypeIdPropertyMap != null) {
termTypeIdPropertyMap.close();
}
}
}
}
use of org.gbif.dwc.ArchiveFile in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCA method resolveLocalResourceIds.
private static void resolveLocalResourceIds(Archive archive, Map<String, Map<String, Map<String, String>>> termIdPropMap, Set<String> referencedSourceIds, Set<String> referencedTargetIds, List<DwcTerm> termTypes) {
List<ArchiveFile> archiveFiles = new ArrayList<>();
archiveFiles.add(archive.getCore());
ArchiveFile taxon = findResourceExtension(archive, EXTENSION_TAXON);
if (taxon != null) {
archiveFiles.add(taxon);
}
for (ArchiveFile archiveFile : archiveFiles) {
for (Record record : archiveFile) {
for (DwcTerm termType : termTypes) {
attemptLinkUsingTerm(termIdPropMap, referencedSourceIds, referencedTargetIds, record, termType);
}
}
}
}
Aggregations