Search in sources :

Example 1 with Occurrences

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

the class RuleLookupManagerImpl method matches.

@Override
protected boolean matches(final String key, final String value, final Rule rule) {
    switch(key) {
        case TYPE:
            return CONTAINMENT.equals(value) && (rule instanceof CanContain) || CONNECTION.equals(value) && (rule instanceof CanConnect) || CARDINALITY.equals(value) && (rule instanceof Occurrences) || EDGECARDINALITY.equals(value) && (rule instanceof EdgeOccurrences);
        case ROLES:
            try {
                // Permitted roles on containment rules.
                final CanContain cr = (CanContain) rule;
                final Set<String> rolesSet = toSet(value);
                if (null != rolesSet) {
                    return isIntersect(cr.getAllowedRoles(), rolesSet);
                }
            } catch (final ClassCastException e) {
                return false;
            }
            return true;
        case ID:
            String _id = null;
            if (rule instanceof CanContain) {
                final CanContain er = (CanContain) rule;
                _id = er.getRole();
            } else if (rule instanceof CanConnect) {
                final CanConnect er = (CanConnect) rule;
                _id = er.getRole();
            }
            return _id != null && _id.equals(value);
        case ROLE:
            if (rule instanceof EdgeOccurrences) {
                final EdgeOccurrences er = (EdgeOccurrences) rule;
                return (er.getRole().equals(value));
            }
            return false;
        case ROLE_IN:
            if (rule instanceof EdgeOccurrences) {
                final EdgeOccurrences er = (EdgeOccurrences) rule;
                final Set<String> set = toSet(value);
                if (null != set && !set.isEmpty()) {
                    for (final String s : set) {
                        if (er.getRole().equals(value)) {
                            return true;
                        }
                    }
                }
            }
            return false;
        case EDGE_TYPE:
            try {
                final EdgeOccurrences er = (EdgeOccurrences) rule;
                return er.getDirection().equals(INCOMING.equals(value) ? EdgeCardinalityContext.Direction.INCOMING : EdgeCardinalityContext.Direction.OUTGOING);
            } catch (final ClassCastException e) {
                return false;
            }
        case FROM:
        case TO:
            // Connection rules.
            try {
                final CanConnect cr = (CanConnect) rule;
                final Set<String> fromSet = toSet(value);
                Set<String> ruleSet = getRoles(cr.getPermittedConnections(), FROM.equals(key));
                if (null != fromSet) {
                    return isIntersect(fromSet, ruleSet);
                }
            } catch (final Exception e) {
                return false;
            }
    }
    throw new UnsupportedOperationException("Cannot filter rules by key [" + key + "]");
}
Also used : CanContain(org.kie.workbench.common.stunner.core.rule.impl.CanContain) EdgeOccurrences(org.kie.workbench.common.stunner.core.rule.impl.EdgeOccurrences) EdgeOccurrences(org.kie.workbench.common.stunner.core.rule.impl.EdgeOccurrences) Occurrences(org.kie.workbench.common.stunner.core.rule.impl.Occurrences) CanConnect(org.kie.workbench.common.stunner.core.rule.impl.CanConnect)

Aggregations

CanConnect (org.kie.workbench.common.stunner.core.rule.impl.CanConnect)1 CanContain (org.kie.workbench.common.stunner.core.rule.impl.CanContain)1 EdgeOccurrences (org.kie.workbench.common.stunner.core.rule.impl.EdgeOccurrences)1 Occurrences (org.kie.workbench.common.stunner.core.rule.impl.Occurrences)1