use of org.kie.workbench.common.stunner.core.graph.util.ParentTypesMatcher in project kie-wb-common by kiegroup.
the class ConnectorParentsMatchContainmentHandler method evaluateSingleContainment.
@SuppressWarnings("unchecked")
private void evaluateSingleContainment(final DefaultRuleViolations result, final RuleExtension rule, final NodeContainmentContext context, final Node<? extends Definition<?>, ? extends Edge> candidate) {
final GraphEvaluationState state = context.getState();
final Graph<?, ? extends Node> graph = context.getState().getGraph();
final String connectorId = rule.getId();
// Walk throw the graph and evaluate connector source and target nodes parent match.
treeWalkTraverseProcessor.traverse(graph, candidate, new AbstractTreeTraverseCallback<Graph, Node, Edge>() {
@Override
public boolean startNodeTraversal(final Node node) {
// Process incoming edges into the node as well.
final List<? extends Edge> inEdges = node.getInEdges();
if (null != inEdges) {
inEdges.stream().forEach(this::process);
}
return true;
}
@Override
public boolean startEdgeTraversal(final Edge edge) {
return process(edge);
}
private boolean process(final Edge edge) {
final Optional<String> eId = getId(definitionManager, edge);
if (eId.isPresent() && connectorId.equals(eId.get())) {
final Node sourceNode = state.getConnectionState().getSource(edge);
final Node targetNode = state.getConnectionState().getTarget(edge);
final boolean valid = new ParentTypesMatcher(() -> definitionManager, e -> getParent(context, e), rule.getTypeArguments()).matcher().test(sourceNode, targetNode);
if (!valid) {
addViolation(edge.getUUID(), rule, result);
}
}
return true;
}
});
}
use of org.kie.workbench.common.stunner.core.graph.util.ParentTypesMatcher in project kie-wb-common by kiegroup.
the class ConnectorParentsMatchConnectionHandler method evaluateConnection.
@SuppressWarnings("unchecked")
private RuleViolations evaluateConnection(final RuleExtension rule, final GraphConnectionContext context) {
final Edge connector = context.getConnector();
final GraphEvaluationState.ConnectionState connectionState = context.getState().getConnectionState();
final Node<? extends View<?>, ? extends Edge> sourceNode = (Node<? extends View<?>, ? extends Edge>) context.getSource().orElse(connectionState.getSource(connector));
final Node<? extends View<?>, ? extends Edge> targetNode = (Node<? extends View<?>, ? extends Edge>) context.getTarget().orElse(connectionState.getTarget(connector));
final DefaultRuleViolations result = new DefaultRuleViolations();
final GraphEvaluationState.ContainmentState containmentState = context.getState().getContainmentState();
final boolean isValid = new ParentTypesMatcher(() -> definitionManager, containmentState::getParent, rule.getTypeArguments()).matcher().test(sourceNode, targetNode);
if (!isValid) {
addViolation(context.getConnector().getUUID(), rule, result);
}
return result;
}
Aggregations