Search in sources :

Example 1 with Rule

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

the class CommonLookups method lookupConnectionRules.

private <T> List<Rule> lookupConnectionRules(final String defSetId, final T sourceDefinition, final String edgeId, final int page, final int pageSize) {
    if (null != defSetId) {
        final Set<String> defLabels = getDefinitionLabels(sourceDefinition);
        final RuleLookupRequest.Builder builder = new RuleLookupRequest.Builder();
        builder.definitionSetId(defSetId).type(RuleLookupRequest.Builder.RuleType.CONNECTION).from(defLabels).page(page).pageSize(pageSize);
        if (null != edgeId) {
            builder.id(edgeId);
        }
        final RuleLookupRequest request = builder.build();
        final LookupManager.LookupResponse<Rule> response = ruleLookupManager.lookup(request);
        return response.getResults();
    }
    return null;
}
Also used : RuleLookupRequest(org.kie.workbench.common.stunner.core.lookup.rule.RuleLookupRequest) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) LookupManager(org.kie.workbench.common.stunner.core.lookup.LookupManager) DefinitionLookupManager(org.kie.workbench.common.stunner.core.lookup.definition.DefinitionLookupManager) RuleLookupManager(org.kie.workbench.common.stunner.core.lookup.rule.RuleLookupManager) Rule(org.kie.workbench.common.stunner.core.rule.Rule)

Example 2 with Rule

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

the class CommonLookups method getConnectionRulesAllowedEdges.

/**
 * Returns the allowed edge identifiers that satisfy connection rules for the given
 * source definition.
 * @oaram sourceDefinition The domain model object ( not a graph element ).
 */
private <T> Set<String> getConnectionRulesAllowedEdges(final String defSetId, final T sourceDefinition, final int page, final int pageSize) {
    final List<Rule> rules = lookupConnectionRules(defSetId, sourceDefinition, null, page, pageSize);
    if (null != rules && !rules.isEmpty()) {
        final Set<String> result = new LinkedHashSet<>();
        for (final Rule rule : rules) {
            final CanConnect cr = (CanConnect) rule;
            final String edgeId = cr.getRole();
            result.add(edgeId);
        }
        return result;
    }
    return null;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Rule(org.kie.workbench.common.stunner.core.rule.Rule) CanConnect(org.kie.workbench.common.stunner.core.rule.impl.CanConnect)

Example 3 with Rule

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

the class CommonLookups method getConnectionRulesAllowedTargets.

/**
 * Returns the allowed ROLES that satisfy connection rules for a given source
 * definition ( domain model object, not a node ).and the given edge (connector) identifier.
 * <p>
 * TODO: Handle several result pages.
 */
private <T> Set<String> getConnectionRulesAllowedTargets(final String defSetId, final T sourceDefinition, final String edgeId, final int page, final int pageSize) {
    final List<Rule> rules = lookupConnectionRules(defSetId, sourceDefinition, edgeId, page, pageSize);
    if (null != rules && !rules.isEmpty()) {
        final Set<String> result = new LinkedHashSet<>();
        final Set<String> sourceDefLabels = getDefinitionLabels(sourceDefinition);
        for (final Rule rule : rules) {
            final CanConnect cr = (CanConnect) rule;
            final List<CanConnect.PermittedConnection> connections = cr.getPermittedConnections();
            if (null != connections && !connections.isEmpty()) {
                for (final CanConnect.PermittedConnection connection : connections) {
                    if (sourceDefLabels != null && sourceDefLabels.contains(connection.getStartRole())) {
                        result.add(connection.getEndRole());
                    }
                }
            }
        }
        return result;
    }
    return null;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Rule(org.kie.workbench.common.stunner.core.rule.Rule) CanConnect(org.kie.workbench.common.stunner.core.rule.impl.CanConnect)

Aggregations

Rule (org.kie.workbench.common.stunner.core.rule.Rule)3 LinkedHashSet (java.util.LinkedHashSet)2 CanConnect (org.kie.workbench.common.stunner.core.rule.impl.CanConnect)2 LookupManager (org.kie.workbench.common.stunner.core.lookup.LookupManager)1 DefinitionLookupManager (org.kie.workbench.common.stunner.core.lookup.definition.DefinitionLookupManager)1 RuleLookupManager (org.kie.workbench.common.stunner.core.lookup.rule.RuleLookupManager)1 RuleLookupRequest (org.kie.workbench.common.stunner.core.lookup.rule.RuleLookupRequest)1 RuleContextBuilder (org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder)1