Search in sources :

Example 16 with DatasetImpl

use of org.eol.globi.service.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 source", "some doi", "some citation");
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("some:uri"));
    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 source", "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(org.codehaus.jackson.node.ObjectNode) Dataset(org.eol.globi.service.Dataset) Node(org.neo4j.graphdb.Node) ObjectNode(org.codehaus.jackson.node.ObjectNode) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 17 with DatasetImpl

use of org.eol.globi.service.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 source", "some doi", "some citation");
    DatasetImpl dataset = new DatasetImpl(null, null);
    study1.setOriginatingDataset(dataset);
    StudyNode study = getNodeFactory().getOrCreateStudy(study1);
    assertThat(NodeUtil.getDataSetForStudy(study), is(nullValue()));
}
Also used : DatasetImpl(org.eol.globi.service.DatasetImpl) Test(org.junit.Test)

Example 18 with DatasetImpl

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

the class NodeFactoryNeo4jTest method assertDataset.

private void assertDataset(String citationKey) {
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("some:uri"));
    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.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(org.codehaus.jackson.node.ObjectNode) Dataset(org.eol.globi.service.Dataset) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 19 with DatasetImpl

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

the class StudyImporterForSaproxylicIntegrationTest method importAll.

@Test
public void importAll() throws StudyImporterException {
    StudyImporter importer = new StudyImporterTestFactory(nodeFactory).instantiateImporter(StudyImporterForSaproxylic.class);
    importer.setDataset(new DatasetImpl("some/test", URI.create("classpath:/org/eol/globi/data/saproxylic")));
    importStudy(importer);
    assertNotNull(taxonIndex.findTaxonByName("Fagus sylvatica"));
    assertNotNull(taxonIndex.findTaxonByName("Epuraea variegata"));
}
Also used : DatasetImpl(org.eol.globi.service.DatasetImpl) Test(org.junit.Test)

Example 20 with DatasetImpl

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

the class StudyImporterForSeltmannIT method importArchive.

protected void importArchive(String archiveName) throws StudyImporterException {
    StudyImporterForSeltmann importer = new StudyImporterForSeltmann(null, nodeFactory);
    importer.setDataset(new DatasetImpl(null, URI.create(ARCHIVE_URI_PREFIX + archiveName)));
    importStudy(importer);
    List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    for (Study allStudy : allStudies) {
        assertThat(allStudy.getSource(), startsWith("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
        assertThat(allStudy.getCitation(), is("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
        Iterable<Relationship> specimens = NodeUtil.getSpecimens(allStudy);
        for (Relationship specimen : specimens) {
            Specimen spec = new SpecimenNode(specimen.getEndNode());
            Term basisOfRecord = spec.getBasisOfRecord();
            assertThat(basisOfRecord.getId(), either(is("TEST:PreservedSpecimen")).or(is("TEST:LabelObservation")));
            assertThat(basisOfRecord.getName(), either(is("PreservedSpecimen")).or(is("LabelObservation")));
        }
    }
    assertThat(taxonIndex.findTaxonByName("Megandrena mentzeliae"), is(notNullValue()));
    assertThat(taxonIndex.findTaxonByName("Mentzelia tricuspis"), is(notNullValue()));
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) DatasetImpl(org.eol.globi.service.DatasetImpl) Term(org.eol.globi.domain.Term) SpecimenNode(org.eol.globi.domain.SpecimenNode)

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