Search in sources :

Example 1 with DatasetImpl

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

the class StudyImporterForGrayTest method createImporter.

private StudyImporterForGray createImporter() throws IOException {
    StudyImporterForGray gray = new StudyImporterForGray(new ParserFactoryLocal(), nodeFactory);
    JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Gray C, Ma A, Perkins D, Hudson L, Figueroa D, Woodward G (2015). Database of trophic interactions. Zenodo. http://dx.doi.org/10.5281/zenodo.13751\",\n" + "  \"doi\": \"http://dx.doi.org/10.5281/zenodo.13751\",\n" + "  \"format\": \"gray\",\n" + "  \"resources\": {\n" + "    \"links\": \"https://zenodo.org/record/13751/files/trophic.links.2014-11-10.csv\"  \n" + "  }\n" + "}");
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"));
    dataset.setConfig(config);
    gray.setDataset(dataset);
    return gray;
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with DatasetImpl

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

the class DatasetWithCacheTest method datasetLastAccessedAt.

private DatasetWithCache datasetLastAccessedAt(String lastAccessed) {
    Cache cache = Mockito.mock(Cache.class);
    CachedURI cacheURI = Mockito.mock(CachedURI.class);
    when(cacheURI.getAccessedAt()).thenReturn(lastAccessed);
    when(cache.asMeta(any(URI.class))).thenReturn(cacheURI);
    DatasetImpl datasetUncached = new DatasetImpl("some/namespace", URI.create("some:bla"));
    return new DatasetWithCache(datasetUncached, cache);
}
Also used : CachedURI(org.globalbioticinteractions.cache.CachedURI) DatasetImpl(org.eol.globi.service.DatasetImpl) CachedURI(org.globalbioticinteractions.cache.CachedURI) URI(java.net.URI) Cache(org.globalbioticinteractions.cache.Cache)

Example 3 with DatasetImpl

use of org.eol.globi.service.DatasetImpl 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 4 with DatasetImpl

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

the class NodeFactoryWithDatasetContextTest method getOrCreateStudy.

@Test
public void getOrCreateStudy() throws NodeFactoryException {
    NodeFactory factory = Mockito.mock(NodeFactory.class);
    Dataset dataset = new DatasetImpl("some/namespace", URI.create("some:uri"));
    NodeFactoryWithDatasetContext factoryWithDS = new NodeFactoryWithDatasetContext(factory, dataset);
    factoryWithDS.getOrCreateStudy(new StudyImpl("some title"));
    ArgumentCaptor<Study> argument = ArgumentCaptor.forClass(Study.class);
    verify(factory).getOrCreateStudy(argument.capture());
    assertEquals("globi:some/namespace", argument.getValue().getSourceId());
    assertEquals("some title", argument.getValue().getTitle());
}
Also used : Study(org.eol.globi.domain.Study) Dataset(org.eol.globi.service.Dataset) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.eol.globi.service.DatasetImpl) Test(org.junit.Test)

Example 5 with DatasetImpl

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

the class ReferenceUtilTest method generateSourceCitation.

@Test
public void generateSourceCitation() throws IOException, StudyImporterException {
    final InputStream inputStream = getClass().getResourceAsStream("/org/eol/globi/data/test-meta-globi.json");
    DatasetImpl dataset = new DatasetImpl(null, URI.create("http://base"));
    dataset.setConfig(new ObjectMapper().readTree(inputStream));
    String citation = CitationUtil.sourceCitationLastAccessed(dataset);
    assertThat(citation, startsWith("Seltzer, Carrie; Wysocki, William; Palacios, Melissa; Eickhoff, Anna; Pilla, Hannah; Aungst, Jordan; Mercer, Aaron; Quicho, Jamie; Voss, Neil; Xu, Man; J. Ndangalasi, Henry; C. Lovett, Jon; J. Cordeiro, Norbert (2015): Plant-animal interactions from Africa. figshare. https://dx.doi.org/10.6084/m9.figshare.1526128. Accessed at <https://ndownloader.figshare.com/files/2231424>"));
}
Also used : InputStream(java.io.InputStream) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

DatasetImpl (org.eol.globi.service.DatasetImpl)45 Test (org.junit.Test)31 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)24 JsonNode (org.codehaus.jackson.JsonNode)16 Study (org.eol.globi.domain.Study)13 Relationship (org.neo4j.graphdb.Relationship)9 ArrayList (java.util.ArrayList)6 ObjectNode (org.codehaus.jackson.node.ObjectNode)6 StudyImpl (org.eol.globi.domain.StudyImpl)6 Dataset (org.eol.globi.service.Dataset)6 Node (org.neo4j.graphdb.Node)5 InputStream (java.io.InputStream)4 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)4 NodeFactoryWithDatasetContext (org.eol.globi.data.NodeFactoryWithDatasetContext)3 LogContext (org.eol.globi.domain.LogContext)3 Specimen (org.eol.globi.domain.Specimen)3 Taxon (org.eol.globi.domain.Taxon)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 URI (java.net.URI)2