Coverage Report - org.kuali.rice.kew.superuser.web.SuperUserAction
 
Classes in this File Line Coverage Branch Coverage Complexity
SuperUserAction
0%
0/215
0%
0/74
3.3
 
 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.superuser.web;
 18  
 
 19  
 import java.util.Collection;
 20  
 import java.util.Iterator;
 21  
 
 22  
 import javax.servlet.http.HttpServletRequest;
 23  
 import javax.servlet.http.HttpServletResponse;
 24  
 import javax.xml.namespace.QName;
 25  
 
 26  
 import org.apache.commons.lang.ArrayUtils;
 27  
 import org.apache.commons.lang.StringUtils;
 28  
 import org.apache.struts.action.ActionForm;
 29  
 import org.apache.struts.action.ActionForward;
 30  
 import org.apache.struts.action.ActionMapping;
 31  
 import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
 32  
 import org.kuali.rice.core.util.JSTLConstants;
 33  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 34  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 35  
 import org.kuali.rice.kew.dto.AdHocRevokeDTO;
 36  
 import org.kuali.rice.kew.dto.DTOConverter;
 37  
 import org.kuali.rice.kew.dto.RouteNodeInstanceDTO;
 38  
 import org.kuali.rice.kew.exception.WorkflowException;
 39  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
 40  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl;
 41  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 42  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 43  
 import org.kuali.rice.kew.service.WorkflowDocument;
 44  
 import org.kuali.rice.kew.service.WorkflowDocumentActions;
 45  
 import org.kuali.rice.kew.service.WorkflowInfo;
 46  
 import org.kuali.rice.kew.util.KEWConstants;
 47  
 import org.kuali.rice.kew.web.AppSpecificRouteRecipient;
 48  
 import org.kuali.rice.kew.web.KewKualiAction;
 49  
 import org.kuali.rice.kew.web.session.UserSession;
 50  
 import org.kuali.rice.kim.bo.entity.KimPrincipal;
 51  
 import org.kuali.rice.kim.service.IdentityManagementService;
 52  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 53  
 import org.kuali.rice.kns.exception.ValidationException;
 54  
 import org.kuali.rice.kns.util.GlobalVariables;
 55  
 import org.kuali.rice.kns.util.KNSConstants;
 56  
 
 57  
 
 58  
 /**
 59  
  * A Struts Action which provides super user functionality.
 60  
  *
 61  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 62  
  */
 63  0
 public class SuperUserAction extends KewKualiAction {
 64  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserAction.class);
 65  
     public static final String UNAUTHORIZED = "authorizationFailure";
 66  
 
 67  
     //public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 68  
     //        defaultDispatch(mapping, form, request, response);
 69  
     //}
 70  
 
 71  
     @Override
 72  
     public ActionForward execute(ActionMapping mapping, ActionForm form,
 73  
             HttpServletRequest request, HttpServletResponse response)
 74  
             throws Exception {
 75  0
         initForm(request, form);
 76  0
         return super.execute(mapping, form, request, response);
 77  
     }
 78  
 
 79  
     @Override
 80  
     public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 81  0
             ((SuperUserForm) form).getActionRequests().clear();
 82  0
             initForm(request, form);
 83  0
             return defaultDispatch(mapping, form, request, response);
 84  
     }
 85  
     
 86  
     public ActionForward displaySuperUserDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 87  0
         SuperUserForm superUserForm = (SuperUserForm) form;
 88  0
         superUserForm.setDocHandlerUrl(KEWConstants.DOC_HANDLER_REDIRECT_PAGE + "?docId=" + superUserForm.getRouteHeaderId() + "&" + KEWConstants.COMMAND_PARAMETER + "=" + KEWConstants.SUPERUSER_COMMAND);
 89  0
         return defaultDispatch(mapping, form, request, response);
 90  
     }
 91  
 
 92  
     public ActionForward routeLevelApprove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 93  0
         LOG.info("entering routeLevelApprove()...");
 94  0
         SuperUserForm superUserForm = (SuperUserForm) form;
 95  0
         Long documentId = superUserForm.getRouteHeader().getRouteHeaderId();
 96  0
         WorkflowDocumentActions documentActions = getWorkflowDocumentActions(documentId);
 97  0
         documentActions.superUserNodeApproveAction(getUserSession(request).getPrincipalId(), documentId, superUserForm.getDestNodeName(), superUserForm.getAnnotation(), superUserForm.isRunPostProcessorLogic());
 98  0
         saveDocumentMessage("general.routing.superuser.routeLevelApproved", request, superUserForm.getRouteHeaderIdString(), null);
 99  0
         LOG.info("exiting routeLevelApprove()...");
 100  0
         superUserForm.getActionRequests().clear();
 101  0
         initForm(request, form);
 102  0
         return defaultDispatch(mapping, form, request, response);
 103  
     }
 104  
 
 105  
     public ActionForward approve(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 106  0
         LOG.info("entering approve() ...");
 107  0
         SuperUserForm superUserForm = (SuperUserForm) form;
 108  0
         Long documentId = superUserForm.getRouteHeader().getRouteHeaderId();
 109  0
         WorkflowDocumentActions documentActions = getWorkflowDocumentActions(documentId);
 110  0
         documentActions.superUserApprove(getUserSession(request).getPrincipalId(), DTOConverter.convertRouteHeader(superUserForm.getRouteHeader(), null), superUserForm.getAnnotation(), superUserForm.isRunPostProcessorLogic());
 111  0
         saveDocumentMessage("general.routing.superuser.approved", request, superUserForm.getRouteHeaderIdString(), null);
 112  0
         LOG.info("exiting approve() ...");
 113  0
         superUserForm.getActionRequests().clear();
 114  0
         initForm(request, form);
 115  0
         return defaultDispatch(mapping, form, request, response);
 116  
     }
 117  
 
 118  
     public ActionForward disapprove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 119  0
         LOG.info("entering disapprove() ...");
 120  0
         SuperUserForm superUserForm = (SuperUserForm) form;
 121  0
         Long documentId = superUserForm.getRouteHeader().getRouteHeaderId();
 122  0
         WorkflowDocumentActions documentActions = getWorkflowDocumentActions(documentId);
 123  0
         documentActions.superUserDisapprove(getUserSession(request).getPrincipalId(), DTOConverter.convertRouteHeader(superUserForm.getRouteHeader(), null), superUserForm.getAnnotation(), superUserForm.isRunPostProcessorLogic());
 124  0
         saveDocumentMessage("general.routing.superuser.disapproved", request, superUserForm.getRouteHeaderIdString(), null);
 125  0
         LOG.info("exiting disapprove() ...");
 126  0
         superUserForm.getActionRequests().clear();
 127  0
         initForm(request, form);
 128  0
         return defaultDispatch(mapping, form, request, response);
 129  
     }
 130  
 
 131  
     public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 132  0
         LOG.info("entering cancel() ...");
 133  0
         SuperUserForm superUserForm = (SuperUserForm) form;
 134  0
         Long documentId = superUserForm.getRouteHeader().getRouteHeaderId();
 135  0
         WorkflowDocumentActions documentActions = getWorkflowDocumentActions(documentId);
 136  0
         documentActions.superUserCancel(getUserSession(request).getPrincipalId(), DTOConverter.convertRouteHeader(superUserForm.getRouteHeader(), null), superUserForm.getAnnotation(), superUserForm.isRunPostProcessorLogic());
 137  0
         saveDocumentMessage("general.routing.superuser.canceled", request, superUserForm.getRouteHeaderIdString(), null);
 138  0
         LOG.info("exiting cancel() ...");
 139  0
         superUserForm.getActionRequests().clear();
 140  0
         initForm(request, form);
 141  0
         return defaultDispatch(mapping, form, request, response);
 142  
     }
 143  
 
 144  
     public ActionForward returnToPreviousNode(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 145  0
         LOG.info("entering returnToPreviousNode() ...");
 146  0
         SuperUserForm superUserForm = (SuperUserForm) form;
 147  0
         Long documentId = superUserForm.getRouteHeader().getRouteHeaderId();
 148  0
         WorkflowDocumentActions documentActions = getWorkflowDocumentActions(documentId);
 149  0
         documentActions.superUserReturnToPreviousNode(getUserSession(request).getPrincipalId(), documentId, superUserForm.getReturnDestNodeName(), superUserForm.getAnnotation(), superUserForm.isRunPostProcessorLogic());
 150  0
         saveDocumentMessage("general.routing.returnedToPreviousNode", request, "document", superUserForm.getReturnDestNodeName().toString());
 151  0
         LOG.info("exiting returnToPreviousRouteLevel() ...");
 152  0
         superUserForm.getActionRequests().clear();
 153  0
         initForm(request, form);
 154  0
         return defaultDispatch(mapping, form, request, response);
 155  
     }
 156  
 
 157  
     public ActionForward actionRequestApprove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 158  0
         LOG.info("entering actionRequestApprove() ...");
 159  0
         SuperUserForm superUserForm = (SuperUserForm) form;
 160  
         
 161  
         // Retrieve the relevant arguments from the "methodToCall" parameter.
 162  0
         String methodToCallAttr = (String) request.getAttribute(KNSConstants.METHOD_TO_CALL_ATTRIBUTE);
 163  0
         superUserForm.setActionTakenRecipientCode(StringUtils.substringBetween(methodToCallAttr, KNSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KNSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL));
 164  0
         superUserForm.setActionTakenNetworkId(StringUtils.substringBetween(methodToCallAttr, KNSConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, KNSConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL));
 165  0
         superUserForm.setActionTakenWorkGroupId(StringUtils.substringBetween(methodToCallAttr, KNSConstants.METHOD_TO_CALL_PARM4_LEFT_DEL, KNSConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL));
 166  0
         superUserForm.setActionTakenActionRequestId(StringUtils.substringBetween(methodToCallAttr, KNSConstants.METHOD_TO_CALL_PARM5_LEFT_DEL, KNSConstants.METHOD_TO_CALL_PARM5_RIGHT_DEL));
 167  
         
 168  0
         LOG.debug("Routing super user action request approve action");
 169  0
         boolean runPostProcessorLogic = ArrayUtils.contains(superUserForm.getActionRequestRunPostProcessorCheck(), superUserForm.getActionTakenActionRequestId());
 170  0
         Long documentId = superUserForm.getRouteHeader().getRouteHeaderId();
 171  0
         WorkflowDocumentActions documentActions = getWorkflowDocumentActions(documentId);
 172  0
         documentActions.superUserActionRequestApproveAction(getUserSession(request).getPrincipalId(), documentId, new Long(superUserForm.getActionTakenActionRequestId()), superUserForm.getAnnotation(), runPostProcessorLogic);
 173  
         String messageString;
 174  0
         String actionReqest = StringUtils.substringBetween(methodToCallAttr, KNSConstants.METHOD_TO_CALL_PARM6_LEFT_DEL, KNSConstants.METHOD_TO_CALL_PARM6_RIGHT_DEL);
 175  0
         if (actionReqest.equalsIgnoreCase("acknowledge")){
 176  0
                 messageString = "general.routing.superuser.actionRequestAcknowledged";
 177  0
         }else if (actionReqest.equalsIgnoreCase("FYI")){
 178  0
                 messageString = "general.routing.superuser.actionRequestFYI";
 179  0
         }else if (actionReqest.equalsIgnoreCase("complete")){
 180  0
                 messageString = "general.routing.superuser.actionRequestCompleted";
 181  0
         }else if (actionReqest.equalsIgnoreCase("approved")){
 182  0
                 messageString = "general.routing.superuser.actionRequestApproved";
 183  
         }else {
 184  0
                 messageString = "general.routing.superuser.actionRequestApproved";
 185  
         }
 186  0
         saveDocumentMessage(messageString, request, superUserForm.getRouteHeaderIdString(), superUserForm.getActionTakenActionRequestId());
 187  0
         LOG.info("exiting actionRequestApprove() ...");
 188  0
         superUserForm.getActionRequests().clear();
 189  0
         initForm(request, form);
 190  
         
 191  
         // If the action request was also an app specific request, remove it from the app specific route recipient list.
 192  0
         int removalIndex = findAppSpecificRecipientIndex(superUserForm, Long.parseLong(superUserForm.getActionTakenActionRequestId()));
 193  0
         if (removalIndex >= 0) {
 194  0
                 superUserForm.getAppSpecificRouteList().remove(removalIndex);
 195  
         }
 196  
         
 197  0
         return defaultDispatch(mapping, form, request, response);
 198  
     }
 199  
 
 200  
     /**
 201  
      * Finds the index in the app specific route recipient list of the recipient whose routing was handled by the given action request.
 202  
      * 
 203  
      * @param superUserForm The SuperUserForm currently being processed.
 204  
      * @param actionRequestId The ID of the action request that handled the routing of the app specific recipient that is being removed.
 205  
      * @return The index of the app specific route recipient that was handled by the given action request, or -1 if no such recipient was found.
 206  
      */
 207  
     private int findAppSpecificRecipientIndex(SuperUserForm superUserForm, long actionRequestId) {
 208  0
             int tempIndex = 0;
 209  0
             for (Iterator<?> appRouteIter = superUserForm.getAppSpecificRouteList().iterator(); appRouteIter.hasNext();) {
 210  0
                     Long tempActnReqId = ((AppSpecificRouteRecipient) appRouteIter.next()).getActionRequestId();
 211  0
                     if (tempActnReqId != null && tempActnReqId.longValue() == actionRequestId) {
 212  0
                             return tempIndex;
 213  
                     }
 214  0
                     tempIndex++;
 215  0
             }
 216  0
             return -1;
 217  
     }
 218  
     
 219  
     public ActionForward initForm(HttpServletRequest request, ActionForm form) throws Exception {
 220  0
         request.setAttribute("Constants", new JSTLConstants(KEWConstants.class));
 221  0
         SuperUserForm superUserForm = (SuperUserForm) form;
 222  0
         DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(superUserForm.getRouteHeaderId());
 223  0
         superUserForm.setRouteHeader(routeHeader);
 224  0
         String principalId = getUserSession(request).getPrincipalId();
 225  0
         boolean isAuthorized = KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(principalId, routeHeader.getDocumentType());
 226  0
         superUserForm.setAuthorized(isAuthorized);
 227  0
         if (!isAuthorized) {
 228  0
             saveDocumentMessage("general.routing.superuser.notAuthorized", request, superUserForm.getRouteHeaderIdString(), null);
 229  0
             return null;
 230  
         }
 231  
 
 232  0
         superUserForm.setFutureNodeNames(KEWServiceLocator.getRouteNodeService().findFutureNodeNames(routeHeader.getRouteHeaderId()));
 233  
 
 234  
 
 235  0
         Collection actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(routeHeader.getRouteHeaderId());
 236  0
         Iterator requestIterator = actionRequests.iterator();
 237  0
         while (requestIterator.hasNext()) {
 238  0
             ActionRequestValue req = (ActionRequestValue) requestIterator.next();
 239  
            // if (KEWConstants.ACTION_REQUEST_APPROVE_REQ.equalsIgnoreCase(req.getActionRequested())) {
 240  0
                 superUserForm.getActionRequests().add(req);
 241  
            // }
 242  0
         }
 243  
 
 244  
 
 245  0
         superUserForm.setDocId(superUserForm.getRouteHeaderId());
 246  0
         if (superUserForm.getDocId() != null) {
 247  0
             superUserForm.setWorkflowDocument(new WorkflowDocument(getUserSession(request).getPrincipalId(), superUserForm.getDocId()));
 248  0
             superUserForm.establishVisibleActionRequestCds();
 249  
         }
 250  
 
 251  0
         return null;
 252  
     }
 253  
 
 254  
     private void saveDocumentMessage(String messageKey, HttpServletRequest request, String subVariable1, String subVariable2) {
 255  0
         if (subVariable2 == null) {
 256  0
             GlobalVariables.getMessageMap().putInfo("document", messageKey, subVariable1);
 257  
         } else {
 258  0
             GlobalVariables.getMessageMap().putInfo("document", messageKey, subVariable1, subVariable2);
 259  
         }
 260  0
     }
 261  
 
 262  
     public ActionForward routeToAppSpecificRecipient(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 263  0
             SuperUserForm superUserForm = (SuperUserForm) form;
 264  
             
 265  
             //super.routeToAppSpecificRecipient(mapping, form, request, response);
 266  
             //WorkflowRoutingForm routingForm = (WorkflowRoutingForm) form;
 267  0
         String routeType = StringUtils.substringBetween((String) request.getAttribute(KNSConstants.METHOD_TO_CALL_ATTRIBUTE),
 268  
                         KNSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KNSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
 269  0
         AppSpecificRouteRecipient recipient = null;
 270  0
         if (KEWConstants.PERSON.equals(routeType)) {
 271  0
                 recipient = superUserForm.getAppSpecificRouteRecipient();
 272  0
                 recipient.setActionRequested(superUserForm.getAppSpecificRouteActionRequestCd());
 273  0
                 superUserForm.setAppSpecificPersonId(recipient.getId());
 274  
         }
 275  
         else {
 276  0
                 recipient = superUserForm.getAppSpecificRouteRecipient2();
 277  0
                 recipient.setActionRequested(superUserForm.getAppSpecificRouteActionRequestCd2());
 278  0
                 superUserForm.setAppSpecificWorkgroupId(recipient.getId());
 279  
         }
 280  
         
 281  0
         validateAppSpecificRoute(recipient);
 282  
         
 283  
         // Make sure that the requested action is still available.
 284  0
         superUserForm.establishVisibleActionRequestCds();
 285  0
         if (superUserForm.getAppSpecificRouteActionRequestCds().get(recipient.getActionRequested()) == null) {
 286  0
                 GlobalVariables.getMessageMap().putError("appSpecificRouteRecipient" +
 287  
                             ((KEWConstants.WORKGROUP.equals(recipient.getType())) ? "2" : "") + ".id", "appspecificroute.actionrequested.invalid");
 288  
 
 289  0
                 throw new ValidationException("The requested action of '" + recipient.getActionRequested() + "' is no longer available for this document");
 290  
         }
 291  
 
 292  
         try {
 293  0
             String routeNodeName = getAdHocRouteNodeName(superUserForm.getWorkflowDocument().getRouteHeaderId());
 294  
             //if (KEWConstants.PERSON.equals(recipient.getType())) {
 295  0
             if (KEWConstants.PERSON.equals(routeType)) {
 296  0
                 String recipientPrincipalId = KEWServiceLocator.getIdentityHelperService().getIdForPrincipalName(recipient.getId());
 297  0
                 superUserForm.getWorkflowDocument().adHocRouteDocumentToPrincipal(recipient.getActionRequested(), routeNodeName, superUserForm.getAnnotation(), recipientPrincipalId, "", true);
 298  0
             } else {
 299  0
                     String recipientGroupId = KEWServiceLocator.getIdentityHelperService().getIdForGroupName(recipient.getNamespaceCode(), recipient.getId());
 300  0
                 superUserForm.getWorkflowDocument().adHocRouteDocumentToGroup(recipient.getActionRequested(), routeNodeName, superUserForm.getAnnotation(), recipientGroupId, "", true);
 301  
             }
 302  0
         } catch (Exception e) {
 303  0
             LOG.error("Error generating app specific route request", e);
 304  0
             throw new WorkflowServiceErrorException("AppSpecific Route Error", new WorkflowServiceErrorImpl("AppSpecific Route Error", "appspecificroute.systemerror"));
 305  0
         }
 306  
 
 307  0
             superUserForm.getActionRequests().clear();
 308  0
             initForm(request, form);
 309  
             
 310  
             // Retrieve the ID of the latest action request and store it with the app specific route recipient.
 311  0
             ActionRequestValue latestActnReq = getLatestActionRequest(superUserForm);
 312  0
             if (latestActnReq != null) {
 313  0
                     recipient.setActionRequestId(latestActnReq.getActionRequestId());
 314  
             }
 315  
             // Add the recipient to the list.
 316  0
         superUserForm.getAppSpecificRouteList().add(recipient);
 317  0
         superUserForm.resetAppSpecificRoute();
 318  
             
 319  0
         return start(mapping, form, request, response);
 320  
     }
 321  
 
 322  
     /**
 323  
      * Searches the current action requests list for the most recent request, which is the one with the highest ID.
 324  
      * @param superUserForm The SuperUserForm currently being processed.
 325  
      * @return The action request on the form with the highest ID, or null if no action requests exist in the list.
 326  
      */
 327  
     private ActionRequestValue getLatestActionRequest(SuperUserForm superUserForm) {
 328  0
             ActionRequestValue latestActnReq = null;
 329  0
             long latestId = -1;
 330  
             // Search the list for the action request with the highest action request value.
 331  0
             for (Iterator<?> actnReqIter = superUserForm.getActionRequests().iterator(); actnReqIter.hasNext();) {
 332  0
                     ActionRequestValue tmpActnReq = (ActionRequestValue) actnReqIter.next();
 333  0
                     if (tmpActnReq.getActionRequestId().longValue() > latestId) {
 334  0
                             latestActnReq = tmpActnReq;
 335  0
                             latestId = tmpActnReq.getActionRequestId().longValue();
 336  
                     }
 337  0
             }
 338  0
             return latestActnReq;
 339  
     }
 340  
     
 341  
     /**
 342  
      * Removes an existing AppSpecificRouteRecipient from the list.
 343  
      */
 344  
     public ActionForward removeAppSpecificRecipient(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 345  0
             SuperUserForm superUserForm = (SuperUserForm) form;
 346  
             // Make sure a valid route recipient index was specified in the "methodToCall" attribute.
 347  0
         String strIndex = StringUtils.substringBetween((String) request.getAttribute(KNSConstants.METHOD_TO_CALL_ATTRIBUTE),
 348  
                         KNSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KNSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
 349  0
         if (StringUtils.isBlank(strIndex)) {
 350  0
                 throw new WorkflowException("No adhoc route recipient index specified");
 351  
         }
 352  0
         int removeIndex = Integer.parseInt(strIndex);
 353  0
         if (removeIndex < 0 || removeIndex >= superUserForm.getAppSpecificRouteList().size()) {
 354  0
                 throw new WorkflowException("Invalid adhoc route recipient index specified");
 355  
         }
 356  
         // Remove the specified recipient from the routing, based on the recipient's ID and the ID of the action request that handled the recipient.
 357  0
         AppSpecificRouteRecipient removedRec = (AppSpecificRouteRecipient) superUserForm.getAppSpecificRouteList().get(removeIndex);
 358  0
         AdHocRevokeDTO adHocRevokeDTO = new AdHocRevokeDTO();
 359  0
         if (removedRec.getActionRequestId() != null) {
 360  0
                 adHocRevokeDTO.setActionRequestId(removedRec.getActionRequestId());
 361  
         }
 362  
         // Set the ID according to whether the recipient is a person or a group.
 363  0
         if (KEWConstants.PERSON.equals(removedRec.getType())) {
 364  0
                 adHocRevokeDTO.setPrincipalId(KEWServiceLocator.getIdentityHelperService().getIdForPrincipalName(removedRec.getId()));
 365  
         }
 366  
         else {
 367  0
                 adHocRevokeDTO.setGroupId(KEWServiceLocator.getIdentityHelperService().getIdForGroupName(removedRec.getNamespaceCode(), removedRec.getId()));
 368  
         }
 369  0
         superUserForm.getWorkflowDocument().revokeAdHocRequests(adHocRevokeDTO, "");
 370  0
         superUserForm.getAppSpecificRouteList().remove(removeIndex);
 371  
 
 372  0
             superUserForm.getActionRequests().clear();
 373  0
             initForm(request, form);
 374  0
             return start(mapping, form, request, response);
 375  
     }
 376  
 
 377  
     private WorkflowDocumentActions getWorkflowDocumentActions(Long documentId) {
 378  0
             DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByDocumentId(documentId);
 379  0
             String serviceNamespace = documentType.getServiceNamespace();
 380  0
             WorkflowDocumentActions service = (WorkflowDocumentActions)GlobalResourceLoader.getService(new QName(serviceNamespace, "WorkflowDocumentActionsService"));
 381  0
             if (service == null) {
 382  0
                 service = KEWServiceLocator.getWorkflowDocumentActionsService();
 383  
             }
 384  0
             return service;
 385  
     }
 386  
 
 387  
     protected void validateAppSpecificRoute(AppSpecificRouteRecipient recipient) {
 388  0
         if (recipient.getId() == null || recipient.getId().trim().equals("")) {
 389  0
             GlobalVariables.getMessageMap().putError("appSpecificRouteRecipient" +
 390  
                             ((KEWConstants.WORKGROUP.equals(recipient.getType())) ? "2" : "") + ".id", "appspecificroute.recipient.required");
 391  
         }
 392  
         else {
 393  0
                 if (KEWConstants.PERSON.equals(recipient.getType())) {
 394  0
                         KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(recipient.getId());
 395  0
                         if (principal == null) {
 396  0
                                 LOG.error("App Specific user recipient not found");
 397  0
                                 GlobalVariables.getMessageMap().putError("appSpecificRouteRecipient.id", "appspecificroute.user.invalid");
 398  
                         }
 399  0
                 }
 400  0
                 else if (KEWConstants.WORKGROUP.equals(recipient.getType())) {
 401  
                         //if (getIdentityManagementService().getGroup(recipient.getId()) == null) {
 402  0
                         if (getIdentityManagementService().getGroupByName(recipient.getNamespaceCode(), recipient.getId()) == null) {
 403  0
                                 GlobalVariables.getMessageMap().putError("appSpecificRouteRecipient2.id", "appspecificroute.workgroup.invalid");
 404  
                         }
 405  
                 }
 406  
         }
 407  0
         if (GlobalVariables.getMessageMap().hasErrors()) {
 408  0
             throw new ValidationException("AppSpecific Route validation Errors");
 409  
         }
 410  
 
 411  0
     }
 412  
 
 413  
     protected String getAdHocRouteNodeName(Long routeHeaderId) throws WorkflowException {
 414  0
         WorkflowInfo info = new WorkflowInfo();
 415  0
         RouteNodeInstanceDTO[] nodeInstances = info.getActiveNodeInstances(routeHeaderId);
 416  0
         if (nodeInstances == null || nodeInstances.length == 0) {
 417  0
             nodeInstances = info.getTerminalNodeInstances(routeHeaderId);
 418  
         }
 419  0
         if (nodeInstances == null || nodeInstances.length == 0) {
 420  0
             throw new WorkflowException("Could not locate a node on the document to send the ad hoc request to.");
 421  
         }
 422  0
         return nodeInstances[0].getName();
 423  
     }
 424  
 
 425  
     private IdentityManagementService getIdentityManagementService() {
 426  0
         return (IdentityManagementService) KIMServiceLocator.getService(KIMServiceLocator.KIM_IDENTITY_MANAGEMENT_SERVICE);
 427  
     }
 428  
     public static UserSession getUserSession(HttpServletRequest request) {
 429  0
         return UserSession.getAuthenticatedUser();
 430  
     }
 431  
     
 432  
 }