Skip to content

Commit

Permalink
Merge branch 'OndraZizka-refactorClsfAndHintServices-WINDUP-1067'
Browse files Browse the repository at this point in the history
  • Loading branch information
jsight committed Jun 7, 2016
2 parents ea4f296 + 8525080 commit 8275a9d
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 145 deletions.
Expand Up @@ -11,6 +11,7 @@
import com.tinkerpop.frames.modules.javahandler.JavaHandler;
import com.tinkerpop.frames.modules.javahandler.JavaHandlerContext;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;
import org.jboss.windup.reporting.TagUtil;

/**
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a>
Expand Down Expand Up @@ -38,9 +39,21 @@ public interface TaggableModel extends WindupVertexFrame
@Adjacency(label = TAG, direction = Direction.OUT)
TagSetModel getTagModel();

/**
* Gets the {@link Set} of tags associated with this vertex.
*/
@JavaHandler
Set<String> getTags();

/**
* Returns true if this {@link TaggableModel} matches the provided inclusion and exclusion tags.
*
* {@see TagUtil}
*/
@JavaHandler
boolean matchesTags(Set<String> includeTags, Set<String> excludeTags);


abstract class Impl implements TaggableModel, JavaHandlerContext<Vertex>
{
@Override
Expand All @@ -51,5 +64,10 @@ public Set<String> getTags()
return Collections.emptySet();
return tagSetModel.getTags();
}

public boolean matchesTags(Set<String> includeTags, Set<String> excludeTags)
{
return TagUtil.checkMatchingTags(this.getTags(), includeTags, excludeTags);
}
}
}
@@ -1,8 +1,5 @@
package org.jboss.windup.reporting.service;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

Expand All @@ -13,10 +10,8 @@
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.graph.service.FileService;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.graph.traversal.ProjectModelTraversal;
import org.jboss.windup.reporting.TagUtil;
import org.jboss.windup.reporting.model.ClassificationModel;
import org.jboss.windup.reporting.model.EffortReportModel;
import org.jboss.windup.reporting.model.Severity;
Expand All @@ -29,13 +24,13 @@
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.frames.structures.FramedVertexIterable;
import com.tinkerpop.gremlin.java.GremlinPipeline;
import com.tinkerpop.pipes.PipeFunction;
import org.apache.tools.ant.taskdefs.Length.FileMode;

/**
* Adds methods for loading and querying ClassificationModel related data.
*
*
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a>
*
*
*/
public class ClassificationService extends GraphService<ClassificationModel>
{
Expand Down Expand Up @@ -91,7 +86,8 @@ public Iterable<ClassificationModel> getClassificationByName(FileModel model, St

/**
* <p>
* Returns the total effort points in all of the {@link ClassificationModel}s associated with the files in this project.
* Returns the total effort points in all of the {@link ClassificationModel}s
* associated with the {@link FileMode} instances in the given {@link ProjectModelTraversal}.
* </p>
* <p>
* If set to recursive, then also include the effort points from child projects.
Expand All @@ -100,109 +96,71 @@ public Iterable<ClassificationModel> getClassificationByName(FileModel model, St
* The result is a Map, the key contains the effort level and the value contains the number of incidents.
* </p>
*/
public Map<Integer, Integer> getMigrationEffortByPoints(ProjectModelTraversal initialProject, Set<String> includeTags, Set<String> excludeTags,
public Map<Integer, Integer> getMigrationEffortByPoints(ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags,
boolean recursive, boolean includeZero)
{
final Map<Integer, Integer> results = new HashMap<>();

EffortAccumulatorFunction accumulator = new EffortAccumulatorFunction()
{
@Override
public void accumulate(Vertex effortReportVertex)
{
MapSumEffortAccumulatorFunction<Integer> accumulator = new MapSumEffortAccumulatorFunction(){
public Integer vertexToKey(Vertex effortReportVertex) {
Integer migrationEffort = effortReportVertex.getProperty(EffortReportModel.EFFORT);
if (!results.containsKey(migrationEffort))
results.put(migrationEffort, 1);
else
results.put(migrationEffort, results.get(migrationEffort) + 1);
return migrationEffort;
}
};

getMigrationEffortDetails(initialProject, includeTags, excludeTags, recursive, includeZero, accumulator);

return results;
getMigrationEffortDetails(traversal, includeTags, excludeTags, recursive, includeZero, accumulator);
return accumulator.getResults();
}

/**
* <p>
* Returns the total incidents in all of the {@link ClassificationModel}s associated with the files in this project by severity.
* </p>
*/
public Map<Severity, Integer> getMigrationEffortBySeverity(ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags,
boolean recursive)
public Map<Severity, Integer> getMigrationEffortBySeverity(
ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags, boolean recursive)
{
final Map<Severity, Integer> results = new HashMap<>();

EffortAccumulatorFunction accumulator = new EffortAccumulatorFunction()
{
@Override
public void accumulate(Vertex effortReportVertex)
{
Severity severity = frame(effortReportVertex).getSeverity();
if (!results.containsKey(severity))
results.put(severity, 1);
else
results.put(severity, results.get(severity) + 1);
MapSumEffortAccumulatorFunction<Severity> accumulator = new MapSumEffortAccumulatorFunction(){
public Severity vertexToKey(Vertex effortReportVertex) {
return frame(effortReportVertex).getSeverity();
}
};

getMigrationEffortDetails(traversal, includeTags, excludeTags, recursive, true, accumulator);

return results;
this.getMigrationEffortDetails(traversal, includeTags, excludeTags, recursive, true, accumulator);
return accumulator.getResults();
}

private void getMigrationEffortDetails(ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags, boolean recursive,
boolean includeZero, EffortAccumulatorFunction accumulatorFunction)
{
FileService fileService = new FileService(getGraphContext());

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

GremlinPipeline<Vertex, Vertex> classificationPipeline = new GremlinPipeline<>(getGraphContext().getGraph());
classificationPipeline.V();
GremlinPipeline<Vertex, Vertex> pipeline = new GremlinPipeline<>(this.getGraphContext().getGraph());
pipeline.V();
// If the multivalue index is not 1st, then it doesn't work - https://github.com/thinkaurelius/titan/issues/403
if (!includeZero)
{
classificationPipeline.has(EffortReportModel.EFFORT, Compare.GREATER_THAN, 0);
classificationPipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, ClassificationModel.TYPE);
pipeline.has(EffortReportModel.EFFORT, Compare.GREATER_THAN, 0);
pipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, ClassificationModel.TYPE);
}
else
{
classificationPipeline.has(WindupVertexFrame.TYPE_PROP, ClassificationModel.TYPE);
pipeline.has(WindupVertexFrame.TYPE_PROP, ClassificationModel.TYPE);
}

classificationPipeline.as("classification");
classificationPipeline.out(ClassificationModel.FILE_MODEL);
classificationPipeline.in(ProjectModel.PROJECT_MODEL_TO_FILE);
classificationPipeline.filter(new PipeFunction<Vertex, Boolean>()
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.back("classification");

boolean checkTags = !includeTags.isEmpty() || !excludeTags.isEmpty();
for (Vertex v : pipeline)
{
@Override
public Boolean compute(Vertex argument)
{
return initialVertices.contains(argument);
}
});
classificationPipeline.back("classification");

for (Vertex v : classificationPipeline)
{
Integer migrationEffort = v.getProperty(EffortReportModel.EFFORT);
if (migrationEffort == null)
continue;

// only check tags if we have some passed in
if (!includeTags.isEmpty() || !excludeTags.isEmpty())
{
ClassificationModel classificationModel = frame(v);
if (!TagUtil.checkMatchingTags(classificationModel.getTags(), includeTags, excludeTags))
continue;
}
if (checkTags && !frame(v).matchesTags(includeTags, excludeTags))
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.
for (Vertex fileVertex : v.getVertices(Direction.OUT, ClassificationModel.FILE_MODEL))
{
FileModel fileModel = fileService.frame(fileVertex);
if (initialVertices.contains(fileModel.getProjectModel().asVertex()))
accumulatorFunction.accumulate(v);
}
accumulatorFunction.accumulate(v);
}
}

Expand Down
Expand Up @@ -33,6 +33,7 @@
import com.tinkerpop.pipes.PipeFunction;

import javax.annotation.Nullable;
import org.jboss.windup.reporting.model.ClassificationModel;

/**
* This provides helper functions for finding and creating {@link InlineHintModel} instances within the graph.
Expand Down Expand Up @@ -145,8 +146,8 @@ private Iterable<InlineHintModel> getInlineHintModels(Iterable<Vertex> initialPr

/**
* <p>
* Returns the total effort points in all of the {@link InlineHintModel} instances associated with the {@link FileMode} instances in the given
* {@link ProjectModel}.
* Returns the total effort points in all of the {@link InlineHintModel}s
* associated with the {@link FileMode} instances in the given {@link ProjectModelTraversal}.
* </p>
* <p>
* If set to recursive, then also include the effort points from child projects.
Expand All @@ -155,98 +156,64 @@ private Iterable<InlineHintModel> getInlineHintModels(Iterable<Vertex> initialPr
* The result is a Map, the key contains the effort level and the value contains the number of incidents.
* </p>
*/
public Map<Integer, Integer> getMigrationEffortByPoints(ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags,
boolean recursive, boolean includeZero)
public Map<Integer, Integer> getMigrationEffortByPoints(
ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags, boolean recursive, boolean includeZero)
{
final Map<Integer, Integer> results = new HashMap<>();

EffortAccumulatorFunction accumulator = new EffortAccumulatorFunction()
{
@Override
public void accumulate(Vertex effortReportVertex)
{
MapSumEffortAccumulatorFunction<Integer> accumulator = new MapSumEffortAccumulatorFunction(){
public Object vertexToKey(Vertex effortReportVertex) {
Integer migrationEffort = effortReportVertex.getProperty(EffortReportModel.EFFORT);
if (!results.containsKey(migrationEffort))
results.put(migrationEffort, 1);
else
results.put(migrationEffort, results.get(migrationEffort) + 1);
return migrationEffort;
}
};

getMigrationEffortDetails(traversal, includeTags, excludeTags, recursive, includeZero, accumulator);

return results;
return accumulator.getResults();
}

/**
* <p>
* Returns the total incidents in all of the {@link InlineHintModel}s associated with the files in this project by severity.
* </p>
*/
public Map<Severity, Integer> getMigrationEffortBySeverity(ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags,
boolean recursive)
{
final Map<Severity, Integer> results = new HashMap<>();

EffortAccumulatorFunction accumulator = new EffortAccumulatorFunction()
{
@Override
public void accumulate(Vertex effortReportVertex)
{
Severity severity = frame(effortReportVertex).getSeverity();
if (!results.containsKey(severity))
results.put(severity, 1);
else
results.put(severity, results.get(severity) + 1);
MapSumEffortAccumulatorFunction<Severity> accumulator = new MapSumEffortAccumulatorFunction(){
public Severity vertexToKey(Vertex effortReportVertex) {
return frame(effortReportVertex).getSeverity();
}
};

getMigrationEffortDetails(traversal, includeTags, excludeTags, recursive, true, accumulator);

return results;
this.getMigrationEffortDetails(traversal, includeTags, excludeTags, recursive, true, accumulator);
return accumulator.getResults();
}

private void getMigrationEffortDetails(ProjectModelTraversal traversal, Set<String> includeTags, Set<String> excludeTags, boolean recursive,
boolean includeZero, EffortAccumulatorFunction accumulatorFunction)
{

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

GremlinPipeline<Vertex, Vertex> inlineHintPipeline = new GremlinPipeline<>(getGraphContext().getGraph());
inlineHintPipeline.V();
GremlinPipeline<Vertex, Vertex> pipeline = new GremlinPipeline<>(this.getGraphContext().getGraph());
pipeline.V();
// If the multivalue index is not 1st, then it doesn't work - https://github.com/thinkaurelius/titan/issues/403
if (!includeZero)
{
inlineHintPipeline.has(EffortReportModel.EFFORT, Compare.GREATER_THAN, 0);
inlineHintPipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, InlineHintModel.TYPE);
pipeline.has(EffortReportModel.EFFORT, Compare.GREATER_THAN, 0);
pipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, InlineHintModel.TYPE);
}
else
{
inlineHintPipeline.has(WindupVertexFrame.TYPE_PROP, InlineHintModel.TYPE);
pipeline.has(WindupVertexFrame.TYPE_PROP, InlineHintModel.TYPE);
}

inlineHintPipeline.as("hint");
inlineHintPipeline.out(InlineHintModel.FILE_MODEL);
inlineHintPipeline.in(ProjectModel.PROJECT_MODEL_TO_FILE);
inlineHintPipeline.filter(new PipeFunction<Vertex, Boolean>()
{
@Override
public Boolean compute(Vertex argument)
{
return initialVertices.contains(argument);
}
});
inlineHintPipeline.back("hint");

for (Vertex v : inlineHintPipeline)
pipeline.as("hint");
pipeline.out(InlineHintModel.FILE_MODEL);
pipeline.in(ProjectModel.PROJECT_MODEL_TO_FILE);
pipeline.filter(new SetMembersFilter(initialVertices));
pipeline.back("hint");

boolean checkTags = !includeTags.isEmpty() || !excludeTags.isEmpty();
for (Vertex v : pipeline)
{
// only check tags if we have some passed in
if (!includeTags.isEmpty() || !excludeTags.isEmpty())
{
InlineHintModel hintModel = frame(v);
if (!TagUtil.checkMatchingTags(hintModel.getTags(), includeTags, excludeTags))
continue;
if (checkTags && !frame(v).matchesTags(includeTags, excludeTags))
continue;

}
accumulatorFunction.accumulate(v);
}
}
Expand Down

0 comments on commit 8275a9d

Please sign in to comment.