Search in sources :

Example 21 with Dataset

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

the class NodeFactoryNeo4j method createStudy.

@Override
public StudyNode createStudy(Study study) {
    Transaction transaction = graphDb.beginTx();
    StudyNode studyNode;
    try {
        Node node = graphDb.createNode();
        studyNode = new StudyNode(node, study.getTitle());
        studyNode.setSource(study.getSource());
        studyNode.setCitation(study.getCitation());
        studyNode.setDOI(study.getDOI());
        if (StringUtils.isBlank(study.getExternalId()) && StringUtils.isNotBlank(study.getDOI())) {
            studyNode.setExternalId(ExternalIdUtil.urlForExternalId(study.getDOI()));
        } else {
            studyNode.setExternalId(study.getExternalId());
        }
        studyNode.setSourceId(study.getSourceId());
        Dataset dataset = getOrCreateDatasetNoTx(study.getOriginatingDataset());
        if (dataset != null && dataset instanceof DatasetNode) {
            studyNode.createRelationshipTo(dataset, RelTypes.IN_DATASET);
        }
        studies.add(node, StudyConstant.TITLE, study.getTitle());
        studies.add(node, StudyConstant.TITLE_IN_NAMESPACE, getTitleInNamespace(study));
        transaction.success();
    } finally {
        transaction.finish();
    }
    return studyNode;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Dataset(org.eol.globi.service.Dataset) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node)

Example 22 with Dataset

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

the class NodeFactoryNeo4j method getOrCreateDatasetNoTx.

private Dataset getOrCreateDatasetNoTx(Dataset originatingDataset) {
    Dataset datasetCreated = null;
    if (originatingDataset != null && StringUtils.isNotBlank(originatingDataset.getNamespace())) {
        IndexHits<Node> datasetHits = datasets.get(DatasetConstant.NAMESPACE, originatingDataset.getNamespace());
        Node datasetNode = datasetHits.hasNext() ? datasetHits.next() : createDatasetNode(originatingDataset);
        datasetCreated = new DatasetNode(datasetNode);
    }
    return datasetCreated;
}
Also used : Dataset(org.eol.globi.service.Dataset) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node)

Example 23 with Dataset

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

the class NodeFactoryNeo4j method createInteraction.

@Override
public Interaction createInteraction(Study study) throws NodeFactoryException {
    Transaction transaction = graphDb.beginTx();
    InteractionNode interactionNode;
    try {
        Node node = graphDb.createNode();
        StudyNode studyNode = getOrCreateStudy(study);
        interactionNode = new InteractionNode(node);
        interactionNode.createRelationshipTo(studyNode, RelTypes.DERIVED_FROM);
        Dataset dataset = getOrCreateDatasetNoTx(study.getOriginatingDataset());
        if (dataset != null && dataset instanceof DatasetNode) {
            interactionNode.createRelationshipTo(dataset, RelTypes.ACCESSED_AT);
        }
        transaction.success();
    } finally {
        transaction.finish();
    }
    return interactionNode;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Dataset(org.eol.globi.service.Dataset) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node)

Example 24 with Dataset

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

the class DatasetFinderLocalTest method init.

@Before
public void init() throws URISyntaxException {
    URL accessFile = getClass().getResource("/test-cache/globalbioticinteractions/template-dataset/access.tsv");
    assertNotNull(accessFile);
    File cacheDir = new File(accessFile.toURI()).getParentFile().getParentFile().getParentFile();
    datasetFinderLocal = new DatasetFinderLocal(cacheDir.getAbsolutePath(), dataset -> CacheUtil.cacheFor(dataset.getNamespace(), cacheDir.getAbsolutePath()));
}
Also used : CacheUtil(org.globalbioticinteractions.cache.CacheUtil) DatasetFinderException(org.eol.globi.service.DatasetFinderException) URL(java.net.URL) Assert.assertNotNull(org.junit.Assert.assertNotNull) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test) StringEndsWith.endsWith(org.hamcrest.core.StringEndsWith.endsWith) File(java.io.File) Assert.assertThat(org.junit.Assert.assertThat) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Dataset(org.eol.globi.service.Dataset) Is.is(org.hamcrest.core.Is.is) IsCollectionContaining.hasItem(org.junit.internal.matchers.IsCollectionContaining.hasItem) Before(org.junit.Before) File(java.io.File) URL(java.net.URL) Before(org.junit.Before)

Example 25 with Dataset

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

the class DatasetFinderLocalTest method dataset.

@Test
public void dataset() throws DatasetFinderException, URISyntaxException {
    Dataset actual = datasetFinderLocal.datasetFor("globalbioticinteractions/template-dataset");
    assertThat(actual, is(notNullValue()));
    assertThat(actual.getConfigURI().toString(), endsWith("/test-cache/globalbioticinteractions/template-dataset/6bfc17b8717e6e8e478552f12404bc8887d691a155ffd9cd9bfc80cb6747c5d2!/template-dataset-8abd2ba18457288f33527193299504015fae6def/globi.json"));
    assertThat(actual.getArchiveURI().toString(), is("https://github.com/globalbioticinteractions/template-dataset/archive/8abd2ba18457288f33527193299504015fae6def.zip"));
    assertThat(actual.getCitation(), is("Jorrit H. Poelen. 2014. Species associations manually extracted from literature. Accessed on 2017-09-14T16:45:38Z via <https://github.com/globalbioticinteractions/template-dataset/archive/8abd2ba18457288f33527193299504015fae6def.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