Skip to content

Commit

Permalink
WINDUP-264: Display a technology Tag for individual files in the report
Browse files Browse the repository at this point in the history
  • Loading branch information
jsight committed Sep 22, 2014
1 parent 8a7112a commit b0c27ba
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 3 deletions.
Expand Up @@ -24,6 +24,30 @@ 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.
Expand Down
Expand Up @@ -39,6 +39,24 @@ public Iterable<InlineHintModel> getHintsForFile(FileModel file)
InlineHintModel.class);
}

/**
* Returns the total effort points in all of the {@link InlineHintModel}s associated with the provided
* {@link FileModel}.
*/
public int getMigrationEffortPoints(FileModel fileModel)
{
GremlinPipeline<Vertex, Vertex> inlineHintPipeline = new GremlinPipeline<>(fileModel.asVertex());
inlineHintPipeline.in(InlineHintModel.FILE_MODEL);
inlineHintPipeline.has(WindupVertexFrame.TYPE_PROP, Text.CONTAINS, InlineHintModel.TYPE);

int hintEffort = 0;
for (Vertex v : inlineHintPipeline)
{
hintEffort += (Integer) v.getProperty(InlineHintModel.EFFORT);
}
return hintEffort;
}

/**
* Returns the total effort points in all of the {@link InlineHintModel}s associated with the files in this project.
*
Expand Down
@@ -0,0 +1,55 @@
package org.jboss.windup.reporting.freemarker;

import java.util.List;

import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.reporting.service.ClassificationService;
import org.jboss.windup.reporting.service.InlineHintService;

import freemarker.ext.beans.StringModel;
import freemarker.template.TemplateModelException;

/**
* Gets the number of effort points involved in migrating this particular file
*
* Called from a freemarker template as follows:
*
* getMigrationEffortPointsForFile(FileModel):int
*
* @author jsightler <jesse.sightler@gmail.com>
*
*/
public class GetEffortForFile implements WindupFreeMarkerMethod
{
private ClassificationService classificationService;
private InlineHintService inlineHintService;

@Override
public void setGraphContext(GraphContext context)
{
this.classificationService = new ClassificationService(context);
this.inlineHintService = new InlineHintService(context);
}

@Override
public String getMethodName()
{
return "getMigrationEffortPointsForFile";
}

@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
if (arguments.size() != 1)
{
throw new TemplateModelException(
"Error, method expects two arguments (FileModel)");
}
StringModel fileModelArg = (StringModel) arguments.get(0);
FileModel fileModel = (FileModel) fileModelArg.getWrappedObject();

return classificationService.getMigrationEffortPoints(fileModel)
+ inlineHintService.getMigrationEffortPoints(fileModel);
}
}
Expand Up @@ -63,6 +63,7 @@
<h3>Classification</h3>

<ul>
<li>Estimated Story Points: ${getMigrationEffortPointsForFile(reportModel.sourceFileModel)}</li>
<li>
<#list getTechnologyTagsForFile(reportModel.sourceFileModel).iterator() as techTag>
<span class="label label-info">${techTag.name}</span>
Expand Down
Expand Up @@ -58,7 +58,27 @@ public void testHintEffort() throws Exception

ProjectModel projectModel = fillData(context);
int totalEffort = classificationService.getMigrationEffortPoints(projectModel, true);
Assert.assertEquals(140, totalEffort);
Assert.assertEquals(143, totalEffort);

boolean foundF1Effort = false;
boolean foundF2Effort = false;
for (FileModel fm : projectModel.getFileModels())
{
if (fm.getFilePath().equals("/f1"))
{
int fileEffort = classificationService.getMigrationEffortPoints(fm);
Assert.assertEquals(140, fileEffort);
foundF1Effort = true;
}
else if (fm.getFilePath().equals("/f2"))
{
int fileEffort = classificationService.getMigrationEffortPoints(fm);
Assert.assertEquals(3, fileEffort);
foundF2Effort = true;
}
}
Assert.assertTrue(foundF1Effort);
Assert.assertTrue(foundF2Effort);
}
}

Expand All @@ -78,6 +98,10 @@ private ProjectModel fillData(GraphContext context)
b1b.addFileModel(f1);
b1b.setEffort(120);

ClassificationModel b2 = classificationService.create();
b2.addFileModel(f2);
b2.setEffort(3);

ProjectModel projectModel = context.getFramed().addVertex(null, ProjectModel.class);
projectModel.addFileModel(f1);
f1.setProjectModel(projectModel);
Expand Down
Expand Up @@ -58,7 +58,27 @@ public void testHintEffort() throws Exception

ProjectModel projectModel = fillData(context);
int totalEffort = inlineHintService.getMigrationEffortPoints(projectModel, true);
Assert.assertEquals(150, totalEffort);
Assert.assertEquals(153, totalEffort);

boolean foundF1Effort = false;
boolean foundF2Effort = false;
for (FileModel fm : projectModel.getFileModels())
{
if (fm.getFilePath().equals("/f1"))
{
int fileEffort = inlineHintService.getMigrationEffortPoints(fm);
Assert.assertEquals(150, fileEffort);
foundF1Effort = true;
}
else if (fm.getFilePath().equals("/f2"))
{
int fileEffort = inlineHintService.getMigrationEffortPoints(fm);
Assert.assertEquals(3, fileEffort);
foundF2Effort = true;
}
}
Assert.assertTrue(foundF1Effort);
Assert.assertTrue(foundF2Effort);
}
}

Expand All @@ -78,6 +98,10 @@ private ProjectModel fillData(GraphContext context)
b1b.setFile(f1);
b1b.setEffort(100);

InlineHintModel b2 = inlineHintService.create();
b2.setEffort(3);
b2.setFile(f2);

ProjectModel projectModel = context.getFramed().addVertex(null, ProjectModel.class);
projectModel.addFileModel(f1);
f1.setProjectModel(projectModel);
Expand Down
Expand Up @@ -33,6 +33,10 @@
</ul>
</#if>
</td>
<td>
<#assign fileEffort = getMigrationEffortPointsForFile(sourceReportModel.sourceFileModel)>
${fileEffort}
</td>
</tr>
</#if>
</#macro>
Expand All @@ -42,14 +46,21 @@
<div class="panel-heading">
<h3 class="panel-title">${projectModel.rootFileModel.prettyPath}</h3>

<div class='col-md-3 text-right totalSummary'>
<div class='totalLoe'>
${getMigrationEffortPoints(projectModel, false)}
</div>
<div class='totalDesc'>Story Points</div>
</div>

<div class='col-md-6 pull-right windupPieGraph archiveGraphContainer'>
<div id="project_${projectModel.asVertex().getId()?string("0")}_pie" class='windupPieGraph'></div>
</div>

</div>
<table class="table table-striped table-bordered">
<tr>
<th>Name</th><th>Technology</th><th>Issues</th>
<th>Name</th><th>Technology</th><th>Issues</th><th>Estimated Story Points</th>
</tr>
<#list sortFilesByPathAscending(projectModel.fileModelsNoDirectories) as fileModel>
<@fileModelRenderer fileModel/>
Expand Down
Expand Up @@ -15,6 +15,50 @@
public class TestJavaApplicationOverviewUtil extends TestReportUtil
{

/**
* Checks if the given App section, filepath, and effort level can be seen in the report.
*
* For example checkFilePathEffort("src_example", "src/main/resources/test.properties", 13) will ensure that an
* application called "src_example" is in the report, with a line referencing "src/main/resources/test.properties"
* and that this line contains the effort level 13).
*/
public boolean checkFilePathEffort(String appSection, String filePath, int effort)
{
WebElement appSectionEl = getAppSectionElement(appSection);
if (appSectionEl == null)
{
return false;
}

WebElement fileRowElement = getFileRowElement(appSection, filePath);
if (fileRowElement == null)
{
return false;
}

List<WebElement> elements = fileRowElement.findElements(By.xpath("./td[position() = 4]"));
for (WebElement element : elements)
{
if (element.getText() != null)
{
try
{
int number = Integer.parseInt(element.getText());
if (number == effort)
{
return true;
}
}
catch (NumberFormatException e)
{
// ignore
}

}
}
return false;
}

/**
* Checks if the given App section, filepath, and tag can be found in the report.
*
Expand Down
@@ -1,6 +1,8 @@
package org.jboss.windup.tests.application;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
Expand All @@ -10,8 +12,12 @@
import org.jboss.forge.furnace.repositories.AddonDependencyEntry;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.reporting.model.ReportModel;
import org.jboss.windup.reporting.service.ReportService;
import org.jboss.windup.rules.apps.java.model.JarManifestModel;
import org.jboss.windup.rules.apps.java.reporting.rules.CreateJavaApplicationOverviewReportRuleProvider;
import org.jboss.windup.rules.apps.java.service.JarManifestService;
import org.jboss.windup.testutil.html.TestJavaApplicationOverviewUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -26,6 +32,8 @@ public class WindupArchitectureMediumBinaryModeTest extends WindupArchitectureTe
@AddonDependency(name = "org.jboss.windup.reporting:windup-reporting"),
@AddonDependency(name = "org.jboss.windup.exec:windup-exec"),
@AddonDependency(name = "org.jboss.windup.rules.apps:rules-java"),
@AddonDependency(name = "org.jboss.windup.rules.apps:rules-java-ee"),
@AddonDependency(name = "org.jboss.windup.tests:test-util"),
@AddonDependency(name = "org.jboss.windup.ext:windup-config-groovy"),
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi"),
})
Expand All @@ -40,6 +48,8 @@ public static ForgeArchive getDeployment()
AddonDependencyEntry.create("org.jboss.windup.reporting:windup-reporting"),
AddonDependencyEntry.create("org.jboss.windup.exec:windup-exec"),
AddonDependencyEntry.create("org.jboss.windup.rules.apps:rules-java"),
AddonDependencyEntry.create("org.jboss.windup.rules.apps:rules-java-ee"),
AddonDependencyEntry.create("org.jboss.windup.tests:test-util"),
AddonDependencyEntry.create("org.jboss.windup.ext:windup-config-groovy"),
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi")
);
Expand All @@ -55,6 +65,7 @@ public void testRunWindupMedium() throws Exception
{
super.runTest(context, path, false);
validateManifestEntries(context);
validateReports(context);
}
}

Expand All @@ -80,4 +91,25 @@ private void validateManifestEntries(GraphContext context) throws Exception
Assert.assertEquals(9, numberFound);
Assert.assertTrue(warManifestFound);
}

/**
* Validate that the report pages were generated correctly
*/
private void validateReports(GraphContext context)
{
ReportService reportService = new ReportService(context);
ReportModel reportModel = reportService.getUniqueByProperty(
ReportModel.TEMPLATE_PATH,
CreateJavaApplicationOverviewReportRuleProvider.TEMPLATE_APPLICATION_REPORT);
Path appReportPath = Paths.get(reportService.getReportDirectory(), reportModel.getReportFilename());

TestJavaApplicationOverviewUtil util = new TestJavaApplicationOverviewUtil();
util.loadPage(appReportPath);
Assert.assertTrue(util.checkFilePathAndTag("Windup1x-javaee-example.war",
"META-INF/maven/javaee/javaee/pom.properties", "Properties"));
Assert.assertTrue(util.checkFilePathEffort("Windup1x-javaee-example.war",
"META-INF/maven/javaee/javaee/pom.properties", 0));
Assert.assertTrue(util.checkFilePathEffort("Windup1x-javaee-example.war/WEB-INF/lib/joda-time-2.0.jar",
"org.joda.time.tz.DateTimeZoneBuilder", 48));
}
}

0 comments on commit b0c27ba

Please sign in to comment.