Search in sources :

Example 21 with RelationshipListener

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

the class ExporterRDF method exportStudy.

@Override
public void exportStudy(StudyNode study, ExportUtil.Appender appender, boolean includeHeader) throws IOException {
    AtomicReference<IOException> lastException = new AtomicReference<>();
    RelationshipListener handler = relationship -> {
        try {
            Node agentNode = relationship.getEndNode();
            for (Relationship ixnR : agentNode.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j())) {
                writeStatement(appender, Arrays.asList(blankNode(ixnR), iriNode(HAS_TYPE), iriNode(INTERACTION)));
                writeParticipantStatements(appender, ixnR, ixnR.getEndNode());
                writeParticipantStatements(appender, ixnR, agentNode);
                writeStatement(appender, Arrays.asList(blankNode(agentNode), iriNode(InteractType.valueOf(ixnR.getType().name()).getIRI()), blankNode(ixnR.getEndNode())));
            }
        } catch (IOException ex) {
            lastException.set(ex);
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
    if (lastException.get() != null) {
        throw lastException.get();
    }
}
Also used : Arrays(java.util.Arrays) NodeUtil(org.eol.globi.util.NodeUtil) Direction(org.neo4j.graphdb.Direction) LocationNode(org.eol.globi.domain.LocationNode) Environment(org.eol.globi.domain.Environment) ExternalIdUtil(org.eol.globi.util.ExternalIdUtil) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) StringUtils(org.apache.commons.lang3.StringUtils) RelTypes(org.eol.globi.domain.RelTypes) AtomicReference(java.util.concurrent.atomic.AtomicReference) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) ArrayList(java.util.ArrayList) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener) SpecimenNode(org.eol.globi.domain.SpecimenNode) TaxonNode(org.eol.globi.domain.TaxonNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) LocationNode(org.eol.globi.domain.LocationNode) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) TaxonNode(org.eol.globi.domain.TaxonNode) Relationship(org.neo4j.graphdb.Relationship) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) RelationshipListener(org.eol.globi.util.RelationshipListener)

Example 22 with RelationshipListener

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

the class ExporterAssociations 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 {
                handleSpecimen(study, writer, properties, specimenNode);
            } 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) Direction(org.neo4j.graphdb.Direction) 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) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) Map(java.util.Map) 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)

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