@Override public Iterable<Edge> edges() { if (!hasFilter) { return VertexiumBlueprintsConvert.toBlueprintsEdges(graph, graph.getGraph().getEdges(graph.getFetchHints(), authorizations), authorizations); } Iterable<org.vertexium.Edge> edges = q.edges(graph.getFetchHints()); return VertexiumBlueprintsConvert.toBlueprintsEdges(graph, edges, authorizations); }
@Test public void testSearchingForHiddenEdges() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_ALL); Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_ALL); Edge e1 = graph.addEdge("v1tov2", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_ALL); Edge e2 = graph.addEdge("v2tov3", v2, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_ALL); graph.flush(); graph.markEdgeHidden(e1, VISIBILITY_B, AUTHORIZATIONS_ALL); graph.flush(); FetchHints propertiesFetchHints = FetchHints.builder() .setIncludeAllProperties(true) .build(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .edges(propertiesFetchHints); assertResultsCount(2, edges); assertEdgeIdsAnyOrder(edges, e1.getId(), e2.getId()); edges = graph.query(AUTHORIZATIONS_A_AND_B) .edges(propertiesFetchHints); assertResultsCount(1, edges); assertEdgeIdsAnyOrder(edges, e2.getId()); graph.markEdgeVisible(e1, VISIBILITY_B, AUTHORIZATIONS_ALL); graph.flush(); edges = graph.query(AUTHORIZATIONS_A_AND_B) .edges(propertiesFetchHints); assertResultsCount(2, edges); assertEdgeIdsAnyOrder(edges, e1.getId(), e2.getId()); }
@Test public void testSearchingForHiddenEdges() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_ALL); Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_ALL); Edge e1 = graph.addEdge("v1tov2", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_ALL); Edge e2 = graph.addEdge("v2tov3", v2, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_ALL); graph.flush(); graph.markEdgeHidden(e1, VISIBILITY_B, AUTHORIZATIONS_ALL); graph.flush(); FetchHints propertiesFetchHints = FetchHints.builder() .setIncludeAllProperties(true) .build(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .edges(propertiesFetchHints); assertResultsCount(2, edges); assertEdgeIdsAnyOrder(edges, e1.getId(), e2.getId()); edges = graph.query(AUTHORIZATIONS_A_AND_B) .edges(propertiesFetchHints); assertResultsCount(1, edges); assertEdgeIdsAnyOrder(edges, e2.getId()); graph.markEdgeVisible(e1, VISIBILITY_B, AUTHORIZATIONS_ALL); graph.flush(); edges = graph.query(AUTHORIZATIONS_A_AND_B) .edges(propertiesFetchHints); assertResultsCount(2, edges); assertEdgeIdsAnyOrder(edges, e1.getId(), e2.getId()); }
@Test(expected = VertexiumNotSupportedException.class) public void testRetrievingVerticesFromElasticsearchEdge() { graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .edges(FetchHints.NONE); assertResultsCount(1, 1, edges); toList(edges).get(0).getVertices(AUTHORIZATIONS_A); }
@Test public void testGraphQueryWithQueryStringWithAuthorizations() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); v1.setProperty("description", "This is vertex 1 - dog.", VISIBILITY_A, AUTHORIZATIONS_ALL); Vertex v2 = graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_ALL); v2.setProperty("description", "This is vertex 2 - cat.", VISIBILITY_B, AUTHORIZATIONS_ALL); Edge e1 = graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); e1.setProperty("edgeDescription", "This is edge 1 - dog to cat.", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).vertices(); assertEquals(1, count(vertices)); if (isIterableWithTotalHitsSupported(vertices)) { IterableWithTotalHits hits = (IterableWithTotalHits) vertices; assertEquals(1, hits.getTotalHits()); } Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A).edges(); assertEquals(1, count(edges)); }
@Test public void testGraphQueryWithQueryStringWithAuthorizations() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); v1.setProperty("description", "This is vertex 1 - dog.", VISIBILITY_A, AUTHORIZATIONS_ALL); Vertex v2 = graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_ALL); v2.setProperty("description", "This is vertex 2 - cat.", VISIBILITY_B, AUTHORIZATIONS_ALL); Edge e1 = graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); e1.setProperty("edgeDescription", "This is edge 1 - dog to cat.", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).vertices(); assertEquals(1, count(vertices)); if (isIterableWithTotalHitsSupported(vertices)) { IterableWithTotalHits hits = (IterableWithTotalHits) vertices; assertEquals(1, hits.getTotalHits()); } Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A).edges(); assertEquals(1, count(edges)); }
@Test public void testQueryReturningElasticsearchEdge() { graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .edges(FetchHints.NONE); assertResultsCount(1, 1, edges); Edge e1 = toList(edges).get(0); assertEquals(LABEL_LABEL1, e1.getLabel()); assertEquals("v1", e1.getVertexId(Direction.OUT)); assertEquals("v2", e1.getVertexId(Direction.IN)); assertEquals("e1", e1.getId()); }
assertIdsAnyOrder(vertexIds, v1.getId(), v2.getId(), v3.getId()); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A).edges(FetchHints.ALL); assertResultsCount(1, edges); assertEdgeIdsAnyOrder(edges, e2.getId()); assertIdsAnyOrder(edgeIds, e2.getId()); edges = graph.query(AUTHORIZATIONS_A).edges(FetchHints.ALL_INCLUDING_HIDDEN); assertResultsCount(2, edges); assertEdgeIdsAnyOrder(edges, e1.getId(), e2.getId());
assertIdsAnyOrder(vertexIds, v1.getId(), v2.getId(), v3.getId()); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A).edges(FetchHints.ALL); assertResultsCount(1, edges); assertEdgeIdsAnyOrder(edges, e2.getId()); assertIdsAnyOrder(edgeIds, e2.getId()); edges = graph.query(AUTHORIZATIONS_A).edges(FetchHints.ALL_INCLUDING_HIDDEN); assertResultsCount(2, edges); assertEdgeIdsAnyOrder(edges, e1.getId(), e2.getId());
assertResultsCount(1, 2, vertices); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A).edges(); assertResultsCount(2, 2, edges);
assertResultsCount(1, 2, vertices); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A).edges(); assertResultsCount(2, 2, edges);