Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#toList()
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#toList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TechnologyTagService.java From windup with Eclipse Public License 1.0 | 6 votes |
/** * Return an {@link Iterable} containing all {@link TechnologyTagModel}s that are directly associated with the provided {@link FileModel}. */ public Iterable<TechnologyTagModel> findTechnologyTagsForFile(FileModel fileModel) { GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(fileModel.getElement()); pipeline.in(TechnologyTagModel.TECH_TAG_TO_FILE_MODEL).has(WindupVertexFrame.TYPE_PROP, TechnologyTagModel.TYPE); Comparator<TechnologyTagModel> comparator = new DefaultTechnologyTagComparator(); pipeline.order().by((a, b) -> { TechnologyTagModel aModel = getGraphContext().getFramed().frameElement(a, TechnologyTagModel.class); TechnologyTagModel bModel = getGraphContext().getFramed().frameElement(b, TechnologyTagModel.class); return comparator.compare(aModel, bModel); }); return new FramedVertexIterable<>(getGraphContext().getFramed(), pipeline.toList(), TechnologyTagModel.class); }
Example 2
Source File: TechnologyTagService.java From windup with Eclipse Public License 1.0 | 6 votes |
/** * Return an {@link Iterable} containing all {@link TechnologyTagModel}s that are directly associated with the provided {@link ProjectModel}. */ public Iterable<TechnologyTagModel> findTechnologyTagsForProject(ProjectModelTraversal traversal) { Set<TechnologyTagModel> results = new TreeSet<>(new DefaultTechnologyTagComparator()); GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(traversal.getCanonicalProject().getElement()); pipeline.out(ProjectModel.PROJECT_MODEL_TO_FILE); pipeline.in(TechnologyTagModel.TECH_TAG_TO_FILE_MODEL).has(WindupVertexFrame.TYPE_PROP, Text.textContains(TechnologyTagModel.TYPE)); Iterable<TechnologyTagModel> modelIterable = new FramedVertexIterable<>(getGraphContext().getFramed(), pipeline.toList(), TechnologyTagModel.class); results.addAll(Iterators.asSet(modelIterable)); for (ProjectModelTraversal childTraversal : traversal.getChildren()) { results.addAll(Iterators.asSet(findTechnologyTagsForProject(childTraversal))); } return results; }
Example 3
Source File: TestGremlinOptional.java From sqlg with MIT License | 6 votes |
@Test public void testOptionalWithNestedOptionalAndRepeat() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B"); Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "halo"); a1.addEdge("ab", b1); b1.addEdge("bc", c1); this.sqlgGraph.tx().commit(); GraphTraversal<Vertex, Path> gt = this.sqlgGraph.traversal().V().hasLabel("A") .out("ab").as("b") .optional( __.outE("bc").otherV().as("c") .optional( __.repeat(__.out("cd")).times(3) ) ) .path(); List<Path> paths = gt.toList(); Assert.assertEquals(1, paths.size()); }
Example 4
Source File: ClassificationService.java From windup with Eclipse Public License 1.0 | 6 votes |
/** * Returns the total effort points in all of the {@link ClassificationModel}s associated with the provided {@link FileModel}. */ public int getMigrationEffortPoints(FileModel fileModel) { GraphTraversal<Vertex, Vertex> classificationPipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(fileModel.getElement()); classificationPipeline.in(ClassificationModel.FILE_MODEL); classificationPipeline.has(EffortReportModel.EFFORT, P.gt(0)); classificationPipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(ClassificationModel.TYPE)); int classificationEffort = 0; for (Vertex v : classificationPipeline.toList()) { Property<Integer> migrationEffort = v.property(ClassificationModel.EFFORT); if (migrationEffort.isPresent()) { classificationEffort += migrationEffort.value(); } } return classificationEffort; }
Example 5
Source File: RelatedListFacetDescriptionTest.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Test public void filterLetsTheParserParseEachDatabaseValue() { RelatedListFacetDescription instance = new RelatedListFacetDescription(FACET_NAME, PROPERTY, parser, RELATION); List<FacetValue> facets = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(VALUE1))); GraphTraversal<Vertex, Vertex> traversal = newGraph() .withVertex("v1", v -> v.withTimId("id1").withProperty(PROPERTY, VALUE1)) .withVertex("v2", v -> v.withTimId("id2").withProperty(PROPERTY, VALUE2)) .withVertex("v3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "v1")) .withVertex("v4", v -> v.withTimId("id4").withOutgoingRelation(RELATION, "v2")) .build().traversal().V(); instance.filter(traversal, facets); traversal.toList(); // needed to verify the parser verify(parser).parse(VALUE1); verify(parser).parse(VALUE2); }
Example 6
Source File: RelatedListFacetDescriptionTest.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Test public void filterAddsAFilterToTheGraphTraversal() { RelatedListFacetDescription instance = new RelatedListFacetDescription(FACET_NAME, PROPERTY, parser, RELATION); List<FacetValue> facets = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(VALUE1))); GraphTraversal<Vertex, Vertex> traversal = newGraph() .withVertex("v1", v -> v.withTimId("id1").withProperty(PROPERTY, VALUE1)) .withVertex("v2", v -> v.withTimId("id2").withProperty(PROPERTY, VALUE2)) .withVertex("v3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "v1")) .withVertex("v4", v -> v.withTimId("id4").withOutgoingRelation(RELATION, "v2")) .build().traversal().V(); instance.filter(traversal, facets); List<Vertex> vertices = traversal.toList(); assertThat(vertices, contains(likeVertex().withTimId("id3"))); }
Example 7
Source File: TestTraversalFilterStepBarrier.java From sqlg with MIT License | 6 votes |
@Test public void testWhereVertexStepTraversalStep() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1"); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1"); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2"); Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3"); a1.addEdge("ab", b1); a1.addEdge("ab", b2); a1.addEdge("ab", b3); a2.addEdge("ab", b1); this.sqlgGraph.tx().commit(); GraphTraversal<Vertex, Vertex> traversal = this.sqlgGraph.traversal().V().hasLabel("A").where(__.out().has("name", "b3")); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(1, vertices.size()); }
Example 8
Source File: CharterPortaalFondsFacetDescriptionTest.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Test public void filterChecksIfTheVertexContainsTheRightFondsAndFondsNaam() { // fonds is unique, but two fondsen could have the same name. Graph graph = newGraph().withVertex(v -> v.withTimId("id1") .withProperty(FONDS, "fonds") .withProperty(FONDS_NAAM, "fondsNaam")) .withVertex(v -> v.withProperty(FONDS, "fonds1") .withProperty(FONDS_NAAM, "fondsNaam")) .build(); CharterPortaalFondsFacetDescription instance = new CharterPortaalFondsFacetDescription(FACET_NAME, Mockito.mock(PropertyParser.class)); GraphTraversal<Vertex, Vertex> traversal = graph.traversal().V(); instance.filter(traversal, Lists.newArrayList(new ListFacetValue("facetName", Lists.newArrayList("fondsNaam (fonds)")))); List<Vertex> actual = traversal.toList(); assertThat(actual, contains(likeVertex().withTimId("id1"))); }
Example 9
Source File: RelatedMultiValueListFacetDescriptionTest.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Test public void filterAddsAFilterToTheGraphTraversal() { RelatedMultiValueListFacetDescription instance = new RelatedMultiValueListFacetDescription(FACET_NAME, PROPERTY, RELATION); List<FacetValue> facets = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(FACET_VALUE))); GraphTraversal<Vertex, Vertex> traversal = newGraph() .withVertex("v1", v -> v.withTimId("id1").withProperty(PROPERTY, VALUE1)) .withVertex("v2", v -> v.withTimId("id2").withProperty(PROPERTY, VALUE2)) .withVertex("v3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "v1")) .withVertex("v4", v -> v.withTimId("id4").withOutgoingRelation(RELATION, "v2")) .build().traversal().V(); instance.filter(traversal, facets); List<Vertex> vertices = traversal.toList(); assertThat(vertices, contains(likeVertex().withTimId("id3"))); }
Example 10
Source File: TestHasLabelAndId.java From sqlg with MIT License | 6 votes |
@Test public void testNeqWithinID() { Vertex a = sqlgGraph.addVertex("A"); Vertex b1 = sqlgGraph.addVertex("B"); Vertex b2 = sqlgGraph.addVertex("B"); Vertex c = sqlgGraph.addVertex("C"); a.addEdge("e_a", b1); a.addEdge("e_a", b2); a.addEdge("e_a", c); GraphTraversal<Vertex, Vertex> t = sqlgGraph.traversal().V(a).out().has(T.id, P.without(b1.id())); List<Vertex> vertices = t.toList(); Assert.assertEquals(2, vertices.size()); Assert.assertTrue(vertices.contains(b2)); Assert.assertTrue(vertices.contains(c)); }
Example 11
Source File: SortDescriptionTest.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void sortAddsASortParameterToTheSearchResultsForEachOfTheSortParameters() { GraphTraversal<Vertex, Vertex> traversal = newGraph() .withVertex(v -> v.withTimId("id1") .withProperty(PROPERTY_1, "value1.2") .withProperty(PROPERTY_2, "value2")) .withVertex(v -> v.withTimId("id2") .withProperty(PROPERTY_1, "value1") .withProperty(PROPERTY_2, "value2.1")) .withVertex(v -> v.withTimId("id3") .withProperty(PROPERTY_1, "value1") .withProperty(PROPERTY_2, "value2")) .build() .traversal() .V(); List<SortParameter> sortParameters = Lists.newArrayList( new SortParameter(SORT_FIELD_1, asc), new SortParameter(SORT_FIELD_2, asc)); instance.sort(traversal, sortParameters); List<Vertex> actual = traversal.toList(); assertThat(actual, contains( likeVertex().withTimId("id3"), likeVertex().withTimId("id2"), likeVertex().withTimId("id1"))); }
Example 12
Source File: InlineHintService.java From windup with Eclipse Public License 1.0 | 5 votes |
private Iterable<InlineHintModel> getInlineHintModels(List<Vertex> initialProjectVertices) { GraphTraversal<Vertex, Vertex> inlineHintPipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(initialProjectVertices); inlineHintPipeline.out(ProjectModel.PROJECT_MODEL_TO_FILE); inlineHintPipeline.in(InlineHintModel.FILE_MODEL).has(WindupVertexFrame.TYPE_PROP, P.eq(InlineHintModel.TYPE)); Set<InlineHintModel> results = new LinkedHashSet<>(); for (Vertex v : inlineHintPipeline.toList()) { results.add(frame(v)); } return results; }
Example 13
Source File: TestHasLabelAndId.java From sqlg with MIT License | 5 votes |
@Test public void testCollectionIds() { Vertex a = this.sqlgGraph.addVertex(T.label, "A"); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A"); Vertex b = this.sqlgGraph.addVertex(T.label, "B"); Vertex c = this.sqlgGraph.addVertex(T.label, "C"); Vertex d = this.sqlgGraph.addVertex(T.label, "D"); this.sqlgGraph.tx().commit(); GraphTraversal<Vertex, Vertex> traversal = this.sqlgGraph.traversal().V().hasId(a.id()).hasId(b.id()); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(0, vertices.size()); traversal = this.sqlgGraph.traversal().V(a.id()).hasId(b.id()); vertices = traversal.toList(); Assert.assertEquals(0, vertices.size()); traversal = this.sqlgGraph.traversal().V(a.id()).has(T.id, P.within(b.id(), c.id(), d.id())); vertices = traversal.toList(); Assert.assertEquals(0, vertices.size()); traversal = this.sqlgGraph.traversal().V(a.id()).has(T.id, P.within(a2.id(), b.id(), c.id(), d.id())); vertices = traversal.toList(); Assert.assertEquals(0, vertices.size()); traversal = this.sqlgGraph.traversal().V(Arrays.asList(a.id(), a2.id(), b.id(), c.id(), d.id())); vertices = traversal.toList(); Assert.assertEquals(5, vertices.size()); }
Example 14
Source File: InlineHintService.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * Gets all {@link InlineHintModel} instances that are directly associated with the given {@link FileReferenceModel} */ public Iterable<InlineHintModel> getHintsForFileReference(FileReferenceModel reference) { GraphTraversal<Vertex, Vertex> inlineHintPipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(reference.getElement()); inlineHintPipeline.in(InlineHintModel.FILE_LOCATION_REFERENCE); inlineHintPipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(InlineHintModel.TYPE)); return new FramedVertexIterable<>(getGraphContext().getFramed(), inlineHintPipeline.toList(), InlineHintModel.class); }
Example 15
Source File: ClassificationService.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * Return all {@link ClassificationModel} instances that are attached to the given {@link FileModel} instance. */ public Iterable<ClassificationModel> getClassifications(FileModel model) { GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(model.getElement()); pipeline.in(ClassificationModel.FILE_MODEL); pipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(ClassificationModel.TYPE)); return new FramedVertexIterable<>(getGraphContext().getFramed(), pipeline.toList(), ClassificationModel.class); }
Example 16
Source File: Example2.java From hugegraph with Apache License 2.0 | 5 votes |
public static List<Path> shortestPath(final HugeGraph graph, Object from, Object to, int maxDepth) { GraphTraversal<Vertex, Path> t = graph.traversal() .V(from) .repeat(__.out().simplePath()) .until(__.hasId(to).or().loops().is(P.gt(maxDepth))) .hasId(to) .path().by("name") .limit(1); return t.toList(); }
Example 17
Source File: HibernateEntityService.java From windup with Eclipse Public License 1.0 | 5 votes |
/** * Gets an {@link Iterable} of {@link }s for the given {@link ProjectModel}. */ public Iterable<HibernateEntityModel> findAllByApplication(ProjectModel application) { GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(application.getElement()); pipeline.in(HibernateEntityModel.APPLICATIONS); pipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(HibernateEntityModel.TYPE)); return new FramedVertexIterable<>(getGraphContext().getFramed(), pipeline.toList(), HibernateEntityModel.class); }
Example 18
Source File: TestDropStepBarrier.java From sqlg with MIT License | 5 votes |
@Test public void playlistPaths() { Assume.assumeTrue(!isMsSqlServer()); loadGratefulDead(); final GraphTraversal<Vertex, Vertex> traversal = getPlaylistPaths(this.sqlgGraph.traversal()); printTraversalForm(traversal); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(100, vertices.size()); getPlaylistPaths(this.dropTraversal).barrier().drop().iterate(); this.sqlgGraph.tx().commit(); Long count = this.sqlgGraph.traversal().V().count().next(); //Sometimes its 804 and sometimes 803. //Probably something to do with the limit Assert.assertTrue(count == 804 || count == 803); }
Example 19
Source File: TestUnion.java From sqlg with MIT License | 4 votes |
@Test public void testUnionHasPath() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "A1"); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "A2"); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "A3"); Vertex a4 = this.sqlgGraph.addVertex(T.label, "A", "name", "A4"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "B1"); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "B2"); Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "B3"); Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "C1"); Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "C2"); Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "C3"); a1.addEdge("toB", b1); a1.addEdge("toB", b2); a1.addEdge("toB", b3); b1.addEdge("toC", c1); b2.addEdge("toC", c2); b3.addEdge("toC", c3); GraphTraversal<Vertex, Path> traversal = this.sqlgGraph.traversal().V().has("A", "name", "A1") .union( __.out("toB").has("name", P.eq("B1")).out("toC"), __.out("toB").has("name", P.eq("B2")).out("toC")) .path(); printTraversalForm(traversal); Set<Object> objs = new HashSet<>(); while (traversal.hasNext()) { Path p = traversal.next(); Assert.assertEquals(3, p.size()); Object root0 = p.get(0); Assert.assertEquals(a1, root0); Object child0 = p.get(1); Assert.assertEquals("B", ((Vertex) child0).label()); Object child1 = p.get(2); Assert.assertEquals("C", ((Vertex) child1).label()); objs.add(child0); objs.add(child1); } Assert.assertEquals(4, objs.size()); Assert.assertTrue(objs.contains(b1)); Assert.assertTrue(objs.contains(b2)); Assert.assertTrue(objs.contains(c1)); Assert.assertTrue(objs.contains(c2)); traversal = this.sqlgGraph.traversal().V().hasLabel("A") .union( __.optional(__.out("toB").has("name", P.eq("B1")).optional(__.out("toC"))), __.optional(__.out("toB").has("name", P.eq("B2")).optional(__.out("toC")))) .path(); printTraversalForm(traversal); List<Path> paths = traversal.toList(); Assert.assertEquals(8, paths.size()); Assert.assertEquals(2, paths.stream().filter(p -> p.size() == 3).count()); }
Example 20
Source File: TestHasLabelAndId.java From sqlg with MIT License | 4 votes |
@Test public void testOutEWithHasLabelAndId() { Vertex a = this.sqlgGraph.addVertex(T.label, "A"); Vertex b = this.sqlgGraph.addVertex(T.label, "B"); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B"); Vertex c = this.sqlgGraph.addVertex(T.label, "C"); Vertex c2 = this.sqlgGraph.addVertex(T.label, "C"); Vertex d = this.sqlgGraph.addVertex(T.label, "D"); Vertex d2 = this.sqlgGraph.addVertex(T.label, "D"); Edge ab = b.addEdge("ab", a); Edge ab2 = b2.addEdge("ab", a); Edge ac = c.addEdge("ac", a); Edge ac2 = c2.addEdge("ac", a); Edge ad = d.addEdge("ad", a); Edge ad2 = d2.addEdge("ad", a); this.sqlgGraph.tx().commit(); GraphTraversal<Edge, Vertex> traversal = this.sqlgGraph.traversal().E().hasLabel("ab").inV(); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(2, vertices.size()); Assert.assertEquals(a, vertices.get(0)); Assert.assertEquals(a, vertices.get(1)); traversal = this.sqlgGraph.traversal().E().hasLabel("ab").inV().hasLabel("B"); vertices = traversal.toList(); Assert.assertEquals(0, vertices.size()); traversal = this.sqlgGraph.traversal().E().hasLabel("ab").inV().hasLabel("A"); vertices = traversal.toList(); Assert.assertEquals(2, vertices.size()); Assert.assertEquals(a, vertices.get(0)); Assert.assertEquals(a, vertices.get(1)); traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).inV().hasLabel("A", "B"); vertices = traversal.toList(); Assert.assertEquals(6, vertices.size()); Assert.assertTrue(vertices.stream().allMatch(v -> v.equals(a))); traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B"); vertices = traversal.toList(); Assert.assertEquals(4, vertices.size()); Assert.assertTrue(vertices.contains(b) && vertices.contains(b2) && vertices.contains(c) && vertices.contains(c2)); traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B").has(T.id, P.eq(b)); vertices = traversal.toList(); Assert.assertEquals(1, vertices.size()); Assert.assertEquals(b, vertices.get(0)); traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B").has(T.id, P.neq(b)); vertices = traversal.toList(); Assert.assertEquals(3, vertices.size()); Assert.assertTrue(vertices.contains(b2) && vertices.contains(c) && vertices.contains(c2)); traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B").has(T.id, P.within(b.id(), b2.id(), c.id())); vertices = traversal.toList(); Assert.assertEquals(3, vertices.size()); Assert.assertTrue(vertices.contains(b) && vertices.contains(b2) && vertices.contains(c)); traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B").has(T.id, P.without(b.id(), b2.id(), c.id())); vertices = traversal.toList(); Assert.assertEquals(1, vertices.size()); Assert.assertEquals(c2, vertices.get(0)); }