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;
}
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);
}
Aggregations