Search in sources :

Example 21 with DefaultRuleViolations

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CanConnect(org.kie.workbench.common.stunner.core.rule.impl.CanConnect) ConnectionRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ConnectionRuleViolation) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Pair(org.uberfire.commons.data.Pair)

Example 22 with DefaultRuleViolations

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);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) EdgeCardinalityContext(org.kie.workbench.common.stunner.core.rule.context.EdgeCardinalityContext) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 23 with DefaultRuleViolations

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

Example 24 with DefaultRuleViolations

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

Example 25 with DefaultRuleViolations

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;
}
Also used : Violation(org.kie.workbench.common.stunner.core.validation.Violation) EdgeCardinalityMinRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.EdgeCardinalityMinRuleViolation) EdgeCardinalityMaxRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.EdgeCardinalityMaxRuleViolation) EdgeCardinalityMinRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.EdgeCardinalityMinRuleViolation) EdgeCardinalityContext(org.kie.workbench.common.stunner.core.rule.context.EdgeCardinalityContext) CardinalityContext(org.kie.workbench.common.stunner.core.rule.context.CardinalityContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) EdgeCardinalityContext(org.kie.workbench.common.stunner.core.rule.context.EdgeCardinalityContext) EdgeCardinalityMaxRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.EdgeCardinalityMaxRuleViolation)

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