Search in sources :

Example 1 with Link

use of org.drools.impact.analysis.graph.Link in project drools by kiegroup.

the class GraphImageGenerator method convertGraph.

private guru.nidi.graphviz.model.Graph convertGraph(Graph g) {
    guru.nidi.graphviz.model.Graph graph = graph(graphName).directed().graphAttr().with(Rank.dir(rankDir).sep(sep));
    List<Node> nodeList = g.getNodeMap().values().stream().collect(Collectors.toList());
    for (Node n : nodeList) {
        guru.nidi.graphviz.model.Node node = node(n.getRuleName());
        if (n.getStatus() == Node.Status.CHANGED) {
            node = node.with(Color.RED, Style.FILLED);
        } else if (n.getStatus() == Node.Status.IMPACTED) {
            node = node.with(Color.YELLOW, Style.FILLED);
        } else if (n.getStatus() == Node.Status.TARGET) {
            node = node.with(Color.ORANGE, Style.FILLED);
        } else if (n.getStatus() == Node.Status.IMPACTING) {
            node = node.with(Color.LIGHTBLUE, Style.FILLED);
        }
        for (Link l : n.getOutgoingLinks()) {
            if (!nodeList.contains(l.getTarget())) {
                // a sub map may have a link to a node which doesn't exist in the sub map
                continue;
            }
            Style<ForNodeLink> style;
            if (l.getReactivityType() == ReactivityType.POSITIVE) {
                style = Style.SOLID;
            } else if (l.getReactivityType() == ReactivityType.NEGATIVE) {
                style = Style.DASHED;
            } else {
                // UNKNOWN
                style = Style.DOTTED;
            }
            node = node.link(to(node(l.getTarget().getRuleName())).with(style));
        }
        graph = graph.with(node);
    }
    return graph;
}
Also used : ForNodeLink(guru.nidi.graphviz.attribute.ForNodeLink) Node(org.drools.impact.analysis.graph.Node) ForNodeLink(guru.nidi.graphviz.attribute.ForNodeLink) Link(org.drools.impact.analysis.graph.Link)

Example 2 with Link

use of org.drools.impact.analysis.graph.Link in project drools by kiegroup.

the class AbstractGraphTest method assertLink.

/**
 * Assert that there are exact links with the types between source node and target node.
 * If no expectedTypes, it means there is no link
 */
protected void assertLink(Graph graph, String sourceFqdn, String targetFqdn, ReactivityType... expectedTypes) {
    Node source = graph.getNodeMap().get(sourceFqdn);
    Node target = graph.getNodeMap().get(targetFqdn);
    List<Link> outgoingLinks = source.getOutgoingLinks().stream().filter(l -> l.getTarget().equals(target)).collect(Collectors.toList());
    List<Link> incomingLinks = target.getIncomingLinks().stream().filter(l -> l.getSource().equals(source)).collect(Collectors.toList());
    assertThat(outgoingLinks).hasSameElementsAs(incomingLinks);
    List<ReactivityType> outgoingLinkTypelist = outgoingLinks.stream().map(l -> l.getReactivityType()).collect(Collectors.toList());
    List<ReactivityType> expectedTypeList = Arrays.asList(expectedTypes);
    assertThat(outgoingLinkTypelist).hasSameElementsAs(expectedTypeList);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) DefaultAgendaEventListener(org.drools.core.event.DefaultAgendaEventListener) Arrays(java.util.Arrays) GraphImageGenerator(org.drools.impact.analysis.graph.graphviz.GraphImageGenerator) Logger(org.slf4j.Logger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Graph(org.drools.impact.analysis.graph.Graph) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) ReactivityType(org.drools.impact.analysis.graph.ReactivityType) Collectors(java.util.stream.Collectors) KieResources(org.kie.api.io.KieResources) ArrayList(java.util.ArrayList) ReleaseId(org.kie.api.builder.ReleaseId) Resource(org.kie.api.io.Resource) List(java.util.List) Rule(org.junit.Rule) Node(org.drools.impact.analysis.graph.Node) TestName(org.junit.rules.TestName) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) Link(org.drools.impact.analysis.graph.Link) Node(org.drools.impact.analysis.graph.Node) ReactivityType(org.drools.impact.analysis.graph.ReactivityType) Link(org.drools.impact.analysis.graph.Link)

Aggregations

Link (org.drools.impact.analysis.graph.Link)2 Node (org.drools.impact.analysis.graph.Node)2 ForNodeLink (guru.nidi.graphviz.attribute.ForNodeLink)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 DefaultAgendaEventListener (org.drools.core.event.DefaultAgendaEventListener)1 Graph (org.drools.impact.analysis.graph.Graph)1 ReactivityType (org.drools.impact.analysis.graph.ReactivityType)1 GraphImageGenerator (org.drools.impact.analysis.graph.graphviz.GraphImageGenerator)1 Rule (org.junit.Rule)1 TestName (org.junit.rules.TestName)1 KieServices (org.kie.api.KieServices)1 KieFileSystem (org.kie.api.builder.KieFileSystem)1 ReleaseId (org.kie.api.builder.ReleaseId)1 AfterMatchFiredEvent (org.kie.api.event.rule.AfterMatchFiredEvent)1 KieResources (org.kie.api.io.KieResources)1