Search in sources :

Example 1 with ImpactAnalysisKieModule

use of org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule in project drools by kiegroup.

the class ModelBuilder method build.

public AnalysisModel build(String... stringRules) {
    KieBuilder kieBuilder = createKieBuilder(stringRules);
    ImpactAnalysisKieModule analysisKieModule = (ImpactAnalysisKieModule) kieBuilder.getKieModule();
    return analysisKieModule.getAnalysisModel();
}
Also used : ImpactAnalysisKieModule(org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule) KieBuilder(org.kie.api.builder.KieBuilder)

Example 2 with ImpactAnalysisKieModule

use of org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule in project drools by kiegroup.

the class ExampleUsageTest method testExampleUsage.

@Test
public void testExampleUsage() throws IOException {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.drools.impact.analysis.example", "order-process", "1.0.0");
    KieFileSystem kfs = createKieFileSystemWithClassPathResourceNames(releaseId, getClass(), "/org/drools/impact/analysis/example/CustomerCheck.xls", "/org/drools/impact/analysis/example/PriceCheck.xls", "/org/drools/impact/analysis/example/StatusCheck.xls", "/org/drools/impact/analysis/example/inventory.drl");
    // --- Just to confirm that this rule can run. This part is not actually required for impact analysis
    Order order = new Order(1, "Guitar", 6000, 65, 5);
    Product guitar = new Product("Guitar", 5500, 8);
    KieSession kieSession = RuleExecutionHelper.getKieSession(kfs);
    List<Order> resultList = new ArrayList<>();
    kieSession.setGlobal("resultList", resultList);
    kieSession.insert(order);
    kieSession.insert(guitar);
    kieSession.fireAllRules();
    kieSession.dispose();
    // ---
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(ImpactAnalysisProject.class);
    ImpactAnalysisKieModule analysisKieModule = (ImpactAnalysisKieModule) kieBuilder.getKieModule();
    AnalysisModel analysisModel = analysisKieModule.getAnalysisModel();
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    // whole graph
    generateImage(graph, "example-whole-graph");
    ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper();
    // Assume you want to modify RHS of PriceCheck_11
    Graph impactedSubGraph = impactFilter.filterImpactedNodes(graph, "org.drools.impact.analysis.example.PriceCheck_11");
    // changed node and impacted nodes
    generateImage(impactedSubGraph, "example-impacted-sub-graph");
    // whole graph with impact coloring
    generateImage(graph, "example-impacted-whole-graph");
    // Collapse graph based on rule name prefix (= RuleSet in spreadsheet)
    Graph collapsedGraph = new GraphCollapsionHelper().collapseWithRuleNamePrefix(graph);
    generateImage(collapsedGraph, "example-collapsed-graph");
    // You can also do impact analysis for the collapsedGraph
    Graph impactedCollapsedSubGraph = impactFilter.filterImpactedNodes(collapsedGraph, "org.drools.impact.analysis.example.PriceCheck");
    generateImage(impactedCollapsedSubGraph, "example-impacted-collapsed-sub-graph");
    // Simple text output
    System.out.println("--- toHierarchyText ---");
    String hierarchyText = TextReporter.toHierarchyText(impactedSubGraph);
    System.out.println(hierarchyText);
    System.out.println("--- toFlatText ---");
    String flatText = TextReporter.toFlatText(impactedSubGraph);
    System.out.println(flatText);
    // Reusing the Graph instance for another filtering is allowed. All nodes status are reset to NONE implicitly
    // Backward analysis. View which rules affect StatusCheck_11
    Graph impactingSubGraph = impactFilter.filterImpactingNodes(graph, "org.drools.impact.analysis.example.StatusCheck_11");
    // target node and impacting nodes
    generateImage(impactingSubGraph, "example-impacting-sub-graph");
}
Also used : Order(org.drools.impact.analysis.example.domain.Order) KieFileSystem(org.kie.api.builder.KieFileSystem) ArrayList(java.util.ArrayList) Product(org.drools.impact.analysis.example.domain.Product) GraphCollapsionHelper(org.drools.impact.analysis.graph.GraphCollapsionHelper) KieServices(org.kie.api.KieServices) ImpactAnalysisHelper(org.drools.impact.analysis.graph.ImpactAnalysisHelper) ReleaseId(org.kie.api.builder.ReleaseId) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ImpactAnalysisKieModule(org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule) KieSession(org.kie.api.runtime.KieSession) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 3 with ImpactAnalysisKieModule

use of org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule in project drools by kiegroup.

the class GraphCollapsionTest method testSpreadsheet.

@Test
public void testSpreadsheet() throws IOException {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.drools.impact.analysis.integrationtests", "spreadsheet-test", "1.0.0");
    KieFileSystem kfs = createKieFileSystemWithClassPathResourceNames(releaseId, getClass(), "collapsion01.xls", "collapsion02.xls", "collapsion03.xls");
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(ImpactAnalysisProject.class);
    ImpactAnalysisKieModule analysisKieModule = (ImpactAnalysisKieModule) kieBuilder.getKieModule();
    AnalysisModel analysisModel = analysisKieModule.getAnalysisModel();
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    Graph collapsedGraph = new GraphCollapsionHelper().collapseWithRuleNamePrefix(graph);
    assertEquals(3, collapsedGraph.getNodeMap().size());
    assertLink(collapsedGraph, "mypkg2.CustomerCheck", "mypkg2.PriceCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg2.PriceCheck", "mypkg2.StatusCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg2.StatusCheck", "mypkg2.PriceCheck", ReactivityType.NEGATIVE);
    // --- impact analysis
    // Assuming that "modify" action in PriceCheck_X is changed
    // modify action in PriceCheck_X
    Node changedNode = collapsedGraph.getNodeMap().get("mypkg2.PriceCheck");
    ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper();
    Graph impactedSubGraph = impactFilter.filterImpactedNodes(collapsedGraph, changedNode);
    assertNull(impactedSubGraph.getNodeMap().get("mypkg2.CustomerCheck"));
    assertEquals(Status.CHANGED, impactedSubGraph.getNodeMap().get("mypkg2.PriceCheck").getStatus());
    assertEquals(Status.IMPACTED, impactedSubGraph.getNodeMap().get("mypkg2.StatusCheck").getStatus());
}
Also used : Graph(org.drools.impact.analysis.graph.Graph) KieFileSystem(org.kie.api.builder.KieFileSystem) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) Node(org.drools.impact.analysis.graph.Node) ImpactAnalysisKieModule(org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule) GraphCollapsionHelper(org.drools.impact.analysis.graph.GraphCollapsionHelper) KieServices(org.kie.api.KieServices) ImpactAnalysisHelper(org.drools.impact.analysis.graph.ImpactAnalysisHelper) ReleaseId(org.kie.api.builder.ReleaseId) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Aggregations

ImpactAnalysisKieModule (org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule)3 KieBuilder (org.kie.api.builder.KieBuilder)3 Graph (org.drools.impact.analysis.graph.Graph)2 GraphCollapsionHelper (org.drools.impact.analysis.graph.GraphCollapsionHelper)2 ImpactAnalysisHelper (org.drools.impact.analysis.graph.ImpactAnalysisHelper)2 ModelToGraphConverter (org.drools.impact.analysis.graph.ModelToGraphConverter)2 AnalysisModel (org.drools.impact.analysis.model.AnalysisModel)2 Test (org.junit.Test)2 KieServices (org.kie.api.KieServices)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 ReleaseId (org.kie.api.builder.ReleaseId)2 ArrayList (java.util.ArrayList)1 Order (org.drools.impact.analysis.example.domain.Order)1 Product (org.drools.impact.analysis.example.domain.Product)1 Node (org.drools.impact.analysis.graph.Node)1 KieSession (org.kie.api.runtime.KieSession)1