Search in sources :

Example 71 with RuleViolation

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

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();
}
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) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 73 with RuleViolation

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

Example 74 with RuleViolation

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();
}
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 75 with RuleViolation

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));
}
Also used : Collection(java.util.Collection) ModelValidator(org.kie.workbench.common.stunner.core.validation.ModelValidator) DiagramValidator(org.kie.workbench.common.stunner.core.validation.DiagramValidator) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Supplier(java.util.function.Supplier) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Consumer(java.util.function.Consumer) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) BiConsumer(java.util.function.BiConsumer) Element(org.kie.workbench.common.stunner.core.graph.Element) Optional(java.util.Optional) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) LinkedList(java.util.LinkedList) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) LinkedList(java.util.LinkedList)

Aggregations

RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)122 Test (org.junit.Test)81 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)59 Node (org.kie.workbench.common.stunner.core.graph.Node)27 Edge (org.kie.workbench.common.stunner.core.graph.Edge)26 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)21 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)18 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)18 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)16 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)16 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)15 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)15 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)13 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)12 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)11 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)10 Collection (java.util.Collection)8 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 Binding (org.kie.workbench.common.dmn.api.definition.v1_1.Binding)7