Search in sources :

Example 1 with DatasetFinder

use of org.eol.globi.service.DatasetFinder in project eol-globi-data by jhpoelen.

the class DatasetFinderLocal method datasetFor.

@Override
public Dataset datasetFor(String namespace) throws DatasetFinderException {
    Dataset dataset;
    try {
        final URI sourceURI = findLastCachedDatasetURI(namespace);
        dataset = sourceURI == null ? null : DatasetFactory.datasetFor(namespace, new DatasetFinder() {

            @Override
            public Collection<String> findNamespaces() throws DatasetFinderException {
                return Collections.singletonList(namespace);
            }

            @Override
            public Dataset datasetFor(String s) throws DatasetFinderException {
                Dataset dataset = new DatasetImpl(namespace, sourceURI);
                return new DatasetWithCache(dataset, cacheFactory.cacheFor(dataset));
            }
        });
    } catch (IOException e) {
        throw new DatasetFinderException("failed to access [" + namespace + "]", e);
    }
    if (dataset == null) {
        throw new DatasetFinderException("failed to retrieve/cache dataset in namespace [" + namespace + "]");
    }
    return dataset;
}
Also used : Dataset(org.eol.globi.service.Dataset) DatasetFinder(org.eol.globi.service.DatasetFinder) Collection(java.util.Collection) DatasetImpl(org.eol.globi.service.DatasetImpl) IOException(java.io.IOException) DatasetFinderException(org.eol.globi.service.DatasetFinderException) URI(java.net.URI)

Example 2 with DatasetFinder

use of org.eol.globi.service.DatasetFinder in project eol-globi-data by jhpoelen.

the class DatasetFinderWithCacheIT method hafnerTest.

@Test
public void hafnerTest() throws DatasetFinderException, IOException {
    DatasetFinder finder = new DatasetFinderWithCache(new DatasetFinderGitHubArchive(), cachePath);
    Dataset dataset = DatasetFactory.datasetFor("globalbioticinteractions/hafner", finder);
    assertNotNull(dataset.getResource("hafner/gopher_lice_int.csv"));
}
Also used : DatasetFinder(org.eol.globi.service.DatasetFinder) Dataset(org.eol.globi.service.Dataset) DatasetFinderGitHubArchive(org.eol.globi.service.DatasetFinderGitHubArchive) Test(org.junit.Test)

Example 3 with DatasetFinder

use of org.eol.globi.service.DatasetFinder in project eol-globi-data by jhpoelen.

the class DatasetFinderWithCacheIT method gitHubTest.

@Test
public void gitHubTest() throws DatasetFinderException {
    DatasetFinder finder = new DatasetFinderWithCache(new DatasetFinderGitHubArchive(), cachePath);
    Dataset dataset = DatasetFactory.datasetFor("globalbioticinteractions/Catalogue-of-Afrotropical-Bees", finder);
    assertThat(dataset.getArchiveURI().toString(), containsString("github.com"));
    assertThat(dataset.getResourceURI("globi.json").toString(), startsWith("jar:file:/"));
    assertThat(dataset.getCitation(), startsWith("Shan Kothari, Pers. Comm. 2014."));
}
Also used : DatasetFinder(org.eol.globi.service.DatasetFinder) Dataset(org.eol.globi.service.Dataset) DatasetFinderGitHubArchive(org.eol.globi.service.DatasetFinderGitHubArchive) Test(org.junit.Test)

Example 4 with DatasetFinder

use of org.eol.globi.service.DatasetFinder in project eol-globi-data by jhpoelen.

the class DatasetFinderWithCacheIT method assertTemplateDataset.

private void assertTemplateDataset(String expectedURIFragment, DatasetFinder datasetFinder, String expectedCitation) throws DatasetFinderException, IOException {
    DatasetFinder finder = new DatasetFinderWithCache(datasetFinder, cachePath);
    Dataset dataset = DatasetFactory.datasetFor("globalbioticinteractions/template-dataset", finder);
    assertThat(dataset.getArchiveURI().toString(), containsString(expectedURIFragment));
    assertThat(dataset.getResourceURI("globi.json").toString(), startsWith("jar:file:/"));
    assertThat(dataset.getCitation(), startsWith(expectedCitation));
}
Also used : DatasetFinder(org.eol.globi.service.DatasetFinder) Dataset(org.eol.globi.service.Dataset)

Example 5 with DatasetFinder

use of org.eol.globi.service.DatasetFinder in project eol-globi-data by jhpoelen.

the class Normalizer method importData.

void importData(GraphDatabaseService graphService, String cacheDir) {
    NodeFactoryNeo4j factory = new NodeFactoryNeo4j(graphService);
    factory.setEcoregionFinder(getEcoregionFinder());
    factory.setDoiResolver(new DOIResolverImpl());
    try {
        CacheFactory cacheFactory = dataset -> new CacheLocalReadonly(dataset.getNamespace(), cacheDir);
        DatasetFinder finder = new DatasetFinderLocal(cacheDir, cacheFactory);
        StudyImporter importer = new StudyImporterForGitHubData(new ParserFactoryLocal(), factory, finder);
        importer.setDataset(new DatasetLocal());
        importer.setLogger(new StudyImportLogger());
        importer.importStudy();
    } catch (StudyImporterException e) {
        LOG.error("problem encountered while importing [" + StudyImporterForGitHubData.class.getName() + "]", e);
    }
    EcoregionFinder regionFinder = getEcoregionFinder();
    if (regionFinder != null) {
        regionFinder.shutdown();
    }
}
Also used : OpenTreeTaxonIndex(org.eol.globi.opentree.OpenTreeTaxonIndex) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) EcoregionFinder(org.eol.globi.geo.EcoregionFinder) DatasetFinderLocal(org.globalbioticinteractions.dataset.DatasetFinderLocal) URISyntaxException(java.net.URISyntaxException) Options(org.apache.commons.cli.Options) TaxonCacheService(org.eol.globi.taxon.TaxonCacheService) DOIResolverCache(org.eol.globi.service.DOIResolverCache) ResolvingTaxonIndex(org.eol.globi.taxon.ResolvingTaxonIndex) HelpFormatter(org.apache.commons.cli.HelpFormatter) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) StudyImporterException(org.eol.globi.data.StudyImporterException) EcoregionFinderProxy(org.eol.globi.service.EcoregionFinderProxy) ParserFactoryLocal(org.eol.globi.data.ParserFactoryLocal) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) GraphService(org.eol.globi.db.GraphService) URI(java.net.URI) EcoregionFinderFactoryImpl(org.eol.globi.geo.EcoregionFinderFactoryImpl) HttpUtil(org.eol.globi.util.HttpUtil) Option(org.apache.commons.cli.Option) Taxon(org.eol.globi.domain.Taxon) CommandLineParser(org.apache.commons.cli.CommandLineParser) MalformedURLException(java.net.MalformedURLException) CacheLocalReadonly(org.globalbioticinteractions.cache.CacheLocalReadonly) DatasetFinder(org.eol.globi.service.DatasetFinder) DatasetLocal(org.eol.globi.service.DatasetLocal) StudyImporterForGitHubData(org.eol.globi.data.StudyImporterForGitHubData) DOIResolverImpl(org.eol.globi.service.DOIResolverImpl) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) List(java.util.List) StudyImporter(org.eol.globi.data.StudyImporter) ParseException(org.apache.commons.cli.ParseException) GraphExporterImpl(org.eol.globi.export.GraphExporterImpl) Version(org.eol.globi.Version) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) CacheFactory(org.globalbioticinteractions.cache.CacheFactory) EcoregionFinder(org.eol.globi.geo.EcoregionFinder) StudyImporterForGitHubData(org.eol.globi.data.StudyImporterForGitHubData) DOIResolverImpl(org.eol.globi.service.DOIResolverImpl) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) DatasetLocal(org.eol.globi.service.DatasetLocal) StudyImporter(org.eol.globi.data.StudyImporter) CacheLocalReadonly(org.globalbioticinteractions.cache.CacheLocalReadonly) StudyImporterException(org.eol.globi.data.StudyImporterException) DatasetFinder(org.eol.globi.service.DatasetFinder) CacheFactory(org.globalbioticinteractions.cache.CacheFactory) DatasetFinderLocal(org.globalbioticinteractions.dataset.DatasetFinderLocal) ParserFactoryLocal(org.eol.globi.data.ParserFactoryLocal)

Aggregations

DatasetFinder (org.eol.globi.service.DatasetFinder)5 Dataset (org.eol.globi.service.Dataset)4 URI (java.net.URI)2 DatasetFinderGitHubArchive (org.eol.globi.service.DatasetFinderGitHubArchive)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 BasicParser (org.apache.commons.cli.BasicParser)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Option (org.apache.commons.cli.Option)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1