-
Notifications
You must be signed in to change notification settings - Fork 128
/
ClassificationService.java
96 lines (88 loc) · 3.49 KB
/
ClassificationService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package org.jboss.windup.reporting.service;
import org.jboss.windup.graph.GraphContext;
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.GraphService;
import org.jboss.windup.reporting.model.ClassificationModel;
import com.thinkaurelius.titan.core.attribute.Text;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;
/**
* Adds methods for loading and querying ClassificationModel related data.
*
* @author jsightler <jesse.sightler@gmail.com>
*
*/
public class ClassificationService extends GraphService<ClassificationModel>
{
public ClassificationService(GraphContext context)
{
super(context, ClassificationModel.class);
}
/**
* Returns the total effort points in all of the {@link ClassificationModel}s associated with the provided
* {@link FileModel}.
*
*/
public int getMigrationEffortPoints(FileModel fileModel)
{
// 1. Get all classification models
GremlinPipeline<Vertex, Vertex> classificationPipeline = new GremlinPipeline<>(fileModel.asVertex());
classificationPipeline.in(ClassificationModel.FILE_MODEL);
classificationPipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, ClassificationModel.TYPE);
int classificationEffort = 0;
for (Vertex v : classificationPipeline)
{
Integer migrationEffort = v.getProperty(ClassificationModel.PROPERTY_EFFORT);
if (migrationEffort != null)
{
classificationEffort += migrationEffort;
}
}
return classificationEffort;
}
/**
* Returns the total effort points in all of the {@link ClassificationModel}s associated with the files in this
* project.
*
* If set to recursive, then also include the effort points from child projects.
*
*/
public int getMigrationEffortPoints(ProjectModel projectModel, boolean recursive)
{
// 1. Get all classification models
GremlinPipeline<Vertex, Vertex> classificationPipeline = new GremlinPipeline<>(projectModel.asVertex());
classificationPipeline.out(ProjectModel.PROJECT_MODEL_TO_FILE).in(ClassificationModel.FILE_MODEL);
classificationPipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, ClassificationModel.TYPE);
int classificationEffort = 0;
for (Vertex v : classificationPipeline)
{
Integer migrationEffort = v.getProperty(ClassificationModel.PROPERTY_EFFORT);
if (migrationEffort != null)
{
classificationEffort += migrationEffort;
}
}
if (recursive)
{
for (ProjectModel childProject : projectModel.getChildProjects())
{
classificationEffort += getMigrationEffortPoints(childProject, recursive);
}
}
return classificationEffort;
}
public void attachClassification(FileModel fileModel, String classificationText, String description)
{
ClassificationModel model = getUnique(getTypedQuery()
.has(ClassificationModel.PROPERTY_CLASSIFICATION, classificationText));
if (model == null)
{
model = create();
model.setClassifiation(classificationText);
model.setDescription(description);
}
model.addFileModel(fileModel);
}
}