private JSONObject edgeToJson(Edge edge) { JSONObject json = elementToJson(edge); json.put("outVertexId", edge.getVertexId(Direction.OUT)); json.put("inVertexId", edge.getVertexId(Direction.IN)); json.put("label", edge.getLabel()); return json; }
@Override protected boolean isIncluded(Edge edge) { switch (direction) { case IN: return edge.getVertexId(Direction.IN).equals(getId()); case OUT: return edge.getVertexId(Direction.OUT).equals(getId()); default: return true; } } };
@Override protected boolean isIncluded(Edge edge) { switch (direction) { case BOTH: return true; case IN: return edge.getVertexId(Direction.IN).equals(sourceVertex.getId()); case OUT: return edge.getVertexId(Direction.OUT).equals(sourceVertex.getId()); default: throw new RuntimeException("Unexpected direction: " + direction); } } };
@Override protected boolean isIncluded(Edge edge) { switch (direction) { case BOTH: return true; case IN: return edge.getVertexId(Direction.IN).equals(sourceVertex.getId()); case OUT: return edge.getVertexId(Direction.OUT).equals(sourceVertex.getId()); default: throw new RuntimeException("Unexpected direction: " + direction); } } };
@Override public String toString() { if (this instanceof Edge) { Edge edge = (Edge) this; return getId() + ":[" + edge.getVertexId(Direction.OUT) + "-" + edge.getLabel() + "->" + edge.getVertexId(Direction.IN) + "]"; } return getId(); }
@Override public String toString() { if (this instanceof Edge) { Edge edge = (Edge) this; return getId() + ":[" + edge.getVertexId(Direction.OUT) + "-" + edge.getLabel() + "->" + edge.getVertexId(Direction.IN) + "]"; } return getId(); }
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"); }
public EdgeBuilderByVertexId prepareEdge(Edge edge) { return prepareEdge( edge.getId(), edge.getVertexId(Direction.OUT), edge.getVertexId(Direction.IN), edge.getLabel(), edge.getVisibility() ); }
void addInEdge(Edge edge) { this.inEdges.put(edge.getId(), new EdgeInfo(edge.getLabel(), edge.getVertexId(Direction.OUT))); }
void addOutEdge(Edge edge) { this.outEdges.put(edge.getId(), new EdgeInfo(edge.getLabel(), edge.getVertexId(Direction.IN))); }
@Override public void markEdgeHidden(Edge edge, Visibility visibility, Authorizations authorizations) { if (!((InMemoryEdge) edge).canRead(authorizations)) { return; } Vertex inVertex = getVertex(edge.getVertexId(Direction.IN), authorizations); checkNotNull(inVertex, "Could not find in vertex: " + edge.getVertexId(Direction.IN)); Vertex outVertex = getVertex(edge.getVertexId(Direction.OUT), authorizations); checkNotNull(outVertex, "Could not find out vertex: " + edge.getVertexId(Direction.OUT)); this.edges.get(edge.getId()).addHiddenVisibility(visibility); getSearchIndex().addElement(this, edge, authorizations); if (hasEventListeners()) { fireGraphEvent(new MarkHiddenEdgeEvent(this, edge)); } }
@Override public void markEdgeVisible(Edge edge, Visibility visibility, Authorizations authorizations) { if (!((InMemoryEdge) edge).canRead(authorizations)) { return; } Vertex inVertex = getVertex(edge.getVertexId(Direction.IN), FetchHint.ALL_INCLUDING_HIDDEN, authorizations); checkNotNull(inVertex, "Could not find in vertex: " + edge.getVertexId(Direction.IN)); Vertex outVertex = getVertex(edge.getVertexId(Direction.OUT), FetchHint.ALL_INCLUDING_HIDDEN, authorizations); checkNotNull(outVertex, "Could not find out vertex: " + edge.getVertexId(Direction.OUT)); this.edges.get(edge.getId()).removeHiddenVisibility(visibility); getSearchIndex().addElement(this, edge, authorizations); if (hasEventListeners()) { fireGraphEvent(new MarkVisibleEdgeEvent(this, edge)); } }
public boolean alterEdgeVertexInVertex(Mutation mvin, Edge edge, Visibility newVisibility) { ColumnVisibility currentColumnVisibility = visibilityToAccumuloVisibility(edge.getVisibility()); ColumnVisibility newColumnVisibility = visibilityToAccumuloVisibility(newVisibility); if (currentColumnVisibility.equals(newColumnVisibility)) { return false; } EdgeInfo edgeInfo = new EdgeInfo(edge.getLabel(), edge.getVertexId(Direction.OUT)); mvin.putDelete(AccumuloVertex.CF_IN_EDGE, new Text(edge.getId()), currentColumnVisibility); mvin.put(AccumuloVertex.CF_IN_EDGE, new Text(edge.getId()), newColumnVisibility, edgeInfo.toValue()); return true; }
public boolean alterEdgeVertexOutVertex(Mutation mvout, Edge edge, Visibility newVisibility) { ColumnVisibility currentColumnVisibility = visibilityToAccumuloVisibility(edge.getVisibility()); ColumnVisibility newColumnVisibility = visibilityToAccumuloVisibility(newVisibility); if (currentColumnVisibility.equals(newColumnVisibility)) { return false; } EdgeInfo edgeInfo = new EdgeInfo(edge.getLabel(), edge.getVertexId(Direction.IN)); mvout.putDelete(AccumuloVertex.CF_OUT_EDGE, new Text(edge.getId()), currentColumnVisibility); mvout.put(AccumuloVertex.CF_OUT_EDGE, new Text(edge.getId()), newColumnVisibility, edgeInfo.toValue()); return true; }
@Override public void removeEdge(Edge edge, Authorizations authorizations) { checkNotNull(edge); getSearchIndex().removeElement(this, edge, authorizations); ColumnVisibility visibility = visibilityToAccumuloVisibility(edge.getVisibility()); Mutation outMutation = new Mutation(AccumuloConstants.VERTEX_ROW_KEY_PREFIX + edge.getVertexId(Direction.OUT)); outMutation.putDelete(AccumuloVertex.CF_OUT_EDGE, new Text(edge.getId()), visibility); Mutation inMutation = new Mutation(AccumuloConstants.VERTEX_ROW_KEY_PREFIX + edge.getVertexId(Direction.IN)); inMutation.putDelete(AccumuloVertex.CF_IN_EDGE, new Text(edge.getId()), visibility); addMutations(getVerticesWriter(), outMutation, inMutation); // Remove everything else related to edge. addMutations(getEdgesWriter(), getDeleteRowMutation(AccumuloConstants.EDGE_ROW_KEY_PREFIX + edge.getId())); if (hasEventListeners()) { queueEvent(new RemoveEdgeEvent(this, edge)); } }
void alterElementVisibility(AccumuloElement element, Visibility newVisibility) { BatchWriter elementWriter = getWriterFromElementType(element); String rowPrefix = getRowPrefixForElement(element); String elementRowKey = rowPrefix + element.getId(); if (element instanceof Edge) { BatchWriter vertexWriter = getVerticesWriter(); Edge edge = (Edge) element; String voutRowKey = AccumuloConstants.VERTEX_ROW_KEY_PREFIX + edge.getVertexId(Direction.OUT); Mutation mvout = new Mutation(voutRowKey); if (elementMutationBuilder.alterEdgeVertexOutVertex(mvout, edge, newVisibility)) { addMutations(vertexWriter, mvout); } String vinRowKey = AccumuloConstants.VERTEX_ROW_KEY_PREFIX + edge.getVertexId(Direction.IN); Mutation mvin = new Mutation(vinRowKey); if (elementMutationBuilder.alterEdgeVertexInVertex(mvin, edge, newVisibility)) { addMutations(vertexWriter, mvin); } } Mutation m = new Mutation(elementRowKey); if (elementMutationBuilder.alterElementVisibility(m, element, newVisibility)) { addMutations(elementWriter, m); } }
@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 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)); } }
assertEquals("e1", addedEdge.getId()); 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("e1", e.getId()); 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());
assertEquals("label2", single(v2.getEdgeLabels(Direction.IN, AUTHORIZATIONS_A))); graph.prepareEdge(e.getId(), e.getVertexId(Direction.OUT), e.getVertexId(Direction.IN), e.getLabel(), e.getVisibility()) .alterEdgeLabel("label3") .save(AUTHORIZATIONS_A);