Skip to content

Commit

Permalink
Moved query into the *Service class and limited it to related Applica…
Browse files Browse the repository at this point in the history
…tionReportModels.
  • Loading branch information
jsight committed Oct 13, 2014
1 parent 29d0de8 commit e57e505
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 57 deletions.
Expand Up @@ -8,9 +8,8 @@
import com.tinkerpop.frames.modules.typedgraph.TypeValue;

/**
* These reports are directly associated with an application, and that application's project model. These can include
* things like an Application Overview report (with various hints, etc) as well as more specific reports (hibernate
* reports, ejb reports, classloading reports, etc).
* These reports are directly associated with an application, and that application's project model. These can include things like an Application
* Overview report (with various hints, etc) as well as more specific reports (hibernate reports, ejb reports, classloading reports, etc).
*
* @author jsightler <jesse.sightler@gmail.com>
*/
Expand All @@ -23,7 +22,7 @@ public interface ApplicationReportModel extends ReportModel
public static final String REPORT_TO_APPLICATION_NOTE = "reportToApplicationNote";
public static final String REPORT_TO_PROJECT_MODEL = "reportToProjectModel";
public static final String REPORT_PRIORITY = "reportPriority";
public static final String MAIN_APPLICATION_REPORT= "mainApplicationModel";
public static final String MAIN_APPLICATION_REPORT = "mainApplicationModel";

/**
* Provides a link to the Navigation Index that is used for this particular report
Expand All @@ -50,15 +49,15 @@ public interface ApplicationReportModel extends ReportModel
public void setReportPriority(int priority);

/**
* Indicates whether or not to display this in the list of all applications. Usually this would be true for a main
* "overview" type report for a particular application, and false for everything else.
* Indicates whether or not to display this in the list of all applications. Usually this would be true for a main "overview" type report for a
* particular application, and false for everything else.
*/
@Property(DISPLAY_IN_APPLICATION_LIST)
public Boolean getDisplayInApplicationList();

/**
* Indicates whether or not to display this in the list of all applications. Usually this would be true for a main
* "overview" type report for a particular application, and false for everything else.
* Indicates whether or not to display this in the list of all applications. Usually this would be true for a main "overview" type report for a
* particular application, and false for everything else.
*/
@Property(DISPLAY_IN_APPLICATION_LIST)
public void setDisplayInApplicationList(Boolean displayInApplicationList);
Expand All @@ -74,17 +73,18 @@ public interface ApplicationReportModel extends ReportModel
*/
@Property(DISPLAY_IN_APPLICATION_REPORT_INDEX)
public void setDisplayInApplicationReportIndex(Boolean displayInIndex);



@Property(MAIN_APPLICATION_REPORT)
public Boolean getMainApplicationReport();

@Property(MAIN_APPLICATION_REPORT)
public void setMainApplicationReport(Boolean mainApplicationReport);




/**
* Indicates whether or not this is the main report for the application.
*/
@Property(MAIN_APPLICATION_REPORT)
public Boolean isMainApplicationReport();

/**
* Indicates whether or not this is the main report for the application.
*/
@Property(MAIN_APPLICATION_REPORT)
public void setMainApplicationReport(Boolean mainApplicationReport);

/**
* Application notes allow custom text to be added
Expand Down
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -113,26 +112,26 @@ public interface ReportModel extends WindupVertexFrame

@Adjacency(label = CHILD_REPORT, direction = Direction.OUT)
public void addChildReport(final ReportModel reportResource);

/**
* Get all ReportModels that should be displayed in the path to this report.
*/
@JavaHandler
public List<ReportModel> getAllParentsInReversedOrder();

abstract class Impl implements ReportModel, JavaHandlerContext<Vertex>
{
public List<ReportModel> getAllParentsInReversedOrder()
{
List<ReportModel> reports = new ArrayList<>();
ReportModel currentReport = this;
reports.add(this);
while(currentReport.getParentReport() != null) {
while (currentReport.getParentReport() != null)
{
reports.add(currentReport.getParentReport());
currentReport = currentReport.getParentReport();
}


Collections.reverse(reports);
return reports;
}
Expand Down
@@ -1,9 +1,15 @@
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.ApplicationReportModel;

import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;

/**
* This class provides helpful utility methods for creating and finding {@link ApplicationReportModel} vertices.
*
Expand All @@ -17,4 +23,32 @@ public ApplicationReportService(GraphContext context)
super(context, ApplicationReportModel.class);
}

public ApplicationReportModel getMainApplicationReportForFile(FileModel fileModel)
{
GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<>(getGraphContext().getGraph());
pipe.V(WindupVertexFrame.TYPE_PROP, ApplicationReportModel.TYPE);
pipe.has(ApplicationReportModel.MAIN_APPLICATION_REPORT, true);
pipe.as("applicationReport");
pipe.out(ApplicationReportModel.REPORT_TO_PROJECT_MODEL);

// check that the project for this application report is the same as the root project for the provided fileModel
ProjectModel rootProjectModel = fileModel.getProjectModel();
while (rootProjectModel.getParentProject() != null)
{
rootProjectModel = rootProjectModel.getParentProject();
}
String rootFilePath = rootProjectModel.getRootFileModel().getFilePath();
pipe.out(ProjectModel.ROOT_FILE_MODEL);
pipe.has(FileModel.FILE_PATH, rootFilePath);

pipe.back("applicationReport");

if (pipe.iterator().hasNext())
{
Vertex v = pipe.iterator().next();
ApplicationReportModel mainAppReport = frame(v);
return mainAppReport;
}
return null;
}
}
@@ -1,11 +1,5 @@
package org.jboss.windup.reporting.rules.generation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.tinkerpop.blueprints.Vertex;

import javax.inject.Inject;

import org.jboss.forge.furnace.services.Imported;
Expand All @@ -16,7 +10,6 @@
import org.jboss.windup.config.operation.ruleelement.AbstractIterationOperation;
import org.jboss.windup.config.query.Query;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.graph.model.resource.FileModel;
import org.jboss.windup.graph.model.resource.SourceFileModel;
import org.jboss.windup.graph.service.GraphService;
Expand All @@ -27,16 +20,14 @@
import org.jboss.windup.reporting.model.TemplateType;
import org.jboss.windup.reporting.model.source.SourceReportModel;
import org.jboss.windup.reporting.query.FindClassifiedFilesGremlinCriterion;
import org.jboss.windup.reporting.service.ApplicationReportService;
import org.jboss.windup.reporting.service.ReportService;
import org.jboss.windup.reporting.service.SourceReportModelService;
import org.ocpsoft.rewrite.config.Condition;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.context.EvaluationContext;

import com.tinkerpop.blueprints.Element;
import com.tinkerpop.gremlin.java.GremlinPipeline;

/**
* This creates SourceReportModel entries for every relevant item within the graph.
*
Expand Down Expand Up @@ -84,30 +75,12 @@ public void perform(GraphRewrite event, EvaluationContext context, FileModel pay
sm.setReportName(payload.getFileName());
sm.setTemplatePath(TEMPLATE);
sm.setTemplateType(TemplateType.FREEMARKER);
GraphService<ApplicationReportModel> applicationReportService =
new GraphService<ApplicationReportModel>(event.getGraphContext(),
ApplicationReportModel.class);
Iterable<ApplicationReportModel> allApplicationReports = applicationReportService.findAll();
List<Vertex> vertices = new ArrayList<Vertex>();
for (ApplicationReportModel model : allApplicationReports)
{
vertices.add(model.asVertex());
}
GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<>(vertices);
if (payload.getProjectModel() != null && payload.getProjectModel().getRootFileModel() != null)
{

String payloadProjectFilePath = payload.getProjectModel().getRootFileModel().getFilePath();
pipe.as("result").has(ApplicationReportModel.MAIN_APPLICATION_REPORT, true).back("result");

if (pipe.iterator().hasNext())
{
Vertex v = pipe.iterator().next();
ApplicationReportModel parentReport = event.getGraphContext().getFramed()
.frame(v, ApplicationReportModel.class);
sm.setParentReport(parentReport);
}
ApplicationReportService applicationReportService = new ApplicationReportService(event.getGraphContext());
ApplicationReportModel mainAppReport = applicationReportService.getMainApplicationReportForFile(payload);
if (mainAppReport != null) {
sm.setParentReport(mainAppReport);
}

GraphService.addTypeToModel(event.getGraphContext(), sm, FreeMarkerSourceReportModel.class);
ReportService reportService = new ReportService(event.getGraphContext());
reportService.setUniqueFilename(sm, payload.getFileName(), "html");
Expand Down

0 comments on commit e57e505

Please sign in to comment.