Search in sources :

Example 36 with DefaultRuleViolations

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

the class RuleExtensionMultiHandlerTest method setup.

@Before
public void setup() throws Exception {
    context = RuleContextBuilder.DomainContexts.containment(Collections.singleton("id1"), Collections.emptySet());
    violation1 = new RuleViolationImpl("v1");
    violations1 = new DefaultRuleViolations().addViolation(violation1);
    when(handler1.getRuleType()).thenReturn(RuleExtension.class);
    when(handler1.getContextType()).thenReturn(ContainmentContext.class);
    when(handler2.getRuleType()).thenReturn(RuleExtension.class);
    when(handler2.getContextType()).thenReturn(ContainmentContext.class);
    tested = new RuleExtensionMultiHandler();
    tested.addHandler(handler1);
    tested.addHandler(handler2);
}
Also used : RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Before(org.junit.Before)

Example 37 with DefaultRuleViolations

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

the class SingleConnectorPerTypeGraphRule method evaluate.

@Override
@SuppressWarnings("unchecked")
public RuleViolations evaluate(final RuleExtension rule, final GraphConnectionContext context) {
    final Optional<Node<? extends View<?>, ? extends Edge>> oSource = context.getSource();
    final Optional<Node<? extends View<?>, ? extends Edge>> oTarget = context.getTarget();
    final DefaultRuleViolations result = new DefaultRuleViolations();
    // Only validate when source and target nodes are set
    if (!(oSource.isPresent() && oTarget.isPresent())) {
        return result;
    }
    final Node<? extends View<?>, ? extends Edge> source = oSource.get();
    final Node<? extends View<?>, ? extends Edge> target = oTarget.get();
    final Edge<? extends View<?>, ? extends Node> connector = context.getConnector();
    if (isConnectionAlreadyFormed(source, target, connector)) {
        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) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

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