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;
}
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;
}
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;
}
Aggregations