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