private Vertex getOtherVertexFromEdge(Edge edge, Authorizations authorizations) { if (edge.getVertexId(Direction.IN).equals(getId())) { return edge.getVertex(Direction.OUT, authorizations); } if (edge.getVertexId(Direction.OUT).equals(getId())) { return edge.getVertex(Direction.IN, authorizations); } throw new IllegalStateException("Edge does not contain vertex on either end"); }
@Override public void addElement(SearchIndex searchIndex, Graph graph, Element element, Authorizations authorizations) { if (!getConfig().isUpdateEdgeBoost()) { return; } if (!(element instanceof Edge)) { return; } Element vOut = ((Edge) element).getVertex(Direction.OUT, authorizations); if (vOut != null) { searchIndex.addElement(graph, vOut, authorizations); } Element vIn = ((Edge) element).getVertex(Direction.IN, authorizations); if (vIn != null) { searchIndex.addElement(graph, vIn, authorizations); } }
@Override public void markEdgeHidden(Edge edge, Visibility visibility, Authorizations authorizations) { checkNotNull(edge); Vertex out = edge.getVertex(Direction.OUT, authorizations); if (out == null) { throw new SecureGraphException(String.format("Unable to mark edge hidden %s, can't find out vertex %s", edge.getId(), edge.getVertexId(Direction.OUT))); } Vertex in = edge.getVertex(Direction.IN, authorizations); if (in == null) { throw new SecureGraphException(String.format("Unable to mark edge hidden %s, can't find in vertex %s", edge.getId(), edge.getVertexId(Direction.IN))); } ColumnVisibility columnVisibility = visibilityToAccumuloVisibility(visibility); Mutation outMutation = new Mutation(AccumuloConstants.VERTEX_ROW_KEY_PREFIX + out.getId()); outMutation.put(AccumuloVertex.CF_OUT_EDGE_HIDDEN, new Text(edge.getId()), columnVisibility, AccumuloElement.HIDDEN_VALUE); Mutation inMutation = new Mutation(AccumuloConstants.VERTEX_ROW_KEY_PREFIX + in.getId()); inMutation.put(AccumuloVertex.CF_IN_EDGE_HIDDEN, new Text(edge.getId()), columnVisibility, AccumuloElement.HIDDEN_VALUE); addMutations(getVerticesWriter(), outMutation, inMutation); // Remove everything else related to edge. addMutations(getEdgesWriter(), getMarkHiddenRowMutation(AccumuloConstants.EDGE_ROW_KEY_PREFIX + edge.getId(), columnVisibility)); if (out instanceof AccumuloVertex) { ((AccumuloVertex) out).removeOutEdge(edge); } if (in instanceof AccumuloVertex) { ((AccumuloVertex) in).removeInEdge(edge); } if (hasEventListeners()) { queueEvent(new MarkHiddenEdgeEvent(this, edge)); } }
@Override public void addElement(SearchIndex searchIndex, Graph graph, Element element, Authorizations authorizations) { if (!getConfig().isUpdateEdgeBoost()) { return; } if (!(element instanceof Edge)) { return; } Element vOut = ((Edge) element).getVertex(Direction.OUT, authorizations); if (vOut != null) { searchIndex.addElement(graph, vOut, authorizations); } Element vIn = ((Edge) element).getVertex(Direction.IN, authorizations); if (vIn != null) { searchIndex.addElement(graph, vIn, authorizations); } }
@Override public void markEdgeVisible(Edge edge, Visibility visibility, Authorizations authorizations) { checkNotNull(edge); Vertex out = edge.getVertex(Direction.OUT, FetchHint.ALL_INCLUDING_HIDDEN, authorizations); if (out == null) { throw new SecureGraphException(String.format("Unable to mark edge visible %s, can't find out vertex %s", edge.getId(), edge.getVertexId(Direction.OUT))); } Vertex in = edge.getVertex(Direction.IN, FetchHint.ALL_INCLUDING_HIDDEN, authorizations); if (in == null) { throw new SecureGraphException(String.format("Unable to mark edge visible %s, can't find in vertex %s", edge.getId(), edge.getVertexId(Direction.IN))); } ColumnVisibility columnVisibility = visibilityToAccumuloVisibility(visibility); Mutation outMutation = new Mutation(AccumuloConstants.VERTEX_ROW_KEY_PREFIX + out.getId()); outMutation.putDelete(AccumuloVertex.CF_OUT_EDGE_HIDDEN, new Text(edge.getId()), columnVisibility); Mutation inMutation = new Mutation(AccumuloConstants.VERTEX_ROW_KEY_PREFIX + in.getId()); inMutation.putDelete(AccumuloVertex.CF_IN_EDGE_HIDDEN, new Text(edge.getId()), columnVisibility); addMutations(getVerticesWriter(), outMutation, inMutation); // Remove everything else related to edge. addMutations(getEdgesWriter(), getMarkVisibleRowMutation(AccumuloConstants.EDGE_ROW_KEY_PREFIX + edge.getId(), columnVisibility)); if (out instanceof AccumuloVertex) { ((AccumuloVertex) out).addOutEdge(edge); } if (in instanceof AccumuloVertex) { ((AccumuloVertex) in).addInEdge(edge); } if (hasEventListeners()) { queueEvent(new MarkVisibleEdgeEvent(this, edge)); } }
@Override public int addElement(ElasticSearchSearchIndexBase searchIndex, Graph graph, BulkRequestWithCount bulkRequestWithCount, IndexInfo indexInfo, Element element, Authorizations authorizations) { int totalCount = 0; if (!getConfig().isUpdateEdgeBoost()) { return totalCount; } if (!(element instanceof Edge)) { return totalCount; } Element vOut = ((Edge) element).getVertex(Direction.OUT, authorizations); if (vOut != null) { searchIndex.addElementToBulkRequest(graph, bulkRequestWithCount.getBulkRequest(), indexInfo, vOut, authorizations); bulkRequestWithCount.incrementCount(); totalCount++; } Element vIn = ((Edge) element).getVertex(Direction.IN, authorizations); if (vIn != null) { searchIndex.addElementToBulkRequest(graph, bulkRequestWithCount.getBulkRequest(), indexInfo, vIn, authorizations); bulkRequestWithCount.incrementCount(); totalCount++; } return totalCount; }
assertEquals("label1", addedEdge.getLabel()); assertEquals("v1", addedEdge.getVertexId(Direction.OUT)); assertEquals(v1, addedEdge.getVertex(Direction.OUT, AUTHORIZATIONS_A)); assertEquals("v2", addedEdge.getVertexId(Direction.IN)); assertEquals(v2, addedEdge.getVertex(Direction.IN, AUTHORIZATIONS_A)); assertEquals(VISIBILITY_A, addedEdge.getVisibility()); assertEquals("label1", e.getLabel()); assertEquals("v1", e.getVertexId(Direction.OUT)); assertEquals(v1, e.getVertex(Direction.OUT, AUTHORIZATIONS_A)); assertEquals("v2", e.getVertexId(Direction.IN)); assertEquals(v2, e.getVertex(Direction.IN, AUTHORIZATIONS_A)); assertEquals(VISIBILITY_A, e.getVisibility());
@Override public int addElement(ElasticSearchSearchIndexBase searchIndex, Graph graph, BulkRequestWithCount bulkRequestWithCount, IndexInfo indexInfo, Element element, Authorizations authorizations) { int totalCount = 0; if (!getConfig().isUpdateEdgeBoost()) { return totalCount; } if (!(element instanceof Edge)) { return totalCount; } Element vOut = ((Edge) element).getVertex(Direction.OUT, authorizations); if (vOut != null) { searchIndex.addElementToBulkRequest(graph, bulkRequestWithCount.getBulkRequest(), indexInfo, vOut, authorizations); bulkRequestWithCount.incrementCount(); totalCount++; } Element vIn = ((Edge) element).getVertex(Direction.IN, authorizations); if (vIn != null) { searchIndex.addElementToBulkRequest(graph, bulkRequestWithCount.getBulkRequest(), indexInfo, vIn, authorizations); bulkRequestWithCount.incrementCount(); totalCount++; } return totalCount; }
assertEquals("label1", addedEdge.getLabel()); assertEquals("v1", addedEdge.getVertexId(Direction.OUT)); assertEquals(v1, addedEdge.getVertex(Direction.OUT, AUTHORIZATIONS_A)); assertEquals("v2", addedEdge.getVertexId(Direction.IN)); assertEquals(v2, addedEdge.getVertex(Direction.IN, AUTHORIZATIONS_A)); assertEquals(VISIBILITY_A, addedEdge.getVisibility()); assertEquals("label1", e.getLabel()); assertEquals("v1", e.getVertexId(Direction.OUT)); assertEquals(v1, e.getVertex(Direction.OUT, AUTHORIZATIONS_A)); assertEquals("v2", e.getVertexId(Direction.IN)); assertEquals(v2, e.getVertex(Direction.IN, AUTHORIZATIONS_A)); assertEquals(VISIBILITY_A, e.getVisibility());
@Override public Vertex getVertex(Direction direction) throws IllegalArgumentException { org.securegraph.Direction sgDirection = SecureGraphBlueprintsConvert.toSecureGraph(direction); Authorizations authorizations = getGraph().getAuthorizationsProvider().getAuthorizations(); return SecureGraphBlueprintsVertex.create(getGraph(), getSecureGraphElement().getVertex(sgDirection, authorizations), authorizations); }
@Override public Vertex getVertex(Direction direction) throws IllegalArgumentException { org.securegraph.Direction sgDirection = SecureGraphBlueprintsConvert.toSecureGraph(direction); Authorizations authorizations = getGraph().getAuthorizationsProvider().getAuthorizations(); return SecureGraphBlueprintsVertex.create(getGraph(), getSecureGraphElement().getVertex(sgDirection, authorizations), authorizations); }