Search in sources :

Example 26 with DefaultRuleViolations

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);
}
Also used : RuleEvaluationHandler(org.kie.workbench.common.stunner.core.rule.RuleEvaluationHandler) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Set(java.util.Set) CanConnect(org.kie.workbench.common.stunner.core.rule.impl.CanConnect) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) View(org.kie.workbench.common.stunner.core.graph.content.view.View) GraphConnectionContext(org.kie.workbench.common.stunner.core.rule.context.GraphConnectionContext) Inject(javax.inject.Inject) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Optional(java.util.Optional) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Node(org.kie.workbench.common.stunner.core.graph.Node) Set(java.util.Set) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)

Example 27 with DefaultRuleViolations

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);
}
Also used : DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)

Example 28 with DefaultRuleViolations

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());
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Test(org.junit.Test)

Example 29 with DefaultRuleViolations

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));
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 30 with DefaultRuleViolations

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());
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Test(org.junit.Test)

Aggregations

DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)37 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)18 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)18 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)16 Test (org.junit.Test)13 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)13 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)12 Edge (org.kie.workbench.common.stunner.core.graph.Edge)11 Node (org.kie.workbench.common.stunner.core.graph.Node)9 View (org.kie.workbench.common.stunner.core.graph.content.view.View)7 Before (org.junit.Before)5 Graph (org.kie.workbench.common.stunner.core.graph.Graph)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 List (java.util.List)3 TestScopeModelFactory (org.kie.workbench.common.stunner.backend.definition.factory.TestScopeModelFactory)3 BPMNDefinitionSet (org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet)3 BPMNDiagramMarshaller (org.kie.workbench.common.stunner.bpmn.backend.BPMNDiagramMarshaller)3 BPMNDirectDiagramMarshaller (org.kie.workbench.common.stunner.bpmn.backend.BPMNDirectDiagramMarshaller)3 BPMNGraphObjectBuilderFactory (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.builder.BPMNGraphObjectBuilderFactory)3