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

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#in() . 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: ClassificationService.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 2
Source File: ApplicationReportService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Takes the first {@link ApplicationReportModel} that has set boolean value {@link ApplicationReportModel#MAIN_APPLICATION_REPORT} to true and whose
 * projectModel is the same as the rootProjectModel of the given file
 * @param fileModel A FileModel for which we are looking for the main application report to link to.
 * @return
 */
public ApplicationReportModel getMainApplicationReportForFile(FileModel fileModel)
{
    ProjectModel rootProjectModel = fileModel.getProjectModel();
    if (rootProjectModel == null)
    {
        return null;
    }
    else
    {
        rootProjectModel = rootProjectModel.getRootProjectModel();
    }
    GraphTraversal<Vertex, Vertex> pipe = new GraphTraversalSource(getGraphContext().getGraph()).V(rootProjectModel.getElement());
    pipe.in(ApplicationReportModel.REPORT_TO_PROJECT_MODEL);
    pipe.has(ApplicationReportModel.MAIN_APPLICATION_REPORT, true);

    ApplicationReportModel mainAppReport = null;
    for (Vertex v : pipe.toList())
    {
        ApplicationReportModel appReport = frame(v);

        if(mainAppReport != null) {
            LOG.warning("There are multiple ApplicationReportModels for a single file " + fileModel.getFilePath() +". This may cause some broken"
                        + "links in the report file");
        }
        mainAppReport = appReport;
    }
    return mainAppReport;
}
 
Example 3
Source File: RMIServiceModelService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private RMIServiceModel findByInterface(JavaClassModel rmiInterface)
{
    GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(rmiInterface.getElement());
    pipeline.in(RMIServiceModel.RMI_INTERFACE);
    pipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(RMIServiceModel.TYPE));

    if (pipeline.hasNext())
    {
        return frame(pipeline.next());
    }
    else
    {
        return null;
    }
}
 
Example 4
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 5
Source File: SpringBeanService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets an {@link Iterable} of {@link SpringBeanModel}s for the given {@link ProjectModel}.
 *
 * @return an iterable of SpringBeanModel entries for the given application
 */
public Iterable<SpringBeanModel> findAllByApplication(ProjectModel application)
{
    GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(application.getElement());
    pipeline.in(SpringBeanModel.APPLICATIONS);
    pipeline.has(WindupVertexFrame.TYPE_PROP, P.eq(SpringBeanModel.TYPE));

    return new FramedVertexIterable<>(getGraphContext().getFramed(), pipeline.toList(), SpringBeanModel.class);
}
 
Example 6
Source File: ClassificationService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return all {@link ClassificationModel} instances that are attached to the given {@link FileModel} instance with a specific classification name.
 */
public Iterable<ClassificationModel> getClassificationByName(FileModel model, String classificationName)
{
    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));
    pipeline.has(ClassificationModel.CLASSIFICATION, classificationName);
    return new FramedVertexIterable<>(getGraphContext().getFramed(), pipeline.toList(), ClassificationModel.class);
}
 
Example 7
Source File: ClassificationService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 8
Source File: ApplicationReportIndexService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the {@link ApplicationReportIndexModel} associated with the provided ProjectModel
 */
public ApplicationReportIndexModel getApplicationReportIndexForProjectModel(ProjectModel projectModel)
{
    GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(projectModel.getElement());
    pipeline.in(ApplicationReportIndexModel.APPLICATION_REPORT_INDEX_TO_PROJECT_MODEL);

    ApplicationReportIndexModel applicationReportIndex = null;
    if (pipeline.hasNext())
    {
        applicationReportIndex = frame(pipeline.next());
    }
    return applicationReportIndex;
}
 
Example 9
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 10
Source File: InlineHintService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the total effort points in all of the {@link InlineHintModel} instances associated with the provided {@link FileModel}.
 */
public int getMigrationEffortPoints(FileModel fileModel)
{
    GraphTraversal<Vertex, Vertex> inlineHintPipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(fileModel.getElement());
    inlineHintPipeline.in(InlineHintModel.FILE_MODEL);
    inlineHintPipeline.has(EffortReportModel.EFFORT, P.gt(0));
    inlineHintPipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(InlineHintModel.TYPE));

    int hintEffort = 0;
    for (Vertex v : inlineHintPipeline.toList())
    {
        hintEffort += (Integer) v.property(InlineHintModel.EFFORT).value();
    }
    return hintEffort;
}
 
Example 11
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 FileModel}
 */
public Iterable<InlineHintModel> getHintsForFile(FileModel file)
{
    GraphTraversal<Vertex, Vertex> inlineHintPipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(file.getElement());
    inlineHintPipeline.in(FileReferenceModel.FILE_MODEL);
    inlineHintPipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(InlineHintModel.TYPE));
    return new FramedVertexIterable<>(getGraphContext().getFramed(), inlineHintPipeline.toList(), InlineHintModel.class);
}
 
Example 12
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 13
Source File: SourceReportService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find the SourceReportModel instance for this fileModel (this is a 1:1 relationship).
 */
public SourceReportModel getSourceReportForFileModel(FileModel fileModel)
{
    GraphTraversal<Vertex, Vertex> pipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(fileModel.getElement());
    pipeline.in(SourceReportModel.SOURCE_REPORT_TO_SOURCE_FILE_MODEL);

    SourceReportModel result = null;
    if (pipeline.hasNext())
    {
        result = frame(pipeline.next());
    }
    return result;
}
 
Example 14
Source File: InPlaysFragment.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.isVertex(traversal);
    if (required()) {
        vertexTraversal.inE(PLAYS.getLabel()).has(Schema.EdgeProperty.REQUIRED.name()).otherV();
    } else {
        vertexTraversal.in(PLAYS.getLabel());
    }

    return Fragments.inSubs(vertexTraversal);
}
 
Example 15
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 16
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 17
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;
}