Search in sources :

Example 21 with Dataset

use of org.globalbioticinteractions.dataset.Dataset 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 22 with Dataset

use of org.globalbioticinteractions.dataset.Dataset 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)

Example 23 with Dataset

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

the class DatasetImporterForSzoboszlaiTest method importShapes2.

@Test
public void importShapes2() throws IOException {
    Dataset testDataset = getTestDataset();
    ParserFactory parserFactory = new ParserFactoryForDataset(testDataset);
    DatasetImporterForSzoboszlai studyImporterForSzoboszlai = new DatasetImporterForSzoboszlai(parserFactory, nodeFactory);
    studyImporterForSzoboszlai.setDataset(testDataset);
    Map<Integer, LatLng> localityMap = studyImporterForSzoboszlai.importShapes2();
    assertLocalityMap(localityMap);
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) LatLng(org.eol.globi.geo.LatLng) Test(org.junit.Test)

Example 24 with Dataset

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

the class DatasetImporterForSzoboszlaiTest method getTestDataset.

private Dataset getTestDataset() throws IOException {
    JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Szoboszlai AI, Thayer JA, Wood SA, Sydeman WJ, Koehn LE (2015) Data from: Forage species in predator diets: synthesis of data from the California Current. Dryad Digital Repository. https://doi.org/10.5061/dryad.nv5d2\",\n" + "  \"doi\": \"https://doi.org/10.5061/dryad.nv5d2\",\n" + "  \"format\": \"szoboszlai\",\n" + "  \"resources\": {\n" + "    \"links\": \"szoboszlai/CCPDDlinkdata_v2.csv\",\n" + "    \"shapes\": \"szoboszlai/CCPDDlocationdata_test.zip\"\n" + "  }\n" + "}");
    Dataset dataset = new DatasetLocal(inStream -> inStream);
    dataset.setConfig(config);
    return dataset;
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetLocal(org.eol.globi.service.DatasetLocal) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 25 with Dataset

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

the class CmdGenerateReportTest method generateCollectionReport.

@Test
public void generateCollectionReport() throws NodeFactoryException {
    DatasetImpl originatingDataset = new DatasetImpl("some/namespace", URI.create("http://example.com"), inStream -> inStream);
    Dataset originatingDatasetNode = nodeFactory.getOrCreateDataset(originatingDataset);
    StudyImpl study1 = new StudyImpl("a title", null, "citation");
    study1.setOriginatingDataset(originatingDatasetNode);
    createStudy(study1);
    StudyImpl study2 = new StudyImpl("another title", null, "citation");
    study2.setOriginatingDataset(originatingDatasetNode);
    createStudy(study2);
    resolveNames();
    new CmdGenerateReport(getGraphDb(), cacheService).generateReportForCollection();
    IndexHits<Node> reports = getGraphDb().index().forNodes("reports").query("*", "*");
    assertThat(reports.size(), is(1));
    Node reportNode = reports.getSingle();
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES), is(1));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS), is(1));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES), is(2));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS), is(8));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA), is(3));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH), is(2));
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) Node(org.neo4j.graphdb.Node) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Test(org.junit.Test)

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