Search in sources :

Example 6 with RuleViolationImpl

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

the class AddCanvasControlPointCommand method allow.

@Override
public CommandResult<CanvasViolation> allow(AbstractCanvasHandler context) {
    if (checkExistingControlPoints(ShapeUtils.getControlPoints(candidate, context))) {
        return buildResult();
    }
    ShapeUtils.hideControlPoints(candidate, context);
    List<ControlPoint> addedControlPoints = ShapeUtils.addControlPoints(candidate, context, this.controlPoints);
    if (addedControlPoints.stream().map(ControlPoint::getIndex).anyMatch(Objects::isNull)) {
        return new CanvasCommandResultBuilder().setType(CommandResult.Type.ERROR).addViolation(new CanvasViolationImpl.Builder().build(new RuleViolationImpl("Control Point out of connector"))).build();
    }
    ShapeUtils.showControlPoints(candidate, context);
    allowed = Boolean.TRUE;
    return buildResult();
}
Also used : RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) Objects(java.util.Objects) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) CanvasViolationImpl(org.kie.workbench.common.stunner.core.client.command.CanvasViolationImpl)

Example 7 with RuleViolationImpl

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

the class RuleManagerImplTest method setup.

@Before
public void setup() throws Exception {
    rule1 = new CanContain("r1", "r1-cId", new HashSet<String>(2) {

        {
            add("role1");
            add("role2");
        }
    });
    rule2 = new CanContain("r2", "r2-cId", new HashSet<String>(2) {

        {
            add("role1");
            add("role2");
        }
    });
    ruleEvaluationContext = RuleContextBuilder.DomainContexts.containment(Collections.singleton("r1-cId"), new HashSet<String>(1) {

        {
            add("r2-cId");
        }
    });
    ruleViolation1 = new RuleViolationImpl("error - v1");
    ruleViolation2 = new RuleViolationImpl("error - v2");
    ruleViolation3 = new RuleViolationImpl("error - v3");
    ruleViolations1 = new DefaultRuleViolations().addViolation(ruleViolation1);
    ruleViolations2 = new DefaultRuleViolations().addViolation(ruleViolation2);
    ruleViolations3 = new DefaultRuleViolations().addViolation(ruleViolation3);
    ruleExtension = new RuleExtension("re1", "cId").setHandlerType(RuleExtensionHandler.class);
    ruleSet = new RuleSetImpl("rs1", new ArrayList<Rule>(2) {

        {
            add(rule1);
            add(rule2);
            add(ruleExtension);
        }
    });
    handlers.add(handler1);
    handlers.add(handler2);
    when(registryFactory.newRuleHandlerRegistry()).thenReturn(registry);
    when(registry.getHandlersByContext(any(Class.class))).thenReturn(handlers);
    when(registry.getExtensionHandler(eq(RuleExtensionHandler.class))).thenReturn(extensionHandler);
    when(handler1.getRuleType()).thenReturn(CanContain.class);
    when(handler1.getContextType()).thenReturn(ContainmentContext.class);
    when(handler2.getRuleType()).thenReturn(CanContain.class);
    when(handler2.getContextType()).thenReturn(ContainmentContext.class);
    when(extensionHandler.getRuleType()).thenReturn(RuleExtension.class);
    when(extensionHandler.getContextType()).thenReturn(ContainmentContext.class);
    tested = new RuleManagerImpl(registryFactory);
}
Also used : CanContain(org.kie.workbench.common.stunner.core.rule.impl.CanContain) RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) RuleExtensionHandler(org.kie.workbench.common.stunner.core.rule.ext.RuleExtensionHandler) ArrayList(java.util.ArrayList) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) HashSet(java.util.HashSet) RuleExtension(org.kie.workbench.common.stunner.core.rule.ext.RuleExtension) Before(org.junit.Before)

Example 8 with RuleViolationImpl

use of org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl 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 9 with RuleViolationImpl

use of org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl 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

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