Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#out()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#out() . 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: ClassificationServiceCache.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Indicates whether or not the given {@link FileModel} is already attached to the {@link ClassificationModel}.
 *
 * Note that this assumes all {@link ClassificationModel} attachments are handled via the {@link ClassificationService}.
 *
 * Outside of tests, this should be a safe assumption to make.
 */
static boolean isClassificationLinkedToFileModel(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel)
{
    String key = getClassificationFileModelCacheKey(classificationModel, fileModel);
    Boolean linked = getCache(event).get(key);

    if (linked == null)
    {
        GraphTraversal<Vertex, Vertex> existenceCheck = new GraphTraversalSource(event.getGraphContext().getGraph()).V(classificationModel.getElement());
        existenceCheck.out(ClassificationModel.FILE_MODEL);
        existenceCheck.filter(vertexTraverser -> vertexTraverser.get().equals(fileModel.getElement()));

        linked = existenceCheck.hasNext();
        cacheClassificationFileModel(event, classificationModel, fileModel, linked);
    }
    return linked;
}
 
Example 2
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 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: ShortestPathQueryBuilder.java    From graph-examples with Apache License 2.0 5 votes vote down vote up
/**
 * @return The inner {@code repeat()) traversal.
 */
private Traversal<?, E> buildRepeatTraversal() {
    GraphTraversal<?, E> traversal = __.start();
    if (traverseEdges()) {
        switch (direction) {
            case OUT:
                computeDistance(traversal.outE(edgeLabels)).inV();
                break;
            case IN:
                computeDistance(traversal.inE(edgeLabels)).outV();
                break;
            default:
                computeDistance(traversal.bothE(edgeLabels)).otherV();
                break;
        }
    } else {
        switch (direction) {
            case OUT:
                traversal.out(edgeLabels);
                break;
            case IN:
                traversal.in(edgeLabels);
                break;
            default:
                traversal.both(edgeLabels);
                break;
        }
        computeDistance(traversal);
        if (maxDistance != null) {
            // stop traversing if maximum distance is reached or exceeded
            traversal.filter(__.sack().is(P.lt(maxDistance)));
        }
    }
    traversal.simplePath().from(START_LABEL);
    return traversal;
}
 
Example 4
Source File: OutPlaysFragment.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public GraphTraversal<Vertex, ? extends Element> applyTraversalInner(
        GraphTraversal<Vertex, ? extends Element> traversal, ConceptManager conceptManager, Collection<Variable> vars) {

    GraphTraversal<Vertex, Vertex> vertexTraversal = Fragments.outSubs(Fragments.isVertex(traversal));

    if (required()) {
        return vertexTraversal.outE(PLAYS.getLabel()).has(Schema.EdgeProperty.REQUIRED.name()).otherV();
    } else {
        return vertexTraversal.out(PLAYS.getLabel());
    }
}
 
Example 5
Source File: TraversalExplanationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldWordWrapCorrectly() {
    GraphTraversal<?, ?> traversal = __.V().out().out();
    String toString = traversal.explain().prettyPrint();
    assertFalse(toString.contains("VertexStep(OUT,vertex),\n"));
    //System.out.println(toString);
    ///
    traversal = __.V().out().out().out().out();
    toString = traversal.explain().prettyPrint();
    assertTrue(toString.contains("VertexStep(OUT,vertex),"));
    //System.out.println(toString);
    ///
    for (int i = 0; i < 30; i++) {
        traversal = __.V();
        for (int j = 0; j < i; j++) {
            traversal.out();
        }
        traversal.asAdmin().setStrategies(TraversalStrategies.GlobalCache.getStrategies(Graph.class));
        toString = traversal.explain().prettyPrint();
        if (i < 3)
            assertFalse(toString.contains("VertexStep(OUT,vertex),\n"));
        else {
            assertTrue(Stream.of(toString.split("\n"))
                    .filter(s -> s.startsWith(" "))
                    .map(String::trim)
                    .filter(s -> Character.isLowerCase(s.charAt(0)))
                    .findAny()
                    .isPresent()); // all indented word wraps should start with steps
            assertTrue(toString.contains("vertex"));
        }
        for (int j = 80; j < 200; j++) {
            for (final String line : traversal.explain().prettyPrint(j).split("\n")) {
                assertTrue(line.length() <= j);
            }
        }
        // System.out.println(toString);
    }
}
 
Example 6
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 7
Source File: JaxRSWebServiceModelService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
public JaxRSWebServiceModel getOrCreate(ProjectModel application, String path, JavaClassModel implementationClass)
{
    GraphTraversal<Vertex, Vertex> pipeline;
    if (implementationClass == null)
    {
        pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V();
        pipeline.has(WindupVertexFrame.TYPE_PROP, JaxRSWebServiceModel.TYPE);
    }
    else
    {
        pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(implementationClass.getElement());
        pipeline.out(JaxRSWebServiceModel.JAXRS_IMPLEMENTATION_CLASS);
        pipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(JaxRSWebServiceModel.TYPE));
    }
    pipeline.has(JaxRSWebServiceModel.PATH, path);

    if (pipeline.hasNext())
    {
        JaxRSWebServiceModel result = frame(pipeline.next());
        if (!result.isAssociatedWithApplication(application))
            result.addApplication(application);
        return result;
    }
    else
    {
        JaxRSWebServiceModel jaxWebService = create();
        jaxWebService.addApplication(application);
        jaxWebService.setPath(path);

        jaxWebService.setImplementationClass(implementationClass);
        return jaxWebService;
    }
}
 
Example 8
Source File: VendorSpecificationExtensionService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
public Iterable<VendorSpecificationExtensionModel> getVendorSpecificationExtensions(FileModel model)
{
    GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(model.getElement());
    pipeline.out(VendorSpecificationExtensionModel.REF);
    pipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(VendorSpecificationExtensionModel.TYPE));
    return new FramedVertexIterable<>(getGraphContext().getFramed(), pipeline.toList(), VendorSpecificationExtensionModel.class);
}
 
Example 9
Source File: JarManifestService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets all {@link JarManifestModel}s associated with this archive.
 */
public Iterable<JarManifestModel> getManifestsByArchive(ArchiveModel archiveModel)
{
    GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(archiveModel.getElement());
    pipeline.out(JarManifestModel.ARCHIVE);
    return new FramedVertexIterable<>(getGraphContext().getFramed(), pipeline.toList(), JarManifestModel.class);
}
 
Example 10
Source File: Out.java    From gremlin-ogm with Apache License 2.0 4 votes vote down vote up
@Override
public GraphTraversal<Element, Vertex> apply(GraphTraversal<Element, Element> traversal) {
  return traversal.out(label);
}
 
Example 11
Source File: AdjacentStepPipe.java    From pixy with Apache License 2.0 4 votes vote down vote up
private GraphTraversal addAdjStep(GraphTraversal ans) {
	if (labels == null) {
		switch (step) {
		case in:
			ans = ans.in();
			break;

		case out:
			ans = ans.out();
			break;

		case both:
			ans = ans.both();
			break;

		case inV:
			ans = ans.inV();
			break;

		case outV:
			ans = ans.outV();
			break;
			
		case bothV:
			ans = ans.bothV();
			break;
			
		case inE:
			ans = ans.inE();
			break;
			
		case outE:
			ans = ans.outE();
			break;
			
		case bothE:
			ans = ans.bothE();
			break;
			
		default:
			throw new PixyException(PixyErrorCodes.INTERNAL_ERROR, "Unhandled adjacent step: " + step);
		}
	} else {
		switch (step) {
		case in:
			ans = ans.in(labels);
			break;
			
		case out:
			ans = ans.out(labels);
			break;
			
		case both:
			ans = ans.both(labels);
			break;

		case inE:
			ans = ans.inE(labels);
			break;
			
		case outE:
			ans = ans.outE(labels);
			break;
			
		case bothE:
			ans = ans.bothE(labels);
			break;

		default:
			throw new PixyException(PixyErrorCodes.INTERNAL_ERROR, "Unhandled adjacent step: " + step);
		}
	}
	return ans;
}
 
Example 12
Source File: InlineHintService.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
private void getMigrationEffortDetails(ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags,
                                       Set<String> issueCategoryIDs, boolean recursive, boolean includeZero,
                                       EffortAccumulatorFunction accumulatorFunction)
{
    LOG.log(Level.INFO, String.format(System.lineSeparator()+"\t\t\tEFFORT H: getMigrationEffortDetails() with: %s, %srecur, %sincludeZero, %s, tags: %s, excl: %s",
            traversal, recursive ? "" : "!", includeZero ? "" : "!", accumulatorFunction, includeTags, excludeTags));

    final Set<Vertex> initialVertices = traversal.getAllProjectsAsVertices(recursive);

    GraphTraversal<Vertex, Vertex> pipeline = this.getGraphContext().getGraph().traversal().V();
    // If the multivalue index is not 1st, then it doesn't work - https://github.com/thinkaurelius/titan/issues/403
    if (!includeZero)
    {
        pipeline.has(EffortReportModel.EFFORT, P.gt(0));
        pipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(InlineHintModel.TYPE));
    }
    else
    {
        pipeline.has(WindupVertexFrame.TYPE_PROP, InlineHintModel.TYPE);
    }
    pipeline.as("hint");
    pipeline.out(InlineHintModel.FILE_MODEL);
    pipeline.in(ProjectModel.PROJECT_MODEL_TO_FILE);
    pipeline.filter(new SetMembersFilter(initialVertices));
    pipeline.select("hint");

    boolean checkTags = !includeTags.isEmpty() || !excludeTags.isEmpty();
    for (Vertex v : pipeline.toSet())
    {
        if (checkTags || !issueCategoryIDs.isEmpty())
        {
            InlineHintModel hintModel = frame(v);

            // only check tags if we have some passed in
            if (checkTags && !hintModel.matchesTags(includeTags, excludeTags))
                continue;

            if (!issueCategoryIDs.isEmpty() && !issueCategoryIDs.contains(hintModel.getIssueCategory().getCategoryID()))
                continue;
        }

        accumulatorFunction.accumulate(v);
    }
}
 
Example 13
Source File: ClassificationService.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
private void getMigrationEffortDetails(ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags,
                                       Set<String> issueCategoryIDs, boolean recursive, boolean includeZero,
                                       EffortAccumulatorFunction accumulatorFunction)
{
    LOG.log(Level.INFO, String.format(System.lineSeparator()+"\t\t\tEFFORT C: getMigrationEffortDetails() with: %s, %srecur, %sincludeZero, %s, tags: %s, excl: %s",
            traversal, recursive ? "" : "!", includeZero ? "" : "!", accumulatorFunction, includeTags, excludeTags));

    final Set<Vertex> initialVertices = traversal.getAllProjectsAsVertices(recursive);

    GraphTraversal<Vertex, Vertex> pipeline = this.getGraphContext().getGraph().traversal().V();
    // If the multivalue index is not 1st, then it doesn't work - https://github.com/thinkaurelius/titan/issues/403
    if (!includeZero)
    {
        pipeline.has(EffortReportModel.EFFORT, P.gt(0));
        pipeline.has(WindupVertexFrame.TYPE_PROP, P.eq(ClassificationModel.TYPE));
    }
    else
    {
        pipeline.has(WindupVertexFrame.TYPE_PROP, ClassificationModel.TYPE);
    }
    pipeline.as("classification");
    // For each classification, count it repeatedly for each file that is within given set of Projects (from the traversal).
    pipeline.out(ClassificationModel.FILE_MODEL);
    pipeline.in(ProjectModel.PROJECT_MODEL_TO_FILE);
    pipeline.filter(new SetMembersFilter(initialVertices));
    pipeline.select("classification");

    boolean checkTags = !includeTags.isEmpty() || !excludeTags.isEmpty();
    FileService fileService = new FileService(getGraphContext());
    for (Vertex v : pipeline.toSet())
    {
        if (checkTags || !issueCategoryIDs.isEmpty())
        {
            ClassificationModel classificationModel = frame(v);

            // only check tags if we have some passed in
            if (checkTags && !classificationModel.matchesTags(includeTags, excludeTags))
                continue;

            if (!issueCategoryIDs.isEmpty() && !issueCategoryIDs.contains(classificationModel.getIssueCategory().getCategoryID()))
                continue;
        }

        // For each classification, count it repeatedly for each file.
        // TODO: .accumulate(v, count);
        // TODO: This could be all done just within the query (provided that the tags would be taken care of).
        //       Accumulate could be a PipeFunction.
        Iterator<Vertex> fileVertexIterator = v.vertices(Direction.OUT, ClassificationModel.FILE_MODEL);
        while (fileVertexIterator.hasNext())
        {
            Vertex fileVertex = fileVertexIterator.next();

            // Make sure that this file is actually in an accepted project. The pipeline condition will return
            // classifications that aren't necessarily in the same project.
            FileModel fileModel = fileService.frame(fileVertex);
            if (initialVertices.contains(fileModel.getProjectModel().getElement()))
                accumulatorFunction.accumulate(v);
        }
    }
}
 
Example 14
Source File: OutCriterion.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void query(GraphRewrite event, GraphTraversal<?, Vertex> pipeline)
{
    pipeline.out(edgeLabel);
}