Search in sources :

Example 11 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForRoopnarineTest method validateSpecimen.

private int validateSpecimen() {
    AtomicInteger totalRels = new AtomicInteger(0);
    RelationshipListener handler = rel -> {
        Node specimen = rel.getEndNode();
        assertNotNull(specimen);
        Relationship collectedAtRelationship = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING);
        assertNotNull("missing location information", collectedAtRelationship);
        Node locationNode = collectedAtRelationship.getEndNode();
        assertNotNull(locationNode);
        assertTrue(locationNode.hasProperty(LocationConstant.LATITUDE));
        assertTrue(locationNode.hasProperty(LocationConstant.LONGITUDE));
        totalRels.incrementAndGet();
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(getStudySingleton(getGraphDb()).getUnderlyingNode()), handler);
    return totalRels.get();
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) Direction(org.neo4j.graphdb.Direction) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Is(org.hamcrest.core.Is) Relationship(org.neo4j.graphdb.Relationship) Ignore(org.junit.Ignore) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LocationConstant(org.eol.globi.domain.LocationConstant) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener)

Example 12 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForSimonsTest method createAndPopulateStudy.

@Test
public void createAndPopulateStudy() throws StudyImporterException {
    String csvString = "\"Obs\",\"spcode\", \"sizecl\", \"cruise\", \"stcode\", \"numstom\", \"numfood\", \"pctfull\", \"predator famcode\", \"prey\", \"number\", \"season\", \"depth\", \"transect\", \"alphcode\", \"taxord\", \"station\", \"long\", \"lat\", \"time\", \"sizeclass\", \"predator\"\n";
    csvString += "1, 1, 16, 3, 2, 6, 6, 205.5, 1, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 60, \"Chandeleur Islands\", \"aabd\", 47.11, \"C2\", 348078.84, 3257617.25, 313, \"201-300\", \"Rhynchoconger flavus\"\n";
    csvString += "1, 1, 16, 3, 2, 6, 6, 205.5, 1, \"Ampelisca agassizi\", 1, \"Summer\", 60, \"Chandeleur Islands\", \"aabd\", 47.11, \"C2\", 348078.84, 3257617.25, 313, \"201-300\", \"Rhynchoconger flavus\"\n";
    csvString += "2, 11, 2, 1, 1, 20, 15, 592.5, 6, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 20, \"Chandeleur Islands\", \"aabd\", 47.11, \"C1\", 344445.31, 3323087.25, 144, \"26-50\", \"Halieutichthys aculeatus\"\n";
    DatasetImporterForSimons importer = new DatasetImporterForSimons(new TestParserFactory(csvString), nodeFactory);
    importStudy(importer);
    assertNotNull(taxonIndex.findTaxonByName("Rhynchoconger flavus"));
    assertNotNull(taxonIndex.findTaxonByName("Halieutichthys aculeatus"));
    assertNotNull(taxonIndex.findTaxonByName("Ampelisca sp. (abdita complex)"));
    assertNotNull(nodeFactory.findStudy(new StudyImpl("Simons 1997")));
    assertNotNull(nodeFactory.findLocation(new LocationImpl(LAT_1, LONG_1, -60.0d, null)));
    assertNotNull(nodeFactory.findLocation(new LocationImpl(LAT_2, LONG_2, -20.0d, null)));
    assertNotNull(nodeFactory.findSeason("summer"));
    StudyNode foundStudy = (StudyNode) nodeFactory.findStudy(new StudyImpl("Simons 1997"));
    assertNotNull(foundStudy);
    RelationshipListener handler = rel -> {
        Node specimen = rel.getEndNode();
        Node speciesNode = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
        String scientificName = (String) speciesNode.getProperty("name");
        if ("Rhynchoconger flavus".equals(scientificName)) {
            String seasonName = "summer";
            String genusName = "Ampelisca sp. (abdita complex)";
            double length = (201.0d + 300.0d) / 2.0d;
            assertSpecimen(specimen, LONG_1, LAT_1, -60.0, seasonName, genusName, length);
            Iterable<Relationship> ateRelationships = specimen.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
            List<String> preyNames = new ArrayList<String>();
            for (Relationship ateRel : ateRelationships) {
                Node preyTaxonNode = ateRel.getEndNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS)).iterator().next().getEndNode();
                preyNames.add(preyTaxonNode.getProperty(PropertyAndValueDictionary.NAME).toString());
            }
            assertThat(preyNames, hasItem("Ampelisca sp. (abdita complex)"));
            assertThat(preyNames.contains("Ampelisca agassizi"), Is.is(true));
            assertThat(preyNames.size(), Is.is(2));
        } else if ("Halieutichthys aculeatus".equals(scientificName)) {
            String genusName = "Ampelisca sp. (abdita complex)";
            String seasonName = "summer";
            double length = (26.0d + 50.0d) / 2.0d;
            assertSpecimen(specimen, LONG_2, LAT_2, -20.0, seasonName, genusName, length);
        } else if ("Ampelisca sp. (abdita complex)".equals(scientificName)) {
            Node locationNode = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING).getEndNode();
            assertNotNull(locationNode);
            assertTrue(locationNode.hasProperty(LocationConstant.LONGITUDE));
            assertTrue(locationNode.hasProperty(LocationConstant.ALTITUDE));
            assertTrue(locationNode.hasProperty(LocationConstant.LATITUDE));
        } else if ("Ampelisca agassizi".equals(scientificName)) {
            assertPreySpecimen(specimen, LONG_1, LAT_1, -60.0);
        } else {
            fail("found predator with unexpected scientificName [" + scientificName + "]");
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(foundStudy.getUnderlyingNode()), handler);
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) NodeUtil(org.eol.globi.util.NodeUtil) Direction(org.neo4j.graphdb.Direction) LocationImpl(org.eol.globi.domain.LocationImpl) RelTypes(org.eol.globi.domain.RelTypes) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) Is(org.hamcrest.core.Is) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RelationshipListener(org.eol.globi.util.RelationshipListener) Is.is(org.hamcrest.core.Is.is) UTMRef(uk.me.jstott.jcoord.UTMRef) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Iterator(java.util.Iterator) LatLng(uk.me.jstott.jcoord.LatLng) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) Assert(org.junit.Assert) LocationConstant(org.eol.globi.domain.LocationConstant) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) StudyImpl(org.eol.globi.domain.StudyImpl) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 13 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForBaremoreTest method validateSpecimen.

private int validateSpecimen(StudyNode study) {
    AtomicInteger totalRels = new AtomicInteger(0);
    RelationshipListener handler = rel -> {
        assertTrue(rel.hasProperty(SpecimenConstant.EVENT_DATE));
        Node specimen = rel.getEndNode();
        assertNotNull(specimen);
        Iterable<Relationship> rels = specimen.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
        for (Relationship ignored : rels) {
            assertTrue(specimen.hasProperty(SpecimenConstant.LENGTH_IN_MM));
            assertTrue(specimen.hasProperty(SpecimenConstant.LIFE_STAGE_LABEL));
        }
        Relationship collectedAtRelationship = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING);
        assertNotNull(collectedAtRelationship);
        Node locationNode = collectedAtRelationship.getEndNode();
        assertNotNull(locationNode);
        assertThat(locationNode.getProperty(LocationConstant.LATITUDE), is(29.219302));
        assertThat(locationNode.getProperty(LocationConstant.LONGITUDE), is(-87.06665));
        totalRels.incrementAndGet();
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
    return totalRels.get();
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) Direction(org.neo4j.graphdb.Direction) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Is(org.hamcrest.core.Is) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Is.is(org.hamcrest.core.Is.is) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LocationConstant(org.eol.globi.domain.LocationConstant) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener)

Example 14 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForAkinTest method importHeaderAndASingleSpecimen.

@Test
public void importHeaderAndASingleSpecimen() throws StudyImporterException, ParseException {
    String csvString = ",\"Fish No\",\"Fish Species\",\"Date \",,\"Site \",\"SL(mm)\",\"Stomach volume\",\"Stomach status\",\"C. Method\",\"Detritus\",\"Sand\",\"Diatoms\",\"Centric diatoms\",\"Pennate diatoms\",\"Oscillatoria \",\"Filamentous algae\",\"Green algae\",\"Other blue green algae\",\"Unicellular green algae\",\"Brown algae\",\"Golden brown algae\",\"Nostocales (Blue green algae)\",\"Chara\",\"Ruppia maritima\",\"Other macrophytes\",\"Seeds\",\"Invertebrate eggs \",\"Fish bones\",\"Lucania parva eggs\",\"Other fish eggs\",\"Catfish egg\",\"Unidentified bone\",\"Fish eyes\",\"Fish otolith\",\"Ctenoid fish scale\",\"Cycloid fish scale\",\"Dinoflagellates (Noctiluca spp.)\",\"Protozoa\",\"Bivalvia\",\"Gastropoda\",\"Nematode\",\"Nemotode(Parasite)\",\"Calanoida copepoda\",\"Harpacticoida copepoda\",\"Copepoda nauplii\",\"Cyclopoid copepoda\",\"Cladocera\",\"Rotifera\",\"Unidefined zooplankton\",\"Chironomidae larvae\",\"Diptera 1\",\"Diptera 2\",\"Diptera midges(pupa)\",\"Polycheate worm\",\"Other annelid worms\",\"Amphipoda(Gammarus spp.)\",\"Corophium sp(amphipoda)\",\"Decopoda larvae\",\"Isopoda\",\"Unidentified invertebrate\",\"Other Ephemeroptera(Mayfly)\",\"Ephemeroptera(Baetidae)\",\"Coleoptera\",\"Other Hymenoptera\",\"Odonate\",\"Damselfly\",\"Other Thrips\",\"Thysanoptera (thrips)\",\"Pteromalitidae(Hymenoptera)\",\"Hemiptera\",\"Homoptera\",\"Unidentified insect larvae\",\"Arachnida \",\"Unidentified insects\",\"Mollusks (Oyster)\",\"Other Mollusks\",\"Ostracoda\",\"Brachyura (Crab zoea)\",\"Mysidacea\",\"Penneid shrimp post larvae\",\"Unidentified shrimp\",\"Palaemonotes pugio\",\"Peneaus setiferus\",\"Peneaus aztecus\",\"Callinectes sapidus\",\"Other crabs\",\"Neopunope sayi(mud crab)\",\"Myrophis punctatus (speckled worm eel)\",\"Mugil cephalus\",\"Brevoortia patronus\",\"Lepisosteus osseus \",\"Fundulus  grandis\",\"Other fundulus species\",\"Cyprinodon variegatus\",\"Pogonias cromis\",\"Menidia beryllina\",\"Anchoa mitchilli\",\"Other Sciaenidae species\",\"Lagodon rhomboides\",\"Arius felis\",\"Leiostomus xanthurus\",\"Gobiosoma bosc\",\"Lucania parva\",\"Micropogonias undulatus\",\"Cynoscion nebulosus\",\"Poecilia latipinna\",\"Unidentified fish\",\"Unidentified fish larvae\",\"Other Gobiidae \",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + ",1,\"Pogonias cromis\",\"03.07.98\",,1,226,3,,\"Gillnet\",,0.15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0.6,,,,,,0.45,,,,,,,,,,,,,,,,,,1.35,0.45,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
    DatasetImporter importer = new StudyImporterTestFactory(new TestParserFactory(csvString), nodeFactory).instantiateImporter((Class) DatasetImporterForAkin.class);
    importStudy(importer);
    StudyNode study = getStudySingleton(getGraphDb());
    Taxon taxon = taxonIndex.findTaxonByName("Pogonias cromis");
    assertNotNull(taxon);
    AtomicBoolean success = new AtomicBoolean(false);
    RelationshipListener relHandler = rel -> {
        assertThat(rel, is(not(nullValue())));
        if (rel.hasProperty(SpecimenConstant.EVENT_DATE)) {
            assertThat(rel.getProperty(SpecimenConstant.EVENT_DATE), is("1998-03-07T00:00:00Z"));
            Node specimenNode = rel.getEndNode();
            assertThat(specimenNode.getProperty(SpecimenConstant.LENGTH_IN_MM), is(226.0));
            assertThat(specimenNode.getProperty(SpecimenConstant.STOMACH_VOLUME_ML), is(3.0));
            Specimen specimen = new SpecimenNode(specimenNode);
            assertThat(specimen.getSampleLocation().getAltitude(), is(-0.7));
            Node speciesNode = specimenNode.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
            assertThat(speciesNode.getProperty("name"), is("Pogonias cromis"));
            Iterable<Relationship> ateRels = specimenNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
            Map<String, Map<String, Object>> preys = new TreeMap<String, Map<String, Object>>();
            for (Relationship ateRel : ateRels) {
                Node preyNode = ateRel.getEndNode();
                Node taxonNode = preyNode.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
                String name = (String) taxonNode.getProperty("name");
                Map<String, Object> propertyMap = new TreeMap<String, Object>();
                propertyMap.put("name", name);
                propertyMap.put(SpecimenConstant.VOLUME_IN_ML, preyNode.getProperty(SpecimenConstant.VOLUME_IN_ML));
                preys.put(name, propertyMap);
            }
            Map<String, Object> sand = preys.get("Sand");
            assertThat(sand, is(notNullValue()));
            assertThat(sand.get("name"), is("Sand"));
            assertThat(sand.get(SpecimenConstant.VOLUME_IN_ML), is(0.15d));
            Map<String, Object> chironomidae = preys.get("Chironomidae larvae");
            assertThat(chironomidae, is(notNullValue()));
            assertThat(chironomidae.get("name"), is("Chironomidae larvae"));
            assertThat(chironomidae.get(SpecimenConstant.VOLUME_IN_ML), is(0.6d));
            Map<String, Object> amphipoda = preys.get("Amphipoda(Gammarus spp.)");
            assertThat(amphipoda, is(notNullValue()));
            assertThat(amphipoda.get("name"), is("Amphipoda(Gammarus spp.)"));
            assertThat(amphipoda.get(SpecimenConstant.VOLUME_IN_ML), is(0.45d));
            Map<String, Object> insecta = preys.get("Unidentified insects");
            assertThat(insecta, is(notNullValue()));
            assertThat(insecta.get("name"), is("Unidentified insects"));
            assertThat(insecta.get(SpecimenConstant.VOLUME_IN_ML), is(1.35d));
            Map<String, Object> mollusca = preys.get("Mollusks (Oyster)");
            assertThat(mollusca, is(notNullValue()));
            assertThat(mollusca.get("name"), is("Mollusks (Oyster)"));
            assertThat(mollusca.get(SpecimenConstant.VOLUME_IN_ML), is(0.45d));
            Node locationNode = specimenNode.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING).getEndNode();
            assertThat(locationNode.getProperty(LocationConstant.LATITUDE), is(28.645202d));
            assertThat(locationNode.getProperty(LocationConstant.LONGITUDE), is(-96.099923d));
            success.set(true);
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), relHandler);
    assertTrue(success.get());
}
Also used : DateUtil(org.eol.globi.util.DateUtil) NodeUtil(org.eol.globi.util.NodeUtil) Specimen(org.eol.globi.domain.Specimen) Date(java.util.Date) Direction(org.neo4j.graphdb.Direction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) IsNull.nullValue(org.hamcrest.core.IsNull.nullValue) RelationshipListener(org.eol.globi.util.RelationshipListener) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) ParseException(java.text.ParseException) IsNot.not(org.hamcrest.core.IsNot.not) Taxon(org.eol.globi.domain.Taxon) UberonLookupService(org.eol.globi.taxon.UberonLookupService) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Relationship(org.neo4j.graphdb.Relationship) TreeMap(java.util.TreeMap) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) SpecimenNode(org.eol.globi.domain.SpecimenNode) LocationConstant(org.eol.globi.domain.LocationConstant) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Taxon(org.eol.globi.domain.Taxon) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 15 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForICESTest method parseSelection.

@Test
public void parseSelection() throws NodeFactoryException, StudyImporterException, ParseException {
    String firstBunchOfLines = "File Name,Latitude,Longitude,Estimated Lat/Lon,Date/Time,Year,Quarter,Month,Day,Time,Station/Haul,Sample Number,ICES StomachID,Depth,Temperature,Country,Ship,ICES Rectangle,Sampling Method,Predator,Predator NODC Code,Predator (mean) Lengh,Predator (mean) Weight,Predator (mean) Age,Predator Lower Length Bound,Predator Upper Length Bound,CPUE,Number Stomachs With Food,Number Stomachs Regurgitated,Number Stomachs With Skeletal Remains,Number Stomachs Empty,Number Stomachs,Digestion Stage,Prey Species Name,Prey NODC Code,Prey Weight,Prey Lower Length Bound,Prey Upper Length Bound,Prey Number,ICES Internal ID\n" + "Exccoddatsto_815,55.25,8.5,Yes,01/01/1981 00:00:00,1981,1,1,1,,,26,26,,,,,39F8,Demersal sampling,Gadus morhua,8791030402,125,,,100,150,29,26,0,0,2,28,,Polychaeta,5001000000,1.5,,,5,1\n" + "Exccoddatsto_815,55.25,8.5,Yes,01/01/1981 00:00:00,1981,1,1,1,,,26,26,,,,,39F8,Demersal sampling,Gadus morhua,8791030402,125,,,100,150,29,26,0,0,2,28,,Nereis,5001240400,5.3,,,1,2\n" + "Exccoddatsto_815,55.25,8.5,Yes,01/01/1981 00:00:00,1981,1,1,1,,,26,26,,,,,39F8,Demersal sampling,Gadus morhua,8791030402,125,,,100,150,29,26,0,0,2,28,,,5515290302,4.8,,,2,3";
    DatasetImporterForICES importer = new DatasetImporterForICES(new TestParserFactory(firstBunchOfLines), nodeFactory);
    importStudy(importer);
    StudyNode study = getStudySingleton(getGraphDb());
    assertNotNull(taxonIndex.findTaxonByName("Gadus morhua"));
    assertNotNull(taxonIndex.findTaxonByName("Polychaeta"));
    assertNotNull(taxonIndex.findTaxonByName("Nereis"));
    AtomicInteger specimenCollected = new AtomicInteger(0);
    AtomicInteger preyEaten = new AtomicInteger(0);
    RelationshipListener handler = new RelationshipListener() {

        @Override
        public void on(Relationship rel) {
            assertThat(rel.getProperty(SpecimenConstant.EVENT_DATE), is("1981-01-01T00:00:00Z"));
            Node specimen = rel.getEndNode();
            assertNotNull(specimen);
            Iterable<Relationship> relationships = specimen.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
            for (Relationship ignored : relationships) {
                assertThat(specimen.getProperty(SpecimenConstant.LENGTH_IN_MM), is(125.0));
                preyEaten.incrementAndGet();
            }
            Relationship collectedAtRelationship = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING);
            assertNotNull(collectedAtRelationship);
            Node locationNode = collectedAtRelationship.getEndNode();
            assertNotNull(locationNode);
            assertThat(locationNode.getProperty(LocationConstant.LATITUDE), is(55.25));
            assertThat(locationNode.getProperty(LocationConstant.LONGITUDE), is(8.5));
            specimenCollected.incrementAndGet();
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
    assertThat(specimenCollected.get(), Is.is(3));
    assertThat(preyEaten.get(), Is.is(2));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Relationship(org.neo4j.graphdb.Relationship) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Test(org.junit.Test)

Aggregations

NodeTypeDirection (org.eol.globi.util.NodeTypeDirection)22 RelationshipListener (org.eol.globi.util.RelationshipListener)22 Node (org.neo4j.graphdb.Node)22 Relationship (org.neo4j.graphdb.Relationship)22 NodeUtil (org.eol.globi.util.NodeUtil)21 StudyNode (org.eol.globi.domain.StudyNode)20 Direction (org.neo4j.graphdb.Direction)19 Test (org.junit.Test)18 RelTypes (org.eol.globi.domain.RelTypes)17 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 InteractType (org.eol.globi.domain.InteractType)14 Is.is (org.hamcrest.core.Is.is)14 IOException (java.io.IOException)13 Assert.assertTrue (org.junit.Assert.assertTrue)13 SpecimenConstant (org.eol.globi.domain.SpecimenConstant)12 SpecimenNode (org.eol.globi.domain.SpecimenNode)12 List (java.util.List)11 TreeMap (java.util.TreeMap)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 TaxonNode (org.eol.globi.domain.TaxonNode)11