Search in sources :

Example 6 with DatasetRegistryException

use of org.globalbioticinteractions.dataset.DatasetRegistryException in project eol-globi-data by jhpoelen.

the class CacheLocalReadonly method getContentProvenance.

public static ContentProvenance getContentProvenance(URI resourceURI, String cachePath, String namespace) {
    AtomicReference<ContentProvenance> meta = new AtomicReference<>(null);
    File accessFile;
    try {
        File cacheDirForNamespace = CacheUtil.findCacheDirForNamespace(cachePath, namespace);
        String hashCandidate = getHashCandidate(resourceURI, cacheDirForNamespace.toURI());
        accessFile = ProvenanceLog.findProvenanceLogFile(namespace, cachePath);
        if (accessFile.exists()) {
            try (InputStream is = new FileInputStream(accessFile)) {
                ProvenanceLog.parseProvenanceStream(is, new ProvenanceLog.ProvenanceEntryListener() {

                    @Override
                    public void onValues(String[] values) {
                        if (values.length > 3) {
                            URI sourceURI = URI.create(values[1]);
                            String sha256 = values[2];
                            String accessedAt = StringUtils.trim(values[3]);
                            if (StringUtils.isNotBlank(sha256)) {
                                ContentProvenance provenance = getProvenance(resourceURI, hashCandidate, sourceURI, sha256, accessedAt, cacheDirForNamespace, namespace);
                                if (provenance != null) {
                                    meta.set(provenance);
                                }
                            }
                        }
                    }
                });
            }
        }
    } catch (IOException | DatasetRegistryException e) {
        LOG.error("unexpected exception on getting meta for [" + resourceURI + "]", e);
    }
    return meta.get();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) URI(java.net.URI) FileInputStream(java.io.FileInputStream) DatasetRegistryException(org.globalbioticinteractions.dataset.DatasetRegistryException) File(java.io.File)

Example 7 with DatasetRegistryException

use of org.globalbioticinteractions.dataset.DatasetRegistryException in project eol-globi-data by jhpoelen.

the class DatasetImporterFactoryImplIT method defaultTSVImporterCached.

@Test
public void defaultTSVImporterCached() throws StudyImporterException, DatasetRegistryException, IOException {
    final DatasetRegistry datasetRegistry = new DatasetRegistryWithCache(new DatasetRegistryGitHubArchive(inStream -> inStream), dataset -> CacheUtil.cacheFor(dataset.getNamespace(), "target/datasets", inStream -> inStream));
    DatasetImporter importer = getTemplateImporter(datasetRegistry, "globalbioticinteractions/template-dataset");
    DatasetImporterForTSV importerTSV = (DatasetImporterForTSV) importer;
    assertThat(importerTSV.getBaseUrl(), startsWith("https://github.com/globalbioticinteractions/template-dataset/"));
    assertThat(importerTSV.getDataset().retrieve(URI.create("globi.json")), is(notNullValue()));
}
Also used : CacheUtil(org.globalbioticinteractions.cache.CacheUtil) DatasetImporterForGoMexSI2(org.eol.globi.data.DatasetImporterForGoMexSI2) DatasetRegistryGitHubRemote(org.globalbioticinteractions.dataset.DatasetRegistryGitHubRemote) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) DatasetImporterForHurlbert(org.eol.globi.data.DatasetImporterForHurlbert) DatasetConstant(org.globalbioticinteractions.dataset.DatasetConstant) DatasetImporterForMetaTable(org.eol.globi.data.DatasetImporterForMetaTable) DatasetImporterForHafner(org.eol.globi.data.DatasetImporterForHafner) DatasetImporterForSzoboszlai(org.eol.globi.data.DatasetImporterForSzoboszlai) StudyImporterException(org.eol.globi.data.StudyImporterException) BaseDatasetImporter(org.eol.globi.data.BaseDatasetImporter) Is.is(org.hamcrest.core.Is.is) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImporter(org.eol.globi.data.DatasetImporter) DatasetImporterForJSONLD(org.eol.globi.data.DatasetImporterForJSONLD) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) DatasetRegistry(org.globalbioticinteractions.dataset.DatasetRegistry) DatasetRegistryZenodo(org.globalbioticinteractions.dataset.DatasetRegistryZenodo) DatasetRegistryException(org.globalbioticinteractions.dataset.DatasetRegistryException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) IOException(java.io.IOException) DatasetImporterForCoetzer(org.eol.globi.data.DatasetImporterForCoetzer) DatasetRegistryGitHubArchive(org.globalbioticinteractions.dataset.DatasetRegistryGitHubArchive) DatasetImporterForPlanque(org.eol.globi.data.DatasetImporterForPlanque) DatasetImporterForTSV(org.eol.globi.data.DatasetImporterForTSV) DatasetFactory(org.globalbioticinteractions.dataset.DatasetFactory) Dataset(org.globalbioticinteractions.dataset.Dataset) DatasetImporterForRSS(org.eol.globi.data.DatasetImporterForRSS) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) DatasetImporterForWood(org.eol.globi.data.DatasetImporterForWood) DatasetRegistryWithCache(org.globalbioticinteractions.dataset.DatasetRegistryWithCache) Matchers.containsString(org.hamcrest.Matchers.containsString) InputStream(java.io.InputStream) DatasetImporterForTSV(org.eol.globi.data.DatasetImporterForTSV) DatasetRegistry(org.globalbioticinteractions.dataset.DatasetRegistry) DatasetRegistryWithCache(org.globalbioticinteractions.dataset.DatasetRegistryWithCache) BaseDatasetImporter(org.eol.globi.data.BaseDatasetImporter) DatasetImporter(org.eol.globi.data.DatasetImporter) DatasetRegistryGitHubArchive(org.globalbioticinteractions.dataset.DatasetRegistryGitHubArchive) Test(org.junit.Test)

Example 8 with DatasetRegistryException

use of org.globalbioticinteractions.dataset.DatasetRegistryException in project eol-globi-data by jhpoelen.

the class DatasetImporterForRegistry method importData.

private void importData(String namespace) throws StudyImporterException {
    try {
        LOG.info("[" + namespace + "] checking status...");
        Dataset dataset = new DatasetFactory(getRegistry()).datasetFor(namespace);
        if (datasetFilter.test(dataset)) {
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();
            LOG.info("[" + namespace + "] is active, importing...");
            getNodeFactory().getOrCreateDataset(dataset);
            importData(dataset);
            stopWatch.stop();
            LOG.info("[" + namespace + "] imported in " + stopWatch.getTime(TimeUnit.SECONDS) + "s");
        } else {
            LOG.info("[" + namespace + "] is deprecated, not importing.");
        }
    } catch (StudyImporterException | DatasetRegistryException ex) {
        String msg = "failed to import data from repo [" + namespace + "]";
        LOG.error(msg, ex);
        throw new StudyImporterException(msg, ex);
    }
}
Also used : DatasetRegistryException(org.globalbioticinteractions.dataset.DatasetRegistryException) Dataset(org.globalbioticinteractions.dataset.Dataset) DatasetFactory(org.globalbioticinteractions.dataset.DatasetFactory) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

DatasetRegistryException (org.globalbioticinteractions.dataset.DatasetRegistryException)8 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 URI (java.net.URI)5 Dataset (org.globalbioticinteractions.dataset.Dataset)5 DatasetRegistry (org.globalbioticinteractions.dataset.DatasetRegistry)5 StudyImporterException (org.eol.globi.data.StudyImporterException)4 DatasetFactory (org.globalbioticinteractions.dataset.DatasetFactory)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 BaseDatasetImporter (org.eol.globi.data.BaseDatasetImporter)3 DatasetImporter (org.eol.globi.data.DatasetImporter)3 DatasetImporterForCoetzer (org.eol.globi.data.DatasetImporterForCoetzer)3 DatasetImporterForGoMexSI2 (org.eol.globi.data.DatasetImporterForGoMexSI2)3 DatasetImporterForHafner (org.eol.globi.data.DatasetImporterForHafner)3 DatasetImporterForHurlbert (org.eol.globi.data.DatasetImporterForHurlbert)3 DatasetImporterForJSONLD (org.eol.globi.data.DatasetImporterForJSONLD)3 DatasetImporterForMetaTable (org.eol.globi.data.DatasetImporterForMetaTable)3 DatasetImporterForPlanque (org.eol.globi.data.DatasetImporterForPlanque)3 DatasetImporterForRSS (org.eol.globi.data.DatasetImporterForRSS)3 DatasetImporterForSzoboszlai (org.eol.globi.data.DatasetImporterForSzoboszlai)3