use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class GraphConnectionEvaluationHandler method evaluate.
@Override
public RuleViolations evaluate(final CanConnect rule, final GraphConnectionContext context) {
final Edge<? extends View<?>, ? extends Node> connector = context.getConnector();
final Node<? extends View<?>, ? extends Edge> source = context.getSource().orElse(null);
final Node<? extends View<?>, ? extends Edge> target = context.getTarget().orElse(null);
if (source == null || target == null) {
return new DefaultRuleViolations();
}
final Set<String> edgeLabels = evalUtils.getLabels(connector);
final Optional<Set<String>> sourceLabels = Optional.of(evalUtils.getLabels(source));
final Optional<Set<String>> targetLabels = Optional.of(evalUtils.getLabels(target));
final DefaultRuleViolations result = new DefaultRuleViolations();
edgeLabels.stream().filter(pr -> rule.getRole().equals(pr)).forEach(pr -> result.addViolations(connectionEvaluationHandler.evaluate(rule, RuleContextBuilder.DomainContexts.connection(pr, sourceLabels, targetLabels))));
return GraphEvaluationHandlerUtils.addViolationsSourceUUID(connector.getUUID(), result);
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class NodeContainmentEvaluationHandler method evaluate.
@Override
public RuleViolations evaluate(final CanContain rule, final NodeContainmentContext context) {
final Element<? extends Definition<?>> source = context.getParent();
final Node<? extends Definition<?>, ? extends Edge> target = context.getCandidate();
final Set<String> candidateLabels = evalUtils.getLabels(target);
final Set<String> parentLabels = evalUtils.getLabels(source);
final DefaultRuleViolations result = new DefaultRuleViolations();
result.addViolations(containmentHandler.evaluate(rule, RuleContextBuilder.DomainContexts.containment(parentLabels, candidateLabels)));
return GraphEvaluationHandlerUtils.addViolationsSourceUUID(target.getUUID(), result);
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class AddChildNodeCommandTest method testNotAllowed.
@Test
@SuppressWarnings("unchecked")
public void testNotAllowed() {
final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID));
when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class AddNodeCommandTest method testExecuteCheckFailed.
@Test
@SuppressWarnings("unchecked")
public void testExecuteCheckFailed() {
final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new ContainmentRuleViolation(graph.getUUID(), UUID));
when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
verify(graph, times(0)).addNode(eq(node));
verify(graphIndex, times(0)).addNode(eq(node));
verify(graphIndex, times(0)).addEdge(any(Edge.class));
verify(graph, times(0)).removeNode(eq(UUID));
verify(graphIndex, times(0)).removeNode(eq(node));
verify(graphIndex, times(0)).removeEdge(any(Edge.class));
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class DeleteConnectorCommandTest method testNotAllowed.
@Test
@SuppressWarnings("unchecked")
public void testNotAllowed() {
final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new ContainmentRuleViolation(graph.getUUID(), UUID));
when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
}
Aggregations