@Test public void getShouldGenerateAD3Graph() throws NotFoundException, IOException { Graph graph = newGraph() .withVertex("relationCollection", v -> v.withProperty(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, "wwrelation") .withProperty(Collection.IS_RELATION_COLLECTION_PROPERTY_NAME, true) ) .withVertex("vreNode", v -> v.withProperty(Vre.VRE_NAME_PROPERTY_NAME, "WomenWriters") .withOutgoingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "relationCollection") ) .withVertex(v -> v.withLabel(Collection.DATABASE_LABEL) .withProperty(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, "wwperson") .withIncomingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "vreNode") ) .withVertex("v1", v -> v .withProperty("isLatest", true) .withTimId(THE_UUID) .withProperty("types", TYPES) .withProperty("wwperson_tempName", "name1") ) .withVertex("v2", v -> v .withTimId("2") .withProperty("types", TYPES) .withOutgoingRelation(RELATION_NAME, "v1", r -> r.withAccepted("wwrelation", true) .withIsLatest(true) ) .withProperty("wwperson_tempName", "name2") ) .withVertex("v3", v -> v .withTimId("3") .withProperty("types", TYPES) .withOutgoingRelation(RELATION_NAME_2, "v1", r -> r.withAccepted("wwrelation", true) .withIsLatest(true) ) .withProperty("wwperson_tempName", "name3") ) .withVertex("v4", v -> v .withTimId("4") .withProperty("types", TYPES) .withOutgoingRelation(RELATION_NAME, "v2", r -> r.withAccepted("wwrelation", true) .withIsLatest(true) ) .withProperty("wwperson_tempName", "name4") ) .withVertex("v5", v -> v .withTimId("5") .withProperty("types", TYPES) .withOutgoingRelation(UNREQUESTED_RELATION, "v1", r -> r.withAccepted("wwrelation_accepted", true) .withIsLatest(true) ) .withProperty("wwperson_tempName", "name5") ) .withVertex("v6", v -> v .withTimId("6") .withProperty("types", TYPES) .withOutgoingRelation(RELATION_NAME, "v4", r -> r.withAccepted("wwrelation", true) .withIsLatest(true) ) .withProperty("wwperson_tempName", "name6") ) .build(); List<Vertex> vertices = graph.traversal().V() .has("wwperson_tempName") .asAdmin().clone().toList(); Collections.sort(vertices, Comparator.comparing(vertexA -> ((String) vertexA.property("wwperson_tempName").value())) ); GraphWrapper graphWrapper = createGraphWrapper(graph); D3GraphGeneratorService underTest = new D3GraphGeneratorService(graphWrapper, HuygensIng.mappings); D3Graph result = underTest.get( "wwperson", UUID.fromString(THE_UUID), Lists.newArrayList(RELATION_NAME, RELATION_NAME_2), 2); assertThat(result.getNodes().get(0), is(new Node(vertices.get(0), "wwperson"))); assertThat(result.getNodes(), containsInAnyOrder( new Node(vertices.get(0), "wwperson"), new Node(vertices.get(1), "wwperson"), new Node(vertices.get(2), "wwperson"), new Node(vertices.get(3), "wwperson") )); int indexOfRoot = getIndex(result.getNodes(), "077bf0b5-6b7d-45aa-89ff-6ecf2cfc549c"); int indexOfPerson1 = getIndex(result.getNodes(), "2"); int indexOfPerson2 = getIndex(result.getNodes(), "3"); int indexOfPerson3 = getIndex(result.getNodes(), "4"); assertThat(result.getLinks(), containsInAnyOrder( new Link(mockEdge(RELATION_NAME), indexOfRoot, indexOfPerson1), new Link(mockEdge(RELATION_NAME_2), indexOfRoot, indexOfPerson2), new Link(mockEdge(RELATION_NAME), indexOfPerson1, indexOfPerson3) )); }
public D3Graph get(String type, UUID uuid, List<String> relationNames, int depth) throws NotFoundException { final String vreId = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).next() .property(Vre.VRE_NAME_PROPERTY_NAME).value(); final String relationTypeName = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).out(Vre.HAS_COLLECTION_RELATION_NAME) .where(__.has(Collection.IS_RELATION_COLLECTION_PROPERTY_NAME, true)).next() .property(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME).value(); GraphTraversal<Vertex, Vertex> result = graphWrapper.getGraph().traversal().V() .has("tim_id", uuid.toString()).filter( x -> ((String) x.get().property("types").value()).contains("\"" + type + "\"") ).has("isLatest", true) .not(__.has("deleted", true)); if (!result.hasNext()) { throw new NotFoundException(); } Vertex vertex = result.next(); D3Graph d3Graph = new D3Graph(); generateD3Graph(relationTypeName, vreId, d3Graph, vertex, relationNames, depth, 1); return d3Graph; }
D3GraphGeneratorService { public D3Graph get(String type, UUID uuid, List<String> relationNames, int depth) throws NotFoundException { final String vreId = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).next() .property(Vre.VRE_NAME_PROPERTY_NAME).value(); final String relationTypeName = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).out(Vre.HAS_COLLECTION_RELATION_NAME) .where(__.has(Collection.IS_RELATION_COLLECTION_PROPERTY_NAME, true)).next() .property(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME).value(); GraphTraversal<Vertex, Vertex> result = graphWrapper.getGraph().traversal().V() .has("tim_id", uuid.toString()).filter( x -> ((String) x.get().property("types").value()).contains("\"" + type + "\"") ).has("isLatest", true) .not(__.has("deleted", true)); if (!result.hasNext()) { throw new NotFoundException(); } Vertex vertex = result.next(); D3Graph d3Graph = new D3Graph(); generateD3Graph(relationTypeName, vreId, d3Graph, vertex, relationNames, depth, 1); return d3Graph; } }
D3GraphGeneratorService { public D3Graph get(String type, UUID uuid, List<String> relationNames, int depth) throws NotFoundException { final String vreId = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).next() .property(Vre.VRE_NAME_PROPERTY_NAME).value(); final String relationTypeName = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).out(Vre.HAS_COLLECTION_RELATION_NAME) .where(__.has(Collection.IS_RELATION_COLLECTION_PROPERTY_NAME, true)).next() .property(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME).value(); GraphTraversal<Vertex, Vertex> result = graphWrapper.getGraph().traversal().V() .has("tim_id", uuid.toString()).filter( x -> ((String) x.get().property("types").value()).contains("\"" + type + "\"") ).has("isLatest", true) .not(__.has("deleted", true)); if (!result.hasNext()) { throw new NotFoundException(); } Vertex vertex = result.next(); D3Graph d3Graph = new D3Graph(); generateD3Graph(relationTypeName, vreId, d3Graph, vertex, relationNames, depth, 1); return d3Graph; } D3GraphGeneratorService(GraphWrapper wrapper, Vres mappings); }
D3GraphGeneratorService { public D3Graph get(String type, UUID uuid, List<String> relationNames, int depth) throws NotFoundException { final String vreId = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).next() .property(Vre.VRE_NAME_PROPERTY_NAME).value(); final String relationTypeName = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).out(Vre.HAS_COLLECTION_RELATION_NAME) .where(__.has(Collection.IS_RELATION_COLLECTION_PROPERTY_NAME, true)).next() .property(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME).value(); GraphTraversal<Vertex, Vertex> result = graphWrapper.getGraph().traversal().V() .has("tim_id", uuid.toString()).filter( x -> ((String) x.get().property("types").value()).contains("\"" + type + "\"") ).has("isLatest", true) .not(__.has("deleted", true)); if (!result.hasNext()) { throw new NotFoundException(); } Vertex vertex = result.next(); D3Graph d3Graph = new D3Graph(); generateD3Graph(relationTypeName, vreId, d3Graph, vertex, relationNames, depth, 1); return d3Graph; } D3GraphGeneratorService(GraphWrapper wrapper, Vres mappings); D3Graph get(String type, UUID uuid, List<String> relationNames, int depth); }
D3GraphGeneratorService { public D3Graph get(String type, UUID uuid, List<String> relationNames, int depth) throws NotFoundException { final String vreId = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).next() .property(Vre.VRE_NAME_PROPERTY_NAME).value(); final String relationTypeName = (String) graphWrapper.getGraph().traversal().V() .hasLabel(Collection.DATABASE_LABEL) .has(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, type) .in(Vre.HAS_COLLECTION_RELATION_NAME).out(Vre.HAS_COLLECTION_RELATION_NAME) .where(__.has(Collection.IS_RELATION_COLLECTION_PROPERTY_NAME, true)).next() .property(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME).value(); GraphTraversal<Vertex, Vertex> result = graphWrapper.getGraph().traversal().V() .has("tim_id", uuid.toString()).filter( x -> ((String) x.get().property("types").value()).contains("\"" + type + "\"") ).has("isLatest", true) .not(__.has("deleted", true)); if (!result.hasNext()) { throw new NotFoundException(); } Vertex vertex = result.next(); D3Graph d3Graph = new D3Graph(); generateD3Graph(relationTypeName, vreId, d3Graph, vertex, relationNames, depth, 1); return d3Graph; } D3GraphGeneratorService(GraphWrapper wrapper, Vres mappings); D3Graph get(String type, UUID uuid, List<String> relationNames, int depth);  }