Search in sources :

Example 1 with DatasetRegistryException

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

the class DatasetImporterFactoryImplIT method jsonldImporterCached.

@Test
public void jsonldImporterCached() throws StudyImporterException, DatasetRegistryException {
    final DatasetRegistry datasetRegistry = new DatasetRegistryWithCache(new DatasetRegistryGitHubArchive(inStream -> inStream), dataset -> CacheUtil.cacheFor(dataset.getNamespace(), "target/datasets", inStream -> inStream));
    Dataset dataset = new DatasetFactory(datasetRegistry).datasetFor("globalbioticinteractions/jsonld-template-dataset");
    DatasetImporter importer = new StudyImporterFactoryImpl(null).createImporter(dataset);
    assertThat(importer, is(notNullValue()));
    assertThat(importer, is(instanceOf(DatasetImporterForJSONLD.class)));
}
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) Dataset(org.globalbioticinteractions.dataset.Dataset) DatasetRegistry(org.globalbioticinteractions.dataset.DatasetRegistry) DatasetRegistryWithCache(org.globalbioticinteractions.dataset.DatasetRegistryWithCache) BaseDatasetImporter(org.eol.globi.data.BaseDatasetImporter) DatasetImporter(org.eol.globi.data.DatasetImporter) DatasetFactory(org.globalbioticinteractions.dataset.DatasetFactory) DatasetRegistryGitHubArchive(org.globalbioticinteractions.dataset.DatasetRegistryGitHubArchive) Test(org.junit.Test)

Example 2 with DatasetRegistryException

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

the class DatasetImporterFactoryImplIT method defaultTSVImporterCachedZenodo.

@Test
public void defaultTSVImporterCachedZenodo() throws StudyImporterException, DatasetRegistryException {
    final DatasetRegistry datasetRegistry = new DatasetRegistryWithCache(new DatasetRegistryZenodo(inStream -> inStream), dataset -> CacheUtil.cacheFor(dataset.getNamespace(), "target/datasets", inStream -> inStream));
    DatasetImporter importer = getTemplateImporter(datasetRegistry, "globalbioticinteractions/template-dataset");
    DatasetImporterForTSV importerTSV = (DatasetImporterForTSV) importer;
    assertThat(importerTSV.getSourceCitation(), containsString("doi.org"));
}
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) DatasetRegistryZenodo(org.globalbioticinteractions.dataset.DatasetRegistryZenodo) DatasetRegistry(org.globalbioticinteractions.dataset.DatasetRegistry) DatasetRegistryWithCache(org.globalbioticinteractions.dataset.DatasetRegistryWithCache) BaseDatasetImporter(org.eol.globi.data.BaseDatasetImporter) DatasetImporter(org.eol.globi.data.DatasetImporter) Test(org.junit.Test)

Example 3 with DatasetRegistryException

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

the class DatasetImporterForRegistryTest method filteredDatasets.

@Test
public void filteredDatasets() throws StudyImporterException {
    DatasetImporterForRegistry importer = new DatasetImporterForRegistry(null, null, new DatasetRegistry() {

        @Override
        public Collection<String> findNamespaces() throws DatasetRegistryException {
            return Collections.singletonList("some/namespace");
        }

        @Override
        public Dataset datasetFor(String namespace) throws DatasetRegistryException {
            DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), in -> in) {

                @Override
                public InputStream retrieve(URI resource) throws IOException {
                    if (!StringUtils.endsWith(resource.toString(), "globi.json")) {
                        throw new IOException();
                    }
                    return IOUtils.toInputStream("{\"some\":\"thing\"}", StandardCharsets.UTF_8);
                }
            };
            return dataset;
        }
    });
    importer.setDatasetFilter(x -> false);
    importer.importStudy();
}
Also used : DatasetRegistryException(org.globalbioticinteractions.dataset.DatasetRegistryException) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Collection(java.util.Collection) Test(org.junit.Test) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) StandardCharsets(java.nio.charset.StandardCharsets) Is(org.hamcrest.core.Is) IOUtils(org.apache.commons.io.IOUtils) Dataset(org.globalbioticinteractions.dataset.Dataset) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections(java.util.Collections) DatasetRegistry(org.globalbioticinteractions.dataset.DatasetRegistry) InputStream(java.io.InputStream) DatasetRegistryException(org.globalbioticinteractions.dataset.DatasetRegistryException) Dataset(org.globalbioticinteractions.dataset.Dataset) InputStream(java.io.InputStream) Collection(java.util.Collection) DatasetRegistry(org.globalbioticinteractions.dataset.DatasetRegistry) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Example 4 with DatasetRegistryException

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

the class ProvenanceLog method parseProvenanceStream.

public static void parseProvenanceStream(InputStream is, ProvenanceEntryListener listener) throws DatasetRegistryException {
    try (InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
        BufferedReader bufferedReader = IOUtils.toBufferedReader(reader);
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            listener.onValues(CSVTSVUtil.splitTSV(line));
        }
    } catch (IOException e) {
        throw new DatasetRegistryException("failed to read ", e);
    }
}
Also used : DatasetRegistryException(org.globalbioticinteractions.dataset.DatasetRegistryException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 5 with DatasetRegistryException

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

the class IndexerDataset method indexDatasets.

private static void indexDatasets(DatasetRegistry registry, NodeFactory nodeFactory) {
    try {
        final Collection<String> namespaces = registry.findNamespaces();
        String namespacelist = StringUtils.join(namespaces, CharsetConstant.SEPARATOR);
        LOG.info("found dataset namespaces: {" + namespacelist + "}");
        DatasetImporterForRegistry importer = new DatasetImporterForRegistry(new ParserFactoryLocal(), nodeFactory, registry);
        importer.setDatasetFilter(x -> !DatasetUtil.isDeprecated(x));
        importer.setDataset(new DatasetLocal(inStream -> inStream));
        importer.setLogger(new NullImportLogger());
        importer.importStudy();
    } catch (DatasetRegistryException | StudyImporterException e) {
        LOG.error("problem encountered while importing [" + DatasetImporterForRegistry.class.getName() + "]", e);
    }
}
Also used : DatasetRegistryException(org.globalbioticinteractions.dataset.DatasetRegistryException) Logger(org.slf4j.Logger) Collection(java.util.Collection) NodeFactory(org.eol.globi.data.NodeFactory) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) DatasetLocal(org.eol.globi.service.DatasetLocal) StudyImporterException(org.eol.globi.data.StudyImporterException) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ParserFactoryLocal(org.eol.globi.data.ParserFactoryLocal) GraphServiceFactory(org.eol.globi.db.GraphServiceFactory) DatasetImporterForRegistry(org.eol.globi.data.DatasetImporterForRegistry) DatasetUtil(org.globalbioticinteractions.dataset.DatasetUtil) Transaction(org.neo4j.graphdb.Transaction) CharsetConstant(org.eol.globi.data.CharsetConstant) DatasetRegistry(org.globalbioticinteractions.dataset.DatasetRegistry) DatasetImporterForRegistry(org.eol.globi.data.DatasetImporterForRegistry) DatasetRegistryException(org.globalbioticinteractions.dataset.DatasetRegistryException) StudyImporterException(org.eol.globi.data.StudyImporterException) ParserFactoryLocal(org.eol.globi.data.ParserFactoryLocal) DatasetLocal(org.eol.globi.service.DatasetLocal)

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