Search in sources :

Example 1 with NodeTypeDirection

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

the class ExporterMeasurementOrFact method doExportStudy.

@Override
public void doExportStudy(StudyNode study, ExportUtil.Appender writer, boolean includeHeader) throws IOException {
    Map<String, String> properties = new TreeMap<String, String>();
    AtomicReference<IOException> lastException = new AtomicReference<>();
    RelationshipListener handler = collectedRel -> {
        Node specimenNode = collectedRel.getEndNode();
        if (isSpecimenClassified(specimenNode)) {
            try {
                writeMeasurements(writer, properties, specimenNode, collectedRel, study);
            } catch (IOException ex) {
                lastException.set(ex);
            }
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
    if (lastException.get() != null) {
        throw lastException.get();
    }
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) AtomicReference(java.util.concurrent.atomic.AtomicReference) Node(org.neo4j.graphdb.Node) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Relationship(org.neo4j.graphdb.Relationship) TreeMap(java.util.TreeMap) RelationshipListener(org.eol.globi.util.RelationshipListener) Map(java.util.Map) Writer(java.io.Writer) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) Study(org.eol.globi.domain.Study) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) TreeMap(java.util.TreeMap) RelationshipListener(org.eol.globi.util.RelationshipListener)

Example 2 with NodeTypeDirection

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

the class IndexInteractionsTest method indexInteractions.

@Test
public void indexInteractions() throws NodeFactoryException {
    TaxonIndex taxonIndex = getOrCreateTaxonIndex();
    // see https://github.com/globalbioticinteractions/globalbioticinteractions/wiki/Nanopubs
    StudyImpl study = new StudyImpl("some study", new DOI("123.23", "222"), "some study citation");
    NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri"), inStream -> inStream));
    Study interaction = factory.getOrCreateStudy(study);
    TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
    Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
    donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
    TaxonImpl mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
    Taxon mickeyTaxonNCBI = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
    NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonNCBI, getGraphDb(), RelTypes.SAME_AS);
    Specimen mickey = factory.createSpecimen(interaction, mickeyTaxon);
    mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxon));
    donald.ate(mickey);
    new IndexInteractions(new GraphServiceFactoryProxy(getGraphDb())).index();
    NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j2(getGraphDb());
    StudyImpl study1 = new StudyImpl("some study", new DOI("123.23", "222"), "come citation");
    study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream));
    StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
    assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
    assertThat(interaction.getTitle(), is(someStudy.getTitle()));
    RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
    Set<Long> ids = new HashSet<>();
    List<Long> idList = new ArrayList<>();
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(someStudy.getUnderlyingNode()), new RelationshipListener() {

        @Override
        public void on(Relationship specimen) {
            assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
            Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(hasParticipant, Direction.INCOMING);
            for (Relationship relationship : relationships) {
                long id = relationship.getStartNode().getId();
                ids.add(id);
                idList.add(id);
            }
        }
    });
    assertThat(ids.size(), Is.is(1));
    assertThat(idList.size(), Is.is(2));
    Node interactionNode = getGraphDb().getNodeById(idList.get(0));
    assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.DERIVED_FROM)));
    assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.ACCESSED_AT)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TaxonIndex(org.eol.globi.data.TaxonIndex) NodeUtil(org.eol.globi.util.NodeUtil) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Specimen(org.eol.globi.domain.Specimen) Direction(org.neo4j.graphdb.Direction) RelTypes(org.eol.globi.domain.RelTypes) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) Is(org.hamcrest.core.Is) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TaxonImpl(org.eol.globi.domain.TaxonImpl) RelationshipListener(org.eol.globi.util.RelationshipListener) DOI(org.globalbioticinteractions.doi.DOI) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Taxon(org.eol.globi.domain.Taxon) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) 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) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryException(org.eol.globi.data.NodeFactoryException) RelationshipType(org.neo4j.graphdb.RelationshipType) Study(org.eol.globi.domain.Study) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) TaxonNode(org.eol.globi.domain.TaxonNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayList(java.util.ArrayList) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) RelationshipListener(org.eol.globi.util.RelationshipListener) Specimen(org.eol.globi.domain.Specimen) TaxonIndex(org.eol.globi.data.TaxonIndex) DOI(org.globalbioticinteractions.doi.DOI) HashSet(java.util.HashSet) Study(org.eol.globi.domain.Study) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) StudyNode(org.eol.globi.domain.StudyNode) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) Test(org.junit.Test)

Example 3 with NodeTypeDirection

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

the class StudyTest method populateStudy.

@Test
public void populateStudy() throws NodeFactoryException {
    Study study = nodeFactory.createStudy(new StudyImpl("Our first study", null, null));
    taxonIndex.getOrCreateTaxon(new TaxonImpl(CARCHARODON_CARCHARIAS, null));
    Specimen goldFish = nodeFactory.createSpecimen(study, new TaxonImpl(CARASSIUS_AURATUS_AURATUS, null));
    Specimen shark = nodeFactory.createSpecimen(study, new TaxonImpl(CARCHARODON_CARCHARIAS, null));
    Specimen fuzzyShark = nodeFactory.createSpecimen(study, new TaxonImpl(CARCHARODON, null));
    shark.ate(goldFish);
    fuzzyShark.ate(goldFish);
    Location bolinasBay = nodeFactory.getOrCreateLocation(new LocationImpl(12.2d, 12.1d, -100.0d, null));
    shark.caughtIn(bolinasBay);
    Season winter = nodeFactory.createSeason("winter");
    shark.caughtDuring(winter);
    shark.setLengthInMm(1.2d);
    resolveNames();
    StudyNode foundStudy = getStudySingleton(getGraphDb());
    assertEquals(study.getTitle(), foundStudy.getTitle());
    RelationshipListener handler = rel -> {
        Specimen specimen = new SpecimenNode(rel.getEndNode());
        Relationship caughtDuringRel = rel.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CAUGHT_DURING), Direction.OUTGOING);
        if (caughtDuringRel != null) {
            Node seasonNode = caughtDuringRel.getEndNode();
            if (seasonNode != null && seasonNode.getProperty(SeasonNode.TITLE).equals("winter")) {
                Relationship next = NodeUtil.getClassifications(specimen).iterator().next();
                Node endNode = next.getEndNode();
                String speciesName = (String) endNode.getProperty("name");
                assertEquals(CARCHARODON_CARCHARIAS, speciesName);
                assertEquals(new Double(-100.0d), specimen.getSampleLocation().getAltitude());
                assertEquals(new Double(1.2d), specimen.getLengthInMm());
            } else {
                fail("expected to findNamespaces a specimen");
            }
        } else if (specimen.equals(goldFish)) {
            Node genusNode = NodeUtil.getClassifications(specimen).iterator().next().getEndNode();
            assertEquals(CARASSIUS_AURATUS_AURATUS, genusNode.getProperty("name"));
        } else if (specimen.equals(fuzzyShark)) {
            Node genusNode = NodeUtil.getClassifications(specimen).iterator().next().getEndNode();
            assertEquals(CARCHARODON, genusNode.getProperty("name"));
        } else {
            fail("found unexpected specimen [" + specimen + "] in study");
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(foundStudy.getUnderlyingNode()), handler);
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryException(org.eol.globi.data.NodeFactoryException) RelationshipListener(org.eol.globi.util.RelationshipListener) Direction(org.neo4j.graphdb.Direction) Test(org.junit.Test) Assert.fail(org.junit.Assert.fail) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Node(org.neo4j.graphdb.Node) Assert.assertEquals(org.junit.Assert.assertEquals) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) RelationshipListener(org.eol.globi.util.RelationshipListener) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 4 with NodeTypeDirection

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

the class DatasetImporterForBlewettTest method importLines.

@Test
public void importLines() throws StudyImporterException {
    String predatorPreyMapping = "\"Collection #\",\"Sp#\",\"Standard Length\",\"ID\",\"Far duoraum\",\"Cal sapidus\",\"Unid fish\",\"Anchoa spp\",\"Mug gyrans\",\"Bai chrysoura\",\"Portunus spp\",\"Bivalves\",\"Portunidae\",\"Lag rhomboides\",\"Xanthidae\",\"Palaemonidae\",\"Eucinostomus spp\",\"Mugil spp\",\"Alpheidae\",\"Atherinidae\",\"Syn foetens\",\"Ort chrysoptera\",\"Snails\",\"Euc gula\",\"Cynoscion spp\",\"Cyp. Variegatus\",\"Fun majalis\",\"Poe latipinna\",\"Unid crab\",\"Har jaguana\",\"Arm mierii\",\"Fun grandis\",\"Mic gulosus\",\"Ari felis\",\"Clupeidae\",\"Fundulus spp\",\"Diapterus/Eugerres spp\",\"Isopods\",\"Cyn nebulosus\",\"Opi oglinum\",\"Flo carpio\",\"Luc parva\",\"Uca spp\",\"Majidae\",\"Mug cephalus\",\"Squ empusa\",\"Opi robinsi\",\"Ariidae\",\"Sci ocellatus\",\"Unid shrimp\",\"Uca thayeri\",\"Grapsidae\",\"Lei xanthurus\",\"Elo saurus\",\"Brevoortia spp\"\n" + "\"CHD01101502\",1,549,,,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHD01102504\",1,548,\"E\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHD01102504\",2,550,,3,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHM000152\",1,580,\"E\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHM000152\",2,556,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
    String dateLocationString = "\"Collection #\",\"Longitude\",\"Latitude\",\"Time\",\"Date\",\"Temperature\",\"Salinity\"\n" + "\"CHD01101502\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHD01102504\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHM000151\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHM000152\",-82.103833,26.651833,12:40:00,1-Mar-00,24.8,30.3\n" + "\"CHM000153\",-82.087333,26.644833,13:40:00,1-Mar-00,25.1,30.1\n" + "\"CHM000154\",-82.083167,26.671167,14:40:00,1-Mar-00,26,30.4\n" + "\"CHM000175\",-82.197833,26.688167,10:00:00,8-Mar-00,22.2,35.05\n" + "\"CHM000176\",-82.191333,26.667333,11:00:00,8-Mar-00,22.7,35.25";
    final TestParserFactory preyPredatorFactory = new TestParserFactory(predatorPreyMapping);
    final TestParserFactory dateLocationFactory = new TestParserFactory(dateLocationString);
    ParserFactory testFactory = (studyResource, characterEncoding) -> {
        LabeledCSVParser parser;
        if (studyResource.toString().contains("abundance")) {
            parser = preyPredatorFactory.createParser(studyResource, characterEncoding);
        } else {
            parser = dateLocationFactory.createParser(studyResource, characterEncoding);
        }
        return parser;
    };
    DatasetImporter importer = new StudyImporterTestFactory(testFactory, nodeFactory).instantiateImporter(DatasetImporterForBlewett.class);
    importStudy(importer);
    StudyNode study = getStudySingleton(getGraphDb());
    AtomicBoolean success = new AtomicBoolean(false);
    RelationshipListener handler1 = collectedRel -> {
        Date unixEpochProperty = null;
        try {
            unixEpochProperty = nodeFactory.getUnixEpochProperty(new SpecimenNode(collectedRel.getEndNode()));
        } catch (NodeFactoryException e) {
            fail(e.getMessage());
        }
        assertThat(unixEpochProperty, is(not(nullValue())));
        String actual = dateToString(unixEpochProperty);
        Node predatorNode = collectedRel.getEndNode();
        if (StringUtils.equals(actual, "2000-03-01T10:55:00.000-06:00") && predatorNode.hasProperty(SpecimenConstant.LIFE_STAGE_LABEL) && predatorNode.hasRelationship(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING)) {
            assertThat(predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_LABEL), is("post-juvenile adult stage"));
            assertThat(predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_ID), is("UBERON:0000113"));
            Node predatorTaxonNode = predatorNode.getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).iterator().next().getEndNode();
            assertThat(predatorTaxonNode.getProperty(PropertyAndValueDictionary.NAME), is("Centropomus undecimalis"));
            Set<String> preyNames = new HashSet<>();
            Iterable<Relationship> ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
            for (Relationship preyRels : ate) {
                Node preyNode = preyRels.getEndNode();
                assertThat(preyNode, is(not(nullValue())));
                Node taxonNode = preyNode.getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).iterator().next().getEndNode();
                assertThat(taxonNode, is(not(nullValue())));
                preyNames.add((String) taxonNode.getProperty(PropertyAndValueDictionary.NAME));
            }
            assertThat(preyNames, hasItem("Lag rhomboides"));
            success.set(true);
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler1);
    assertTrue(success.get());
    success.set(false);
    RelationshipListener handler2 = collectedRel -> {
        Node predatorNode = collectedRel.getEndNode();
        if (predatorNode.hasProperty(SpecimenConstant.LENGTH_IN_MM) && (Double) predatorNode.getProperty(SpecimenConstant.LENGTH_IN_MM) == 548.0) {
            Iterable<Relationship> ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
            assertThat(ate.iterator().hasNext(), is(false));
            Location location = null;
            try {
                location = nodeFactory.findLocation(new LocationImpl(26.651833, -82.103833, 0.0, null));
            } catch (NodeFactoryException e) {
                fail(e.getMessage());
            }
            assertThat(location, is(not(nullValue())));
            Iterable<Relationship> specimenCaughtHere = NodeUtil.getSpecimenCaughtHere(location);
            Iterator<Relationship> iterator = specimenCaughtHere.iterator();
            assertThat(iterator.hasNext(), is(true));
            iterator.next();
            assertThat(iterator.hasNext(), is(true));
            iterator.next();
            assertThat(iterator.hasNext(), is(true));
            iterator.next();
            assertThat(iterator.hasNext(), is(false));
            success.set(true);
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler2);
    assertTrue(success.get());
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) NodeUtil(org.eol.globi.util.NodeUtil) Location(org.eol.globi.domain.Location) Date(java.util.Date) Direction(org.neo4j.graphdb.Direction) LocationImpl(org.eol.globi.domain.LocationImpl) CoreMatchers.not(org.hamcrest.CoreMatchers.not) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TermLookupService(org.eol.globi.service.TermLookupService) StringUtils(org.apache.commons.lang3.StringUtils) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) HashSet(java.util.HashSet) Calendar(java.util.Calendar) RelationshipListener(org.eol.globi.util.RelationshipListener) Is.is(org.hamcrest.core.Is.is) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ParseException(java.text.ParseException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Taxon(org.eol.globi.domain.Taxon) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) Iterator(java.util.Iterator) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) UberonLookupService(org.eol.globi.taxon.UberonLookupService) Assert.assertNotNull(org.junit.Assert.assertNotNull) DateTime(org.joda.time.DateTime) 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) Relationship(org.neo4j.graphdb.Relationship) Matchers.hasItem(org.hamcrest.Matchers.hasItem) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) SpecimenNode(org.eol.globi.domain.SpecimenNode) HashSet(java.util.HashSet) Set(java.util.Set) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) SpecimenNode(org.eol.globi.domain.SpecimenNode) Date(java.util.Date) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Relationship(org.neo4j.graphdb.Relationship) Iterator(java.util.Iterator) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Example 5 with NodeTypeDirection

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

the class DatasetImporterForCookTest method importFirstFewLines.

@Test
public void importFirstFewLines() throws IOException, NodeFactoryException, StudyImporterException {
    String firstFiveLines = "\"Date\",\"Individual\",\"Fish Length\",\"Infected\",\"Iso 1\",\"Iso 2\",\"Iso 3\",\"Iso 4 \",\"Iso 5\",\"Iso #\",,\n" + "8/10/2010,22,15.6,1,\"NA\",\"NA\",0,0,0,2,,\"Notes: All fish collected were Atlantic Croaker (Micropogonias undulatus) and measured in total length (cm). Isopods collected were Cymothoa excisa. For the Infected column 1= infected and 0= not infected. Numbers for the isopods are total length in cm and the Iso# represents the number of isopods found per fish. \"\n" + "8/10/2010,1,14.7,1,1.6,0.67,0,0,0,2,,\n" + "8/10/2010,5,14.2,1,1.53,0.7,0,0,0,2,,\n" + "8/10/2010,2,13.2,1,1.42,0.71,0.52,0.45,0,4,,\n";
    DatasetImporterForCook importer = new DatasetImporterForCook(new TestParserFactory(firstFiveLines), nodeFactory);
    importStudy(importer);
    StudyNode study = getStudySingleton(getGraphDb());
    Taxon hostTaxon = taxonIndex.findTaxonByName("Micropogonias undulatus");
    assertThat(hostTaxon, is(notNullValue()));
    Taxon parasiteTaxon = taxonIndex.findTaxonByName("Cymothoa excisa");
    assertThat(parasiteTaxon, is(notNullValue()));
    assertThat("missing location", nodeFactory.findLocation(new LocationImpl(27.85, -(97.0 + 8.0 / 60.0), -3.0, null)), is(notNullValue()));
    AtomicInteger count = new AtomicInteger(0);
    AtomicBoolean foundFirstHost = new AtomicBoolean(false);
    RelationshipListener handler = relationship -> {
        assertThat(relationship.getProperty(SpecimenConstant.EVENT_DATE), is(notNullValue()));
        Node specimen = relationship.getEndNode();
        if (specimen.hasProperty(SpecimenConstant.LENGTH_IN_MM)) {
            Object property = specimen.getProperty(SpecimenConstant.LENGTH_IN_MM);
            if (new Double(156.0).equals(property)) {
                assertTaxonClassification(specimen, ((NodeBacked) hostTaxon).getUnderlyingNode());
                foundFirstHost.set(true);
                Iterable<Relationship> parasiteRel = specimen.getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(InteractType.PARASITE_OF));
                for (Relationship rel : parasiteRel) {
                    Node parasite = rel.getStartNode();
                    assertThat(parasite.hasProperty(SpecimenConstant.LENGTH_IN_MM), is(false));
                    assertTaxonClassification(parasite, ((NodeBacked) parasiteTaxon).getUnderlyingNode());
                }
            }
        }
        count.incrementAndGet();
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
    assertThat(count.get(), is(14));
    assertThat(foundFirstHost.get(), is(true));
}
Also used : Taxon(org.eol.globi.domain.Taxon) NodeBacked(org.eol.globi.domain.NodeBacked) NodeUtil(org.eol.globi.util.NodeUtil) Direction(org.neo4j.graphdb.Direction) LocationImpl(org.eol.globi.domain.LocationImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) IOException(java.io.IOException) 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) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Is.is(org.hamcrest.core.Is.is) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Taxon(org.eol.globi.domain.Taxon) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodeBacked(org.eol.globi.domain.NodeBacked) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) Test(org.junit.Test)

Aggregations

NodeTypeDirection (org.eol.globi.util.NodeTypeDirection)29 StudyNode (org.eol.globi.domain.StudyNode)25 Node (org.neo4j.graphdb.Node)21 Relationship (org.neo4j.graphdb.Relationship)20 Test (org.junit.Test)19 NodeUtil (org.eol.globi.util.NodeUtil)16 RelationshipListener (org.eol.globi.util.RelationshipListener)16 SpecimenNode (org.eol.globi.domain.SpecimenNode)15 Direction (org.neo4j.graphdb.Direction)14 RelTypes (org.eol.globi.domain.RelTypes)12 Specimen (org.eol.globi.domain.Specimen)10 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)10 TaxonNode (org.eol.globi.domain.TaxonNode)9 IOException (java.io.IOException)8 InteractType (org.eol.globi.domain.InteractType)8 Is.is (org.hamcrest.core.Is.is)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Study (org.eol.globi.domain.Study)7 Assert.assertTrue (org.junit.Assert.assertTrue)7