Search in sources :

Example 31 with DatasetImpl

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

the class NodeFactoryNeo4jTest method createStudyWithSameExternalIdInDifferentNamespace.

@Test
public void createStudyWithSameExternalIdInDifferentNamespace() throws NodeFactoryException {
    StudyImpl study1 = new StudyImpl("myTitle", new DOI("myDoi", "123"), null);
    study1.setOriginatingDataset(new DatasetImpl("name/space", URI.create("foo:bar"), is -> is));
    study1.setExternalId("foo:bar");
    StudyNode study1Created = getNodeFactory().getOrCreateStudy(study1);
    StudyImpl study2 = new StudyImpl("myTitle", new DOI("myDoi", "123"), null);
    study2.setOriginatingDataset(new DatasetImpl("name/spacz", URI.create("foo:bar"), is -> is));
    study2.setExternalId("foo:bar");
    StudyNode study2Created = getNodeFactory().getOrCreateStudy(study2);
    assertThat(study1Created.getExternalId(), is("foo:bar"));
    assertThat(study1Created.getOriginatingDataset().getNamespace(), is("name/space"));
    assertThat(study2Created.getExternalId(), is("foo:bar"));
    assertThat(study2Created.getOriginatingDataset().getNamespace(), is("name/spacz"));
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Location(org.eol.globi.domain.Location) Date(java.util.Date) Direction(org.neo4j.graphdb.Direction) ExternalIdUtil(org.eol.globi.util.ExternalIdUtil) StringUtils(org.apache.commons.lang3.StringUtils) StudyImpl(org.eol.globi.domain.StudyImpl) InteractType(org.eol.globi.domain.InteractType) TaxonImpl(org.eol.globi.domain.TaxonImpl) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) LocationNode(org.eol.globi.domain.LocationNode) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) EnvironmentNode(org.eol.globi.domain.EnvironmentNode) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) SpecimenNode(org.eol.globi.domain.SpecimenNode) DateUtil(org.eol.globi.util.DateUtil) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Term(org.eol.globi.domain.Term) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) Specimen(org.eol.globi.domain.Specimen) TermImpl(org.eol.globi.domain.TermImpl) LocationImpl(org.eol.globi.domain.LocationImpl) CoreMatchers.not(org.hamcrest.CoreMatchers.not) Environment(org.eol.globi.domain.Environment) DatasetConstant(org.globalbioticinteractions.dataset.DatasetConstant) TermLookupService(org.eol.globi.service.TermLookupService) RelTypes(org.eol.globi.domain.RelTypes) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) DOI(org.globalbioticinteractions.doi.DOI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) DatasetNode(org.eol.globi.domain.DatasetNode) NodeBacked(org.eol.globi.domain.NodeBacked) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) Relationship(org.neo4j.graphdb.Relationship) Dataset(org.globalbioticinteractions.dataset.Dataset) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Interaction(org.eol.globi.domain.Interaction) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) DOI(org.globalbioticinteractions.doi.DOI) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Example 32 with DatasetImpl

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

the class NodeFactoryNeo4jTest method addDatasetToStudyNulls.

@Test
public void addDatasetToStudyNulls() throws NodeFactoryException {
    StudyImpl study1 = new StudyImpl("my title", SOME_DOI, "some citation");
    DatasetImpl dataset = new DatasetImpl(null, null, inStream -> inStream);
    study1.setOriginatingDataset(dataset);
    StudyNode study = getNodeFactory().getOrCreateStudy(study1);
    assertThat(NodeUtil.getDataSetForStudy(study), is(nullValue()));
}
Also used : StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Example 33 with DatasetImpl

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

the class NodeFactoryNeo4jTest method addDatasetToStudy.

@Test
public void addDatasetToStudy() throws NodeFactoryException, IOException {
    StudyImpl study1 = new StudyImpl("my title", SOME_DOI, "some citation");
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream);
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put(DatasetConstant.SHOULD_RESOLVE_REFERENCES, false);
    dataset.setConfig(objectNode);
    study1.setOriginatingDataset(dataset);
    StudyNode study = getNodeFactory().getOrCreateStudy(study1);
    Dataset origDataset = study.getOriginatingDataset();
    assertThat(origDataset, is(notNullValue()));
    assertThat(origDataset.getArchiveURI().toString(), is("some:uri"));
    assertThat(origDataset.getOrDefault(DatasetConstant.SHOULD_RESOLVE_REFERENCES, "true"), is("false"));
    String expectedConfig = new ObjectMapper().writeValueAsString(objectNode);
    assertThat(new ObjectMapper().writeValueAsString(origDataset.getConfig()), is(expectedConfig));
    Node datasetNode = NodeUtil.getDataSetForStudy(study);
    assertThat(datasetNode.getProperty(DatasetConstant.NAMESPACE), is("some/namespace"));
    assertThat(datasetNode.getProperty("archiveURI"), is("some:uri"));
    assertThat(datasetNode.getProperty(DatasetConstant.SHOULD_RESOLVE_REFERENCES), is("false"));
    StudyImpl otherStudy = new StudyImpl("my other title", SOME_DOI, "some citation");
    otherStudy.setOriginatingDataset(dataset);
    StudyNode studySameDataset = getNodeFactory().getOrCreateStudy(otherStudy);
    Node datasetNodeOther = NodeUtil.getDataSetForStudy(studySameDataset);
    assertThat(datasetNode.getId(), is(datasetNodeOther.getId()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Dataset(org.globalbioticinteractions.dataset.Dataset) LocationNode(org.eol.globi.domain.LocationNode) EnvironmentNode(org.eol.globi.domain.EnvironmentNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Node(org.neo4j.graphdb.Node) DatasetNode(org.eol.globi.domain.DatasetNode) StudyNode(org.eol.globi.domain.StudyNode) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Example 34 with DatasetImpl

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

the class NodeFactoryNeo4jTest method createStudyWithDifferentExternalIdInSameNamespace.

@Test
public void createStudyWithDifferentExternalIdInSameNamespace() throws NodeFactoryException {
    StudyImpl study1 = new StudyImpl("myTitle", new DOI("myDoi", "123"), null);
    study1.setOriginatingDataset(new DatasetImpl("name/space", URI.create("foo:bar"), is -> is));
    study1.setExternalId("foo:bar");
    StudyNode study1Created = getNodeFactory().getOrCreateStudy(study1);
    StudyImpl study2 = new StudyImpl("myTitle", new DOI("myDoi", "123"), null);
    study2.setOriginatingDataset(new DatasetImpl("name/space", URI.create("foo:bar"), is -> is));
    study2.setExternalId("foo:baz");
    StudyNode study2Created = getNodeFactory().getOrCreateStudy(study2);
    assertThat(study1Created.getExternalId(), is("foo:bar"));
    assertThat(study2Created.getExternalId(), is("foo:baz"));
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Location(org.eol.globi.domain.Location) Date(java.util.Date) Direction(org.neo4j.graphdb.Direction) ExternalIdUtil(org.eol.globi.util.ExternalIdUtil) StringUtils(org.apache.commons.lang3.StringUtils) StudyImpl(org.eol.globi.domain.StudyImpl) InteractType(org.eol.globi.domain.InteractType) TaxonImpl(org.eol.globi.domain.TaxonImpl) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) LocationNode(org.eol.globi.domain.LocationNode) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) EnvironmentNode(org.eol.globi.domain.EnvironmentNode) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) SpecimenNode(org.eol.globi.domain.SpecimenNode) DateUtil(org.eol.globi.util.DateUtil) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Term(org.eol.globi.domain.Term) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) Specimen(org.eol.globi.domain.Specimen) TermImpl(org.eol.globi.domain.TermImpl) LocationImpl(org.eol.globi.domain.LocationImpl) CoreMatchers.not(org.hamcrest.CoreMatchers.not) Environment(org.eol.globi.domain.Environment) DatasetConstant(org.globalbioticinteractions.dataset.DatasetConstant) TermLookupService(org.eol.globi.service.TermLookupService) RelTypes(org.eol.globi.domain.RelTypes) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) DOI(org.globalbioticinteractions.doi.DOI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) DatasetNode(org.eol.globi.domain.DatasetNode) NodeBacked(org.eol.globi.domain.NodeBacked) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) Relationship(org.neo4j.graphdb.Relationship) Dataset(org.globalbioticinteractions.dataset.Dataset) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Interaction(org.eol.globi.domain.Interaction) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) DOI(org.globalbioticinteractions.doi.DOI) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Example 35 with DatasetImpl

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

the class NodeFactoryNeo4jTest method assertDataset.

protected void assertDataset(String citationKey) {
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream);
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put(DatasetConstant.SHOULD_RESOLVE_REFERENCES, false);
    objectNode.put(citationKey, "some citation");
    dataset.setConfig(objectNode);
    Dataset origDataset = getNodeFactory().getOrCreateDataset(dataset);
    assertThat(origDataset, is(notNullValue()));
    assertThat(origDataset.getArchiveURI().toString(), is("some:uri"));
    assertThat(origDataset.getOrDefault(DatasetConstant.SHOULD_RESOLVE_REFERENCES, "true"), is("false"));
    assertThat(origDataset.getOrDefault(DatasetConstant.CITATION, "no citation"), is("some citation"));
    assertThat(origDataset.getCitation(), is("some citation"));
    assertThat(origDataset.getOrDefault(DatasetConstant.LAST_SEEN_AT, "1"), is(not("1")));
    Dataset datasetAnother = getNodeFactory().getOrCreateDataset(dataset);
    assertThat(((DatasetNode) datasetAnother).getNodeID(), is(((DatasetNode) origDataset).getNodeID()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Dataset(org.globalbioticinteractions.dataset.Dataset) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DatasetNode(org.eol.globi.domain.DatasetNode)

Aggregations

DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)83 Test (org.junit.Test)73 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)50 URI (java.net.URI)32 JsonNode (com.fasterxml.jackson.databind.JsonNode)31 Dataset (org.globalbioticinteractions.dataset.Dataset)25 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)21 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)21 InteractionListener (org.eol.globi.process.InteractionListener)19 URL (java.net.URL)18 Map (java.util.Map)17 StudyNode (org.eol.globi.domain.StudyNode)17 HashMap (java.util.HashMap)16 Is.is (org.hamcrest.core.Is.is)16 List (java.util.List)15 StudyImpl (org.eol.globi.domain.StudyImpl)15 StringUtils (org.apache.commons.lang3.StringUtils)14 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)14 Is (org.hamcrest.core.Is)14