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;
}
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);
}
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));
}
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();
}
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);
}
Aggregations