Search in sources :

Example 26 with NodeTypeDirection

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

the class ExporterOccurrences method doExportStudy.

@Override
public void doExportStudy(StudyNode study, ExportUtil.Appender writer, boolean includeHeader) throws IOException {
    final List<IOException> first10Exceptions = new ArrayList<>();
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), collectedRel -> {
        Node specimenNode = collectedRel.getEndNode();
        if (isSpecimenClassified(specimenNode)) {
            try {
                handleSpecimen(study, writer, collectedRel, specimenNode);
            } catch (IOException e) {
                if (first10Exceptions.size() < 10) {
                    first10Exceptions.add(e);
                }
            }
        }
    });
    if (first10Exceptions.size() > 0) {
        throw first10Exceptions.get(0);
    }
}
Also used : NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 27 with NodeTypeDirection

use of org.eol.globi.util.NodeTypeDirection 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 28 with NodeTypeDirection

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

Example 29 with NodeTypeDirection

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

the class ExporterSiteMapForNames method export.

@Override
public void export(GraphDatabaseService graphDatabase, File baseDir) throws StudyImporterException {
    Set<String> names = new HashSet<String>();
    names.add("Homo sapiens");
    NodeUtil.findStudies(graphDatabase, node -> NodeUtil.handleCollectedRelationships(new NodeTypeDirection(new StudyNode(node).getUnderlyingNode()), specimen -> {
        final Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
        if (relationships.iterator().hasNext()) {
            final Node endNode = relationships.iterator().next().getEndNode();
            final TaxonNode taxonNode = new TaxonNode(endNode);
            names.add(taxonNode.getName());
        }
    }));
    final String queryParamName = "interactionType=interactsWith&sourceTaxon=";
    final String siteMapLocation = "https://depot.globalbioticinteractions.org/snapshot/target/data/sitemap/names/";
    SiteMapUtils.generateSiteMap(names, baseDir, queryParamName, siteMapLocation);
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) NodeListener(org.eol.globi.util.NodeListener) Direction(org.neo4j.graphdb.Direction) Set(java.util.Set) StudyNode(org.eol.globi.domain.StudyNode) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) File(java.io.File) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) StudyImporterException(org.eol.globi.data.StudyImporterException) SiteMapUtils(org.eol.globi.data.export.SiteMapUtils) HashSet(java.util.HashSet) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Study(org.eol.globi.domain.Study) TaxonNode(org.eol.globi.domain.TaxonNode) TaxonNode(org.eol.globi.domain.TaxonNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) HashSet(java.util.HashSet) StudyNode(org.eol.globi.domain.StudyNode)

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