Search in sources :

Example 1 with ArchiveFile

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;
}
Also used : ArchiveFile(org.gbif.dwc.ArchiveFile)

Example 2 with ArchiveFile

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();
            }
        }
    }
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) BTreeMap(org.mapdb.BTreeMap) TreeMap(java.util.TreeMap) ArchiveFile(org.gbif.dwc.ArchiveFile)

Example 3 with ArchiveFile

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);
        }
    };
}
Also used : BTreeMap(org.mapdb.BTreeMap) InteractionListenerClosable(org.eol.globi.process.InteractionListenerClosable) Record(org.gbif.dwc.record.Record) BTreeMap(org.mapdb.BTreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) BTreeMap(org.mapdb.BTreeMap) TreeMap(java.util.TreeMap) ArchiveFile(org.gbif.dwc.ArchiveFile)

Example 4 with ArchiveFile

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();
            }
        }
    }
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) BTreeMap(org.mapdb.BTreeMap) TreeMap(java.util.TreeMap) DB(org.mapdb.DB) ArchiveFile(org.gbif.dwc.ArchiveFile)

Example 5 with ArchiveFile

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);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Record(org.gbif.dwc.record.Record) ArchiveFile(org.gbif.dwc.ArchiveFile) DwcTerm(org.gbif.dwc.terms.DwcTerm)

Aggregations

ArchiveFile (org.gbif.dwc.ArchiveFile)7 HashMap (java.util.HashMap)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)5 BTreeMap (org.mapdb.BTreeMap)5 ArrayList (java.util.ArrayList)2 Record (org.gbif.dwc.record.Record)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1