drools-impact-analysis/README.md
This tool can:
This is an experimental feature. The APIs may change in future versions.
You can find an example usage in ExampleUsageTest.java
drools-impact-analysis-graph-graphviz in your project dependency <dependency>
<groupId>org.drools</groupId>
<artifactId>drools-impact-analysis-graph-graphviz</artifactId>
<version>${drools.version}</version>
</dependency>
KieFileSystem to store your assets as usual. Then call KieBuilder.buildAll(ImpactAnalysisProject.class). You can get AnalysisModel. // set up KieFileSystem
...
KieBuilder kieBuilder = KieServices.Factory.get().newKieBuilder(kfs).buildAll(ImpactAnalysisProject.class);
ImpactAnalysisKieModule analysisKieModule = (ImpactAnalysisKieModule) kieBuilder.getKieModule();
AnalysisModel analysisModel = analysisKieModule.getAnalysisModel();
AnalysisModel to Graph using ModelToGraphConverter ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
ImpactAnalysisHelper will produce a sub graph which contains the changed rule and impacted rules ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper();
Graph impactedSubGraph = impactFilter.filterImpactedNodes(graph, "org.drools.impact.analysis.example.PriceCheck_11");
GraphImageGenerator. You can choose the format from DOT, SVG and PNG. GraphImageGenerator generator = new GraphImageGenerator("example-impacted-sub-graph");
generator.generateSvg(impactedSubGraph);
TextReporter. You can choose the format from HierarchyText and FlatText. String hierarchyText = TextReporter.toHierarchyText(impactedSubGraph);
System.out.println(hierarchyText);
GraphCollapsionHelper. It will help you to see the overview. You can also use ImpactAnalysisHelper to the collapsed graph. Graph collapsedGraph = new GraphCollapsionHelper().collapseWithRuleNamePrefix(graph);
Graph impactedCollapsedSubGraph = impactFilter.filterImpactedNodes(collapsedGraph, "org.drools.impact.analysis.example.PriceCheck");
positiveOnly to true for ModelToGraphConverter, ImpactAnalysisHelper and GraphCollapsionHelper constructor. So you can view only positive relations. ModelToGraphConverter converter = new ModelToGraphConverter(true);
Graph graph = converter.toGraph(analysisModel);
ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper(true);
Graph impactedSubGraph = impactFilter.filterImpactedNodes(graph, "org.drools.impact.analysis.example.PriceCheck_11");
[*] is a changed rule. [+] is impacted rules. A rule with parentheses means a circular reference so it doesn't render further.--- toHierarchyText ---
Inventory shortage[+]
PriceCheck_11[*]
StatusCheck_12[+]
(Inventory shortage)
StatusCheck_13[+]
StatusCheck_11[+]
(PriceCheck_11)
--- toFlatText ---
Inventory shortage[+]
PriceCheck_11[*]
StatusCheck_11[+]
StatusCheck_12[+]
StatusCheck_13[+]
ImpactAnalysisHelper.filterImpactingNodes and specify the target rule so you can view rules which impacts on it. Orange node is a target rule. Light blue nodes are impacting rules. Graph impactingSubGraph = impactFilter.filterImpactingNodes(graph, "org.drools.impact.analysis.example.StatusCheck_11");
If you get the warning message when rendering SVG or PNG:
graphviz-java failed to render an image. Solutions would be:
1. Install graphviz tools in your local machine. graphviz-java will use graphviz command line binary (e.g. /usr/bin/dot) if available.
2. Consider generating a graph in DOT format and then visualize it with an external tool.
You would need to install graphviz tools in your local machine. If not possible, you would need to generate the graph in DOT format so that you can render it with another tool later on.