Search in sources :

Example 1 with RuleViolationImpl

use of org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl in project kie-wb-common by kiegroup.

the class AcyclicDirectedGraphRule method evaluate.

@Override
@SuppressWarnings("unchecked")
public RuleViolations evaluate(final RuleExtension rule, final GraphConnectionContext context) {
    final Graph<?, Node> graph = (Graph<?, Node>) context.getGraph();
    final Optional<Node<? extends View<?>, ? extends Edge>> oSource = context.getSource();
    final Optional<Node<? extends View<?>, ? extends Edge>> oTarget = context.getTarget();
    final Edge<? extends View<?>, ? extends Node> oConnector = context.getConnector();
    final DefaultRuleViolations result = new DefaultRuleViolations();
    // Only validate DAG when source and target nodes are set
    if (!(oSource.isPresent() && oTarget.isPresent())) {
        return result;
    }
    final Node<?, Edge> source = (Node<?, Edge>) oSource.get();
    final Node<?, Edge> target = (Node<?, Edge>) oTarget.get();
    final Edge<?, Node> connector = (Edge<?, Node>) oConnector;
    try {
        final TreeWalkTraverseProcessor walker = getTreeWalker(source, target, connector);
        walker.traverse(graph, new TreeTraverseCallback<Graph, Node, Edge>() {

            final Set<Node> inProgress = new HashSet<>();

            @Override
            public void startGraphTraversal(final Graph graph) {
            }

            @Override
            public boolean startNodeTraversal(final Node node) {
                if (inProgress.contains(node)) {
                    throw new DirectedAcrylicGraphViolationException();
                }
                inProgress.add(node);
                return true;
            }

            @Override
            public boolean startEdgeTraversal(final Edge edge) {
                return true;
            }

            @Override
            public void endNodeTraversal(final Node node) {
                inProgress.remove(node);
            }

            @Override
            public void endEdgeTraversal(final Edge edge) {
            }

            @Override
            public void endGraphTraversal() {
            }
        });
    } catch (DirectedAcrylicGraphViolationException e) {
        result.addViolation(new RuleViolationImpl(ERROR_MESSAGE));
    }
    return result;
}
Also used : RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Edge(org.kie.workbench.common.stunner.core.graph.Edge) HashSet(java.util.HashSet)

Example 2 with RuleViolationImpl

use of org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl in project kie-wb-common by kiegroup.

the class AbstractParentsMatchHandler method addViolation.

protected void addViolation(final String uuid, final RuleExtension rule, final DefaultRuleViolations result) {
    final RuleViolationImpl violation = new RuleViolationImpl(getViolationMessage(rule));
    violation.setUUID(uuid);
    result.addViolation(violation);
}
Also used : RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl)

Example 3 with RuleViolationImpl

use of org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl in project kie-wb-common by kiegroup.

the class CompositeCommandTest method testExecuteFailedThenUndo.

@Test
@SuppressWarnings("unchecked")
public void testExecuteFailedThenUndo() {
    Command c1 = mock(Command.class);
    when(c1.allow(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
    when(c1.execute(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
    Command c2 = mock(Command.class);
    when(c2.allow(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
    when(c2.execute(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
    CommandResult<RuleViolation> failed = new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singletonList(new RuleViolationImpl("failed")));
    Command c3 = mock(Command.class);
    when(c3.allow(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
    when(c3.execute(eq(commandExecutionContext))).thenReturn(failed);
    CompositeCommand composite = new CompositeCommand.Builder<>().addCommand(c1).addCommand(c2).addCommand(c3).build();
    CommandResult result = composite.execute(commandExecutionContext);
    assertEquals(CommandResult.Type.ERROR, result.getType());
    verify(c1, times(1)).undo(eq(commandExecutionContext));
    verify(c2, times(1)).undo(eq(commandExecutionContext));
    verify(c3, times(1)).undo(eq(commandExecutionContext));
}
Also used : RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) Command(org.kie.workbench.common.stunner.core.command.Command) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Test(org.junit.Test)

Example 4 with RuleViolationImpl

use of org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl in project kie-wb-common by kiegroup.

the class CanvasHighlightTest method testViolations.

@Test
@SuppressWarnings("unchecked")
public void testViolations() {
    final List<RuleViolation> violations = new LinkedList<>();
    final RuleViolationImpl v1 = new RuleViolationImpl("m1");
    v1.setUUID(ID1);
    final RuleViolationImpl v2 = new RuleViolationImpl("m2");
    v2.setUUID(ID2);
    violations.add(v1);
    violations.add(v2);
    tested.invalid(violations);
    verify(shape1, times(1)).applyState(eq(ShapeState.INVALID));
    verify(shape2, times(1)).applyState(eq(ShapeState.INVALID));
    verify(canvasView, times(2)).setCursor(eq(AbstractCanvas.Cursors.NOT_ALLOWED));
    verify(canvas, times(1)).draw();
}
Also used : RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with RuleViolationImpl

use of org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl in project kie-wb-common by kiegroup.

the class CanvasViolationImplTest method setup.

@Before
public void setup() throws Exception {
    ruleViolation = new RuleViolationImpl(MESSAGE);
    ruleViolation.setUUID(UUID);
}
Also used : RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) Before(org.junit.Before)

Aggregations

RuleViolationImpl (org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl)9 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)4 Before (org.junit.Before)3 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 View (org.kie.workbench.common.stunner.core.graph.content.view.View)2 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Objects (java.util.Objects)1 CanvasCommandResultBuilder (org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder)1 CanvasViolationImpl (org.kie.workbench.common.stunner.core.client.command.CanvasViolationImpl)1 Command (org.kie.workbench.common.stunner.core.command.Command)1 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)1 Graph (org.kie.workbench.common.stunner.core.graph.Graph)1 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)1 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)1 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)1