use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder in project kie-wb-common by kiegroup.
the class DeregisterNodeCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
// And check it really exist on the graph storage as well.
final org.kie.workbench.common.stunner.core.graph.Graph graph = getGraph(context);
final Node<View<?>, Edge> candidate = (Node<View<?>, Edge>) checkCandidateNotNull(context);
final GraphCommandResultBuilder builder = new GraphCommandResultBuilder();
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(graph, Optional.of(candidate), Optional.of(CardinalityContext.Operation.DELETE)));
builder.addViolations(cardinalityRuleViolations);
return builder.build();
}
use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder in project kie-wb-common by kiegroup.
the class DockNodeCommand 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> dockingRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.docking(getGraph(context), parent, candidate));
return new GraphCommandResultBuilder(dockingRuleViolations).build();
}
use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder 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.graph.command.GraphCommandResultBuilder 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.graph.command.GraphCommandResultBuilder 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();
}
Aggregations