Coverage Report - org.kuali.rice.kew.rule.FlexRM
 
Classes in this File Line Coverage Branch Coverage Complexity
FlexRM
0%
0/148
0%
0/108
5.059
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.rule;
 18  
 
 19  
 import java.lang.reflect.Method;
 20  
 import java.sql.Timestamp;
 21  
 import java.util.ArrayList;
 22  
 import java.util.Date;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 import org.apache.commons.lang.ObjectUtils;
 27  
 import org.apache.commons.lang.StringUtils;
 28  
 import org.apache.log4j.Logger;
 29  
 import org.kuali.rice.core.api.exception.RiceRuntimeException;
 30  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 31  
 import org.kuali.rice.kew.actionrequest.ActionRequestFactory;
 32  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 33  
 import org.kuali.rice.kew.actionrequest.KimGroupRecipient;
 34  
 import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
 35  
 import org.kuali.rice.kew.actionrequest.Recipient;
 36  
 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
 37  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 38  
 import org.kuali.rice.kew.api.action.ActionRequestStatus;
 39  
 import org.kuali.rice.kew.engine.RouteContext;
 40  
 import org.kuali.rice.kew.engine.node.NodeState;
 41  
 import org.kuali.rice.kew.engine.node.RouteNode;
 42  
 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
 43  
 import org.kuali.rice.kew.exception.WorkflowException;
 44  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 45  
 import org.kuali.rice.kew.rule.bo.RuleAttribute;
 46  
 import org.kuali.rice.kew.rule.bo.RuleTemplate;
 47  
 import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute;
 48  
 import org.kuali.rice.kew.rule.service.RuleDelegationService;
 49  
 import org.kuali.rice.kew.rule.service.RuleService;
 50  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 51  
 import org.kuali.rice.kew.user.RoleRecipient;
 52  
 import org.kuali.rice.kew.util.KEWConstants;
 53  
 import org.kuali.rice.kew.util.PerformanceLogger;
 54  
 import org.kuali.rice.kew.util.ResponsibleParty;
 55  
 import org.kuali.rice.kew.util.Utilities;
 56  
 
 57  
 
 58  
 /**
 59  
  * Generates Action Requests for a Document using the rule system and the specified
 60  
  * {@link RuleTemplate}.
 61  
  *
 62  
  * @see ActionRequestValue
 63  
  * @see RuleTemplate
 64  
  * @see RuleBaseValues
 65  
  *
 66  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 67  
  */
 68  
 public class FlexRM {
 69  
 
 70  0
         private static final Logger LOG = Logger.getLogger(FlexRM.class);
 71  
 
 72  
         /**
 73  
          * The default type of rule selector implementation to use if none is explicitly
 74  
          * specified for the node.
 75  
          */
 76  
         public static final String DEFAULT_RULE_SELECTOR = "Template";
 77  
         /**
 78  
          * Package in which rule selector implementations live
 79  
          */
 80  
         private static final String RULE_SELECTOR_PACKAGE = "org.kuali.rice.kew.rule";
 81  
         /**
 82  
          * The class name suffix all rule selectors should have; e.g. FooRuleSelector
 83  
          */
 84  
         private static final String RULE_SELECTOR_SUFFIX= "RuleSelector";
 85  
 
 86  
         private final Timestamp effectiveDate;
 87  
         /**
 88  
          * An accumulator that keeps track of the number of rules that have been selected over the lifespan of
 89  
          * this FlexRM instance.
 90  
          */
 91  
         private int selectedRules;
 92  
 
 93  0
         public FlexRM() {
 94  0
                 this.effectiveDate = null;
 95  0
         }
 96  
 
 97  0
         public FlexRM(Timestamp effectiveDate) {
 98  0
                 this.effectiveDate = effectiveDate;
 99  0
         }
 100  
 
 101  
         /*public List<ActionRequestValue> getActionRequests(DocumentRouteHeaderValue routeHeader, String ruleTemplateName) throws KEWUserNotFoundException, WorkflowException {
 102  
         return getActionRequests(routeHeader, null, ruleTemplateName);
 103  
     }*/
 104  
 
 105  
         // loads a RuleSelector implementation
 106  
         protected RuleSelector loadRuleSelector(RouteNode routeNodeDef, RouteNodeInstance nodeInstance) throws WorkflowException {
 107  
                 // first see if there ruleselector is configured on a nodeinstance basis
 108  0
                 NodeState ns = null;
 109  0
                 if (nodeInstance != null) {
 110  0
                         ns = nodeInstance.getNodeState(KEWConstants.RULE_SELECTOR_NODE_STATE_KEY);
 111  
                 }
 112  0
                 String ruleSelectorName = null;
 113  0
                 if (ns != null) {
 114  0
                         ruleSelectorName = ns.getValue();
 115  
                 } else {
 116  
                         // otherwise pull it from the RouteNode definition/prototype
 117  0
                         Map<String, String> nodeCfgParams = Utilities.getKeyValueCollectionAsMap(
 118  
                                         routeNodeDef.
 119  
                                         getConfigParams());
 120  0
                         ruleSelectorName = nodeCfgParams.get(RouteNode.RULE_SELECTOR_CFG_KEY);
 121  
                 }
 122  
 
 123  0
                 if (ruleSelectorName == null) {
 124  0
                         ruleSelectorName = DEFAULT_RULE_SELECTOR;
 125  
                 }
 126  0
                 ruleSelectorName = StringUtils.capitalize(ruleSelectorName);
 127  
 
 128  
                 // load up the rule selection implementation
 129  0
                 String className = RULE_SELECTOR_PACKAGE + "." + ruleSelectorName + RULE_SELECTOR_SUFFIX;
 130  
                 Class<?> ruleSelectorClass;
 131  
                 try {
 132  0
                         ruleSelectorClass = ClassLoaderUtils.getDefaultClassLoader().loadClass(className);
 133  0
                 } catch (ClassNotFoundException cnfe) {
 134  0
                         throw new WorkflowException("Rule selector implementation '" + className + "' not found", cnfe);
 135  0
                 }
 136  0
                 if (!RuleSelector.class.isAssignableFrom(ruleSelectorClass)) {
 137  0
                         throw new WorkflowException("Specified class '" + ruleSelectorClass + "' does not implement RuleSelector interface");
 138  
                 }
 139  
                 RuleSelector ruleSelector;
 140  
                 try {
 141  0
                         ruleSelector = ((Class<RuleSelector>) ruleSelectorClass).newInstance();
 142  0
                 } catch (Exception e) {
 143  0
                         if (e instanceof RuntimeException) {
 144  0
                                 throw (RuntimeException)e;
 145  
                         }
 146  0
                         throw new WorkflowException("Error instantiating rule selector implementation '" + ruleSelectorClass + "'", e);
 147  0
                 }
 148  
 
 149  0
                 return ruleSelector;
 150  
         }
 151  
 
 152  
         /**
 153  
          * Generates action requests
 154  
          * @param routeHeader the document route header
 155  
          * @param nodeInstance the route node instance; this may NOT be null
 156  
          * @param ruleTemplateName the rule template
 157  
          * @return list of action requests
 158  
          * @throws WorkflowException
 159  
          */
 160  
         public List<ActionRequestValue> getActionRequests(DocumentRouteHeaderValue routeHeader, RouteNodeInstance nodeInstance, String ruleTemplateName) 
 161  
                         throws WorkflowException {
 162  0
                 return getActionRequests(routeHeader, nodeInstance.getRouteNode(), nodeInstance, ruleTemplateName);
 163  
         }
 164  
 
 165  
         /**
 166  
          * Generates action requests
 167  
          * @param routeHeader the document route header
 168  
          * @param routeNodeDef the RouteNode definition of the route node instance
 169  
          * @param nodeInstance the route node instance; this may be null!
 170  
          * @param ruleTemplateName the rule template
 171  
          * @return list of action requests
 172  
          * @throws WorkflowException
 173  
          */
 174  
         public List<ActionRequestValue> getActionRequests(DocumentRouteHeaderValue routeHeader, RouteNode routeNodeDef, RouteNodeInstance nodeInstance, String ruleTemplateName) 
 175  
                         throws WorkflowException {
 176  0
                 RouteContext context = RouteContext.getCurrentRouteContext();
 177  
                 // TODO really the route context just needs to be able to support nested create and clears
 178  
                 // (i.e. a Stack model similar to transaction intercepting in Spring) and we wouldn't have to do this
 179  0
                 if (context.getDocument() == null) {
 180  0
                         context.setDocument(routeHeader);
 181  
                 }
 182  0
                 if (context.getNodeInstance() == null) {
 183  0
                         context.setNodeInstance(nodeInstance);
 184  
                 }
 185  
 
 186  0
                 LOG.debug("Making action requests for document " + routeHeader.getDocumentId());
 187  
 
 188  0
                 RuleSelector ruleSelector = loadRuleSelector(routeNodeDef, nodeInstance);
 189  
 
 190  0
                 List<Rule> rules = ruleSelector.selectRules(context, routeHeader, nodeInstance, ruleTemplateName, effectiveDate);
 191  
 
 192  
                 // XXX: FIXME: this is a special case hack to expose info from the default selection implementation
 193  
                 // this is used in exactly one place, RoutingReportAction, to make a distinction between no rules being
 194  
                 // selected, and no rules actually matching when evaluated
 195  
                 // if (numberOfRules == 0) {
 196  
                 //   errors.add(new WorkflowServiceErrorImpl("There are no rules.", "routereport.noRules"));
 197  
                 // } else {
 198  
                 //   errors.add(new WorkflowServiceErrorImpl("There are rules, but no matches.", "routereport.noMatchingRules"));
 199  
                 // }
 200  0
                 if (ruleSelector instanceof TemplateRuleSelector) {
 201  0
                         selectedRules += ((TemplateRuleSelector) ruleSelector).getNumberOfSelectedRules();
 202  
                 }
 203  
 
 204  0
                 PerformanceLogger performanceLogger = new PerformanceLogger();
 205  
 
 206  0
                 ActionRequestFactory arFactory = new ActionRequestFactory(routeHeader, context.getNodeInstance());
 207  
 
 208  0
                 List<ActionRequestValue> actionRequests = new ArrayList<ActionRequestValue>();
 209  0
                 if (rules != null) {
 210  0
                         LOG.info("Total number of rules selected by RuleSelector for documentType=" + routeHeader.getDocumentType().getName() + " and ruleTemplate=" + ruleTemplateName + ": " + rules.size());
 211  0
                         for (Rule rule: rules) {
 212  0
                                 RuleExpressionResult result = rule.evaluate(rule, context);
 213  0
                                 if (result.isSuccess() && result.getResponsibilities() != null) {
 214  
                                         // actionRequests.addAll(makeActionRequests(context, rule, routeHeader, null, null));
 215  0
                                         makeActionRequests(arFactory, result.getResponsibilities(), context, rule.getDefinition(), routeHeader, null, null);
 216  
                                 }
 217  0
                         }
 218  
                 }
 219  0
                 actionRequests = new ArrayList<ActionRequestValue>(arFactory.getRequestGraphs());
 220  0
                 performanceLogger.log("Time to make action request for template " + ruleTemplateName);
 221  
 
 222  0
                 return actionRequests;
 223  
         }
 224  
 
 225  
         public ResponsibleParty resolveResponsibilityId(String responsibilityId) {
 226  0
                 if (responsibilityId == null) {
 227  0
                         throw new IllegalArgumentException("A null responsibilityId was passed to resolve responsibility!");
 228  
                 }
 229  0
                 RuleResponsibility resp = getRuleService().findRuleResponsibility(responsibilityId);
 230  0
                 ResponsibleParty responsibleParty = new ResponsibleParty();
 231  0
                 if (resp!=null && resp.isUsingRole()) {
 232  0
                         responsibleParty.setRoleName(resp.getResolvedRoleName());
 233  0
                 } else if (resp!=null && resp.isUsingWorkflowUser()) {
 234  0
                         responsibleParty.setPrincipalId(resp.getRuleResponsibilityName());
 235  0
                 } else if (resp!=null && resp.isUsingGroup()) {
 236  0
                         responsibleParty.setGroupId(resp.getRuleResponsibilityName());
 237  
                 } else {
 238  0
                         throw new RiceRuntimeException("Failed to resolve responsibility from responsibility ID " + responsibilityId + ".  Responsibility was an invalid type: " + resp);
 239  
                 }
 240  0
                 return responsibleParty;
 241  
         }
 242  
 
 243  
         private void makeActionRequests(ActionRequestFactory arFactory, RouteContext context, RuleBaseValues rule, DocumentRouteHeaderValue routeHeader, ActionRequestValue parentRequest, RuleDelegation ruleDelegation)
 244  
                         throws WorkflowException {
 245  
 
 246  0
                 List<RuleResponsibility> responsibilities = rule.getResponsibilities();
 247  0
                 makeActionRequests(arFactory, responsibilities, context, rule, routeHeader, parentRequest, ruleDelegation);
 248  0
         }
 249  
 
 250  
         public void makeActionRequests(ActionRequestFactory arFactory, List<RuleResponsibility> responsibilities, RouteContext context, RuleBaseValues rule, DocumentRouteHeaderValue routeHeader, ActionRequestValue parentRequest, RuleDelegation ruleDelegation)
 251  
                         throws WorkflowException {
 252  
 
 253  
                 //        Set actionRequests = new HashSet();
 254  0
         for (RuleResponsibility responsibility : responsibilities)
 255  
         {
 256  
             //            arFactory = new ActionRequestFactory(routeHeader);
 257  
 
 258  0
             if (responsibility.isUsingRole())
 259  
             {
 260  0
                 makeRoleActionRequests(arFactory, context, rule, responsibility, routeHeader, parentRequest, ruleDelegation);
 261  
             } else
 262  
             {
 263  0
                 makeActionRequest(arFactory, context, rule, routeHeader, responsibility, parentRequest, ruleDelegation);
 264  
             }
 265  
             //            if (arFactory.getRequestGraph() != null) {
 266  
             //            actionRequests.add(arFactory.getRequestGraph());
 267  
             //            }
 268  
         }
 269  0
         }
 270  
 
 271  
         private void buildDelegationGraph(ActionRequestFactory arFactory, RouteContext context, 
 272  
                         RuleBaseValues delegationRule, DocumentRouteHeaderValue routeHeaderValue, ActionRequestValue parentRequest, RuleDelegation ruleDelegation) throws WorkflowException {
 273  0
                 context.setActionRequest(parentRequest);
 274  0
                 if (delegationRule.isActive(new Date())) {
 275  0
             for (RuleResponsibility delegationResp : delegationRule.getResponsibilities())
 276  
             {
 277  0
                 if (delegationResp.isUsingRole())
 278  
                 {
 279  0
                     makeRoleActionRequests(arFactory, context, delegationRule, delegationResp, routeHeaderValue, parentRequest, ruleDelegation);
 280  0
                 } else if (delegationRule.isMatch(context.getDocumentContent()))
 281  
                 {
 282  0
                     makeActionRequest(arFactory, context, delegationRule, routeHeaderValue, delegationResp, parentRequest, ruleDelegation);
 283  
                 }
 284  
             }
 285  
                 }
 286  0
         }
 287  
 
 288  
         /**
 289  
          * Generates action requests for a role responsibility
 290  
          */
 291  
         private void makeRoleActionRequests(ActionRequestFactory arFactory, RouteContext context, 
 292  
                         RuleBaseValues rule, RuleResponsibility resp, DocumentRouteHeaderValue routeHeader, ActionRequestValue parentRequest, 
 293  
                         RuleDelegation ruleDelegation) throws WorkflowException 
 294  
         {
 295  0
                 String roleName = resp.getResolvedRoleName();
 296  0
                 RoleAttribute roleAttribute = resp.resolveRoleAttribute();
 297  0
                 setRuleAttribute(roleAttribute, rule, resp.getRoleAttributeName());
 298  0
                 List<String> qualifiedRoleNames = new ArrayList<String>();
 299  0
                 if (parentRequest != null && parentRequest.getQualifiedRoleName() != null) {
 300  0
                         qualifiedRoleNames.add(parentRequest.getQualifiedRoleName());
 301  
                 } else {
 302  0
                         qualifiedRoleNames.addAll(roleAttribute.getQualifiedRoleNames(roleName, context.getDocumentContent()));
 303  
                 }
 304  0
         for (String qualifiedRoleName : qualifiedRoleNames)
 305  
         {
 306  0
             if (parentRequest == null && isDuplicateActionRequestDetected(routeHeader, context.getNodeInstance(), resp, qualifiedRoleName))
 307  
             {
 308  0
                 continue;
 309  
             }
 310  
 
 311  0
             ResolvedQualifiedRole resolvedRole = roleAttribute.resolveQualifiedRole(context, roleName, qualifiedRoleName);
 312  0
             RoleRecipient recipient = new RoleRecipient(roleName, qualifiedRoleName, resolvedRole);
 313  0
             if (parentRequest == null)
 314  
             {
 315  0
                 ActionRequestValue roleRequest = arFactory.addRoleRequest(recipient, resp.getActionRequestedCd(), resp.getApprovePolicy(), resp.getPriority(), resp.getResponsibilityId(), rule
 316  
                         .getForceAction(), rule.getDescription(), rule.getRuleBaseValuesId());
 317  
 // Old, pre 1.0 delegate code, commenting out for now
 318  
 //
 319  
 //                                if (resp.isDelegating()) {
 320  
 //                                        // create delegations for all the children
 321  
 //                                        for (Iterator iterator = roleRequest.getChildrenRequests().iterator(); iterator.hasNext();) {
 322  
 //                                                ActionRequestValue request = (ActionRequestValue) iterator.next();
 323  
 //                                                for (Iterator ruleDelegationIterator = resp.getDelegationRules().iterator(); ruleDelegationIterator.hasNext();) {
 324  
 //                                                        RuleDelegation childRuleDelegation = (RuleDelegation) ruleDelegationIterator.next();
 325  
 //                                                        buildDelegationGraph(arFactory, context, childRuleDelegation.getDelegationRuleBaseValues(), routeHeader, request, childRuleDelegation);
 326  
 //                                                }
 327  
 //                                        }
 328  
 //                                }
 329  
 
 330  
                 // new Rice 1.0 delegate rule code
 331  
 
 332  0
                 List<RuleDelegation> ruleDelegations = getRuleDelegationService().findByResponsibilityId(resp.getResponsibilityId());
 333  0
                 if (ruleDelegations != null && !ruleDelegations.isEmpty())
 334  
                 {
 335  
                     // create delegations for all the children
 336  0
                     for (ActionRequestValue request : roleRequest.getChildrenRequests())
 337  
                     {
 338  0
                         for (RuleDelegation childRuleDelegation : ruleDelegations)
 339  
                         {
 340  0
                             buildDelegationGraph(arFactory, context, childRuleDelegation.getDelegationRuleBaseValues(), routeHeader, request, childRuleDelegation);
 341  
                         }
 342  
                     }
 343  
                 }
 344  
 
 345  0
             } else
 346  
             {
 347  0
                 arFactory.addDelegationRoleRequest(parentRequest, resp.getApprovePolicy(), recipient, resp.getResponsibilityId(), rule.getForceAction(), ruleDelegation.getDelegationType(), rule.getDescription(), rule.getRuleBaseValuesId());
 348  
             }
 349  0
         }
 350  0
                         }
 351  
 
 352  
         /**
 353  
          * Determines if the attribute has a setRuleAttribute method and then sets the value appropriately if it does.
 354  
          */
 355  
         private void setRuleAttribute(RoleAttribute roleAttribute, RuleBaseValues rule, String roleAttributeName) {
 356  
                 // look for a setRuleAttribute method on the RoleAttribute
 357  0
                 Method setRuleAttributeMethod = null;
 358  
                 try {
 359  0
                         setRuleAttributeMethod = roleAttribute.getClass().getMethod("setRuleAttribute", RuleAttribute.class);
 360  0
                 } catch (NoSuchMethodException e) {}
 361  0
                 if (setRuleAttributeMethod == null) {
 362  0
                         return;
 363  
                 }
 364  
                 // find the RuleAttribute by looking through the RuleTemplate
 365  0
                 RuleTemplate ruleTemplate = rule.getRuleTemplate();
 366  0
                 if (ruleTemplate != null) {
 367  0
             for (RuleTemplateAttribute ruleTemplateAttribute : ruleTemplate.getActiveRuleTemplateAttributes())
 368  
             {
 369  0
                 RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
 370  0
                 if (ruleAttribute.getClassName().equals(roleAttributeName))
 371  
                 {
 372  
                     // this is our RuleAttribute!
 373  
                     try
 374  
                     {
 375  0
                         setRuleAttributeMethod.invoke(roleAttribute, ruleAttribute);
 376  0
                         break;
 377  0
                     } catch (Exception e)
 378  
                     {
 379  0
                         throw new WorkflowRuntimeException("Failed to set RuleAttribute on our RoleAttribute!", e);
 380  
                     }
 381  
                 }
 382  0
             }
 383  
                 }
 384  0
         }
 385  
 
 386  
         /**
 387  
          * Generates action requests for a non-role responsibility, either a user or workgroup
 388  
      * @throws org.kuali.rice.kew.exception.WorkflowException
 389  
      */
 390  
         private void makeActionRequest(ActionRequestFactory arFactory, RouteContext context, RuleBaseValues rule, DocumentRouteHeaderValue routeHeader, RuleResponsibility resp, ActionRequestValue parentRequest,
 391  
                         RuleDelegation ruleDelegation) throws WorkflowException {
 392  0
                 if (parentRequest == null && isDuplicateActionRequestDetected(routeHeader, context.getNodeInstance(), resp, null)) {
 393  0
                         return;
 394  
                 }
 395  
                 Recipient recipient;
 396  0
                 if (resp.isUsingWorkflowUser()) {
 397  0
             recipient = new KimPrincipalRecipient(resp.getPrincipal());
 398  0
         } else if (resp.isUsingGroup()) {
 399  0
             recipient = new KimGroupRecipient(resp.getGroup());
 400  
                 } else {
 401  0
                 throw new RiceRuntimeException("Illegal rule responsibility type encountered: " + resp.getRuleResponsibilityType());
 402  
                 }
 403  
                 ActionRequestValue actionRequest;
 404  0
                 if (parentRequest == null) {
 405  0
                         actionRequest = arFactory.addRootActionRequest(resp.getActionRequestedCd(),
 406  
                                         resp.getPriority(),
 407  
                                         recipient,
 408  
                                         rule.getDescription(),
 409  
                                         resp.getResponsibilityId(),
 410  
                                         rule.getForceAction(),
 411  
                                         resp.getApprovePolicy(),
 412  
                                         rule.getRuleBaseValuesId());
 413  
 
 414  
                         // old, pre 1.0 delegation code, commented out for now
 415  
                         
 416  
 //                        if (resp.isDelegating()) {
 417  
 //                        for (Iterator iterator = resp.getDelegationRules().iterator(); iterator.hasNext();) {
 418  
 //                                RuleDelegation childRuleDelegation = (RuleDelegation) iterator.next();
 419  
 //                                buildDelegationGraph(arFactory, context, childRuleDelegation.getDelegationRuleBaseValues(), routeHeader, actionRequest, childRuleDelegation);
 420  
 //                        }
 421  
 //                }
 422  
 
 423  
                         
 424  
                         // new Rice 1.0 delegate rule code
 425  
                         
 426  0
                         List<RuleDelegation> ruleDelegations = getRuleDelegationService().findByResponsibilityId(resp.getResponsibilityId());
 427  0
                         if (ruleDelegations != null && !ruleDelegations.isEmpty()) {
 428  0
                                 for (RuleDelegation childRuleDelegation : ruleDelegations) {
 429  0
                                         buildDelegationGraph(arFactory, context, childRuleDelegation.getDelegationRuleBaseValues(), routeHeader, actionRequest, childRuleDelegation);
 430  
                                 }
 431  
                         }
 432  
                         
 433  0
                 } else {
 434  0
                         arFactory.addDelegationRequest(parentRequest, recipient, resp.getResponsibilityId(), rule.getForceAction(), ruleDelegation.getDelegationType(), rule.getDescription(), rule.getRuleBaseValuesId());
 435  
                 }
 436  0
         }
 437  
 
 438  
         private boolean isDuplicateActionRequestDetected(DocumentRouteHeaderValue routeHeader, RouteNodeInstance nodeInstance, RuleResponsibility resp, String qualifiedRoleName) {
 439  0
                 List<ActionRequestValue> requests = getActionRequestService().findByStatusAndDocId(ActionRequestStatus.DONE.getCode(), routeHeader.getDocumentId());
 440  0
         for (ActionRequestValue request : requests)
 441  
         {
 442  0
             if (((nodeInstance != null && request.getNodeInstance() != null && request.getNodeInstance().getRouteNodeInstanceId().equals(nodeInstance.getRouteNodeInstanceId())) || request
 443  
                     .getRouteLevel().equals(routeHeader.getDocRouteLevel()))
 444  
                     && request.getResponsibilityId().equals(resp.getResponsibilityId()) && ObjectUtils.equals(request.getQualifiedRoleName(), qualifiedRoleName))
 445  
             {
 446  0
                 return true;
 447  
             }
 448  
         }
 449  0
                 return false;
 450  
         }
 451  
 
 452  
         public RuleService getRuleService() {
 453  0
                 return KEWServiceLocator.getRuleService();
 454  
         }
 455  
 
 456  
         public RuleDelegationService getRuleDelegationService() {
 457  0
                 return KEWServiceLocator.getRuleDelegationService();
 458  
         }
 459  
 
 460  
         
 461  
         private ActionRequestService getActionRequestService() {
 462  0
                 return KEWServiceLocator.getActionRequestService();
 463  
         }
 464  
 
 465  
         public int getNumberOfMatchingRules() {
 466  0
                 return selectedRules;
 467  
         }
 468  
 
 469  
         //  private DocumentContent parseDocumentContent(RouteContext context) throws WorkflowException {
 470  
         //  try {
 471  
         //  return new StandardDocumentContent(context.getDocument().getDocContent(), context);
 472  
         //  } catch (Exception e) {
 473  
         //  throw new WorkflowException("Error parsing doc content for document " + context.getDocument().getDocumentId());
 474  
         //  }
 475  
         //  }
 476  
 }