Search in sources :

Example 1 with RelationshipListener

use of org.eol.globi.util.RelationshipListener 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 RelationshipListener

use of org.eol.globi.util.RelationshipListener 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 RelationshipListener

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

the class InteractionImporterTest method importWithLocalityAndLatLng.

@Test
public void importWithLocalityAndLatLng() throws StudyImporterException {
    final InteractionListener listener = getAssertingInteractionImporter();
    final TreeMap<String, String> link = new TreeMap<>();
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(SOURCE_TAXON_ID, "duck");
    link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
    link.put(TARGET_TAXON_NAME, "mini");
    link.put(TARGET_TAXON_ID, "mouse");
    link.put(LOCALITY_ID, "back:yard");
    link.put(LOCALITY_NAME, "my back yard");
    link.put(DECIMAL_LATITUDE, "12.2");
    link.put(DECIMAL_LONGITUDE, "13.2");
    link.put(REFERENCE_ID, "123");
    link.put(DATASET_CITATION, "some source ref");
    link.put(REFERENCE_CITATION, "");
    link.put(REFERENCE_DOI, "doi:10.12/34");
    listener.on(link);
    AtomicBoolean foundSpecimen = new AtomicBoolean(false);
    RelationshipListener someListener = relationship -> {
        final SpecimenNode someSpecimen = new SpecimenNode(relationship.getEndNode());
        assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED)));
        LocationNode sampleLocation = someSpecimen.getSampleLocation();
        assertThat(sampleLocation.getLatitude(), is(12.2d));
        assertThat(sampleLocation.getLongitude(), is(13.2d));
        assertThat(sampleLocation.getLocality(), is("my back yard"));
        assertThat(sampleLocation.getLocalityId(), is("back:yard"));
        foundSpecimen.set(true);
    };
    handleRelations(someListener, RelTypes.COLLECTED);
    assertThat(foundSpecimen.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) LocationNode(org.eol.globi.domain.LocationNode) TreeMap(java.util.TreeMap) SpecimenNode(org.eol.globi.domain.SpecimenNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Test(org.junit.Test)

Example 4 with RelationshipListener

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

the class InteractionImporterTest method importRefutingClaim.

@Test
public void importRefutingClaim() throws StudyImporterException {
    final InteractionListener listener = getAssertingInteractionImporter();
    final TreeMap<String, String> link = new TreeMap<>();
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(SOURCE_TAXON_ID, "duck");
    link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
    link.put(TARGET_TAXON_NAME, "mini");
    link.put(TARGET_TAXON_ID, "mouse");
    link.put(ARGUMENT_TYPE_ID, "https://en.wiktionary.org/wiki/refute");
    link.put(REFERENCE_ID, "123");
    link.put(DATASET_CITATION, "some source ref");
    link.put(REFERENCE_CITATION, "");
    link.put(REFERENCE_DOI, "doi:10.12/34");
    listener.on(link);
    AtomicBoolean foundSpecimen = new AtomicBoolean(false);
    RelationshipListener relHandler = relationship -> {
        final SpecimenNode someSpecimen = new SpecimenNode(relationship.getEndNode());
        assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.REFUTES)));
        assertFalse(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED)));
        foundSpecimen.set(true);
    };
    handleRelations(relHandler, RelTypes.REFUTES);
    assertThat(foundSpecimen.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) TreeMap(java.util.TreeMap) SpecimenNode(org.eol.globi.domain.SpecimenNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Test(org.junit.Test)

Example 5 with RelationshipListener

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

the class InteractionImporterTest method importWithSex.

@Test
public void importWithSex() throws StudyImporterException {
    final InteractionListener listener = getAssertingInteractionImporter();
    final TreeMap<String, String> link = new TreeMap<>();
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(SOURCE_SEX_NAME, "female");
    link.put(SOURCE_SEX_ID, "some:female");
    link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, InteractType.ATE.getIRI());
    link.put(TARGET_TAXON_NAME, "mini");
    link.put(TARGET_SEX_NAME, "male");
    link.put(TARGET_SEX_ID, "some:male");
    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(InteractType.ATE)));
        if (someSpecimen.getUnderlyingNode().hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE))) {
            assertThat(someSpecimen.getSex().getName(), is("female"));
            assertThat(someSpecimen.getSex().getId(), is("some:female"));
        } else {
            assertThat(someSpecimen.getSex().getName(), is("male"));
            assertThat(someSpecimen.getSex().getId(), is("some:male"));
        }
        foundSpecimen.incrementAndGet();
    };
    handleRelations(someListener, RelTypes.COLLECTED);
    assertThat(foundSpecimen.get(), is(2));
}
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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TreeMap(java.util.TreeMap) SpecimenNode(org.eol.globi.domain.SpecimenNode) 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