Coverage Report - org.kuali.rice.kew.documentoperation.web.DocumentOperationAction
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentOperationAction
0%
0/479
0%
0/270
8.609
 
 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.documentoperation.web;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.struts.action.ActionForm;
 21  
 import org.apache.struts.action.ActionForward;
 22  
 import org.apache.struts.action.ActionMapping;
 23  
 import org.apache.struts.action.ActionMessage;
 24  
 import org.apache.struts.action.ActionMessages;
 25  
 import org.kuali.rice.core.util.RiceConstants;
 26  
 import org.kuali.rice.core.util.RiceKeyConstants;
 27  
 import org.kuali.rice.kew.actionitem.ActionItem;
 28  
 import org.kuali.rice.kew.actionlist.service.ActionListService;
 29  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 30  
 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
 31  
 import org.kuali.rice.kew.actionrequest.service.DocumentRequeuerService;
 32  
 import org.kuali.rice.kew.actions.asyncservices.ActionInvocation;
 33  
 import org.kuali.rice.kew.actions.asyncservices.ActionInvocationService;
 34  
 import org.kuali.rice.kew.actions.asyncservices.BlanketApproveProcessorService;
 35  
 import org.kuali.rice.kew.actions.asyncservices.MoveDocumentService;
 36  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 37  
 import org.kuali.rice.kew.actiontaken.service.ActionTakenService;
 38  
 import org.kuali.rice.kew.api.WorkflowDocument;
 39  
 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
 40  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 41  
 import org.kuali.rice.kew.docsearch.service.SearchableAttributeProcessingService;
 42  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 43  
 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
 44  
 import org.kuali.rice.kew.engine.node.Branch;
 45  
 import org.kuali.rice.kew.engine.node.BranchState;
 46  
 import org.kuali.rice.kew.engine.node.NodeState;
 47  
 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
 48  
 import org.kuali.rice.kew.engine.node.service.BranchService;
 49  
 import org.kuali.rice.kew.engine.node.service.RouteNodeService;
 50  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
 51  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl;
 52  
 import org.kuali.rice.kew.messaging.MessageServiceNames;
 53  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 54  
 import org.kuali.rice.kew.routeheader.service.RouteHeaderService;
 55  
 import org.kuali.rice.kew.rule.bo.RuleTemplate;
 56  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 57  
 import org.kuali.rice.kew.util.KEWConstants;
 58  
 import org.kuali.rice.kew.web.KewKualiAction;
 59  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 60  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 61  
 import org.kuali.rice.krad.util.GlobalVariables;
 62  
 import org.kuali.rice.ksb.messaging.service.KSBXMLService;
 63  
 
 64  
 import javax.servlet.ServletException;
 65  
 import javax.servlet.http.HttpServletRequest;
 66  
 import javax.servlet.http.HttpServletResponse;
 67  
 import java.io.IOException;
 68  
 import java.sql.Timestamp;
 69  
 import java.text.ParseException;
 70  
 import java.util.ArrayList;
 71  
 import java.util.HashMap;
 72  
 import java.util.HashSet;
 73  
 import java.util.Iterator;
 74  
 import java.util.List;
 75  
 import java.util.Map;
 76  
 import java.util.Set;
 77  
 import java.util.StringTokenizer;
 78  
 
 79  
 
 80  
 /**
 81  
  * Struts Action for doing editing of workflow documents.
 82  
  *
 83  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 84  
  */
 85  0
 public class DocumentOperationAction extends KewKualiAction {
 86  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentOperationAction.class);
 87  
         private static final String DEFAULT_LOG_MSG = "Admin change via document operation";
 88  
 
 89  
         public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 90  0
                 return mapping.findForward("basic");
 91  
         }
 92  
 
 93  
         public ActionForward getDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 94  0
                 DocumentOperationForm docForm = (DocumentOperationForm) form;
 95  0
                 String docId = null;
 96  
                 
 97  
                 // check if we have a plausible docId first
 98  0
                 if (StringUtils.isEmpty(docForm.getDocumentId())) {
 99  0
                         GlobalVariables.getMessageMap().putError("documentId", RiceKeyConstants.ERROR_REQUIRED, "Document ID");
 100  
                 } else {
 101  
                         try {
 102  0
                                 docId = docForm.getDocumentId().trim();
 103  0
                         } catch (NumberFormatException nfe) {
 104  0
                                 GlobalVariables.getMessageMap().putError("documentId", RiceKeyConstants.ERROR_NUMERIC, "Document ID");
 105  0
                         }
 106  
                 }
 107  
 
 108  0
                 if (docId != null) {
 109  
                         //to clear Document Field first;
 110  0
                         docForm.resetOps();
 111  0
                         DocumentRouteHeaderValue routeHeader = getRouteHeaderService().getRouteHeader(docId);
 112  0
                         List routeNodeInstances=getRouteNodeService().findRouteNodeInstances(docId);
 113  0
                         Map branches1=new HashMap();
 114  0
                         List branches=new ArrayList();
 115  
 
 116  0
                         if (routeHeader == null) {
 117  0
                                 GlobalVariables.getMessageMap().putError("documentId", RiceKeyConstants.ERROR_EXISTENCE, "document");
 118  
                         } else {
 119  0
                                 materializeDocument(routeHeader);
 120  0
                                 docForm.setRouteHeader(routeHeader);
 121  0
                                 setRouteHeaderTimestampsToString(docForm);
 122  0
                                 docForm.setRouteHeaderOp(KEWConstants.NOOP);
 123  0
                                 docForm.setDocumentId(docForm.getDocumentId().trim());
 124  0
                                 String initials="";
 125  0
                                 for(Iterator lInitials=routeHeader.getInitialRouteNodeInstances().iterator();lInitials.hasNext();){
 126  0
                                         String initial=((RouteNodeInstance)lInitials.next()).getRouteNodeInstanceId();
 127  0
                                         LOG.debug(initial);
 128  0
                                         initials=initials+initial+", ";
 129  0
                                 }
 130  0
                                 if(initials.trim().length()>1){
 131  0
                                         initials=initials.substring(0,initials.lastIndexOf(","));
 132  
                                 }
 133  0
                                 docForm.setInitialNodeInstances(initials);
 134  0
                                 request.getSession().setAttribute("routeNodeInstances",routeNodeInstances);
 135  0
                                 docForm.setRouteNodeInstances(routeNodeInstances);
 136  0
                                 if(routeNodeInstances!=null){
 137  0
                                         Iterator routeNodeInstanceIter=routeNodeInstances.iterator();
 138  0
                                         while(routeNodeInstanceIter.hasNext()){
 139  0
                                                 RouteNodeInstance routeNodeInstance=(RouteNodeInstance) routeNodeInstanceIter.next();
 140  0
                                                 Branch branch=routeNodeInstance.getBranch();
 141  0
                                                 if (! branches1.containsKey(branch.getName())){
 142  0
                                                         branches1.put(branch.getName(),branch);
 143  0
                                                         branches.add(branch);
 144  0
                                                         LOG.debug(branch.getName()+"; "+branch.getBranchState());
 145  
                                                 }
 146  0
                                         }
 147  0
                                         if(branches.size()<1){
 148  0
                                                 branches=null;
 149  
                                         }
 150  
                                 }
 151  0
                                 branches1.clear();
 152  0
                                 request.getSession().setAttribute("branches",branches);
 153  0
                                 docForm.setBranches(branches);
 154  
                         }
 155  
                 }
 156  
                         
 157  0
                 return mapping.findForward("basic");
 158  
         }
 159  
 
 160  
         /**
 161  
          * Sets up various objects on the document which are required for use inside of the Struts and JSP framework.
 162  
          *
 163  
          * Specifically, if a document has action requests with null RouteNodeInstances, it will create empty node instance
 164  
          * objects.
 165  
          */
 166  
         private void materializeDocument(DocumentRouteHeaderValue document) {
 167  0
                 for (Iterator iterator = document.getActionRequests().iterator(); iterator.hasNext();) {
 168  0
                         ActionRequestValue request = (ActionRequestValue) iterator.next();
 169  0
                         if (request.getNodeInstance() == null) {
 170  0
                                 request.setNodeInstance(new RouteNodeInstance());
 171  
                         }
 172  0
                 }
 173  0
         }
 174  
 
 175  
         public ActionForward clear(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 176  0
                 DocumentOperationForm docForm = (DocumentOperationForm) form;
 177  0
                 docForm.setRouteHeader(new DocumentRouteHeaderValue());
 178  0
                 docForm.setDocumentId(null);
 179  0
                 return mapping.findForward("basic");
 180  
         }
 181  
 
 182  
         public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm form) throws Exception {
 183  0
                 return null;
 184  
         }
 185  
 
 186  
         public ActionForward flushRuleCache(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 187  0
             KEWServiceLocator.getRuleService().flushRuleCache();
 188  0
             return mapping.findForward("basic");
 189  
         }
 190  
 
 191  
         public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 192  0
                 DocumentOperationForm docForm = (DocumentOperationForm) form;
 193  0
                 boolean change = false;
 194  
 
 195  0
                 String routeHeaderOp = docForm.getRouteHeaderOp();
 196  0
                 if (!KEWConstants.UPDATE.equals(routeHeaderOp) && !KEWConstants.NOOP.equals(routeHeaderOp)) {
 197  0
                         throw new WorkflowServiceErrorException("Document operation not defined", new WorkflowServiceErrorImpl("Document operation not defined", "docoperation.operation.invalid"));
 198  
                 }
 199  0
                 if (KEWConstants.UPDATE.equals(routeHeaderOp)) {
 200  0
                         setRouteHeaderTimestamps(docForm);
 201  0
                         DocumentRouteHeaderValue dHeader = docForm.getRouteHeader();
 202  0
                         String initials=docForm.getInitialNodeInstances();
 203  0
                         List<RouteNodeInstance> lInitials = new ArrayList<RouteNodeInstance>();
 204  0
                         if (StringUtils.isNotEmpty(initials)){ 
 205  0
                                 StringTokenizer tokenInitials=new StringTokenizer(initials,",");
 206  0
                                 while (tokenInitials.hasMoreTokens()) {
 207  0
                                         String instanceId = tokenInitials.nextToken().trim();
 208  0
                                         LOG.debug(instanceId);
 209  0
                                         RouteNodeInstance instance = getRouteNodeService().findRouteNodeInstanceById(instanceId);
 210  0
                                         lInitials.add(instance);
 211  0
                                 }
 212  
                         }
 213  0
                         dHeader.setInitialRouteNodeInstances(lInitials);
 214  0
                         getRouteHeaderService().validateRouteHeader(docForm.getRouteHeader());
 215  0
                         getRouteHeaderService().saveRouteHeader(docForm.getRouteHeader());
 216  0
                         change = true;
 217  
                 }
 218  
 
 219  0
                 for (Iterator actionRequestIter = docForm.getActionRequestOps().iterator(); actionRequestIter.hasNext();) {
 220  0
                         DocOperationIndexedParameter actionRequestOp = (DocOperationIndexedParameter) actionRequestIter.next();
 221  0
                         int index = actionRequestOp.getIndex().intValue();
 222  0
                         String opValue = actionRequestOp.getValue();
 223  0
                         ActionRequestValue actionRequest = docForm.getRouteHeader().getDocActionRequest(index);
 224  0
                         String createDateParamName = "actionRequestCreateDate" + index;
 225  
 
 226  0
                         if (!KEWConstants.UPDATE.equals(opValue) && !KEWConstants.DELETE.equals(opValue) && !KEWConstants.NOOP.equals(opValue)) {
 227  0
                                 throw new WorkflowServiceErrorException("Action request operation not defined", new WorkflowServiceErrorImpl("Action request operation not defined", "docoperation.actionrequest.operation.invalid"));
 228  
                         }
 229  0
                         if (KEWConstants.UPDATE.equals(opValue)) {
 230  
                                 try {
 231  0
                                         actionRequest.setCreateDate(new Timestamp(RiceConstants.getDefaultDateFormat().parse(request.getParameter(createDateParamName)).getTime()));
 232  0
                                         actionRequest.setCreateDateString(RiceConstants.getDefaultDateFormat().format(actionRequest.getCreateDate()));
 233  0
                                         actionRequest.setDocumentId(docForm.getRouteHeader().getDocumentId());
 234  0
                                         actionRequest.setParentActionRequest(getActionRequestService().findByActionRequestId(actionRequest.getParentActionRequestId()));
 235  0
                                         actionRequest.setActionTaken(getActionTakenService().findByActionTakenId(actionRequest.getActionTakenId()));
 236  0
                                         if (actionRequest.getNodeInstance() != null && actionRequest.getNodeInstance().getRouteNodeInstanceId() == null) {
 237  0
                                                 actionRequest.setNodeInstance(null);
 238  0
                                         } else if (actionRequest.getNodeInstance() != null && actionRequest.getNodeInstance().getRouteNodeInstanceId() != null) {
 239  0
                                                 actionRequest.setNodeInstance(KEWServiceLocator.getRouteNodeService().findRouteNodeInstanceById(actionRequest.getNodeInstance().getRouteNodeInstanceId()));
 240  
                                         }
 241  
                                         // getActionRequestService().validateActionRequest(actionRequest);
 242  0
                                         getActionRequestService().saveActionRequest(actionRequest);
 243  0
                                         change = true;
 244  0
                                 } catch (ParseException pe) {
 245  0
                                         throw new WorkflowServiceErrorException("Action request create date parsing error", new WorkflowServiceErrorImpl("Action request create date parsing error", "docoperation.actionrequests.dateparsing.error", actionRequest.getActionRequestId().toString()));
 246  0
                                 }
 247  
 
 248  
                         }
 249  0
                         if (KEWConstants.DELETE.equals(opValue)) {
 250  0
                             getActionRequestService().deleteActionRequestGraph(actionRequest);
 251  0
                             change = true;
 252  
                         }
 253  0
                 }
 254  
 
 255  0
                 for (Iterator actionTakenIter = docForm.getActionTakenOps().iterator(); actionTakenIter.hasNext();) {
 256  0
                         DocOperationIndexedParameter actionTakenOp = (DocOperationIndexedParameter) actionTakenIter.next();
 257  0
                         int index = actionTakenOp.getIndex().intValue();
 258  0
                         String opValue = actionTakenOp.getValue();
 259  
 
 260  0
                         String actionDateParamName = "actionTakenActionDate" + index;
 261  0
                         ActionTakenValue actionTaken = docForm.getRouteHeader().getDocActionTaken(index);
 262  0
                         if (!KEWConstants.UPDATE.equals(opValue) && !KEWConstants.DELETE.equals(opValue) && !KEWConstants.NOOP.equals(opValue)) {
 263  0
                                 throw new WorkflowServiceErrorException("Action taken operation not defined", new WorkflowServiceErrorImpl("Action taken operation not defined", "docoperation.actiontaken.operation.invalid"));
 264  
                         }
 265  0
                         if (KEWConstants.UPDATE.equals(opValue)) {
 266  
                                 try {
 267  0
                                         actionTaken.setActionDate(new Timestamp(RiceConstants.getDefaultDateFormat().parse(request.getParameter(actionDateParamName)).getTime()));
 268  0
                                         actionTaken.setActionDateString(RiceConstants.getDefaultDateFormat().format(actionTaken.getActionDate()));
 269  
                                         // getActionTakenService().validateActionTaken(actionTaken);
 270  0
                                         getActionTakenService().saveActionTaken(actionTaken);
 271  0
                                         change = true;
 272  0
                                 } catch (ParseException pe) {
 273  0
                                         throw new WorkflowServiceErrorException("Action taken action date parsing error", new WorkflowServiceErrorImpl("Action taken action date parse error", "docoperation.actionstaken.dateparsing.error", actionTaken.getActionTakenId().toString()));
 274  0
                                 }
 275  
                         }
 276  0
                         if (KEWConstants.DELETE.equals(opValue)) {
 277  0
                                 getActionTakenService().delete(actionTaken);
 278  0
                                 change = true;
 279  
                         }
 280  0
                 }
 281  
 
 282  0
                 for (Iterator actionItemIter = docForm.getActionItemOps().iterator(); actionItemIter.hasNext();) {
 283  0
                         DocOperationIndexedParameter actionItemOp = (DocOperationIndexedParameter) actionItemIter.next();
 284  0
                         int index = actionItemOp.getIndex().intValue();
 285  0
                         String opValue = actionItemOp.getValue();
 286  
 
 287  0
                         String dateAssignedParamName = "actionItemDateAssigned" + index;
 288  0
                         ActionItem actionItem = docForm.getRouteHeader().getDocActionItem(index);
 289  0
                         if (!KEWConstants.UPDATE.equals(opValue) && !KEWConstants.DELETE.equals(opValue) && !KEWConstants.NOOP.equals(opValue)) {
 290  0
                                 throw new WorkflowServiceErrorException("Action Item operation not defined", new WorkflowServiceErrorImpl("Action Item operation not defined", "docoperation.operation.invalid"));
 291  
                         }
 292  0
                         if (KEWConstants.UPDATE.equals(opValue)) {
 293  
                                 try {
 294  0
                                         actionItem.setDateAssigned(new Timestamp(RiceConstants.getDefaultDateFormat().parse(request.getParameter(dateAssignedParamName)).getTime()));
 295  0
                                         actionItem.setDateAssignedString(RiceConstants.getDefaultDateFormat().format(actionItem.getDateAssigned()));
 296  0
                                         actionItem.setDocumentId(docForm.getRouteHeader().getDocumentId());
 297  
                                         // getActionItemService().validateActionItem(actionItem);
 298  0
                                         getActionListService().saveActionItem(actionItem);
 299  0
                                         change = true;
 300  0
                                 } catch (ParseException pe) {
 301  0
                                         throw new WorkflowServiceErrorException("Action item date assigned parsing error", new WorkflowServiceErrorImpl("Action item date assigned parse error", "docoperation.actionitem.dateassignedparsing.error", actionItem.getActionItemId().toString()));
 302  0
                                 }
 303  
                         }
 304  0
                         if (KEWConstants.DELETE.equals(opValue)) {
 305  0
                                 getActionListService().deleteActionItem(actionItem);
 306  0
                                 change = true;
 307  
                         }
 308  0
                 }
 309  
 
 310  0
                 List routeNodeInstances=(List)(request.getSession().getAttribute("routeNodeInstances"));
 311  0
                 String ids = (docForm.getNodeStatesDelete() != null) ? docForm.getNodeStatesDelete().trim() : null;
 312  0
                 List statesToBeDeleted=new ArrayList();
 313  0
                 if(ids!=null && !ids.equals("")){
 314  0
                     StringTokenizer idSets=new StringTokenizer(ids);
 315  0
                     while (idSets.hasMoreTokens()) {
 316  0
                             String id=idSets.nextToken().trim();
 317  0
                             statesToBeDeleted.add(Long.valueOf(id));
 318  0
                      }
 319  
                 }
 320  
 
 321  0
                 for (Iterator routeNodeInstanceIter = docForm.getRouteNodeInstanceOps().iterator(); routeNodeInstanceIter.hasNext();) {
 322  0
                         DocOperationIndexedParameter routeNodeInstanceOp = (DocOperationIndexedParameter) routeNodeInstanceIter.next();
 323  0
                         int index = routeNodeInstanceOp.getIndex().intValue();
 324  0
                         String opValue = routeNodeInstanceOp.getValue();
 325  0
             LOG.debug(opValue);
 326  0
                         RouteNodeInstance routeNodeInstance = (RouteNodeInstance)(routeNodeInstances.get(index));
 327  0
                         RouteNodeInstance routeNodeInstanceNew = (RouteNodeInstance)(docForm.getRouteNodeInstance(index));
 328  0
                         if (!KEWConstants.UPDATE.equals(opValue) && !KEWConstants.DELETE.equals(opValue) && !KEWConstants.NOOP.equals(opValue)) {
 329  0
                                 throw new WorkflowServiceErrorException("Route Node Instance Operation not defined", new WorkflowServiceErrorImpl("Route Node Instance Operation not defined", "docoperation.routenodeinstance.operation.invalid"));
 330  
                         }
 331  0
                         if (KEWConstants.UPDATE.equals(opValue)) {
 332  
                                 //LOG.debug("saving routeNodeInstance:"+routeNodeInstance.getRouteNodeInstanceId());
 333  
                                 //getRouteNodeService().save(routeNodeInstance);
 334  0
                                 routeNodeInstance.setActive(routeNodeInstanceNew.isActive());
 335  0
                                 LOG.debug(Boolean.toString(routeNodeInstanceNew.isActive()));
 336  0
                                 routeNodeInstance.setComplete(routeNodeInstanceNew.isComplete());
 337  0
                                 routeNodeInstance.setInitial(routeNodeInstanceNew.isInitial());
 338  0
                                 List nodeStates=routeNodeInstance.getState();
 339  0
                                 List nodeStatesNew=routeNodeInstanceNew.getState();
 340  
 
 341  0
                                 if(nodeStates!=null){
 342  0
                                         for(int i=0;i<nodeStates.size();i++){
 343  0
                                            NodeState nodeState=(NodeState)nodeStates.get(i);
 344  0
                                            NodeState nodeStateNew=(NodeState)nodeStatesNew.get(i);
 345  0
                                            if(nodeStateNew.getKey()!=null && ! nodeStateNew.getKey().trim().equals("")){
 346  0
                                            nodeState.setKey(nodeStateNew.getKey());
 347  0
                                            LOG.debug(nodeState.getKey());
 348  0
                                            nodeState.setValue(nodeStateNew.getValue());
 349  0
                                            LOG.debug(nodeState.getValue());
 350  
                                            }
 351  
                                     }
 352  
                                 }
 353  0
                                 getRouteNodeService().save(routeNodeInstance);
 354  0
                                 LOG.debug("saved");
 355  0
                                 change = true;
 356  
                         }
 357  
 
 358  
 
 359  0
                         if (KEWConstants.DELETE.equals(opValue)) {
 360  0
                                 List nodeStates=routeNodeInstance.getState();
 361  0
                                 List nodeStatesNew=routeNodeInstanceNew.getState();
 362  
 
 363  0
                                 if(nodeStates!=null){
 364  0
                                         for(int i=0;i<nodeStates.size();i++){
 365  0
                                            NodeState nodeState=(NodeState)nodeStates.get(i);
 366  0
                                            NodeState nodeStateNew=(NodeState)nodeStatesNew.get(i);
 367  0
                                            if(nodeStateNew.getKey()==null || nodeStateNew.getKey().trim().equals("")){
 368  0
                                              statesToBeDeleted.remove(nodeState.getNodeStateId());
 369  
                                            }
 370  
                                     }
 371  
                                 }
 372  0
                                 getRouteNodeService().deleteByRouteNodeInstance(routeNodeInstance);
 373  0
                                 LOG.debug(routeNodeInstance.getRouteNodeInstanceId()+" is deleted");
 374  0
                                 change = true;
 375  0
                                 break;
 376  
                         }
 377  
 
 378  0
                         if (KEWConstants.NOOP.equals(opValue)){
 379  0
                                 routeNodeInstanceNew.setActive(routeNodeInstance.isActive());
 380  0
                                 routeNodeInstanceNew.setComplete(routeNodeInstance.isComplete());
 381  0
                                 routeNodeInstanceNew.setInitial(routeNodeInstance.isInitial());
 382  0
                                 List nodeStates=routeNodeInstance.getState();
 383  0
                                 List nodeStatesNew=routeNodeInstanceNew.getState();
 384  0
                                 if(nodeStates!=null){
 385  0
                                    for(int i=0;i<nodeStates.size();i++){
 386  0
                                            NodeState nodeState=(NodeState)nodeStates.get(i);
 387  0
                                            NodeState nodeStateNew=(NodeState)nodeStatesNew.get(i);
 388  0
                                            if(nodeStateNew.getKey()==null || nodeStateNew.getKey().trim().equals("")){
 389  0
                                                      statesToBeDeleted.remove(nodeState.getNodeStateId());
 390  
                                            }
 391  0
                                            nodeStateNew.setKey(nodeState.getKey());
 392  0
                                            nodeStateNew.setValue(nodeState.getValue());
 393  
                                    }
 394  
                                 }
 395  
                         }
 396  
 
 397  
                         //((DocOperationIndexedParameter)(docForm.getRouteNodeInstanceOps().get(index))).setValue(KEWConstants.NOOP);
 398  0
                 }
 399  
 
 400  0
                 if(statesToBeDeleted!=null && statesToBeDeleted.size()>0){
 401  0
                         getRouteNodeService().deleteNodeStates(statesToBeDeleted);
 402  
                 }
 403  
 
 404  
 
 405  0
                 List branches=(List)(request.getSession().getAttribute("branches"));
 406  0
                 String branchStateIds = (docForm.getBranchStatesDelete() != null) ? docForm.getBranchStatesDelete().trim() : null;
 407  0
                 List branchStatesToBeDeleted=new ArrayList();
 408  0
                 if(branchStateIds!=null && !branchStateIds.equals("")){
 409  0
                     StringTokenizer idSets=new StringTokenizer(branchStateIds);
 410  0
                     while (idSets.hasMoreTokens()) {
 411  0
                             String id=idSets.nextToken().trim();
 412  0
                             branchStatesToBeDeleted.add(Long.valueOf(id));
 413  0
                     }
 414  
                 }
 415  
 
 416  0
                 for (Iterator branchesOpIter = docForm.getBranchOps().iterator(); branchesOpIter.hasNext();) {
 417  0
                         DocOperationIndexedParameter branchesOp = (DocOperationIndexedParameter) branchesOpIter.next();
 418  0
                         int index = branchesOp.getIndex().intValue();
 419  0
                         String opValue = branchesOp.getValue();
 420  0
             LOG.debug(opValue);
 421  0
                         Branch branch = (Branch)(branches.get(index));
 422  0
                         Branch branchNew = (Branch)(docForm.getBranche(index));
 423  0
                         if (!KEWConstants.UPDATE.equals(opValue) && !KEWConstants.NOOP.equals(opValue)) {
 424  0
                                 throw new WorkflowServiceErrorException("Route Node Instance Operation not defined", new WorkflowServiceErrorImpl("Route Node Instance Operation not defined", "docoperation.routenodeinstance.operation.invalid"));
 425  
                         }
 426  0
                         if (KEWConstants.UPDATE.equals(opValue)) {
 427  
                                 //LOG.debug("saving routeNodeInstance:"+routeNodeInstance.getRouteNodeInstanceId());
 428  
                                 //getRouteNodeService().save(routeNodeInstance);
 429  0
                                 branch.setName(branchNew.getName());
 430  0
                                 List branchStates=branch.getBranchState();
 431  0
                                 List branchStatesNew=branchNew.getBranchState();
 432  0
                                 if(branchStates!=null){
 433  0
                                    for(int i=0;i<branchStates.size();i++){
 434  0
                                            BranchState branchState=(BranchState)branchStates.get(i);
 435  0
                                            BranchState branchStateNew=(BranchState)branchStatesNew.get(i);
 436  0
                                            if(branchStateNew.getKey()!=null && ! branchStateNew.getKey().trim().equals("")){
 437  0
                                            branchState.setKey(branchStateNew.getKey());
 438  0
                                            LOG.debug(branchState.getKey());
 439  0
                                            branchState.setValue(branchStateNew.getValue());
 440  0
                                            LOG.debug(branchState.getValue());
 441  
                                            }
 442  
                                    }
 443  
                                 }
 444  0
                                 getBranchService().save(branch);
 445  0
                                 LOG.debug("branch saved");
 446  0
                                 change = true;
 447  
 
 448  
                         }
 449  
 
 450  
 
 451  0
                         if (KEWConstants.NOOP.equals(opValue)){
 452  0
                                 branchNew.setName(branch.getName());
 453  0
                                 List branchStates=branch.getBranchState();
 454  0
                                 List branchStatesNew=branchNew.getBranchState();
 455  0
                                 if(branchStates!=null){
 456  0
                                    for(int i=0;i<branchStates.size();i++){
 457  0
                                            BranchState branchState=(BranchState)branchStates.get(i);
 458  0
                                            BranchState branchStateNew=(BranchState)branchStatesNew.get(i);
 459  0
                                            if(branchStateNew.getKey()==null || branchStateNew.getKey().trim().equals("")){
 460  0
                                                    branchStatesToBeDeleted.remove(branchState.getBranchStateId());
 461  
                                            }
 462  0
                                            branchStateNew.setKey(branchState.getKey());
 463  0
                                            LOG.debug(branchState.getKey());
 464  0
                                            branchStateNew.setValue(branchState.getValue());
 465  0
                                            LOG.debug(branchState.getValue());
 466  
                                    }
 467  
                                 }
 468  
                         }
 469  
                         //((DocOperationIndexedParameter)(docForm.getBranchOps().get(index))).setValue(KEWConstants.NOOP);
 470  0
                 }
 471  
 
 472  0
                 if(branchStatesToBeDeleted!=null && branchStatesToBeDeleted.size()>0){
 473  0
                         getBranchService().deleteBranchStates(branchStatesToBeDeleted);
 474  
                 }
 475  
 
 476  0
                 WorkflowDocument workflowDocument = WorkflowDocumentFactory.loadDocument(GlobalVariables.getUserSession().getPrincipalId(), docForm.getDocumentId());
 477  
 
 478  0
                 String annotation = docForm.getAnnotation();
 479  0
                 if (StringUtils.isEmpty(annotation)) {
 480  0
                         annotation = DEFAULT_LOG_MSG;
 481  
                 }
 482  0
                 workflowDocument.logAnnotation(annotation);
 483  
 
 484  0
                 ActionMessages messages = new ActionMessages();
 485  0
                 String forward = null;
 486  0
                 if (change) {
 487  0
                         messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("docoperation.operation.saved"));
 488  0
                         docForm.setRouteHeader(getRouteHeaderService().getRouteHeader(docForm.getRouteHeader().getDocumentId()));
 489  0
                         forward = "summary";
 490  
                 } else {
 491  0
                         messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("docoperation.operation.noop"));
 492  0
                         forward = "basic";
 493  
                 }
 494  0
                 saveMessages(request, messages);
 495  0
                 return mapping.findForward(forward);
 496  
 
 497  
         }
 498  
 
 499  
         private RouteHeaderService getRouteHeaderService() {
 500  0
                 return (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV);
 501  
         }
 502  
 
 503  
         private RouteNodeService getRouteNodeService(){
 504  0
                 return (RouteNodeService) KEWServiceLocator.getService(KEWServiceLocator.ROUTE_NODE_SERVICE);
 505  
         }
 506  
 
 507  
         private ActionRequestService getActionRequestService() {
 508  0
                 return (ActionRequestService) KEWServiceLocator.getService(KEWServiceLocator.ACTION_REQUEST_SRV);
 509  
         }
 510  
 
 511  
         private ActionTakenService getActionTakenService() {
 512  0
                 return (ActionTakenService) KEWServiceLocator.getService(KEWServiceLocator.ACTION_TAKEN_SRV);
 513  
         }
 514  
 
 515  
         private ActionListService getActionListService() {
 516  0
                 return (ActionListService) KEWServiceLocator.getActionListService();
 517  
         }
 518  
 
 519  
         private void setRouteHeaderTimestamps(DocumentOperationForm docForm) {
 520  0
                 if (docForm.getCreateDate() == null || docForm.getCreateDate().trim().equals("")) {
 521  0
                         throw new WorkflowServiceErrorException("Document create date empty", new WorkflowServiceErrorImpl("Document create date empty", "docoperation.routeheader.createdate.empty"));
 522  
                 } else {
 523  
                         try {
 524  
                                 
 525  
 //                                String a_pat = "yyyy-MM-dd hh:mm:ss";
 526  
 //                                SimpleDateFormat fmt = new SimpleDateFormat(a_pat);
 527  
 //                                
 528  
 //                                System.out.println("**********************new*******************");
 529  
 //                                System.out.println(docForm.getCreateDate());
 530  
 //                                System.out.println("**********************old*******************");
 531  
 //                                System.out.println(docForm.getRouteHeader().getCreateDate());
 532  
 //                                System.out.println("********************************************");
 533  
 //        
 534  
         //                        docForm.getRouteHeader().setCreateDate(new Timestamp(fmt.parse(docForm.getCreateDate()).getTime()));
 535  
 
 536  0
                                 docForm.getRouteHeader().setCreateDate(new Timestamp(RiceConstants.getDefaultDateAndTimeFormat().parse(docForm.getCreateDate()).getTime()));
 537  0
                         } catch (ParseException pe) {
 538  0
                                 throw new WorkflowServiceErrorException("RouteHeader create date parsing error", new WorkflowServiceErrorImpl("Date parsing error", "docoperation.routeheader.createdate.invalid"));
 539  0
                         }
 540  
                 }
 541  
 
 542  0
                 if (docForm.getStatusModDate() == null || docForm.getStatusModDate().trim().equals("")) {
 543  0
                         throw new WorkflowServiceErrorException("Document doc status mod date empty", new WorkflowServiceErrorImpl("Document doc status mod date empty", "docoperation.routeheader.statusmoddate.empty"));
 544  
                 } else {
 545  
                         try {
 546  0
                                 docForm.getRouteHeader().setStatusModDate(new Timestamp(RiceConstants.getDefaultDateAndTimeFormat().parse(docForm.getStatusModDate()).getTime()));
 547  0
                         } catch (ParseException pe) {
 548  0
                                 throw new WorkflowServiceErrorException("Document doc status date parsing error", new WorkflowServiceErrorImpl("Document doc status mod date parsing error", "docoperation.routeheader.statusmoddate.invalid"));
 549  0
                         }
 550  
                 }
 551  
 
 552  0
                 if (docForm.getApprovedDate() != null && !docForm.getApprovedDate().trim().equals("")) {
 553  
                         try {
 554  0
                                 docForm.getRouteHeader().setApprovedDate(new Timestamp(RiceConstants.getDefaultDateAndTimeFormat().parse(docForm.getApprovedDate()).getTime()));
 555  0
                         } catch (ParseException pe) {
 556  0
                                 throw new WorkflowServiceErrorException("Document approved date parsing error", new WorkflowServiceErrorImpl("Document approved date parsing error", "docoperation.routeheader.approveddate.invalid"));
 557  0
                         }
 558  
 
 559  
                 }
 560  
 
 561  0
                 if (docForm.getFinalizedDate() != null && !docForm.getFinalizedDate().trim().equals("")) {
 562  
                         try {
 563  0
                                 docForm.getRouteHeader().setFinalizedDate(new Timestamp(RiceConstants.getDefaultDateAndTimeFormat().parse(docForm.getFinalizedDate()).getTime()));
 564  0
                         } catch (ParseException pe) {
 565  0
                                 throw new WorkflowServiceErrorException("Document finalized date parsing error", new WorkflowServiceErrorImpl("Document finalized date parsing error", "docoperation.routeheader.finalizeddate.invalid"));
 566  0
                         }
 567  
                 }
 568  
 
 569  0
                 if (docForm.getRouteStatusDate() != null && !docForm.getRouteStatusDate().trim().equals("")) {
 570  
                         try {
 571  0
                                 docForm.getRouteHeader().setRouteStatusDate(new Timestamp(RiceConstants.getDefaultDateAndTimeFormat().parse(docForm.getRouteStatusDate()).getTime()));
 572  0
                         } catch (ParseException pe) {
 573  0
                                 throw new WorkflowServiceErrorException("Document route status date parsing error", new WorkflowServiceErrorImpl("Document route status date parsing error", "docoperation.routeheader.routestatusdate.invalid"));
 574  0
                         }
 575  
 
 576  
                 }
 577  
 
 578  0
                 if (docForm.getRouteLevelDate() != null && !docForm.getRouteLevelDate().trim().equals("")) {
 579  
                         try {
 580  0
                                 docForm.getRouteHeader().setRouteLevelDate(new Timestamp(RiceConstants.getDefaultDateAndTimeFormat().parse(docForm.getRouteLevelDate()).getTime()));
 581  0
                         } catch (ParseException pe) {
 582  0
                                 throw new WorkflowServiceErrorException("Document route level date parsing error", new WorkflowServiceErrorImpl("Document route level date parsing error", "docoperation.routeheader.routeleveldate.invalid"));
 583  0
                         }
 584  
                 }
 585  0
         }
 586  
 
 587  
         private void setRouteHeaderTimestampsToString(DocumentOperationForm docForm) {
 588  
                 try {
 589  0
                         docForm.setCreateDate(RiceConstants.getDefaultDateAndTimeFormat().format(docForm.getRouteHeader().getCreateDate()));
 590  0
                         docForm.setStatusModDate(RiceConstants.getDefaultDateAndTimeFormat().format(docForm.getRouteHeader().getStatusModDate()));
 591  0
                         docForm.setApprovedDate(RiceConstants.getDefaultDateAndTimeFormat().format(docForm.getRouteHeader().getApprovedDate()));
 592  0
                         docForm.setFinalizedDate(RiceConstants.getDefaultDateAndTimeFormat().format(docForm.getRouteHeader().getFinalizedDate()));
 593  0
                         docForm.setRouteStatusDate(RiceConstants.getDefaultDateAndTimeFormat().format(docForm.getRouteHeader().getRouteStatusDate()));
 594  0
                         docForm.setRouteLevelDate(RiceConstants.getDefaultDateAndTimeFormat().format(docForm.getRouteHeader().getRouteLevelDate()));
 595  
 
 596  0
                 } catch (Exception e) {
 597  0
                         LOG.info("One or more of the dates in routeHeader may be null");
 598  0
                 }
 599  0
         }
 600  
 
 601  
         public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 602  0
                 DocumentOperationForm docForm = (DocumentOperationForm) form;
 603  0
                 String lookupInvocationModule = docForm.getLookupInvocationModule();
 604  0
                 docForm.getRouteHeader().setDocumentId(docForm.getDocumentId());
 605  
 
 606  0
                 if (lookupInvocationModule != null && !lookupInvocationModule.trim().equals("")) {
 607  0
                         String lookupField = docForm.getLookupInvocationField();
 608  0
                         int lookupIndex = new Integer(docForm.getLookupInvocationIndex()).intValue();
 609  0
                         String networkId = request.getParameter("networkId");
 610  0
                         String principalId = KEWServiceLocator.getIdentityHelperService().getIdForPrincipalName(networkId);
 611  
 
 612  0
                         if (lookupInvocationModule.equals("RouteHeader")) {
 613  0
                                 DocumentRouteHeaderValue routeHeader = docForm.getRouteHeader();
 614  0
                                 if ("initiatorWorkflowId".equals(lookupField)) {
 615  0
                                         routeHeader.setInitiatorWorkflowId(principalId);
 616  
                                 }
 617  0
                                 if ("documentTypeId".equals(lookupField)) {
 618  0
                                         DocumentType docType = getDocumentTypeService().findByName(request.getParameter("docTypeFullName"));
 619  0
                                         routeHeader.setDocumentTypeId(docType.getDocumentTypeId());
 620  
                                 }
 621  
                         }
 622  
 
 623  0
                         if (lookupInvocationModule.equals("ActionRequest")) {
 624  0
                                 ActionRequestValue actionRequest = docForm.getRouteHeader().getDocActionRequest(lookupIndex);
 625  0
                                 if ("routeMethodName".equals(lookupField)) {
 626  
 //                                        actionRequest.setRouteMethodName(null);
 627  0
                                         String id = request.getParameter("ruleTemplate.ruleTemplateId");
 628  0
                                         if (id != null && !"".equals(id.trim())) {
 629  0
                                                 RuleTemplate ruleTemplate = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateId(id);
 630  
 //                                                if (ruleTemplate != null) {
 631  
 //                                                        actionRequest.setRouteMethodName(ruleTemplate.getName());
 632  
 //                                                }
 633  
                                         }
 634  
                                 }
 635  0
                                 if ("workflowId".equals(lookupField)) {
 636  0
                                         actionRequest.setPrincipalId(principalId);
 637  
                                 }
 638  0
                                 if ("workgroupId".equals(lookupField)) {
 639  0
                                         if (request.getParameter("workgroupId") != null && !"".equals(request.getParameter("workgroupId").trim())) {
 640  0
                                                 actionRequest.setGroupId(request.getParameter("workgroupId"));
 641  
                                         } else {
 642  0
                                                 actionRequest.setGroupId(null);
 643  
                                         }
 644  
                                 }
 645  0
                                 if ("roleName".equals(lookupField)) {
 646  0
                                         actionRequest.setRoleName(request.getParameter("roleName"));
 647  
                                 }
 648  
                         }
 649  0
                         if (lookupInvocationModule.equals("ActionTaken")) {
 650  0
                                 ActionTakenValue actionTaken = docForm.getRouteHeader().getDocActionTaken(lookupIndex);
 651  0
                                 if ("workflowId".equals(lookupField)) {
 652  0
                                         Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(networkId);
 653  0
                                         if (principal != null) {
 654  0
                                                 actionTaken.setPrincipalId(principal.getPrincipalId());
 655  
                                         } else {
 656  0
                                                 LOG.info("action taken user not found");
 657  0
                                                 actionTaken.setPrincipalId(null);
 658  
                                         }
 659  
                                 }
 660  0
                                 if ("delegatorWorkflowId".equals(lookupField)) {
 661  0
                                         Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(networkId);
 662  0
                                         if (principal != null) {
 663  0
                                                 actionTaken.setDelegatorPrincipalId(principal.getPrincipalId());
 664  
                                         } else {
 665  0
                                                 LOG.info("action taken delegator user not found");
 666  0
                                                 actionTaken.setDelegatorPrincipalId(null);
 667  
                                         }
 668  
                                 }
 669  0
                                 if ("delegatorGroupId".equals(lookupField)) {
 670  0
                                         if (request.getParameter("workgroupId") != null && !"".equals(request.getParameter("workgroupId").trim())) {
 671  0
                                                 actionTaken.setDelegatorGroupId(request.getParameter("workgroupId"));
 672  
                                         } else {
 673  0
                                                 actionTaken.setDelegatorGroupId(null);
 674  
                                         }
 675  
                                 }
 676  
                         }
 677  
 
 678  0
                         if (lookupInvocationModule.equals("ActionItem")) {
 679  0
                                 ActionItem actionItem = docForm.getRouteHeader().getDocActionItem(lookupIndex);
 680  0
                                 if ("workflowId".equals(lookupField)) {
 681  0
                                         Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(networkId);
 682  0
                                         if (principal != null) {
 683  0
                                                 actionItem.setPrincipalId(principal.getPrincipalId());
 684  
                                         } else {
 685  0
                                                 LOG.info("action item user not found");
 686  0
                                                 actionItem.setPrincipalId(null);
 687  
                                         }
 688  
                                 }
 689  
 
 690  0
                                 if ("workgroupId".equals(lookupField)) {
 691  0
                                         if (request.getParameter("workgroupId") != null && !"".equals(request.getParameter("workgroupId").trim())) {
 692  0
                                                 actionItem.setGroupId(request.getParameter("workgroupId"));
 693  
                                         } else {
 694  0
                                                 actionItem.setGroupId(null);
 695  
                                         }
 696  
                                 }
 697  0
                                 if ("roleName".equals(lookupField)) {
 698  0
                                         actionItem.setRoleName(request.getParameter("roleName"));
 699  
                                 }
 700  0
                                 if ("delegatorWorkflowId".equals(lookupField)) {
 701  0
                                         Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(networkId);
 702  0
                                         if (principal != null) {
 703  0
                                                 actionItem.setDelegatorWorkflowId(principal.getPrincipalId());
 704  
                                         } else {
 705  0
                                                 LOG.info("action item delegator user not found");
 706  0
                                                 actionItem.setDelegatorWorkflowId(null);
 707  
                                         }
 708  
                                 }
 709  0
                                 if ("delegatorGroupId".equals(lookupField)) {
 710  0
                                         if (request.getParameter("workgroupId") != null && !"".equals(request.getParameter("workgroupId").trim())) {
 711  0
                                                 actionItem.setDelegatorGroupId(request.getParameter("workgroupId"));
 712  
                                         } else {
 713  0
                                                 actionItem.setDelegatorGroupId(null);
 714  
                                         }
 715  
                                 }
 716  0
                                 if ("docName".equals(lookupField)) {
 717  0
                                         DocumentType docType = getDocumentTypeService().findByName(request.getParameter("docTypeFullName"));
 718  0
                                         actionItem.setDocName(docType.getName());
 719  0
                                         actionItem.setDocLabel(docType.getLabel());
 720  0
                                         actionItem.setDocHandlerURL(docType.getDocHandlerUrl());
 721  
                                 }
 722  
                         }
 723  
                 }
 724  
 
 725  0
                 return mapping.findForward("basic");
 726  
         }
 727  
 
 728  
         public ActionForward queueDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 729  
                 try {
 730  0
                         DocumentOperationForm docForm = (DocumentOperationForm) form;
 731  0
                         KSBXMLService routeDoc = MessageServiceNames.getRouteDocumentMessageService(docForm.getRouteHeader());
 732  0
                         routeDoc.invoke(docForm.getDocumentId());
 733  0
                         ActionMessages messages = new ActionMessages();
 734  0
                         messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("general.message", "Document was successfully queued"));
 735  0
                         saveMessages(request, messages);
 736  0
                         return mapping.findForward("basic");
 737  0
                 } catch (Exception e) {
 738  0
                         throw new WorkflowRuntimeException(e);
 739  
                 }
 740  
         }
 741  
 
 742  
         public ActionForward indexSearchableAttributes(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 743  0
                 DocumentOperationForm docForm = (DocumentOperationForm) form;
 744  0
                 SearchableAttributeProcessingService searchableAttributeService = MessageServiceNames.getSearchableAttributeService(docForm.getRouteHeader());
 745  0
                 searchableAttributeService.indexDocument(docForm.getRouteHeader().getDocumentId());
 746  0
                 ActionMessages messages = new ActionMessages();
 747  0
                 messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("general.message", "Searchable Attribute Indexing was successfully scheduled"));
 748  0
                 saveMessages(request, messages);
 749  0
                 return mapping.findForward("basic");
 750  
         }
 751  
 
 752  
         public ActionForward queueDocumentRequeuer(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 753  0
                 DocumentOperationForm docForm = (DocumentOperationForm) form;
 754  0
                 DocumentRequeuerService docRequeue = MessageServiceNames.getDocumentRequeuerService(docForm.getRouteHeader().getDocumentType().getApplicationId(), docForm.getRouteHeader().getDocumentId(), 0);
 755  0
                 docRequeue.requeueDocument(docForm.getRouteHeader().getDocumentId());
 756  0
                 ActionMessages messages = new ActionMessages();
 757  0
                 messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("general.message", "Document Requeuer was successfully scheduled"));
 758  0
                 saveMessages(request, messages);
 759  0
                 return mapping.findForward("basic");
 760  
         }
 761  
 
 762  
         public ActionForward blanketApproveDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 763  
                 try {
 764  0
                         DocumentOperationForm docForm = (DocumentOperationForm) form;
 765  0
                         String principalId = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(docForm.getBlanketApproveUser()).getPrincipalId();
 766  0
                         Set<String> nodeNames = new HashSet<String>();
 767  0
                         if (!StringUtils.isBlank(docForm.getBlanketApproveNodes())) {
 768  0
                                 String[] nodeNameArray = docForm.getBlanketApproveNodes().split(",");
 769  0
                                 for (String nodeName : nodeNameArray) {
 770  0
                                         nodeNames.add(nodeName.trim());
 771  
                                 }
 772  
                         }
 773  0
                         BlanketApproveProcessorService blanketApprove = MessageServiceNames.getBlanketApproveProcessorService(docForm.getRouteHeader());
 774  0
                         blanketApprove.doBlanketApproveWork(docForm.getRouteHeader().getDocumentId(), principalId, docForm.getBlanketApproveActionTakenId(), nodeNames, true);
 775  0
                         ActionMessages messages = new ActionMessages();
 776  0
                         messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("general.message", "Blanket Approve Processor was successfully scheduled"));
 777  0
                         saveMessages(request, messages);
 778  0
                         return mapping.findForward("basic");
 779  0
                 } catch (Exception e) {
 780  0
                         throw new WorkflowRuntimeException(e);
 781  
                 }
 782  
         }
 783  
         
 784  
         public ActionForward moveDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 785  
                 try {
 786  0
                         DocumentOperationForm docForm = (DocumentOperationForm) form;
 787  0
                         String principalId = KEWServiceLocator.getIdentityHelperService().getIdForPrincipalName(docForm.getBlanketApproveUser());
 788  0
                         Set<String> nodeNames = new HashSet<String>();
 789  0
                         if (!StringUtils.isBlank(docForm.getBlanketApproveNodes())) {
 790  0
                                 String[] nodeNameArray = docForm.getBlanketApproveNodes().split(",");
 791  0
                                 for (String nodeName : nodeNameArray) {
 792  0
                                         nodeNames.add(nodeName.trim());
 793  
                                 }
 794  
                         }
 795  0
                         ActionTakenValue actionTaken = KEWServiceLocator.getActionTakenService().findByActionTakenId(docForm.getBlanketApproveActionTakenId());
 796  0
                         MoveDocumentService moveService = MessageServiceNames.getMoveDocumentProcessorService(docForm.getRouteHeader());
 797  0
                         moveService.moveDocument(principalId, docForm.getRouteHeader(), actionTaken, nodeNames);
 798  0
                         ActionMessages messages = new ActionMessages();
 799  0
                         messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("general.message", "Move Document Processor was successfully scheduled"));
 800  0
                         saveMessages(request, messages);
 801  0
                         return mapping.findForward("basic");
 802  0
                 } catch (Exception e) {
 803  0
                         throw new WorkflowRuntimeException(e);
 804  
                 }
 805  
         }
 806  
 
 807  
         public ActionForward queueActionInvocation(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 808  
                 try {
 809  0
                         DocumentOperationForm docForm = (DocumentOperationForm) form;
 810  0
                         String principalId = KEWServiceLocator.getIdentityHelperService().getIdForPrincipalName(docForm.getActionInvocationUser());
 811  0
                         ActionInvocation invocation = new ActionInvocation(docForm.getActionInvocationActionItemId(), docForm.getActionInvocationActionCode());
 812  0
                         ActionInvocationService actionInvocationService = MessageServiceNames.getActionInvocationProcessorService(docForm.getRouteHeader());
 813  0
                         actionInvocationService.invokeAction(principalId, docForm.getRouteHeader().getDocumentId(), invocation);
 814  0
                         ActionMessages messages = new ActionMessages();
 815  0
                         messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("general.message", "Action Invocation Processor was successfully scheduled"));
 816  0
                         saveMessages(request, messages);
 817  0
                         return mapping.findForward("basic");
 818  0
                 } catch (Exception e) {
 819  0
                         throw new WorkflowRuntimeException(e);
 820  
                 }
 821  
         }
 822  
 
 823  
         private DocumentTypeService getDocumentTypeService() {
 824  0
                 return (DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
 825  
         }
 826  
 
 827  
         private BranchService getBranchService(){
 828  0
                 return (BranchService) KEWServiceLocator.getService(KEWServiceLocator.BRANCH_SERVICE);
 829  
         }
 830  
 }