Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  
  package org.kuali.rice.kew.actionrequest.service.impl;
  
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
Default implementation of the org.kuali.rice.kew.actionrequest.service.ActionRequestService.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
  
  public class ActionRequestServiceImpl implements ActionRequestService {
      private static final Logger LOG = Logger.getLogger(ActionRequestServiceImpl.class);
  
      private ActionRequestDAO actionRequestDAO;
  
      public ActionRequestValue findByActionRequestId(String actionRequestId) {
          return getActionRequestDAO().getActionRequestByActionRequestId(actionRequestId);
      }
  
      public Map<StringStringgetActionsRequested(DocumentRouteHeaderValue routeHeaderString principalIdboolean completeAndApproveTheSame) {
      	return getActionsRequested(principalIdrouteHeader.getActionRequests(), completeAndApproveTheSame);
      }
    
    
Returns a Map of actions that are requested for the given principalId in the given list of action requests.

Parameters:
principalId
actionRequests
completeAndApproveTheSame
Returns:
  
      protected Map<StringStringgetActionsRequested(String principalIdList<ActionRequestValueactionRequestsboolean completeAndApproveTheSame) {
      	Map<StringStringactionsRequested = new HashMap<StringString>();
          actionsRequested.put(."false");
          actionsRequested.put(."false");
          actionsRequested.put(."false");
          actionsRequested.put(."false");
      	String topActionRequested = .;
          for (ActionRequestValue actionRequest : actionRequests) {
             // we are getting the full list of requests here, so no need to look at role requests, if we did this then
             // we could get a "false positive" for "all approve" roles where only part of the request graph is marked
             // as "done"
             if (!..getCode().equals(actionRequest.getRecipientTypeCd()) &&
                     actionRequest.isRecipientRoutedRequest(principalId) && actionRequest.isActive()) {
                 int actionRequestComparison = ActionRequestValue.compareActionCode(actionRequest.getActionRequested(), topActionRequestedcompleteAndApproveTheSame);
                 if (actionRequest.isFYIRequest() && actionRequestComparison >= 0) {
                     actionsRequested.put(."true");
                 } else if (actionRequest.isAcknowledgeRequest() && actionRequestComparison >= 0) {
                     actionsRequested.put(."true");
                     actionsRequested.put(."false");
                     topActionRequested = actionRequest.getActionRequested();
                 } else if (actionRequest.isApproveRequest() && actionRequestComparison >= 0) {
                     actionsRequested.put(."true");
                     actionsRequested.put(."false");
                     actionsRequested.put(."false");
                     topActionRequested = actionRequest.getActionRequested();
                 } else if (actionRequest.isCompleteRequst() && actionRequestComparison >= 0) {
                 	actionsRequested.put(."true");
                 	actionsRequested.put(."false");
                     actionsRequested.put(."false");
                     actionsRequested.put(."false");
                 	if (completeAndApproveTheSame) {
                 		actionsRequested.put(."true");
                 	}
                     topActionRequested = actionRequest.getActionRequested();
                 }
             }
         }
         return actionsRequested;
     }
 
             DocumentRouteHeaderValue documentRouteNodeInstance nodeInstance) {
         if (actionRequest.getParentActionRequest() != null) {
             .warn("-->A non parent action request from doc " + document.getDocumentId());
             actionRequest = KEWServiceLocator.getActionRequestService().getRoot(actionRequest);
         }
         propagatePropertiesToRequestGraph(actionRequestdocumentnodeInstance);
         return actionRequest;
     }
 
     private void propagatePropertiesToRequestGraph(ActionRequestValue actionRequestDocumentRouteHeaderValue document,
             RouteNodeInstance nodeInstance) {
         setPropertiesToRequest(actionRequestdocumentnodeInstance);
         for (ActionRequestValue actionRequestValue : actionRequest.getChildrenRequests())
         {
             propagatePropertiesToRequestGraph(actionRequestValuedocumentnodeInstance);
         }
     }
 
     private void setPropertiesToRequest(ActionRequestValue actionRequestDocumentRouteHeaderValue document,
             RouteNodeInstance nodeInstance) {
         actionRequest.setDocumentId(document.getDocumentId());
         actionRequest.setDocVersion(document.getDocVersion());
         actionRequest.setRouteLevel(document.getDocRouteLevel());
         actionRequest.setNodeInstance(nodeInstance);
         actionRequest.setStatus(..getCode());
     }
 
 
 
     public void activateRequests(Collection actionRequests) {
     }
 
     public void activateRequests(Collection actionRequestsboolean simulate) {
         activateRequests(actionRequestsnew ActivationContext(simulate));
     }
 
     public void activateRequests(Collection actionRequestsActivationContext activationContext) {
         if (actionRequests == null) {
             return;
         }
         PerformanceLogger performanceLogger = null;
         if ( .isInfoEnabled() ) {
         	performanceLogger = new PerformanceLogger();
         }
         activationContext.setGeneratedActionItems(new ArrayList<ActionItem>());
         activateRequestsInternal(actionRequestsactivationContext);
         if (!activationContext.isSimulation()) {
             KEWServiceLocator.getNotificationService().notify(ActionItem.to(activationContext.getGeneratedActionItems()));
         }
         if ( .isInfoEnabled() ) {
         	performanceLogger.log("Time to " + (activationContext.isSimulation() ? "simulate activation of " : "activate ")
         			+ actionRequests.size() + " action requests.");
         }
         if ( .isDebugEnabled() ) {
         	.debug("Generated " + activationContext.getGeneratedActionItems().size() + " action items.");
         }
     }
 
     public void activateRequest(ActionRequestValue actionRequest) {
         activateRequests(Collections.singletonList(actionRequest), new ActivationContext(!.));
     }
 
     public void activateRequest(ActionRequestValue actionRequestboolean simulate) {
         activateRequests(Collections.singletonList(actionRequest), new ActivationContext(simulate));
     }
 
     public void activateRequest(ActionRequestValue actionRequestActivationContext activationContext) {
         activateRequests(Collections.singletonList(actionRequest), activationContext);
     }
 
     public List activateRequestNoNotification(ActionRequestValue actionRequestboolean simulate) {
         return activateRequestNoNotification(actionRequestnew ActivationContext(simulate));
     }
 
     public List activateRequestNoNotification(ActionRequestValue actionRequestActivationContext activationContext) {
         activationContext.setGeneratedActionItems(new ArrayList<ActionItem>());
         activateRequestInternal(actionRequestactivationContext);
         return activationContext.getGeneratedActionItems();
     }

    
Internal helper method for activating a Collection of action requests and their children. Maintains an accumulator for generated action items.

Parameters:
actionRequests
activationContext
 
     private void activateRequestsInternal(Collection actionRequestsActivationContext activationContext) {
         if (actionRequests == null) {
             return;
         }
         List<?> actionRequestList = new ArrayList<Object>(actionRequests);
         for (int i = 0; i < actionRequestList.size(); i++) {
         	activateRequestInternal((ActionRequestValueactionRequestList.get(i), activationContext);
         }
     }

    
Internal helper method for activating a single action requests and it's children. Maintains an accumulator for generated action items.
 
     private void activateRequestInternal(ActionRequestValue actionRequestActivationContext activationContext) {
         PerformanceLogger performanceLogger = null;
         if ( .isInfoEnabled() ) {
         	performanceLogger = new PerformanceLogger();
         }
         if (actionRequest == null || actionRequest.isActive() || actionRequest.isDeactivated()) {
             return;
         }
         processResponsibilityId(actionRequest);
         if (deactivateOnActionAlreadyTaken(actionRequestactivationContext)) {
             return;
         }
         if (deactivateOnInactiveGroup(actionRequestactivationContext)) {
             return;
         }
         if (deactivateOnEmptyGroup(actionRequestactivationContext)) {
         	return;
         }
         actionRequest.setStatus(..getCode());
         if (!activationContext.isSimulation()) {
             saveActionRequest(actionRequest);
             activationContext.getGeneratedActionItems().addAll(generateActionItems(actionRequestactivationContext));
         }
         activateRequestsInternal(actionRequest.getChildrenRequests(), activationContext);
         activateRequestInternal(actionRequest.getParentActionRequest(), activationContext);
         if ( .isInfoEnabled() ) {
         	if (activationContext.isSimulation()) {
                 performanceLogger.log("Time to simulate activation of request.");
 	        } else {
 	            performanceLogger.log("Time to activate action request with id " + actionRequest.getActionRequestId());
 	        }
         }
     }

    
Generates ActionItems for the given ActionRequest and returns the List of generated Action Items.

Parameters:
actionRequest
activationContext
Returns:
the List of generated ActionItems
 
     private List<ActionItemgenerateActionItems(ActionRequestValue actionRequestActivationContext activationContext) {
     	if ( .isDebugEnabled() ) {
     		.debug("generating the action items for request " + actionRequest.getActionRequestId());
     	}
         List<ActionItemactionItems = new ArrayList<ActionItem>();
         if (!actionRequest.isPrimaryDelegator()) {
             if (actionRequest.isGroupRequest()) {
                 List<StringprincipalIds =  KimApiServiceLocator.getGroupService().getMemberPrincipalIds(actionRequest.getGroupId());
                 actionItems.addAll(createActionItemsForPrincipals(actionRequestprincipalIds));
             } else if (actionRequest.isUserRequest()) {
                 ActionItem actionItem = getActionListService().createActionItemForActionRequest(actionRequest);
                 actionItems.add(actionItem);
             }
         }
         if (!activationContext.isSimulation()) {
             for (ActionItem actionItemactionItems) {
             	if ( .isDebugEnabled() ) {
             		.debug("Saving action item: " + actionItems);
             	}
                 getActionListService().saveActionItem(actionItem);
             }
         } else {
         	actionRequest.getSimulatedActionItems().addAll(actionItems);
         }
         return actionItems;
     }
 
     private List<ActionItemcreateActionItemsForPrincipals(ActionRequestValue actionRequestList<StringprincipalIds) {
         List<ActionItemactionItems = new ArrayList<ActionItem>();
         for (String principalIdprincipalIds) {
 
             ActionItem actionItem = getActionListService().createActionItemForActionRequest(actionRequest);
             actionItem.setPrincipalId(principalId);
             actionItem.setRoleName(actionRequest.getQualifiedRoleName());
 
             //KULRICE-3307 Prevent workflow from attempting to activate requests for null principals
             String ignoreUnknownPrincipalIdsValue = ConfigContext.getCurrentContextConfig().getProperty(.);
             boolean ignoreUnknownPrincipalIds = Boolean.parseBoolean(ignoreUnknownPrincipalIdsValue);
 
             if(principalId==null && ignoreUnknownPrincipalIds)
             {
                 .warn("Ignoring action item with actionRequestID of " + actionRequest.getActionRequestId()  + " due to null principalId.");
             }
             else
             {
                 if(principalId==null)
                 {
                     IllegalArgumentException e = new IllegalArgumentException("Exception thrown when trying to add action item with null principalId");
                     .error(e);
                     throw e;
                 }
                 else
                 {
                     actionItems.add(actionItem);
                 }
             }
         }
         return actionItems;
     }
 
     private void processResponsibilityId(ActionRequestValue actionRequest) {
     	if (actionRequest.getResolveResponsibility()) {
 	        String responsibilityId = actionRequest.getResponsibilityId();
 	        try {
 	            RouteModule routeModule = KEWServiceLocator.getRouteModuleService().findRouteModule(actionRequest);
 	            if (responsibilityId != null && actionRequest.isRouteModuleRequest()) {
 	            	if ( .isDebugEnabled() ) {
 	            		.debug("Resolving responsibility id for action request id=" + actionRequest.getActionRequestId()
 	                        + " and responsibility id=" + actionRequest.getResponsibilityId());
 	            	}
 	                ResponsibleParty responsibleParty = routeModule.resolveResponsibilityId(actionRequest.getResponsibilityId());
 	                if (responsibleParty == null) {
 	                    return;
 	                }
 	                if (responsibleParty.getPrincipalId() != null) {
 	                    Principal user = KimApiServiceLocator.getIdentityService()
 	                            .getPrincipal(responsibleParty.getPrincipalId());
 	                    actionRequest.setPrincipalId(user.getPrincipalId());
 	                } else if (responsibleParty.getGroupId() != null) {
 	                	actionRequest.setGroupId(responsibleParty.getGroupId());
 	                } else if (responsibleParty.getRoleName() != null) {
 	                    actionRequest.setRoleName(responsibleParty.getRoleName());
 	                }
 	            }
 	        } catch (Exception e) {
 	            .error("Exception thrown when trying to resolve responsibility id " + responsibilityIde);
 	            throw new RuntimeException(e);
 	        }
     	}
     }
 
     protected boolean deactivateOnActionAlreadyTaken(ActionRequestValue actionRequestToActivate,
             ActivationContext activationContext) {
 
         FutureRequestDocumentStateManager futureRequestStateMngr = null;
 
         if (actionRequestToActivate.isGroupRequest()) {
             futureRequestStateMngr = new FutureRequestDocumentStateManager(actionRequestToActivate.getRouteHeader(), actionRequestToActivate.getGroup());
         } else if (actionRequestToActivate.isUserRequest()) {
             futureRequestStateMngr = new FutureRequestDocumentStateManager(actionRequestToActivate.getRouteHeader(), actionRequestToActivate.getPrincipalId());
         } else {
             return false;
         }
 
         if (futureRequestStateMngr.isReceiveFutureRequests()) {
             return false;
         }
         if (!actionRequestToActivate.getForceAction() || futureRequestStateMngr.isDoNotReceiveFutureRequests()) {
             ActionTakenValue previousActionTaken = null;
             if (!activationContext.isSimulation()) {
                 previousActionTaken = getActionTakenService().getPreviousAction(actionRequestToActivate);
             } else {
                 previousActionTaken = getActionTakenService().getPreviousAction(actionRequestToActivate,
                         activationContext.getSimulatedActionsTaken());
             }
             if (previousActionTaken != null) {
                 if ( .isDebugEnabled() ) {
                 	.debug("found a satisfying action taken so setting this request done.  Action Request Id "
                             + actionRequestToActivate.getActionRequestId());
                 }
                 // set up the delegation for an action taken if this is a delegate request and the delegate has
                 // already taken action.
                 if (!previousActionTaken.isForDelegator() && actionRequestToActivate.getParentActionRequest() != null) {
                     previousActionTaken.setDelegator(actionRequestToActivate.getParentActionRequest().getRecipient());
                     if (!activationContext.isSimulation()) {
                         getActionTakenService().saveActionTaken(previousActionTaken);
                     }
                 }
                 deactivateRequest(previousActionTakenactionRequestToActivatenullactivationContext);
                 return true;
             }
         }
         if ( .isDebugEnabled() ) {
         	.debug("Forcing action for action request " + actionRequestToActivate.getActionRequestId());
         }
         return false;
     }
    
    
Checks if the action request which is being activated has a group with no members. If this is the case then it will immediately initiate de-activation on the request since a group with no members will result in no action items being generated so should be effectively skipped.
 
     protected boolean deactivateOnEmptyGroup(ActionRequestValue actionRequestToActivateActivationContext activationContext) {
     	if (actionRequestToActivate.isGroupRequest()) {
     		 if (KimApiServiceLocator.getGroupService().getMemberPrincipalIds(actionRequestToActivate.getGroup().getId()).isEmpty()) {
     			 deactivateRequest(nullactionRequestToActivatenullactivationContext);
     			 return true;
          	}
     	}
     	return false;
     }

    
Checks if the action request which is being activated is being assigned to an inactive group. If this is the case and if the FailOnInactiveGroup policy is set to false then it will immediately initiate de-activation on the request
 
     protected boolean deactivateOnInactiveGroup(ActionRequestValue actionRequestToActivateActivationContext activationContext) {
         if (actionRequestToActivate.isGroupRequest()) {
             if (!actionRequestToActivate.getGroup().isActive() && !actionRequestToActivate.getRouteHeader().getDocumentType().getFailOnInactiveGroup().getPolicyValue()) {
                 deactivateRequest(nullactionRequestToActivatenullactivationContext);
                 return true;
             }
         }
         return false;
     }
     
     public void deactivateRequest(ActionTakenValue actionTakenActionRequestValue actionRequest) {
         deactivateRequest(actionTakenactionRequestnullnew ActivationContext(!.));
     }
 
     public void deactivateRequest(ActionTakenValue actionTakenActionRequestValue actionRequestboolean simulate) {
         deactivateRequest(actionTakenactionRequestnullnew ActivationContext(simulate));
     }
 
     public void deactivateRequest(ActionTakenValue actionTakenActionRequestValue actionRequest,
             ActivationContext activationContext) {
         deactivateRequest(actionTakenactionRequestnullactivationContext);
     }
 
     public void deactivateRequests(ActionTakenValue actionTakenList actionRequests) {
         deactivateRequests(actionTakenactionRequestsnull,
                 new ActivationContext(!.));
     }
 
     public void deactivateRequests(ActionTakenValue actionTakenList actionRequestsboolean simulate) {
         deactivateRequests(actionTakenactionRequestsnullnew ActivationContext(simulate));
     }
 
     public void deactivateRequests(ActionTakenValue actionTakenList actionRequestsActivationContext activationContext) {
         deactivateRequests(actionTakenactionRequestsnullactivationContext);
     }
 
     private void deactivateRequests(ActionTakenValue actionTakenCollection actionRequests,
             ActionRequestValue deactivationRequesterActivationContext activationContext) {
         if (actionRequests == null) {
             return;
         }
         for (Iterator iterator = actionRequests.iterator(); iterator.hasNext();) {
             ActionRequestValue actionRequest = (ActionRequestValueiterator.next();
             deactivateRequest(actionTakenactionRequestdeactivationRequesteractivationContext);
         }
     }
 
     private void deactivateRequest(ActionTakenValue actionTakenActionRequestValue actionRequest,
             ActionRequestValue deactivationRequesterActivationContext activationContext) {
         if (actionRequest == null || actionRequest.isDeactivated()
                 || haltForAllApprove(actionRequestdeactivationRequester)) {
             return;
         }
         actionRequest.setStatus(..getCode());
         actionRequest.setActionTaken(actionTaken);
         if (actionTaken != null) {
             actionTaken.getActionRequests().add(actionRequest);
         }
         if (!activationContext.isSimulation()) {
             getActionRequestDAO().saveActionRequest(actionRequest);
             deleteActionItems(actionRequest);
         }
         deactivateRequests(actionTakenactionRequest.getChildrenRequests(), actionRequestactivationContext);
         deactivateRequest(actionTakenactionRequest.getParentActionRequest(), actionRequestactivationContext);
     }

    
Returns true if we are dealing with an 'All Approve' request, the requester of the deactivation is a child of the 'All Approve' request, and all of the children have not been deactivated. If all of the children are already deactivated or a non-child request initiated deactivation, then this method returns false. false otherwise.

Parameters:
actionRequest
deactivationRequester
Returns:
 
     private boolean haltForAllApprove(ActionRequestValue actionRequestActionRequestValue deactivationRequester) {
         if (..getCode().equals(actionRequest.getApprovePolicy())
                 && actionRequest.hasChild(deactivationRequester)) {
             boolean allDeactivated = true;
             for (ActionRequestValue childRequest : actionRequest.getChildrenRequests())
             {
                 if (!(allDeactivated = childRequest.isDeactivated()))
                 {
                     return true;
                 }
             }
         }
         return false;
     }
 
     	Set<ActionRequestValueunsavedRequests = new HashSet<ActionRequestValue>();
     	Map<StringActionRequestValuerequestMap = new HashMap<StringActionRequestValue>();
     	for (ActionRequestValue actionRequest1 : actionRequests)
     	{
     		ActionRequestValue actionRequest = (ActionRequestValueactionRequest1;
     		ActionRequestValue rootRequest = getRoot(actionRequest);
     		if (rootRequest.getActionRequestId() != null)
     		{
     			requestMap.put(rootRequest.getActionRequestId(), rootRequest);
     		} else
     		{
     			unsavedRequests.add(rootRequest);
     		}
     	}
     	List<ActionRequestValuerequests = new ArrayList<ActionRequestValue>();
     	requests.addAll(requestMap.values());
     	requests.addAll(unsavedRequests);
     	return requests;
     }
 
     public ActionRequestValue getRoot(ActionRequestValue actionRequest) {
         if (actionRequest == null) {
             return null;
         }
         if (actionRequest.getParentActionRequest() != null) {
             return getRoot(actionRequest.getParentActionRequest());
         }
         return actionRequest;
     }
    
    
Returns all pending requests for a given routing identity

Parameters:
documentId the id of the document header being routed
Returns:
a List of all pending ActionRequestValues for the document
 
     public List<ActionRequestValuefindAllPendingRequests(String documentId) {
     	ActionRequestDAO arDAO = getActionRequestDAO();
         List<ActionRequestValuependingArs = arDAO.findByStatusAndDocId(..getCode(), documentId);
         return pendingArs;
     }
 
     public List findAllValidRequests(String principalIdString documentIdString requestCode) {
         ActionRequestDAO arDAO = getActionRequestDAO();
         Collection pendingArs = arDAO.findByStatusAndDocId(..getCode(), documentId);
         return findAllValidRequests(principalIdpendingArsrequestCode);
     }
 
     public List findAllValidRequests(String principalIdCollection actionRequestsString requestCode) {
         List matchedArs = new ArrayList();
         List<StringarGroups = KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId(principalId);
         return filterActionRequestsByCode((List<ActionRequestValue>)actionRequestsprincipalIdarGroupsrequestCode);
     }
    
    
Filters action requests based on if they occur after the given requestCode, and if they relate to the given principal

Parameters:
actionRequests the List of ActionRequestValues to filter
principalId the id of the principal to find active requests for
principalGroupIds List of group ids that the principal belongs to
requestCode the request code for all ActionRequestValues to be after
Returns:
the filtered List of ActionRequestValues
 
 	public List<ActionRequestValuefilterActionRequestsByCode(List<ActionRequestValueactionRequestsString principalIdList<StringprincipalGroupIdsString requestCode) {
 		List<ActionRequestValuefilteredActionRequests = new ArrayList<ActionRequestValue>();
 		
 		List<StringarGroups = null;
         for (ActionRequestValue ar : actionRequests) {
             if (ActionRequestValue.compareActionCode(ar.getActionRequested(), requestCodetrue) > 0) {
                 continue;
             }
             if (ar.isUserRequest() && principalId.equals(ar.getPrincipalId())) {
             	filteredActionRequests.add(ar);
             } else if (ar.isGroupRequest() && principalGroupIds != null && !principalGroupIds.isEmpty()) {
             	for (String groupId : principalGroupIds) {
             		if (groupId.equals(ar.getGroupId())) {
             			filteredActionRequests.add(ar);
             		}
             	}
             }
         }
 		
 		return filteredActionRequests;
 	}
 
     public void updateActionRequestsForResponsibilityChange(Set<StringresponsibilityIds) {
     	PerformanceLogger performanceLogger = null;
     	if ( .isInfoEnabled() ) {
     		performanceLogger = new PerformanceLogger();
     	}
         Collection documentsAffected = getRouteHeaderService().findPendingByResponsibilityIds(responsibilityIds);
         Long cacheWait = .;
         if (!org.apache.commons.lang.StringUtils.isEmpty(cacheWaitValue)) {
             try {
                 cacheWait = Long.valueOf(cacheWaitValue);
             } catch (NumberFormatException e) {
                 .warn("Cache wait time is not a valid number: " + cacheWaitValue);
             }
         }
         if ( .isInfoEnabled() ) {
         	.info("Scheduling requeue of " + documentsAffected.size() + " documents, affected by " + responsibilityIds.size()
                     + " responsibility changes.  Installing a processing wait time of " + cacheWait
                     + " milliseconds to avoid stale rule cache.");
         }
         for (Object aDocumentsAffected : documentsAffected)
         {
             String documentId = (StringaDocumentsAffected;
 
              String applicationId = null;
              DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByDocumentId(documentId);
                     
              if (documentType != null) {
                 applicationId = documentType.getApplicationId();
              }
 
             if (applicationId == null)
             {
                 applicationId = CoreConfigHelper.getApplicationId();
             }
             if(documentType.getRegenerateActionRequestsOnChange().getPolicyValue()) {
                 DocumentRefreshQueue documentRequeuer = KewApiServiceLocator.getDocumentRequeuerService(applicationId,
                         documentIdcacheWait);
                 documentRequeuer.refreshDocument(documentId);
             }
         }
         if ( .isInfoEnabled() ) {
         	performanceLogger.log("Time to updateActionRequestsForResponsibilityChange");
         }
     }

    
Deletes an action request and all of its action items following the graph down through the action request's children. This method should be invoked on a top-level action request.
 
     public void deleteActionRequestGraph(ActionRequestValue actionRequest) {
         deleteActionItems(actionRequest);
         if (actionRequest.getActionTakenId() != null) {
             ActionTakenValue actionTaken = getActionTakenService().findByActionTakenId(actionRequest.getActionTakenId());
 
             if(actionTaken != null){//iu patch
             getActionTakenService().delete(actionTaken);
             }//iu patch
            
         }
         getActionRequestDAO().delete(actionRequest.getActionRequestId());
         for (ActionRequestValue childactionRequest.getChildrenRequests()) {
             deleteActionRequestGraph(child);
         }
     }

    
Deletes the action items for the action request

Parameters:
actionRequest the action request whose action items to delete
 
     private void deleteActionItems(ActionRequestValue actionRequest) {
     	List<ActionItemactionItems = actionRequest.getActionItems();
     	if ( .isDebugEnabled() ) {
     		.debug("deleting " + actionItems.size() + " action items for action request: " + actionRequest);
     	}
         for (ActionItem actionItemactionItems) {
         	if ( .isDebugEnabled() ) {
         		.debug("deleting action item: " + actionItem);
         	}
             getActionListService().deleteActionItem(actionItem);
         }
     }
 
 
         return getActionRequestDAO().findByDocumentIdIgnoreCurrentInd(documentId);
     }
 
         return getActionRequestDAO().findAllByDocId(documentId);
     }
 
         return getActionRequestDAO().findAllRootByDocId(documentId);
     }
 
     public List<ActionRequestValuefindPendingByActionRequestedAndDocId(String actionRequestedCdString documentId) {
         return getActionRequestDAO().findPendingByActionRequestedAndDocId(actionRequestedCddocumentId);
     }

    
 
     public List<StringgetPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(String actionRequestedCdString documentId) {
     	List<StringprincipalIds = new ArrayList<String>();
     	List<ActionRequestValueactionRequests = findPendingByActionRequestedAndDocId(actionRequestedCddocumentId);
 		for(ActionRequestValue actionRequestactionRequests){
 			if(actionRequest.isUserRequest()){
 				principalIds.add(actionRequest.getPrincipalId());
 			} else if(actionRequest.isGroupRequest()){
 				principalIds.addAll(
 						KimApiServiceLocator.getGroupService().getMemberPrincipalIds(actionRequest.getGroupId()));
 			}
 		}
     	return principalIds;
     }
 
     public List<ActionRequestValuefindPendingByDocIdAtOrBelowRouteLevel(String documentIdInteger routeLevel) {
         return getActionRequestDAO().findPendingByDocIdAtOrBelowRouteLevel(documentIdrouteLevel);
     }
 
         return getRootRequests(findPendingByDoc(documentId));
     }
 
     public List<ActionRequestValuefindPendingRootRequestsByDocIdAtRouteNode(String documentIdString nodeInstanceId) {
         return getActionRequestDAO().findPendingRootRequestsByDocIdAtRouteNode(documentIdnodeInstanceId);
     }
 
     public List<ActionRequestValuefindRootRequestsByDocIdAtRouteNode(String documentIdString nodeInstanceId) {
         return getActionRequestDAO().findRootRequestsByDocIdAtRouteNode(documentIdnodeInstanceId);
     }
 
         return getActionRequestDAO().findPendingRootRequestsByDocIdAtOrBelowRouteLevel(documentIdrouteLevel);
     }
 
     public List<ActionRequestValuefindPendingRootRequestsByDocIdAtRouteLevel(String documentIdInteger routeLevel) {
         return getActionRequestDAO().findPendingRootRequestsByDocIdAtRouteLevel(documentIdrouteLevel);
     }
 
         return getActionRequestDAO().findPendingRootRequestsByDocumentType(documentTypeId);
     }
 
     public void saveActionRequest(ActionRequestValue actionRequest) {
         if (actionRequest.isGroupRequest()) {
              Group group = actionRequest.getGroup();
              if (group == null)  {
                  throw new RiceRuntimeException("Attempted to save an action request with a non-existent group.");
              }
              if (!group.isActive() && actionRequest.getRouteHeader().getDocumentType().getFailOnInactiveGroup().getPolicyValue()) {
         		throw new RiceRuntimeException("Attempted to save an action request with an inactive group.");
         	}
         }
         getActionRequestDAO().saveActionRequest(actionRequest);
     }
 
     public List<ActionRequestValuefindPendingByDoc(String documentId) {
         return getActionRequestDAO().findAllPendingByDocId(documentId);
     }
 
     public List<ActionRequestValuefindPendingByDocRequestCdRouteLevel(String documentIdString requestCodeInteger routeLevel) {
         List<ActionRequestValuerequests = new ArrayList<ActionRequestValue>();
         for (Object object : getActionRequestDAO().findAllPendingByDocId(documentId))
         {
             ActionRequestValue actionRequest = (ActionRequestValueobject;
             if (ActionRequestValue.compareActionCode(actionRequest.getActionRequested(), requestCodetrue) > 0)
             {
                 continue;
             }
             if (actionRequest.getRouteLevel().intValue() == routeLevel.intValue())
             {
                 requests.add(actionRequest);
             }
         }
         return requests;
     }
 
     public List<ActionRequestValuefindPendingByDocRequestCdNodeName(String documentIdString requestCodeString nodeName) {
         List<ActionRequestValuerequests = new ArrayList<ActionRequestValue>();
         for (Object object : getActionRequestDAO().findAllPendingByDocId(documentId))
         {
             ActionRequestValue actionRequest = (ActionRequestValueobject;
             if (ActionRequestValue.compareActionCode(actionRequest.getActionRequested(), requestCodetrue) > 0)
             {
                 continue;
             }
             if (actionRequest.getNodeInstance() != null && actionRequest.getNodeInstance().getName().equals(nodeName))
             {
                 requests.add(actionRequest);
             }
         }
         return requests;
     }
 
     public List findActivatedByGroup(String groupId) {
         return getActionRequestDAO().findActivatedByGroup(groupId);
     }
 
         return (ActionListService) KEWServiceLocator.getActionListService();
     }
 
         return (ActionTakenService) KEWServiceLocator.getActionTakenService();
     }
 
         return ;
     }
 
     public void setActionRequestDAO(ActionRequestDAO actionRequestDAO) {
         this. = actionRequestDAO;
     }
 
         return (RouteHeaderService) KEWServiceLocator.getService(.);
     }
 
     public List<ActionRequestValuefindByStatusAndDocId(String statusCdString documentId) {
         return getActionRequestDAO().findByStatusAndDocId(statusCddocumentId);
     }
 
     public void alterActionRequested(List actionRequestsString actionRequestCd) {
         for (Object actionRequest1 : actionRequests)
         {
             ActionRequestValue actionRequest = (ActionRequestValueactionRequest1;
 
             actionRequest.setActionRequested(actionRequestCd);
             for (ActionItem item : actionRequest.getActionItems())
             {
                 item.setActionRequestCd(actionRequestCd);
             }
 
             saveActionRequest(actionRequest);
         }
     }
 
     // TODO this still won't work in certain cases when checking from the root
     public boolean isDuplicateRequest(ActionRequestValue actionRequest) {
         List<ActionRequestValuerequests = findAllRootActionRequestsByDocumentId(actionRequest.getDocumentId());
         for (ActionRequestValue existingRequest : requests) {
             if (existingRequest.getStatus().equals(..getCode())
                     && existingRequest.getRouteLevel().equals(actionRequest.getRouteLevel())
                     && ObjectUtils.equals(existingRequest.getPrincipalId(), actionRequest.getPrincipalId())
                     && ObjectUtils.equals(existingRequest.getGroupId(), actionRequest.getGroupId())
                     && ObjectUtils.equals(existingRequest.getRoleName(), actionRequest.getRoleName())
                     && ObjectUtils.equals(existingRequest.getQualifiedRoleName(), actionRequest.getQualifiedRoleName())
                     && existingRequest.getActionRequested().equals(actionRequest.getActionRequested())) {
                 return true;
             }
         }
         return false;
     }
 
     public Recipient findDelegator(List actionRequests) {
         Recipient delegator = null;
         String requestCode = .;
         for (Object actionRequest1 : actionRequests)
         {
             ActionRequestValue actionRequest = (ActionRequestValueactionRequest1;
             ActionRequestValue delegatorRequest = findDelegatorRequest(actionRequest);
             if (delegatorRequest != null)
             {
                 if (ActionRequestValue.compareActionCode(delegatorRequest.getActionRequested(), requestCodetrue) >= 0)
                 {
                     delegator = delegatorRequest.getRecipient();
                     requestCode = delegatorRequest.getActionRequested();
                 }
             }
         }
         return delegator;
     }
 
     public Recipient findDelegator(ActionRequestValue actionRequest) {
         ActionRequestValue delegatorRequest = findDelegatorRequest(actionRequest);
         Recipient delegator = null;
         if (delegatorRequest != null) {
             delegator = delegatorRequest.getRecipient();
         }
         return delegator;
     }
 
     public ActionRequestValue findDelegatorRequest(ActionRequestValue actionRequest) {
         ActionRequestValue parentRequest = actionRequest.getParentActionRequest();
         if (parentRequest != null && !(parentRequest.isUserRequest() || parentRequest.isGroupRequest())) {
             parentRequest = findDelegatorRequest(parentRequest);
         }
         return parentRequest;
     }
 
     public void deleteByDocumentId(String documentId) {
         .deleteByDocumentId(documentId);
     }
 
     public void deleteByActionRequestId(String actionRequestId) {
         .delete(actionRequestId);
     }
 
     public void validateActionRequest(ActionRequestValue actionRequest) {
         .debug("Enter validateActionRequest(..)");
         List<WorkflowServiceErrorImplerrors = new ArrayList<WorkflowServiceErrorImpl>();
 
         String actionRequestCd = actionRequest.getActionRequested();
         if (actionRequestCd == null || actionRequestCd.trim().equals("")) {
             errors.add(new WorkflowServiceErrorImpl("ActionRequest cd null.""actionrequest.actionrequestcd.empty",
                     actionRequest.getActionRequestId().toString()));
         } else if (!..containsKey(actionRequestCd)) {
             errors.add(new WorkflowServiceErrorImpl("ActionRequest cd invalid.""actionrequest.actionrequestcd.invalid",
                     actionRequest.getActionRequestId().toString()));
         }
 
         String documentId = actionRequest.getDocumentId();
         if (documentId == null || StringUtils.isEmpty(documentId)) {
         	errors.add(new WorkflowServiceErrorImpl("ActionRequest Document id empty.""actionrequest.documentid.empty",
                     actionRequest.getActionRequestId().toString()));
         } else if (getRouteHeaderService().getRouteHeader(documentId) == null) {
             errors.add(new WorkflowServiceErrorImpl("ActionRequest Document id invalid.",
                     "actionrequest.documentid.invalid"actionRequest.getActionRequestId().toString()));
         }
 
         String actionRequestStatus = actionRequest.getStatus();
         if (actionRequestStatus == null || actionRequestStatus.trim().equals("")) {
             errors.add(new WorkflowServiceErrorImpl("ActionRequest status null.""actionrequest.actionrequeststatus.empty",
                     actionRequest.getActionRequestId().toString()));
         } else if (ActionRequestStatus.fromCode(actionRequestStatus) == null) {
             errors.add(new WorkflowServiceErrorImpl("ActionRequest status invalid.",
                     "actionrequest.actionrequeststatus.invalid"actionRequest.getActionRequestId().toString()));
         }
 
         if (actionRequest.getResponsibilityId() == null) {
             errors.add(new WorkflowServiceErrorImpl("ActionRequest responsibility id null.",
                     "actionrequest.responsibilityid.empty"actionRequest.getActionRequestId().toString()));
         }
 
         Integer priority = actionRequest.getPriority();
         if (priority == null) {
             errors.add(new WorkflowServiceErrorImpl("ActionRequest priority null.""actionrequest.priority.empty",
                     actionRequest.getActionRequestId().toString()));
         }
 
         // if(actionRequest.getRouteMethodName() == null || actionRequest.getRouteMethodName().trim().equals("")){
         // errors.add(new WorkflowServiceErrorImpl("ActionRequest route method name null.",
         // "actionrequest.routemethodname.empty", actionRequest.getActionRequestId().toString()));
         // }
 
         Integer routeLevel = actionRequest.getRouteLevel();
         if (routeLevel == null) {
             errors.add(new WorkflowServiceErrorImpl("ActionRequest route level null.""actionrequest.routelevel.empty",
                     actionRequest.getActionRequestId().toString()));
         } else if (routeLevel < -1) {
             errors.add(new WorkflowServiceErrorImpl("ActionRequest route level invalid.",