Search in sources :

Example 1 with Dataset

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

the class StudyImporterForMetaTable method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    try {
        for (JsonNode tableConfig : collectTables(dataset)) {
            Dataset datasetProxy = new DatasetProxy(dataset);
            datasetProxy.setConfig(tableConfig);
            InteractionListenerImpl interactionListener = new InteractionListenerImpl(nodeFactory, getGeoNamesService(), getLogger());
            final InteractionListener listener = new TableInteractionListenerProxy(datasetProxy, interactionListener);
            importTable(listener, new TableParserFactoryImpl(), tableConfig, datasetProxy, getLogger());
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException("problem importing from [" + getBaseUrl() + "]", e);
    }
}
Also used : Dataset(org.eol.globi.service.Dataset) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) DatasetProxy(org.eol.globi.service.DatasetProxy)

Example 2 with Dataset

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

the class DatasetFinderWithCacheTest method cacheDatasetLocal.

@Test
public void cacheDatasetLocal() throws DatasetFinderException, IOException, URISyntaxException {
    Dataset datasetCached = datasetCached();
    assertNotNull(datasetCached.getArchiveURI());
    URI uri = datasetCached.getResourceURI("globi.json");
    assertThat(uri.isAbsolute(), is(true));
    assertThat(uri.toString(), startsWith("jar:file:"));
    InputStream is = datasetCached.getResource("globi.json");
    assertNotNull(is);
    JsonNode jsonNode = new ObjectMapper().readTree(is);
    assertThat(jsonNode.has("citation"), is(true));
    String[] list = new File(cachePath + "/some/namespace").list();
    assertThat(list.length, is(2));
    assertThat(Arrays.asList(list), hasItem("c9ecb3b0100c890bd00a5c201d06f0a78d92488591f726fbf4de5c88bda39147"));
    assertThat(Arrays.asList(list), hasItem("access.tsv"));
}
Also used : Dataset(org.eol.globi.service.Dataset) InputStream(java.io.InputStream) JsonNode(org.codehaus.jackson.JsonNode) URI(java.net.URI) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 3 with Dataset

use of org.eol.globi.service.Dataset 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 Dataset

use of org.eol.globi.service.Dataset 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 Dataset

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

the class StudyImporterForArthopodEasyCaptureTest method embeddedDataset.

@Test
public void embeddedDataset() throws IOException {
    Dataset embeddedDataset = StudyImporterForArthopodEasyCapture.embeddedDatasetFor(getDatasetGroup(), "some other citation", URI.create("http://example.com/archive.zip"));
    assertThat(embeddedDataset.getCitation(), is("some other citation"));
    assertThat(embeddedDataset.getOrDefault(DatasetConstant.SHOULD_RESOLVE_REFERENCES, "foo"), is("foo"));
    assertThat(DatasetUtil.getNamedResourceURI(embeddedDataset, "archive"), is("http://example.com/archive.zip"));
}
Also used : Dataset(org.eol.globi.service.Dataset) Test(org.junit.Test)

Aggregations

Dataset (org.eol.globi.service.Dataset)31 Test (org.junit.Test)16 JsonNode (org.codehaus.jackson.JsonNode)11 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 DatasetImpl (org.eol.globi.service.DatasetImpl)9 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 URI (java.net.URI)5 URL (java.net.URL)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 DatasetFinder (org.eol.globi.service.DatasetFinder)4 Is.is (org.hamcrest.core.Is.is)4 Assert.assertNotNull (org.junit.Assert.assertNotNull)4 Assert.assertThat (org.junit.Assert.assertThat)4 CSVParser (com.Ostermiller.util.CSVParser)3 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)3 Map (java.util.Map)3 Assert (junit.framework.Assert)3 IOUtils (org.apache.commons.io.IOUtils)3