use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class SafeDeleteNodeCommand method doAllow.
@Override
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> doAllow(final GraphCommandExecutionContext context, final Command<GraphCommandExecutionContext, RuleViolation> command) {
final CommandResult<RuleViolation> result = super.doAllow(context, command);
if (!CommandUtils.isError(result) && hasRules(context)) {
final Graph target = getGraph(context);
final Node<View<?>, Edge> candidate = (Node<View<?>, Edge>) getCandidate(context);
final GraphCommandResultBuilder builder = new GraphCommandResultBuilder();
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(target, Optional.of(candidate), Optional.of(CardinalityContext.Operation.DELETE)));
builder.addViolations(cardinalityRuleViolations);
for (final RuleViolation violation : cardinalityRuleViolations) {
if (builder.isError(violation)) {
return builder.build();
}
}
return builder.build();
}
return result;
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class SetConnectionTargetNodeCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
final GraphCommandResultBuilder resultBuilder = new GraphCommandResultBuilder();
final Node<? extends View<?>, Edge> targetNode = getTargetNode(context);
final Edge<View<?>, Node> edge = (Edge<View<?>, Node>) getEdge(context);
final Node<? extends View<?>, Edge> lastTargetNode = edge.getTargetNode();
// Only check for rules in case the connector's target node is a different one.
if ((null == lastTargetNode && null != targetNode) || (null != lastTargetNode && (!lastTargetNode.equals(targetNode)))) {
final Collection<RuleViolation> connectionRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.connection(getGraph(context), edge, Optional.ofNullable(sourceNode), Optional.ofNullable(targetNode)));
resultBuilder.addViolations(connectionRuleViolations);
final Node<? extends View<?>, Edge> currentTarget = edge.getTargetNode();
if (null != currentTarget) {
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.edgeCardinality(getGraph(context), currentTarget, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.DELETE)));
resultBuilder.addViolations(cardinalityRuleViolations);
}
if (null != targetNode) {
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.edgeCardinality(getGraph(context), targetNode, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.ADD)));
resultBuilder.addViolations(cardinalityRuleViolations);
}
}
return resultBuilder.build();
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class SetConnectionTargetNodeCommand method execute.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
final CommandResult<RuleViolation> results = allow(context);
if (!results.getType().equals(CommandResult.Type.ERROR)) {
final Edge<? extends View, Node> edge = getEdge(context);
final Node<?, Edge> targetNode = getTargetNode(context);
final Node<? extends View<?>, Edge> lastTargetNode = edge.getTargetNode();
// New connection being made
if (null != lastTargetNode) {
lastTargetNodeUUID = lastTargetNode.getUUID();
lastTargetNode.getInEdges().remove(edge);
}
if (null != targetNode) {
targetNode.getInEdges().add(edge);
}
edge.setTargetNode(targetNode);
// Magnet being moved on node
ViewConnector connectionContent = (ViewConnector) edge.getContent();
lastConnection = (Connection) connectionContent.getTargetConnection().orElse(null);
connectionContent.setTargetConnection(connection);
}
return results;
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class SetParentNodeCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
final Node<Definition<?>, Edge> candidate = (Node<Definition<?>, Edge>) getCandidate(context);
final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), parent, candidate));
return new GraphCommandResultBuilder(containmentRuleViolations).build();
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class AbstractDiagramValidator method validate.
@Override
@SuppressWarnings("unchecked")
public void validate(final Diagram diagram, final Consumer<Collection<DiagramElementViolation<RuleViolation>>> resultConsumer) {
final Graph graph = diagram.getGraph();
final List<DiagramElementViolation<RuleViolation>> violations = new LinkedList<>();
graphValidator.validate(graph, Optional.empty(), Optional.of((g, v) -> consumeBeanAndViolations(() -> violations).accept(g, v)), Optional.of((n, v) -> consumeBeanAndViolations(() -> violations).accept(n, v)), Optional.of((e, v) -> consumeBeanAndViolations(() -> violations).accept(e, v)), // to use the resulting ones here.
vs -> resultConsumer.accept(violations));
}
Aggregations