use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder in project kie-wb-common by kiegroup.
the class AddNodeCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
final CommandResult<RuleViolation> parentResult = super.check(context);
final GraphCommandResultBuilder builder = new GraphCommandResultBuilder();
parentResult.getViolations().forEach(builder::addViolation);
final Element<? extends Definition<?>> graph = (Element<? extends Definition<?>>) getGraph(context);
final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), graph, getCandidate()));
builder.addViolations(containmentRuleViolations);
return builder.build();
}
use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder in project kie-wb-common by kiegroup.
the class RegisterNodeCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
final Graph graph = getGraph(context);
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(graph, Optional.of(getCandidate()), Optional.of(CardinalityContext.Operation.ADD)));
return new GraphCommandResultBuilder(cardinalityRuleViolations).build();
}
use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder in project kie-wb-common by kiegroup.
the class SetChildNodeCommand 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.graph.command.GraphCommandResultBuilder in project kie-wb-common by kiegroup.
the class SetConnectionSourceNodeCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
final GraphCommandResultBuilder resultBuilder = new GraphCommandResultBuilder();
final Node<View<?>, Edge> sourceNode = (Node<View<?>, Edge>) getSourceNode(context);
final Edge<View<?>, Node> edge = (Edge<View<?>, Node>) getEdge(context);
final Node<? extends View<?>, Edge> lastSourceNode = edge.getSourceNode();
// Only check for rules in case the connector's source node is a different one.
if ((null == lastSourceNode && null != sourceNode) || (null != lastSourceNode && (!lastSourceNode.equals(sourceNode)))) {
// New connection being made
final Collection<RuleViolation> connectionRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.connection(getGraph(context), edge, Optional.ofNullable(sourceNode), Optional.ofNullable(targetNode)));
resultBuilder.addViolations(connectionRuleViolations);
final Node<View<?>, Edge> currentSource = edge.getSourceNode();
// If the edge has an outoutgoing source node, check cardinality for removing it.
if (null != currentSource) {
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.edgeCardinality(getGraph(context), currentSource, edge, EdgeCardinalityContext.Direction.OUTGOING, Optional.of(CardinalityContext.Operation.DELETE)));
resultBuilder.addViolations(cardinalityRuleViolations);
}
// If the new source node exist, evaluate cardinality rules for this edge.
if (null != sourceNode) {
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.edgeCardinality(getGraph(context), sourceNode, edge, EdgeCardinalityContext.Direction.OUTGOING, 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 AddChildNodeCommand method allow.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> allow(final GraphCommandExecutionContext context) {
ensureInitialized(context);
// Check if rules are present.
if (null == context.getRuleManager()) {
return GraphCommandResultBuilder.SUCCESS;
}
final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), parent, candidate));
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(getGraph(context), Optional.of(candidate), Optional.of(CardinalityContext.Operation.ADD)));
final Collection<RuleViolation> violations = new LinkedList<RuleViolation>();
violations.addAll(containmentRuleViolations);
violations.addAll(cardinalityRuleViolations);
return new GraphCommandResultBuilder(violations).build();
}
Aggregations