@Test public void evidenceIsAdded() { assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(5)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(1)); aspect.invoke(graph); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(6)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(4)); }
@Override public void invoke(Graph graph) { Set<Long> nodeIds = newHashSet(transform(graph.getVertices(), new Function<Vertex, Long>() { @Override public Long apply(Vertex vertex) { return Long.valueOf((String) vertex.getId()); } })); try (Transaction tx = graphDb.beginTx()) { for (Vertex vertex : graph.getVertices()) { Node subject = graphDb.getNodeById(Long.parseLong((String) vertex.getId())); for (Relationship hasSubject : subject.getRelationships(HAS_SUBJECT, Direction.INCOMING)) { Node association = hasSubject.getOtherNode(subject); for (Relationship hasObject : association.getRelationships(HAS_OBJECT, Direction.OUTGOING)) { Node object = hasObject.getOtherNode(association); if (nodeIds.contains(object.getId())) { Iterator<Relationship> objectProperty = association.getRelationships(HAS_PREDICATE, Direction.OUTGOING).iterator(); if (objectProperty.hasNext()) { Relationship hasPredicate = objectProperty.next(); Node relationshipNode = hasPredicate.getOtherNode(association); String objectPropertyRelationship = GraphUtil.getProperty(relationshipNode, NodeProperties.IRI, String.class).get(); String objectPropertyRelationshipCurie = curieUtil.getCurie(objectPropertyRelationship).orElse(objectPropertyRelationship); boolean isEdgeInGraph = false; Iterator<Vertex> connectedVertices = vertex.getVertices(com.tinkerpop.blueprints.Direction.BOTH, objectPropertyRelationshipCurie).iterator(); while (connectedVertices.hasNext()) { if (Long.parseLong((String) connectedVertices.next().getId()) == object.getId()) { isEdgeInGraph = true; } } if (isEdgeInGraph) { TinkerGraphUtil tgu = new TinkerGraphUtil(graph, curieUtil); tgu.addEdge(hasSubject); tgu.addEdge(hasPredicate); tgu.addEdge(hasObject); for (Relationship evidence : association.getRelationships(EVIDENCE, Direction.OUTGOING)) { tgu.addEdge(evidence); } for (Relationship source : association.getRelationships(SOURCE, Direction.OUTGOING)) { tgu.addEdge(source); } } } else { logger.severe(GraphUtil.getProperty(association, NodeProperties.IRI, String.class) .orElse(Long.toString(association.getId())) + " does not have the relation '" + HAS_PREDICATE.name() + "'. Ignoring this association."); } } } } } tx.success(); } }
EvidenceAspect implements GraphAspect { @Override public void invoke(Graph graph) { Set<Long> nodeIds = newHashSet(transform(graph.getVertices(), new Function<Vertex, Long>() { @Override public Long apply(Vertex vertex) { return Long.valueOf((String) vertex.getId()); } })); try (Transaction tx = graphDb.beginTx()) { for (Vertex vertex : graph.getVertices()) { Node subject = graphDb.getNodeById(Long.parseLong((String) vertex.getId())); for (Relationship hasSubject : subject.getRelationships(HAS_SUBJECT, Direction.INCOMING)) { Node association = hasSubject.getOtherNode(subject); for (Relationship hasObject : association.getRelationships(HAS_OBJECT, Direction.OUTGOING)) { Node object = hasObject.getOtherNode(association); if (nodeIds.contains(object.getId())) { Iterator<Relationship> objectProperty = association.getRelationships(HAS_PREDICATE, Direction.OUTGOING).iterator(); if (objectProperty.hasNext()) { Relationship hasPredicate = objectProperty.next(); Node relationshipNode = hasPredicate.getOtherNode(association); String objectPropertyRelationship = GraphUtil.getProperty(relationshipNode, NodeProperties.IRI, String.class).get(); String objectPropertyRelationshipCurie = curieUtil.getCurie(objectPropertyRelationship).orElse(objectPropertyRelationship); boolean isEdgeInGraph = false; Iterator<Vertex> connectedVertices = vertex.getVertices(com.tinkerpop.blueprints.Direction.BOTH, objectPropertyRelationshipCurie).iterator(); while (connectedVertices.hasNext()) { if (Long.parseLong((String) connectedVertices.next().getId()) == object.getId()) { isEdgeInGraph = true; } } if (isEdgeInGraph) { TinkerGraphUtil tgu = new TinkerGraphUtil(graph, curieUtil); tgu.addEdge(hasSubject); tgu.addEdge(hasPredicate); tgu.addEdge(hasObject); for (Relationship evidence : association.getRelationships(EVIDENCE, Direction.OUTGOING)) { tgu.addEdge(evidence); } for (Relationship source : association.getRelationships(SOURCE, Direction.OUTGOING)) { tgu.addEdge(source); } } } else { logger.severe(GraphUtil.getProperty(association, NodeProperties.IRI, String.class) .orElse(Long.toString(association.getId())) + " does not have the relation '" + HAS_PREDICATE.name() + "'. Ignoring this association."); } } } } } tx.success(); } } }
EvidenceAspect implements GraphAspect { @Override public void invoke(Graph graph) { Set<Long> nodeIds = newHashSet(transform(graph.getVertices(), new Function<Vertex, Long>() { @Override public Long apply(Vertex vertex) { return Long.valueOf((String) vertex.getId()); } })); try (Transaction tx = graphDb.beginTx()) { for (Vertex vertex : graph.getVertices()) { Node subject = graphDb.getNodeById(Long.parseLong((String) vertex.getId())); for (Relationship hasSubject : subject.getRelationships(HAS_SUBJECT, Direction.INCOMING)) { Node association = hasSubject.getOtherNode(subject); for (Relationship hasObject : association.getRelationships(HAS_OBJECT, Direction.OUTGOING)) { Node object = hasObject.getOtherNode(association); if (nodeIds.contains(object.getId())) { Iterator<Relationship> objectProperty = association.getRelationships(HAS_PREDICATE, Direction.OUTGOING).iterator(); if (objectProperty.hasNext()) { Relationship hasPredicate = objectProperty.next(); Node relationshipNode = hasPredicate.getOtherNode(association); String objectPropertyRelationship = GraphUtil.getProperty(relationshipNode, NodeProperties.IRI, String.class).get(); String objectPropertyRelationshipCurie = curieUtil.getCurie(objectPropertyRelationship).orElse(objectPropertyRelationship); boolean isEdgeInGraph = false; Iterator<Vertex> connectedVertices = vertex.getVertices(com.tinkerpop.blueprints.Direction.BOTH, objectPropertyRelationshipCurie).iterator(); while (connectedVertices.hasNext()) { if (Long.parseLong((String) connectedVertices.next().getId()) == object.getId()) { isEdgeInGraph = true; } } if (isEdgeInGraph) { TinkerGraphUtil tgu = new TinkerGraphUtil(graph, curieUtil); tgu.addEdge(hasSubject); tgu.addEdge(hasPredicate); tgu.addEdge(hasObject); for (Relationship evidence : association.getRelationships(EVIDENCE, Direction.OUTGOING)) { tgu.addEdge(evidence); } for (Relationship source : association.getRelationships(SOURCE, Direction.OUTGOING)) { tgu.addEdge(source); } } } else { logger.severe(GraphUtil.getProperty(association, NodeProperties.IRI, String.class) .orElse(Long.toString(association.getId())) + " does not have the relation '" + HAS_PREDICATE.name() + "'. Ignoring this association."); } } } } } tx.success(); } } @Inject  EvidenceAspect(GraphDatabaseService graphDb, CurieUtil curieUtil); }
EvidenceAspect implements GraphAspect { @Override public void invoke(Graph graph) { Set<Long> nodeIds = newHashSet(transform(graph.getVertices(), new Function<Vertex, Long>() { @Override public Long apply(Vertex vertex) { return Long.valueOf((String) vertex.getId()); } })); try (Transaction tx = graphDb.beginTx()) { for (Vertex vertex : graph.getVertices()) { Node subject = graphDb.getNodeById(Long.parseLong((String) vertex.getId())); for (Relationship hasSubject : subject.getRelationships(HAS_SUBJECT, Direction.INCOMING)) { Node association = hasSubject.getOtherNode(subject); for (Relationship hasObject : association.getRelationships(HAS_OBJECT, Direction.OUTGOING)) { Node object = hasObject.getOtherNode(association); if (nodeIds.contains(object.getId())) { Iterator<Relationship> objectProperty = association.getRelationships(HAS_PREDICATE, Direction.OUTGOING).iterator(); if (objectProperty.hasNext()) { Relationship hasPredicate = objectProperty.next(); Node relationshipNode = hasPredicate.getOtherNode(association); String objectPropertyRelationship = GraphUtil.getProperty(relationshipNode, NodeProperties.IRI, String.class).get(); String objectPropertyRelationshipCurie = curieUtil.getCurie(objectPropertyRelationship).orElse(objectPropertyRelationship); boolean isEdgeInGraph = false; Iterator<Vertex> connectedVertices = vertex.getVertices(com.tinkerpop.blueprints.Direction.BOTH, objectPropertyRelationshipCurie).iterator(); while (connectedVertices.hasNext()) { if (Long.parseLong((String) connectedVertices.next().getId()) == object.getId()) { isEdgeInGraph = true; } } if (isEdgeInGraph) { TinkerGraphUtil tgu = new TinkerGraphUtil(graph, curieUtil); tgu.addEdge(hasSubject); tgu.addEdge(hasPredicate); tgu.addEdge(hasObject); for (Relationship evidence : association.getRelationships(EVIDENCE, Direction.OUTGOING)) { tgu.addEdge(evidence); } for (Relationship source : association.getRelationships(SOURCE, Direction.OUTGOING)) { tgu.addEdge(source); } } } else { logger.severe(GraphUtil.getProperty(association, NodeProperties.IRI, String.class) .orElse(Long.toString(association.getId())) + " does not have the relation '" + HAS_PREDICATE.name() + "'. Ignoring this association."); } } } } } tx.success(); } } @Inject  EvidenceAspect(GraphDatabaseService graphDb, CurieUtil curieUtil); @Override void invoke(Graph graph); }
EvidenceAspect implements GraphAspect { @Override public void invoke(Graph graph) { Set<Long> nodeIds = newHashSet(transform(graph.getVertices(), new Function<Vertex, Long>() { @Override public Long apply(Vertex vertex) { return Long.valueOf((String) vertex.getId()); } })); try (Transaction tx = graphDb.beginTx()) { for (Vertex vertex : graph.getVertices()) { Node subject = graphDb.getNodeById(Long.parseLong((String) vertex.getId())); for (Relationship hasSubject : subject.getRelationships(HAS_SUBJECT, Direction.INCOMING)) { Node association = hasSubject.getOtherNode(subject); for (Relationship hasObject : association.getRelationships(HAS_OBJECT, Direction.OUTGOING)) { Node object = hasObject.getOtherNode(association); if (nodeIds.contains(object.getId())) { Iterator<Relationship> objectProperty = association.getRelationships(HAS_PREDICATE, Direction.OUTGOING).iterator(); if (objectProperty.hasNext()) { Relationship hasPredicate = objectProperty.next(); Node relationshipNode = hasPredicate.getOtherNode(association); String objectPropertyRelationship = GraphUtil.getProperty(relationshipNode, NodeProperties.IRI, String.class).get(); String objectPropertyRelationshipCurie = curieUtil.getCurie(objectPropertyRelationship).orElse(objectPropertyRelationship); boolean isEdgeInGraph = false; Iterator<Vertex> connectedVertices = vertex.getVertices(com.tinkerpop.blueprints.Direction.BOTH, objectPropertyRelationshipCurie).iterator(); while (connectedVertices.hasNext()) { if (Long.parseLong((String) connectedVertices.next().getId()) == object.getId()) { isEdgeInGraph = true; } } if (isEdgeInGraph) { TinkerGraphUtil tgu = new TinkerGraphUtil(graph, curieUtil); tgu.addEdge(hasSubject); tgu.addEdge(hasPredicate); tgu.addEdge(hasObject); for (Relationship evidence : association.getRelationships(EVIDENCE, Direction.OUTGOING)) { tgu.addEdge(evidence); } for (Relationship source : association.getRelationships(SOURCE, Direction.OUTGOING)) { tgu.addEdge(source); } } } else { logger.severe(GraphUtil.getProperty(association, NodeProperties.IRI, String.class) .orElse(Long.toString(association.getId())) + " does not have the relation '" + HAS_PREDICATE.name() + "'. Ignoring this association."); } } } } } tx.success(); } } @Inject  EvidenceAspect(GraphDatabaseService graphDb, CurieUtil curieUtil); @Override void invoke(Graph graph);  }