Search in sources :

Example 16 with RelationshipListener

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

the class DatasetImporterForLifeWatchGreeceTest method readAssociations.

@Test
public void readAssociations() throws StudyImporterException {
    List<StudyNode> studies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(studies.size(), is(0));
    ParserFactoryLocal parserFactory = new ParserFactoryLocal();
    DatasetImporterForLifeWatchGreece importer = new DatasetImporterForLifeWatchGreece(parserFactory, nodeFactory);
    importer.setDataset(new DatasetLocal(inStream -> inStream));
    importStudy(importer);
    studies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(studies.size(), is(146));
    Set<String> taxa = new HashSet<String>();
    final AtomicInteger totalPredatorPreyRelationships = new AtomicInteger(0);
    for (StudyNode study : studies) {
        assertThat(study.getCitation(), is(notNullValue()));
        assertThat(study.getTitle(), containsString("greece"));
        RelationshipListener handler = relationship -> {
            addTaxonNameForSpecimenNode(taxa, relationship.getEndNode());
            Specimen predatorSpecimen = new SpecimenNode(relationship.getEndNode());
            Iterable<Relationship> prey = NodeUtil.getStomachContents(predatorSpecimen);
            for (Relationship ateRel : prey) {
                totalPredatorPreyRelationships.incrementAndGet();
                addTaxonNameForSpecimenNode(taxa, ateRel.getEndNode());
            }
        };
        NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
    }
    assertThat(taxa.contains("Aves"), is(true));
    assertThat(totalPredatorPreyRelationships.get(), is(793));
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Specimen(org.eol.globi.domain.Specimen) Set(java.util.Set) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) DatasetLocal(org.eol.globi.service.DatasetLocal) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) HashSet(java.util.HashSet) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SpecimenNode(org.eol.globi.domain.SpecimenNode) Matchers.containsString(org.hamcrest.Matchers.containsString) TaxonNode(org.eol.globi.domain.TaxonNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Matchers.containsString(org.hamcrest.Matchers.containsString) SpecimenNode(org.eol.globi.domain.SpecimenNode) DatasetLocal(org.eol.globi.service.DatasetLocal) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Specimen(org.eol.globi.domain.Specimen) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Relationship(org.neo4j.graphdb.Relationship) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with RelationshipListener

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

the class CmdGenerateReport method countInteractionsAndTaxa.

private void countInteractionsAndTaxa(Set<Long> ids, Counter interactionCounter, Set<Long> idsNoMatch, Node studyNode) {
    RelationshipListener handler = specimen -> {
        Iterable<Relationship> relationships = specimen.getEndNode().getRelationships();
        for (Relationship relationship : relationships) {
            InteractType[] types = InteractType.values();
            for (InteractType type : types) {
                if (relationship.isType(NodeUtil.asNeo4j(type)) && !relationship.hasProperty(PropertyAndValueDictionary.INVERTED)) {
                    interactionCounter.count();
                    break;
                }
            }
        }
        Relationship classifiedAs = specimen.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
        if (classifiedAs != null) {
            Node taxonNode = classifiedAs.getEndNode();
            ids.add(taxonNode.getId());
            if (!TaxonUtil.isResolved(new TaxonNode(taxonNode))) {
                idsNoMatch.add(taxonNode.getId());
            }
        }
    };
    NodeUtil.handleCollectedRelationshipsNoTx(new NodeTypeDirection(studyNode), handler);
}
Also used : CacheService(org.eol.globi.service.CacheService) TaxonUtil(org.eol.globi.service.TaxonUtil) Logger(org.slf4j.Logger) NodeUtil(org.eol.globi.util.NodeUtil) Direction(org.neo4j.graphdb.Direction) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) StudyConstant(org.eol.globi.domain.StudyConstant) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) UUID(java.util.UUID) StringUtils(org.apache.commons.lang3.StringUtils) 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) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) RelationshipListener(org.eol.globi.util.RelationshipListener) Dataset(org.globalbioticinteractions.dataset.Dataset) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) DB(org.mapdb.DB) TaxonNode(org.eol.globi.domain.TaxonNode) InteractType(org.eol.globi.domain.InteractType) TaxonNode(org.eol.globi.domain.TaxonNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Relationship(org.neo4j.graphdb.Relationship) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) RelationshipListener(org.eol.globi.util.RelationshipListener)

Example 18 with RelationshipListener

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

the class InteractionImporterTest method importBlankCitation.

@Test
public void importBlankCitation() throws StudyImporterException {
    final InteractionListener listener = new InteractionImporter(nodeFactory, (GeoNamesService) null, null);
    final TreeMap<String, String> link = new TreeMap<String, String>();
    link.put(SOURCE_OCCURRENCE_ID, "123");
    link.put(SOURCE_CATALOG_NUMBER, "catalogNumber123");
    link.put(SOURCE_COLLECTION_CODE, "collectionCode123");
    link.put(SOURCE_COLLECTION_ID, "collectionId123");
    link.put(SOURCE_INSTITUTION_CODE, "institutionCode123");
    link.put(TARGET_OCCURRENCE_ID, "456");
    link.put(TARGET_CATALOG_NUMBER, "targetCatalogNumber123");
    link.put(TARGET_COLLECTION_CODE, "targetCollectionCode123");
    link.put(TARGET_COLLECTION_ID, "targetCollectionId123");
    link.put(TARGET_INSTITUTION_CODE, "targetInstitutionCode123");
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(SOURCE_TAXON_ID, "duck");
    link.put(SOURCE_BODY_PART_ID, "bla:123");
    link.put(SOURCE_BODY_PART_NAME, "snout");
    link.put(SOURCE_LIFE_STAGE_ID, "some:stage");
    link.put(SOURCE_LIFE_STAGE_NAME, "stage");
    link.put(TARGET_TAXON_NAME, "mini");
    link.put(TARGET_TAXON_ID, "mouse");
    link.put(TARGET_BODY_PART_ID, "bla:345");
    link.put(TARGET_BODY_PART_NAME, "tail");
    link.put(DatasetImporterForMetaTable.EVENT_DATE, "20160404T21:31:40Z");
    link.put(DatasetImporterForMetaTable.LATITUDE, "12.1");
    link.put(DatasetImporterForMetaTable.LONGITUDE, "13.2");
    link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
    link.put(REFERENCE_ID, "123");
    link.put(DATASET_CITATION, "some source ref");
    link.put(REFERENCE_CITATION, "");
    link.put(REFERENCE_DOI, "doi:1234");
    listener.on(link);
    final AtomicBoolean foundPair = new AtomicBoolean(false);
    RelationshipListener relationshipListener = relationship -> {
        final SpecimenNode predator = new SpecimenNode(relationship.getEndNode());
        for (Relationship stomachRel : NodeUtil.getStomachContents(predator)) {
            final SpecimenNode prey = new SpecimenNode(stomachRel.getEndNode());
            final TaxonNode preyTaxon = getOrigTaxon(prey);
            final TaxonNode predTaxon = getOrigTaxon(predator);
            assertThat(preyTaxon.getName(), is("mini"));
            assertThat(preyTaxon.getExternalId(), is("mouse"));
            assertThat(predTaxon.getName(), is("donald"));
            assertThat(predTaxon.getExternalId(), is("duck"));
            assertLocation(predator.getSampleLocation());
            assertLocation(prey.getSampleLocation());
            assertThat(predator.getExternalId(), is("123"));
            assertThat(prey.getExternalId(), is("456"));
            assertThat(predator.getLifeStage().getId(), is("some:stage"));
            assertThat(predator.getLifeStage().getName(), is("stage"));
            assertThat(predator.getProperty(OCCURRENCE_ID), is("123"));
            assertThat(predator.getProperty(CATALOG_NUMBER), is("catalogNumber123"));
            assertThat(predator.getProperty(COLLECTION_CODE), is("collectionCode123"));
            assertThat(predator.getProperty(COLLECTION_ID), is("collectionId123"));
            assertThat(predator.getProperty(INSTITUTION_CODE), is("institutionCode123"));
            assertThat(prey.getProperty(OCCURRENCE_ID), is("456"));
            assertThat(prey.getProperty(CATALOG_NUMBER), is("targetCatalogNumber123"));
            assertThat(prey.getProperty(COLLECTION_CODE), is("targetCollectionCode123"));
            assertThat(prey.getProperty(COLLECTION_ID), is("targetCollectionId123"));
            assertThat(prey.getProperty(INSTITUTION_CODE), is("targetInstitutionCode123"));
            foundPair.set(true);
            assertThat(relationship.getProperty(SpecimenConstant.EVENT_DATE), is(notNullValue()));
            List<SpecimenNode> specimens = Arrays.asList(predator, prey);
            for (SpecimenNode specimen : specimens) {
                assertThat(specimen.getBodyPart().getId(), is(notNullValue()));
                assertThat(specimen.getBodyPart().getName(), is(notNullValue()));
            }
        }
    };
    handleRelations(relationshipListener, RelTypes.COLLECTED);
    assertThat(foundPair.get(), is(true));
}
Also used : Arrays(java.util.Arrays) NodeUtil(org.eol.globi.util.NodeUtil) SOURCE_BODY_PART_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_BODY_PART_ID) Date(java.util.Date) Direction(org.neo4j.graphdb.Direction) TARGET_SEX_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_SEX_ID) DatasetImporterForMetaTable(org.eol.globi.data.DatasetImporterForMetaTable) NullImportLogger(org.eol.globi.tool.NullImportLogger) InteractType(org.eol.globi.domain.InteractType) TARGET_TAXON_RANK(org.eol.globi.service.TaxonUtil.TARGET_TAXON_RANK) StudyImporterException(org.eol.globi.data.StudyImporterException) TARGET_TAXON_PATH_IDS(org.eol.globi.service.TaxonUtil.TARGET_TAXON_PATH_IDS) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DECIMAL_LONGITUDE(org.eol.globi.data.DatasetImporterForTSV.DECIMAL_LONGITUDE) COLLECTION_CODE(org.eol.globi.domain.PropertyAndValueDictionary.COLLECTION_CODE) TARGET_TAXON_ID(org.eol.globi.service.TaxonUtil.TARGET_TAXON_ID) SOURCE_TAXON_ID(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_ID) Is.is(org.hamcrest.core.Is.is) SOURCE_LIFE_STAGE_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME) LatLng(org.eol.globi.geo.LatLng) Assert.fail(org.junit.Assert.fail) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) TARGET_OCCURRENCE_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_OCCURRENCE_ID) SOURCE_TAXON_NAME(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_NAME) TARGET_INSTITUTION_CODE(org.eol.globi.data.DatasetImporterForTSV.TARGET_INSTITUTION_CODE) LOCALITY_NAME(org.eol.globi.data.DatasetImporterForTSV.LOCALITY_NAME) REFERENCE_ID(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_ID) SOURCE_COLLECTION_CODE(org.eol.globi.data.DatasetImporterForTSV.SOURCE_COLLECTION_CODE) LocationNode(org.eol.globi.domain.LocationNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) List(java.util.List) SOURCE_COLLECTION_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_COLLECTION_ID) SOURCE_TAXON_SPECIFIC_EPITHET(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_SPECIFIC_EPITHET) Assert.assertFalse(org.junit.Assert.assertFalse) SOURCE_CATALOG_NUMBER(org.eol.globi.data.DatasetImporterForTSV.SOURCE_CATALOG_NUMBER) SOURCE_TAXON_PATH(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_PATH) TARGET_COLLECTION_CODE(org.eol.globi.data.DatasetImporterForTSV.TARGET_COLLECTION_CODE) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) SpecimenNode(org.eol.globi.domain.SpecimenNode) TARGET_BODY_PART_NAME(org.eol.globi.data.DatasetImporterForTSV.TARGET_BODY_PART_NAME) DATASET_CITATION(org.eol.globi.data.DatasetImporterForTSV.DATASET_CITATION) SOURCE_TAXON_RANK(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_RANK) DateUtil(org.eol.globi.util.DateUtil) LogContext(org.eol.globi.domain.LogContext) COLLECTION_ID(org.eol.globi.domain.PropertyAndValueDictionary.COLLECTION_ID) OCCURRENCE_ID(org.eol.globi.domain.PropertyAndValueDictionary.OCCURRENCE_ID) TARGET_CATALOG_NUMBER(org.eol.globi.data.DatasetImporterForTSV.TARGET_CATALOG_NUMBER) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) SOURCE_SEX_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_SEX_NAME) SOURCE_BODY_PART_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_BODY_PART_NAME) SOURCE_TAXON_PATH_NAMES(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_PATH_NAMES) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CATALOG_NUMBER(org.eol.globi.domain.PropertyAndValueDictionary.CATALOG_NUMBER) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) SOURCE_OCCURRENCE_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_OCCURRENCE_ID) ARGUMENT_TYPE_ID(org.eol.globi.data.DatasetImporterForTSV.ARGUMENT_TYPE_ID) SOURCE_INSTITUTION_CODE(org.eol.globi.data.DatasetImporterForTSV.SOURCE_INSTITUTION_CODE) SOURCE_LIFE_STAGE_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_LIFE_STAGE_ID) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) TARGET_TAXON_NAME(org.eol.globi.service.TaxonUtil.TARGET_TAXON_NAME) TARGET_COLLECTION_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_COLLECTION_ID) INSTITUTION_CODE(org.eol.globi.domain.PropertyAndValueDictionary.INSTITUTION_CODE) SOURCE_TAXON_PATH_IDS(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_PATH_IDS) LOCALITY_ID(org.eol.globi.data.DatasetImporterForTSV.LOCALITY_ID) SOURCE_SEX_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_SEX_ID) DatasetImporterForTSV(org.eol.globi.data.DatasetImporterForTSV) GeoNamesService(org.eol.globi.service.GeoNamesService) TARGET_SEX_NAME(org.eol.globi.data.DatasetImporterForTSV.TARGET_SEX_NAME) Relationship(org.neo4j.graphdb.Relationship) TreeMap(java.util.TreeMap) NodeFactoryException(org.eol.globi.data.NodeFactoryException) DECIMAL_LATITUDE(org.eol.globi.data.DatasetImporterForTSV.DECIMAL_LATITUDE) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) REFERENCE_DOI(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_DOI) TARGET_BODY_PART_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_BODY_PART_ID) TaxonNode(org.eol.globi.domain.TaxonNode) REFERENCE_CITATION(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_CITATION) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaxonNode(org.eol.globi.domain.TaxonNode) Relationship(org.neo4j.graphdb.Relationship) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) SpecimenNode(org.eol.globi.domain.SpecimenNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Test(org.junit.Test)

Example 19 with RelationshipListener

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

the class InteractionImporterTest method importWithTaxonHierarchy.

@Test
public void importWithTaxonHierarchy() throws StudyImporterException {
    final InteractionListener listener = getAssertingInteractionImporter();
    final TreeMap<String, String> link = new TreeMap<>();
    link.put(SOURCE_TAXON_NAME, "Donald duck");
    link.put(SOURCE_TAXON_RANK, "species");
    link.put(SOURCE_TAXON_PATH, "Aves | Donald | Donald duck");
    link.put(SOURCE_TAXON_PATH_IDS, "AvesId | DonaldId | DonaldId duckId");
    link.put(SOURCE_TAXON_PATH_NAMES, "class | genus | species");
    link.put(SOURCE_TAXON_SPECIFIC_EPITHET, "duck");
    link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, InteractType.ATE.getIRI());
    link.put(TARGET_TAXON_NAME, "mini");
    link.put(TARGET_TAXON_RANK, "species");
    link.put(TARGET_TAXON_PATH_IDS, "miniId");
    link.put(DATASET_CITATION, "some source ref");
    link.put(REFERENCE_ID, "123");
    link.put(REFERENCE_CITATION, "");
    listener.on(link);
    AtomicInteger foundSpecimen = new AtomicInteger(0);
    RelationshipListener someListener = relationship -> {
        final SpecimenNode someSpecimen = new SpecimenNode(relationship.getEndNode());
        assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED)));
        assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS)));
        Node taxonNode = someSpecimen.getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS), Direction.OUTGOING).getEndNode();
        TaxonNode taxon = new TaxonNode(taxonNode);
        if (someSpecimen.getUnderlyingNode().hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE))) {
            assertThat(taxon.getPath(), is("Aves | Donald | Donald duck"));
            assertThat(taxon.getPathNames(), is("class | genus | species"));
            assertThat(taxon.getRank(), is("species"));
            assertThat(taxon.getPathIds(), is("AvesId | DonaldId | DonaldId duckId"));
            foundSpecimen.incrementAndGet();
        }
    };
    handleRelations(someListener, RelTypes.COLLECTED);
    assertThat(foundSpecimen.get(), is(1));
}
Also used : Arrays(java.util.Arrays) NodeUtil(org.eol.globi.util.NodeUtil) SOURCE_BODY_PART_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_BODY_PART_ID) Date(java.util.Date) Direction(org.neo4j.graphdb.Direction) TARGET_SEX_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_SEX_ID) DatasetImporterForMetaTable(org.eol.globi.data.DatasetImporterForMetaTable) NullImportLogger(org.eol.globi.tool.NullImportLogger) InteractType(org.eol.globi.domain.InteractType) TARGET_TAXON_RANK(org.eol.globi.service.TaxonUtil.TARGET_TAXON_RANK) StudyImporterException(org.eol.globi.data.StudyImporterException) TARGET_TAXON_PATH_IDS(org.eol.globi.service.TaxonUtil.TARGET_TAXON_PATH_IDS) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DECIMAL_LONGITUDE(org.eol.globi.data.DatasetImporterForTSV.DECIMAL_LONGITUDE) COLLECTION_CODE(org.eol.globi.domain.PropertyAndValueDictionary.COLLECTION_CODE) TARGET_TAXON_ID(org.eol.globi.service.TaxonUtil.TARGET_TAXON_ID) SOURCE_TAXON_ID(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_ID) Is.is(org.hamcrest.core.Is.is) SOURCE_LIFE_STAGE_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME) LatLng(org.eol.globi.geo.LatLng) Assert.fail(org.junit.Assert.fail) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) TARGET_OCCURRENCE_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_OCCURRENCE_ID) SOURCE_TAXON_NAME(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_NAME) TARGET_INSTITUTION_CODE(org.eol.globi.data.DatasetImporterForTSV.TARGET_INSTITUTION_CODE) LOCALITY_NAME(org.eol.globi.data.DatasetImporterForTSV.LOCALITY_NAME) REFERENCE_ID(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_ID) SOURCE_COLLECTION_CODE(org.eol.globi.data.DatasetImporterForTSV.SOURCE_COLLECTION_CODE) LocationNode(org.eol.globi.domain.LocationNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) List(java.util.List) SOURCE_COLLECTION_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_COLLECTION_ID) SOURCE_TAXON_SPECIFIC_EPITHET(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_SPECIFIC_EPITHET) Assert.assertFalse(org.junit.Assert.assertFalse) SOURCE_CATALOG_NUMBER(org.eol.globi.data.DatasetImporterForTSV.SOURCE_CATALOG_NUMBER) SOURCE_TAXON_PATH(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_PATH) TARGET_COLLECTION_CODE(org.eol.globi.data.DatasetImporterForTSV.TARGET_COLLECTION_CODE) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) SpecimenNode(org.eol.globi.domain.SpecimenNode) TARGET_BODY_PART_NAME(org.eol.globi.data.DatasetImporterForTSV.TARGET_BODY_PART_NAME) DATASET_CITATION(org.eol.globi.data.DatasetImporterForTSV.DATASET_CITATION) SOURCE_TAXON_RANK(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_RANK) DateUtil(org.eol.globi.util.DateUtil) LogContext(org.eol.globi.domain.LogContext) COLLECTION_ID(org.eol.globi.domain.PropertyAndValueDictionary.COLLECTION_ID) OCCURRENCE_ID(org.eol.globi.domain.PropertyAndValueDictionary.OCCURRENCE_ID) TARGET_CATALOG_NUMBER(org.eol.globi.data.DatasetImporterForTSV.TARGET_CATALOG_NUMBER) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) SOURCE_SEX_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_SEX_NAME) SOURCE_BODY_PART_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_BODY_PART_NAME) SOURCE_TAXON_PATH_NAMES(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_PATH_NAMES) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CATALOG_NUMBER(org.eol.globi.domain.PropertyAndValueDictionary.CATALOG_NUMBER) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) SOURCE_OCCURRENCE_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_OCCURRENCE_ID) ARGUMENT_TYPE_ID(org.eol.globi.data.DatasetImporterForTSV.ARGUMENT_TYPE_ID) SOURCE_INSTITUTION_CODE(org.eol.globi.data.DatasetImporterForTSV.SOURCE_INSTITUTION_CODE) SOURCE_LIFE_STAGE_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_LIFE_STAGE_ID) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) TARGET_TAXON_NAME(org.eol.globi.service.TaxonUtil.TARGET_TAXON_NAME) TARGET_COLLECTION_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_COLLECTION_ID) INSTITUTION_CODE(org.eol.globi.domain.PropertyAndValueDictionary.INSTITUTION_CODE) SOURCE_TAXON_PATH_IDS(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_PATH_IDS) LOCALITY_ID(org.eol.globi.data.DatasetImporterForTSV.LOCALITY_ID) SOURCE_SEX_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_SEX_ID) DatasetImporterForTSV(org.eol.globi.data.DatasetImporterForTSV) GeoNamesService(org.eol.globi.service.GeoNamesService) TARGET_SEX_NAME(org.eol.globi.data.DatasetImporterForTSV.TARGET_SEX_NAME) Relationship(org.neo4j.graphdb.Relationship) TreeMap(java.util.TreeMap) NodeFactoryException(org.eol.globi.data.NodeFactoryException) DECIMAL_LATITUDE(org.eol.globi.data.DatasetImporterForTSV.DECIMAL_LATITUDE) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) REFERENCE_DOI(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_DOI) TARGET_BODY_PART_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_BODY_PART_ID) TaxonNode(org.eol.globi.domain.TaxonNode) REFERENCE_CITATION(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_CITATION) TaxonNode(org.eol.globi.domain.TaxonNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocationNode(org.eol.globi.domain.LocationNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) TaxonNode(org.eol.globi.domain.TaxonNode) TreeMap(java.util.TreeMap) SpecimenNode(org.eol.globi.domain.SpecimenNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Test(org.junit.Test)

Example 20 with RelationshipListener

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

the class DatasetImporterForWrastTest method createAndPopulateStudyFromLavacaBay.

@Test
public void createAndPopulateStudyFromLavacaBay() throws StudyImporterException {
    String csvString = "\"Month\",\"Day\",\"Year\",\"Region\",\"Season\",\"Habitat\",\"Site\",\"Family\",\"Predator Species\",\"TL (mm)\",\"Prey Item Species\",\"Prey item\",\"Number\",\"Condition Index\",\"Volume\",\"Percent Content\",\"Prey Item Trophic Level\",\"Notes\",\"Call #\"\n";
    csvString += "7,24,2001,\"Lower\",\"Fall\",\"Marsh\",1,\"Sciaenidae\",\"Sciaenops ocellatus\",420,\"Acrididae spp. \",\"Acrididae \",1,\"III\",0.4,3.2520325203,2.5,,1\n";
    csvString += "7,25,2001,\"Lower\",\"Spring\",\"Non-Veg \",1,\"Ariidae\",\"Arius felis\",176,\"Aegathoa oculata \",\"Aegathoa oculata\",4,\"I\",0.01,3.3333333333,2.1,,2\n";
    csvString += "7,26,2001,\"Upper\",\"Spring\",\"Reef\",2,\"Depth\",\"Missing depth\",176,\"Aegathoa oculata \",\"Aegathoa oculata\",4,\"I\",0.01,3.3333333333,2.1,,2\n";
    Map<String, String> contentMap = new TreeMap<>();
    String locationString = "\"Location\",\"Latitude\",\"Longitude\",,\"Region\",\"Habitat\",\"Site\"\n" + "\"LM1\",28.595267,-96.477033,,\"Lower\",\"Marsh edge\",1\n" + "\"LSG1\",28.596233,-96.476483,,\"Lower\",\"Marsh edge\",1\n" + "\"LM2\",28.593150,-96.474633,,\"Lower\",\"Marsh edge\",2\n" + "\"LSG2\",28.594833,-96.473967,,\"Lower\",\"Marsh edge\",2\n" + "\"LNV1A\",28.608417,-96.475517,,\"Lower\",\"Non-Veg \",1\n" + "\"LNV1B\",28.607217,-96.474500,,\"Lower\",\"Non-Veg \",1\n" + "\"LNV2A\",28.592400,-96.483033,,\"Lower\",\"Non-Veg \",2\n" + "\"LNV2B\",28.590883,-96.484133,,\"Lower\",\"Non-Veg \",2\n" + "\"UR2B\",28.656483,-96.597217,,\"Upper\",\"Reef\",2";
    String envString = "\"Date\",\"Season\",\"Upper/Lower\",\"Habitat\",\"Site\",\"Air Temp (ºC)\",\"Wind Chill (ºC)\",\"Relative Humidity (%)\",\"Heat Index (ºC)\",\"Dew Point (ºC)\",\"Max Wind intensity (mph)\",\"Ave Wind intensity (mph)\",\"Wind Direction\",\"Cloud Cover (%)\",\"Rain?\",\"Depth (m)\",\"Temp (ºC) Surface\",\"Temp (ºC) Bottom\",\"Mean Temp Surface/Bottom\",\"pH Surface\",\"pH Bottom\",\"Mean pH Surface/Bottom\",\"DO (mg/L) Surface\",\"DO (mg/L) Bottom\",\"Mean DO Surface/Bottom\",\"Sal (o/oo) Surface\",\"Sal (o/oo) Bottom\",\"Mean Sal Surface/Bottom\",\"Secchi (m)\"\n" + "7/24/2006,\"Summer\",\"L\",\"R\",1,\"81.3 (F)\",\"81.5 (F)\",71.8,\"86.2 (F)\",\"70.6 (F)\",8.5,8.1,\"SE\",75,\"Yes\",1.9,30.79,30.34,30.565,8.11,8.13,8.12,5.16,4.8,4.98,22.8,23.07,22.935,0.4\n" + "7/24/2006,\"Summer\",\"L\",\"R\",2,\"81.3 (F)\",\"81.5 (F)\",71.8,\"86.2 (F)\",\"70.6 (F)\",8.5,8.1,\"SE\",75,\"Yes\",2.1,31.07,30.14,30.605,8.11,8.1,8.105,5.14,4.64,4.89,23.37,23.84,23.605,0.48\n" + "10/26/2006,\"Fall\",\"L\",\"M\",1,26.8,26.5,78,30,22.4,17.9,15,\"S \",95,\"No\",0.8,25.57,,25.57,8.29,,8.29,8.32,,8.32,21.26,,21.26,\"Bottom\"\n" + "10/26/2006,\"Fall\",\"L\",\"M\",2,26.8,26.5,78,30,22.4,17.9,15,\"S \",95,\"No\",0.4,25.84,,25.84,8.32,,8.32,8.21,,8.21,21.47,,21.47,\"Bottom\"\n" + "10/26/2006,\"Fall\",\"L\",\"SG\",1,26.8,26.5,78,30,22.4,17.9,15,\"S \",95,\"No\",0.8,25.57,,25.57,8.29,,8.29,8.32,,8.32,21.26,,21.26,\"Bottom\"\n" + "4/27/2007,\"Spring\",\"L\",\"R\",1,22.4,22.3,75,23.1,18.1,10.4,9.1,\"NW\",98,\"No\",1.6,23.43,23.39,23.41,,,,7.31,7.09,7.2,14.64,14.64,14.64,0.32\n" + "4/27/2007,\"Spring\",\"L\",\"R\",2,22.4,22.3,75,23.1,18.1,10.4,9.1,\"NW\",98,\"No\",2,23.77,23.77,23.77,,,,7.01,6.82,6.915,15.04,15.04,15.04,0.38\n" + "4/27/2007,\"Spring\",\"L\",\"NV\",1,22.4,22.3,75,23.1,18.1,10.4,9.1,\"NW\",98,\"No\",2,23.85,23.85,23.85,,,,6.96,6.81,6.885,14.65,14.65,14.65,0.48\n" + "4/27/2007,\"Spring\",\"L\",\"NV\",2,22.4,22.3,75,23.1,18.1,10.4,9.1,\"NW\",98,\"No\",1.8,23.78,23.78,23.78,,,,6.87,6.65,6.76,15.11,15.18,15.145,0.45";
    contentMap.put(DatasetImporterForWrast.LAVACA_BAY_LOCATIONS.toString(), locationString);
    contentMap.put(DatasetImporterForWrast.LAVACA_BAY_DATA_SOURCE.toString(), csvString);
    contentMap.put(DatasetImporterForWrast.LAVACA_BAY_ENVIRONMENTAL.toString(), envString);
    DatasetImporterForWrast importer = new DatasetImporterForWrast(new TestParserFactory(contentMap), nodeFactory);
    importStudy(importer);
    assertThat(getSpecimenCount(getStudySingleton(getGraphDb())), is(5));
    assertNotNull(taxonIndex.findTaxonByName("Sciaenops ocellatus"));
    assertNotNull(taxonIndex.findTaxonByName("Arius felis"));
    assertNotNull(taxonIndex.findTaxonByName("Aegathoa oculata"));
    assertNotNull(nodeFactory.findSeason("spring"));
    assertNotNull(nodeFactory.findSeason("fall"));
    AtomicReference<StudyNode> foundStudyRef = new AtomicReference<>();
    NodeUtil.findStudies(getGraphDb(), new NodeListener() {

        @Override
        public void on(Node node) {
            foundStudyRef.set(new StudyNode(node));
        }
    });
    StudyNode foundStudy = foundStudyRef.get();
    assertNotNull(foundStudy);
    assertThat(foundStudy.getTitle(), is("Wrast 2008"));
    RelationshipListener handler = relationship -> {
        Date unixEpochProperty = null;
        try {
            unixEpochProperty = nodeFactory.getUnixEpochProperty(new SpecimenNode(relationship.getEndNode()));
        } catch (NodeFactoryException e) {
            fail(e.getMessage());
        }
        SimpleDateFormat simpleDateFormat = DatasetImporterForWrast.getSimpleDateFormat();
        Date endDate = null;
        try {
            endDate = simpleDateFormat.parse("7/27/2001");
        } catch (ParseException e) {
            fail(e.getMessage());
        }
        Date startDate = null;
        try {
            startDate = simpleDateFormat.parse("7/23/2001");
        } catch (ParseException e) {
            fail(e.getMessage());
        }
        assertThat(unixEpochProperty.before(endDate), is(true));
        assertThat(unixEpochProperty.after(startDate), is(true));
        Specimen specimen = new SpecimenNode(relationship.getEndNode());
        for (Relationship ignored : NodeUtil.getStomachContents(specimen)) {
            TaxonNode taxon = new TaxonNode(relationship.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode());
            String scientificName = taxon.getName();
            if ("Sciaenops ocellatus".equals(scientificName)) {
                Location location = specimen.getSampleLocation();
                assertThat(location, is(not(nullValue())));
                assertThat(location.getLatitude(), is((28.595267 + 28.596233) / 2.0));
                assertThat(location.getLongitude(), is((-96.477033 - 96.476483) / 2.0));
                assertThat(location.getAltitude(), is(-0.8));
                Iterable<Relationship> stomachContents = NodeUtil.getStomachContents(specimen);
                int count = 0;
                for (Relationship containsRel : stomachContents) {
                    Node endNode = containsRel.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
                    Object name = endNode.getProperty("name");
                    String name1 = (String) name;
                    assertThat(name1.replaceAll("\\W", ""), is("Acrididae"));
                    count++;
                }
                assertEquals(1, count);
                Season season = specimen.getSeason();
                assertEquals("fall", season.getTitle());
                assertEquals(420.0d, specimen.getLengthInMm(), 0.01);
            } else if ("Arius felis".equals(scientificName)) {
                Location location = specimen.getSampleLocation();
                assertThat(location, is(not(nullValue())));
                assertThat(location.getLatitude(), is((28.608417 + 28.607217) / 2.0));
                assertThat(location.getLongitude(), is((-96.475517 - 96.474500) / 2.0));
                assertThat(location.getAltitude(), is(-2.0d));
                Iterable<Relationship> stomachContents = NodeUtil.getStomachContents(specimen);
                int count = 0;
                for (Relationship containsRel : stomachContents) {
                    Object name = containsRel.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode().getProperty("name");
                    assertEquals("Aegathoa oculata", name);
                    count++;
                }
                assertEquals(2, count);
                Season season = specimen.getSeason();
                assertEquals("spring", season.getTitle());
                assertEquals(176.0d, specimen.getLengthInMm(), 0.01);
            } else if ("Missing depth".equals(scientificName)) {
                Location location = specimen.getSampleLocation();
                assertThat(location, is(not(nullValue())));
                assertThat(location.getAltitude(), is(nullValue()));
            } else {
                fail("unexpected scientificName of predator [" + scientificName + "]");
            }
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(getStudySingleton(getGraphDb()).getUnderlyingNode()), handler);
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Specimen(org.eol.globi.domain.Specimen) Location(org.eol.globi.domain.Location) Date(java.util.Date) Direction(org.neo4j.graphdb.Direction) CoreMatchers.not(org.hamcrest.CoreMatchers.not) SimpleDateFormat(java.text.SimpleDateFormat) RelTypes(org.eol.globi.domain.RelTypes) Season(org.eol.globi.domain.Season) AtomicReference(java.util.concurrent.atomic.AtomicReference) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) RelationshipListener(org.eol.globi.util.RelationshipListener) Map(java.util.Map) 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) NodeListener(org.eol.globi.util.NodeListener) Assert.assertNotNull(org.junit.Assert.assertNotNull) 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) SpecimenNode(org.eol.globi.domain.SpecimenNode) Study(org.eol.globi.domain.Study) Assert.assertEquals(org.junit.Assert.assertEquals) TaxonNode(org.eol.globi.domain.TaxonNode) TaxonNode(org.eol.globi.domain.TaxonNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) TaxonNode(org.eol.globi.domain.TaxonNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Specimen(org.eol.globi.domain.Specimen) Season(org.eol.globi.domain.Season) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) NodeListener(org.eol.globi.util.NodeListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) Date(java.util.Date) StudyNode(org.eol.globi.domain.StudyNode) Relationship(org.neo4j.graphdb.Relationship) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Location(org.eol.globi.domain.Location) 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