Search in sources :

Example 31 with Dataset

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

the class DatasetImporterForTSVTest method importFewLines.

@Test
public void importFewLines() throws StudyImporterException {
    Dataset dataset = getDataset(new TreeMap<URI, String>() {

        {
            put(URI.create("/interactions.tsv"), firstFewLinesTSV);
        }
    });
    DatasetImporterForTSV importer = new DatasetImporterForTSV(null, nodeFactory);
    importer.setDataset(dataset);
    importStudy(importer);
    assertExists("Leptoconchus incycloseris");
    assertExists("Sandalolitha dentata");
    assertStudyTitles("someRepodoi:10.1007/s13127-011-0039-1");
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) URI(java.net.URI) Test(org.junit.Test)

Example 32 with Dataset

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

the class DatasetImporterForTSVTest method importFewLinesTSV.

@Test
public void importFewLinesTSV() throws StudyImporterException {
    Dataset dataset = getDataset(new TreeMap<URI, String>() {

        {
            put(URI.create("/interactions.tsv"), firstFewLinesTSV);
        }
    });
    DatasetImporterForTSV importer = new DatasetImporterForTSV(null, nodeFactory);
    importer.setDataset(dataset);
    importStudy(importer);
    assertExists("Leptoconchus incycloseris");
    assertExists("Sandalolitha dentata");
    assertStudyTitles("someRepodoi:10.1007/s13127-011-0039-1");
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) URI(java.net.URI) Test(org.junit.Test)

Example 33 with Dataset

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

the class DatasetImporterForINaturalistTest method setup.

@Before
public void setup() throws DatasetRegistryException {
    Dataset dataset = datasetFor("globalbioticinteractions/inaturalist");
    ParserFactory parserFactory = new ParserFactoryForDataset(dataset);
    importer = new DatasetImporterForINaturalist(parserFactory, nodeFactory);
    importer.setDataset(dataset);
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) Before(org.junit.Before)

Example 34 with Dataset

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

the class NodeFactoryFactoryTransactingOnDatasetNeo4j3 method create.

@Override
public NodeFactory create(GraphDatabaseService service) {
    GraphDatabaseService graphService = graphServiceFactory.getGraphService();
    try (Transaction tx = graphService.beginTx()) {
        NodeFactory nodeFactory = new NodeFactoryNeo4j3(graphService) {

            final AtomicReference<Transaction> tx = new AtomicReference<>();

            final AtomicBoolean closing = new AtomicBoolean(false);

            @Override
            public Dataset getOrCreateDataset(Dataset dataset) {
                if (closing.get()) {
                    throw new IllegalStateException("cannot create a dataset on closing node factory");
                } else {
                    Transaction transaction = tx.get();
                    if (transaction != null) {
                        transaction.success();
                        transaction.close();
                    }
                    tx.set(graphServiceFactory.getGraphService().beginTx());
                }
                return super.getOrCreateDataset(dataset);
            }

            @Override
            public void close() {
                closing.set(true);
                Transaction lastTx = tx.getAndSet(null);
                if (lastTx != null) {
                    lastTx.success();
                    lastTx.close();
                }
            }
        };
        tx.success();
        return nodeFactory;
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.neo4j.graphdb.Transaction) NodeFactory(org.eol.globi.data.NodeFactory) Dataset(org.globalbioticinteractions.dataset.Dataset) AtomicReference(java.util.concurrent.atomic.AtomicReference) NodeFactoryNeo4j3(org.eol.globi.data.NodeFactoryNeo4j3)

Example 35 with Dataset

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

the class DatasetImporterForHurlbertTest method doImport.

public DatasetImporter doImport(final String namespace) throws StudyImporterException {
    DatasetImporter importer = new DatasetImporterForHurlbert(null, nodeFactory);
    Dataset dataset = new DatasetImpl(namespace, URI.create("some:uri"), inStream -> inStream) {

        @Override
        public InputStream retrieve(URI name) {
            return DatasetImporterForHurlbertTest.getResource();
        }
    };
    importer.setDataset(dataset);
    importStudy(importer);
    return importer;
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) URI(java.net.URI)

Aggregations

Dataset (org.globalbioticinteractions.dataset.Dataset)68 Test (org.junit.Test)46 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)25 URI (java.net.URI)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)17 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 Matchers.containsString (org.hamcrest.Matchers.containsString)14 IOException (java.io.IOException)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)10 InputStream (java.io.InputStream)9 Is.is (org.hamcrest.core.Is.is)9 StudyNode (org.eol.globi.domain.StudyNode)8 Node (org.neo4j.graphdb.Node)8 URL (java.net.URL)7 ArrayList (java.util.ArrayList)7 StringStartsWith.startsWith (org.hamcrest.core.StringStartsWith.startsWith)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 BaseDatasetImporter (org.eol.globi.data.BaseDatasetImporter)6 DatasetImporter (org.eol.globi.data.DatasetImporter)6 DatasetNode (org.eol.globi.domain.DatasetNode)6