use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class ConnectionEvaluationHandler method evaluate.
@Override
public RuleViolations evaluate(final CanConnect rule, final ConnectionContext context) {
final List<CanConnect.PermittedConnection> permittedConnections = rule.getPermittedConnections();
final String currentConnectorRole = context.getConnectorRole();
final Set<String> incomingLabels = context.getTargetRoles().orElse(Collections.emptySet());
final Set<String> outgoingLabels = context.getSourceRoles().orElse(Collections.emptySet());
final DefaultRuleViolations results = new DefaultRuleViolations();
final Set<Pair<String, String>> couples = new LinkedHashSet<>();
for (CanConnect.PermittedConnection pc : permittedConnections) {
final boolean startMatch = outgoingLabels.contains(pc.getStartRole());
final boolean endMatch = startMatch && incomingLabels.contains(pc.getEndRole());
if (endMatch) {
return results;
}
couples.add(new Pair<>(pc.getStartRole(), pc.getEndRole()));
}
results.addViolation(new ConnectionRuleViolation(currentConnectorRole, serializeAllowedConnections(couples)));
return results;
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class ConnectorCardinalityEvaluationHandler method evaluate.
@Override
@SuppressWarnings("unchecked")
public RuleViolations evaluate(final EdgeOccurrences rule, final ConnectorCardinalityContext context) {
final DefaultRuleViolations result = new DefaultRuleViolations();
final Node<? extends View<?>, ? extends Edge> candidate = (Node<? extends View<?>, ? extends Edge>) context.getCandidate();
final Edge<? extends View<?>, Node> edge = context.getEdge();
final Optional<CardinalityContext.Operation> operation = context.getOperation();
final EdgeCardinalityContext.Direction direction = context.getDirection();
final List<? extends Edge> edges = isIncoming(direction) ? candidate.getInEdges() : candidate.getOutEdges();
final String edgeId = evalUtils.getElementDefinitionId(edge);
final int count = evalUtils.countEdges(edgeId, edges);
// Delegate to the domain model cardinality rule manager.
result.addViolations(edgeCardinalityEvaluationHandler.evaluate(rule, RuleContextBuilder.DomainContexts.edgeCardinality(candidate.getLabels(), edgeId, count, rule.getDirection(), operation)));
return GraphEvaluationHandlerUtils.addViolationsSourceUUID(edge.getUUID(), result);
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class ContainmentEvaluationHandler method evaluate.
@Override
public RuleViolations evaluate(final CanContain rule, final ContainmentContext context) {
final DefaultRuleViolations results = new DefaultRuleViolations();
final boolean present = context.getCandidateRoles().stream().filter(cr -> rule.getAllowedRoles().contains(cr)).findAny().isPresent();
if (!present) {
results.addViolation(new ContainmentRuleViolation(rule.getRole(), context.getCandidateRoles().toString()));
}
return results;
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class DockingEvaluationHandler method evaluate.
@Override
public RuleViolations evaluate(final CanDock rule, final DockingContext context) {
final DefaultRuleViolations results = new DefaultRuleViolations();
final boolean present = context.getCandidateRoles().stream().filter(cr -> rule.getAllowedRoles().contains(cr)).findAny().isPresent();
if (!present) {
results.addViolation(new DockingRuleViolation(rule.getRole(), context.getCandidateRoles().toString()));
}
return results;
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class EdgeCardinalityEvaluationHandler method evaluate.
@Override
public RuleViolations evaluate(final EdgeOccurrences rule, final EdgeCardinalityContext context) {
final DefaultRuleViolations results = new DefaultRuleViolations();
final int minOccurrences = rule.getMinOccurrences();
final int maxOccurrences = rule.getMaxOccurrences();
final int candidatesCount = context.getCandidateCount();
final Optional<CardinalityContext.Operation> operation = context.getOperation();
final EdgeCardinalityContext.Direction direction = rule.getDirection();
final Violation.Type type = operation.filter(CardinalityContext.Operation.ADD::equals).isPresent() ? Violation.Type.ERROR : Violation.Type.WARNING;
final int _count = !operation.isPresent() ? candidatesCount : (operation.get().equals(CardinalityContext.Operation.ADD) ? candidatesCount + 1 : (candidatesCount > 0 ? candidatesCount - 1 : 0));
if (_count < minOccurrences) {
results.addViolation(new EdgeCardinalityMinRuleViolation(context.getRoles().toString(), context.getEdgeRole(), minOccurrences, candidatesCount, direction, type));
} else if (maxOccurrences > -1 && _count > maxOccurrences) {
results.addViolation(new EdgeCardinalityMaxRuleViolation(context.getRoles().toString(), context.getEdgeRole(), maxOccurrences, candidatesCount, direction, type));
}
return results;
}
Aggregations