Search in sources :

Example 1 with GraphCommandResultBuilder

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();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 2 with GraphCommandResultBuilder

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();
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 3 with GraphCommandResultBuilder

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();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 4 with GraphCommandResultBuilder

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();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 5 with GraphCommandResultBuilder

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();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) LinkedList(java.util.LinkedList)

Aggregations

GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)11 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)10 Node (org.kie.workbench.common.stunner.core.graph.Node)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)7 Element (org.kie.workbench.common.stunner.core.graph.Element)5 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 Graph (org.kie.workbench.common.stunner.core.graph.Graph)3 LinkedList (java.util.LinkedList)1 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)1 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)1 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)1 BoundsExceededViolation (org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation)1