Search in sources :

Example 1 with ConnectionRuleViolation

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

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 CanConnect (org.kie.workbench.common.stunner.core.rule.impl.CanConnect)1 ConnectionRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ConnectionRuleViolation)1 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)1 Pair (org.uberfire.commons.data.Pair)1