org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal. 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: TraversalUtil.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static String page(GraphTraversal<?, ?> traversal) {
    QueryHolder holder = firstPageStep(traversal);
    E.checkState(holder != null,
                 "Invalid paging traversal: %s", traversal.getClass());
    Object page = holder.metadata(PageInfo.PAGE);
    if (page == null) {
        return null;
    }
    /*
     * Page is instance of PageInfo if traversal with condition like:
     * g.V().has("x", 1).has("~page", "").
     * Page is instance of PageState if traversal without condition like:
     * g.V().has("~page", "")
     */
    assert page instanceof PageInfo || page instanceof PageState;
    return page.toString();
}
 
Example #2
Source File: TestTraversalFilterStepBarrier.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testWhereVertexStepTraversalStep1() {
    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());
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(2, vertices.size());
}
 
Example #3
Source File: TestGremlinOptional.java    From sqlg with MIT License 6 votes vote down vote up
@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: RelatedListFacetDescriptionTest.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@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 #5
Source File: GremlinEnabledScriptEngineTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithAliasInBindings() throws Exception {
    final GremlinScriptEngine scriptEngine = manager.getEngineByName(ENGINE_TO_TEST);
    final Graph graph = EmptyGraph.instance();
    final GraphTraversalSource g = graph.traversal();

    // purposefully use "x" to match the name of the traversal source binding for "x" below and
    // thus tests the alias added for "x"
    final GraphTraversal t = getTraversalWithLambda(g);

    final Bindings bindings = new SimpleBindings();
    bindings.put("x", g);
    bindings.put(GremlinScriptEngine.HIDDEN_G, g);

    scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x");
}
 
Example #6
Source File: AddV.java    From gremlin-ogm with Apache License 2.0 6 votes vote down vote up
@Override
@SneakyThrows
public GraphTraversal<Element, Element> apply(GraphTraversalSource g) {
  GraphTraversal traversal = g.addV(element.label());
  if (element.id() != null && HasFeature.Verifier.of(g)
      .verify(supportsUserSuppliedIds(element))) {
    traversal.property(T.id, element.id());
  }
  for (Field field : keyFields(element)) {
    String key = propertyKey(field);
    Object value = propertyValue(field, element);
    if (isMissing(value)) {
      throw org.apache.tinkerpop.gremlin.object.structure.Element.Exceptions.requiredKeysMissing(
          element.getClass(), key);
    }
    traversal.property(key, value);
  }
  return traversal;
}
 
Example #7
Source File: GremlinEnabledScriptEngineTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithInvalidBinding() throws Exception {
    final GremlinScriptEngine scriptEngine = manager.getEngineByName(ENGINE_TO_TEST);
    final Graph graph = EmptyGraph.instance();
    final GraphTraversalSource g = graph.traversal();

    // purposefully use "x" to match the name of the traversal source binding for "x" below and
    // thus tests the alias added for "x"
    final GraphTraversal t = getTraversalWithLambda(g);

    final Bindings bindings = new SimpleBindings();
    bindings.put("z", g);
    bindings.put("x", "invalid-binding-for-x-given-x-should-be-traversal-source");

    scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x");
}
 
Example #8
Source File: GraphTypeManager.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public <P extends Element, T extends Element> GraphTraversal<P, T> hasNotType(GraphTraversal<P, T> traverser, Class<?> type)
{
    String typeValue = getTypeValue((Class<? extends WindupFrame>) type);
    return traverser.filter(new Predicate<Traverser<T>>()
    {
        @Override
        public boolean test(final Traverser<T> toCheck)
        {
            final Property<String> property = toCheck.get().property(WindupFrame.TYPE_PROP);
            if (!property.isPresent())
                return true;

            final String resolvedType = property.value();
            if (typeValue.contains(resolvedType))
                return false;
            else
                return true;
        }
    });
}
 
Example #9
Source File: EdgeListFacetDescriptionTest.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void filterAddsNoFilterIfTheFacetValuesIsEmpty() {
  List<FacetValue> facetValues = Lists.newArrayList(
          new ListFacetValue(FACET_NAME, Lists.newArrayList()));

  SearchRequestV2_1 searchRequest = new SearchRequestV2_1();
  searchRequest.setFacetValues(facetValues);
  GraphTraversal<Vertex, Vertex> traversal = newGraph()
          .withVertex(v -> v.withTimId("1"))
          .withVertex(v -> v.withTimId("2"))
          .build().traversal().V();

  instance.filter(traversal, facetValues);

  assertThat(traversal.toList(),
          containsInAnyOrder(VertexMatcher.likeVertex().withTimId("1"), VertexMatcher.likeVertex().withTimId("2")));
}
 
Example #10
Source File: RelatedMultiValueListFacetDescriptionTest.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@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 #11
Source File: KillrVideoTraversalDsl.java    From graph-examples with Apache License 2.0 6 votes vote down vote up
/**
 * A simple recommendation algorithm that starts from a "user" and examines movies the user has seen filtered by
 * the {@code minRating} which removes movies that hold a rating lower than the value specified. It then samples
 * the actors in the movies the user has seen and uses that to find other movies those actors have been in that
 * the user has not yet seen. Those movies are grouped, counted and sorted based on that count to produce the
 * recommendation.
 *
 * @param recommendations the number of recommended movies to return
 * @param minRating the minimum rating to allow for
 * @param recommender a configuration to supply to the recommendation algorithm to provide control over how
 *                    sampling occurs when selecting the initial set of movies to consider
 * @param include an anonymous traversal that must be "true" for the incoming "movie" vertex to be included in the
 *                recommendation results
 */
public default GraphTraversal<S, Vertex> recommend(int recommendations, int minRating, Recommender recommender, Traversal include) {
    if (recommendations <= 0) throw new IllegalArgumentException("recommendations must be greater than zero");

    return rated(minRating, 0).
            aggregate("seen").
            local(recommender.getTraversal()).
            unfold().in(EDGE_ACTOR).
            where(without("seen")).
            where(include).
            groupCount().
            order(local).
              by(values, decr).
            limit(local,recommendations).
            select(keys).
            unfold();
}
 
Example #12
Source File: MultiValueListFacetDescriptionTest.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void filterDoesNotFilterWhenFacetValuesDoesNotContainTheFacet() {
  GraphTraversal<Vertex, Vertex> traversal = newGraph()
    .withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_NAME, serializedListOf("value1", "value2")))
    .withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_NAME, serializedListOf("value2", "value3")))
    .withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_NAME, serializedListOf("value1", "value3", "value4")))
    .build().traversal().V();
  List<FacetValue> facetValues = Lists.newArrayList();

  instance.filter(traversal, facetValues);

  assertThat(traversal.toList(), containsInAnyOrder(
    likeVertex().withTimId("id1"),
    likeVertex().withTimId("id2"),
    likeVertex().withTimId("id3")));
}
 
Example #13
Source File: DerivedPropertyValueGetterTest.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void getValuesReturnsEmptyListIfThePropertyIsNotPresent() {
  DerivedPropertyValueGetter instance = new DerivedPropertyValueGetter(RELATIONS, RELATION_NAME);

  GraphTraversal<Vertex, Vertex> traversal = newGraph()
          .withVertex("finalTarget1", v -> v.withProperty(PROPERTY_NOT_PRESENT, "value1"))
          .withVertex("finalTarget2", v -> v.withProperty(PROPERTY_NOT_PRESENT, "value2"))
          .withVertex("target1", v -> v.withOutgoingRelation(RELATION_NAME, "finalTarget1"))
          .withVertex("target2", v -> v.withOutgoingRelation(RELATION_NAME, "finalTarget2"))
          .withVertex(v -> v.withOutgoingRelation(RELATIONS[0], "target1"))
          .withVertex(v -> v.withOutgoingRelation(RELATIONS[0], "target2"))
          .build().traversal().V();

  List<List<String>> results = traversal.toList().stream()
          .map(v -> instance.getValues(v, PROPERTY))
          .filter(r -> r.size() > 0).collect(toList());

  assertThat(results, equalTo(Lists.newArrayList()));
}
 
Example #14
Source File: HugeTraverser.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
protected Iterator<Edge> edgesOfVertex(Id source, Directions dir,
                                       Map<Id, String> labels,
                                       Map<String, Object> properties,
                                       long limit) {
    if (properties == null || properties.isEmpty()) {
        return edgesOfVertex(source, dir, labels.keySet(), limit);
    }
    // Use traversal format if has properties filter
    String[] els = labels.values().toArray(new String[labels.size()]);
    GraphTraversal<Vertex, Edge> g;
    g = this.graph().traversal().V(source).toE(dir.direction(), els);
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof List) {
            g = g.has(key, P.within((Collection<?>) value));
        } else {
            g = g.has(key, value);
        }
    }
    return g.limit(limit);
}
 
Example #15
Source File: RelatedDatableRangeFacetDescriptionTest.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void filterIncludesTheVerticesWhereOnlyTheStartFallsInTheRange() {
  GraphTraversal<Vertex, Vertex> traversal = newGraph()
        .withVertex("target1", v -> v.withTimId("id4").withProperty(PROPERTY_NAME, asSerializedDatable("2015/2020")))
        .withVertex("target2", v -> v.withTimId("id5").withProperty(PROPERTY_NAME, asSerializedDatable("0015-01")))
        .withVertex("target3", v -> v.withTimId("id6").withProperty(PROPERTY_NAME, asSerializedDatable("0190-01")))
        .withVertex("source1", v -> v.withTimId("id1").withOutgoingRelation(RELATION, "target1"))
        .withVertex("source2", v -> v.withTimId("id2").withOutgoingRelation(RELATION, "target2"))
        .withVertex("source3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "target3"))
        .build().traversal().V();
  List<FacetValue> facetValues = Lists.newArrayList(new DateRangeFacetValue(FACET_NAME, 20140101L, 20160101L));

  instance.filter(traversal, facetValues);

  assertThat(traversal.toList(), contains(likeVertex().withTimId("id1")));
}
 
Example #16
Source File: TraversalBuilder.java    From sql-gremlin with Apache License 2.0 6 votes vote down vote up
public static GraphTraversal toTraversal(List<RelNode> relList) {
    final GraphTraversal traversal = __.identity();
    TableDef tableDef = null;
    for(RelNode rel : relList) {
        if(rel instanceof GremlinTableScan) {
            GremlinTableScan tableScan = (GremlinTableScan) rel;
            tableDef = tableScan.getGremlinTable().getTableDef();
            traversal.hasLabel(tableDef.label);
        } if(rel instanceof GremlinFilter) {
            GremlinFilter filter = (GremlinFilter) rel;
            RexNode condition = filter.getCondition();
            FilterTranslator translator = new FilterTranslator(tableDef, filter.getRowType().getFieldNames());
            GraphTraversal predicates = translator.translateMatch(condition);
            for(Step step : (List<Step>)predicates.asAdmin().getSteps()) {
                traversal.asAdmin().addStep(step);
            }
        }
    }
    return traversal;
}
 
Example #17
Source File: TestHasLabelAndId.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testGraphStepHasLabelWithinCollection() {
    Vertex a = 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().hasLabel("A", "B");
    printTraversalForm(traversal);
    Assert.assertEquals(2, traversal.toList().size());
    traversal = this.sqlgGraph.traversal().V().hasLabel(P.within("A", "B"));
    Assert.assertEquals(2, traversal.toList().size());
    traversal = this.sqlgGraph.traversal().V().hasLabel(P.within(new HashSet<>(Arrays.asList("A", "B"))));
    Assert.assertEquals(2, traversal.toList().size());

    Assert.assertEquals(0, this.sqlgGraph.traversal().V(a, b).hasLabel(P.within("C")).toList().size());
    List<Vertex> vertices = this.sqlgGraph.traversal().V(a, b).hasLabel(P.within(new HashSet<>(Arrays.asList("A", "B", "D")))).toList();
    Assert.assertEquals(2, vertices.size());
}
 
Example #18
Source File: TechnologyTagService.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #19
Source File: PolymorphicTypeResolver.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@Override
public <P extends Element, T extends Element> GraphTraversal<P, T> hasNotType(final GraphTraversal<P, T> traverser, final Class<?> type) {
    final Set<? extends String> allAllowedValues = this.reflectionCache.getSubTypeNames(type.getName());
    return traverser.filter(new Predicate<Traverser<T>>() {
        @Override
        public boolean test(final Traverser<T> toCheck) {
            final Property<String> property = toCheck.get().property(typeResolutionKey);
            if( !property.isPresent() )
                return true;

            final String resolvedType = property.value();
            if( allAllowedValues.contains(resolvedType) )
                return false;
            else
                return true;
        }
    });
}
 
Example #20
Source File: MultiValueListFacetDescriptionTest.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void filterDoesNotAddAFilterWhenTheFacetValueIsNotAListFacetValue() {
  GraphTraversal<Vertex, Vertex> traversal = newGraph()
    .withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_NAME, serializedListOf("value1", "value2")))
    .withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_NAME, serializedListOf("value2", "value3")))
    .withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_NAME, serializedListOf("value1", "value3", "value4")))
    .build().traversal().V();
  List<FacetValue> facetValues = Lists.newArrayList((FacetValue) () -> FACET_NAME);

  instance.filter(traversal, facetValues);

  assertThat(traversal.toList(), containsInAnyOrder(
    likeVertex().withTimId("id1"),
    likeVertex().withTimId("id2"),
    likeVertex().withTimId("id3")));
}
 
Example #21
Source File: EdgeListFacetDescription.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
  Optional<FacetValue> facetValue =
          facets.stream().filter(facet -> Objects.equals(facet.getName(), facetName)).findFirst();

  if (facetValue.isPresent()) {
    FacetValue value = facetValue.get();
    if (value instanceof ListFacetValue) {

      List<String> values = ((ListFacetValue) value).getValues();

      if (!values.isEmpty()) {
        graphTraversal.where(__.inE(values.toArray(new String[values.size()])));
      }
    }
  }
}
 
Example #22
Source File: SparqlToGremlinCompilerTest.java    From sparql-gremlin with Apache License 2.0 5 votes vote down vote up
@Test
public void testModern13() throws Exception {
    final GraphTraversal expected = mg.V().match(
            as("a").out("created").as("b"),
            as("a").values("name").as("c")).dedup("a", "b", "c").select("a", "b", "c");
    assertEquals(expected, convertToGremlinTraversal(modern, loadQuery("modern", 13)));
}
 
Example #23
Source File: AnyTraversal.java    From gremlin-ogm with Apache License 2.0 5 votes vote down vote up
/**
 * Reveal the steps in the {@link SubTraversal} by passing a {@link DefaultGraphTraversal} to it,
 * and outputting it's string representation.
 */
@Override
@SneakyThrows
default void formatTo(Formatter formatter, int flags, int width, int precision) {
  GraphTraversalSource g = new GraphTraversalSource(EmptyGraph.instance());
  GraphTraversal<?, ?> graphTraversal = apply(g);
  formatter.out().append(graphTraversal.toString());
}
 
Example #24
Source File: Page.java    From gremlin-ogm with Apache License 2.0 5 votes vote down vote up
@Override
@SneakyThrows
public GraphTraversal<Element, Element> apply(GraphTraversal<Element, Element> traversal) {
  return traversal
      .hasLabel(org.apache.tinkerpop.gremlin.object.reflect.Label.of(elementType))
      .range(low, high);
}
 
Example #25
Source File: GremlinEnabledScriptEngineTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithAliasAsTraversalSource() throws Exception {
    final GremlinScriptEngine scriptEngine = manager.getEngineByName(ENGINE_TO_TEST);
    final Graph graph = EmptyGraph.instance();
    final GraphTraversalSource g = graph.traversal();

    // purposefully use "x" to match the name of the traversal source binding for "x" below and
    // thus tests the alias added for "x"
    final GraphTraversal t = getTraversalWithLambda(g);

    final Bindings bindings = new SimpleBindings();
    bindings.put("x", g);

    scriptEngine.eval(t.asAdmin().getBytecode(), bindings, GremlinScriptEngine.HIDDEN_G);
}
 
Example #26
Source File: InlineHintService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 #27
Source File: HibernateEntityService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 #28
Source File: InlineHintService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
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 #29
Source File: SortDescriptionTest.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@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 #30
Source File: CredentialTraversalSourceDsl.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Finds users by name.
 */
public GraphTraversal<Vertex, Vertex> users(final String username, final String... more) {
    if (more.length == 0) {
        return this.clone().V().has(VERTEX_LABEL_USER, PROPERTY_USERNAME, username);
    }

    final int lastIndex;
    final String[] usernames = Arrays.copyOf(more, (lastIndex = more.length) + 1);
    usernames[lastIndex] = username;
    return this.clone().V().has(VERTEX_LABEL_USER, PROPERTY_USERNAME, P.within(usernames));
}