Coverage Report - org.kuali.rice.kew.actions.RouteDocumentAction
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteDocumentAction
0%
0/43
0%
0/16
3.167
 
 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.actions;
 18  
 
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.log4j.MDC;
 22  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 23  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 24  
 import org.kuali.rice.kew.engine.node.Process;
 25  
 import org.kuali.rice.kew.exception.InvalidActionTakenException;
 26  
 import org.kuali.rice.kew.exception.WorkflowException;
 27  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 28  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 29  
 import org.kuali.rice.kew.util.KEWConstants;
 30  
 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
 31  
 
 32  
 
 33  
 /**
 34  
  * Action that puts the document in routing.
 35  
  *
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  *
 38  
  */
 39  
 public class RouteDocumentAction extends ActionTakenEvent {
 40  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RouteDocumentAction.class);
 41  
 
 42  
     public RouteDocumentAction(DocumentRouteHeaderValue rh, PrincipalContract principal) {
 43  0
         super(KEWConstants.ACTION_TAKEN_COMPLETED_CD, rh, principal);
 44  0
     }
 45  
 
 46  
     public RouteDocumentAction(DocumentRouteHeaderValue rh, PrincipalContract principal, String annotation) {
 47  0
         super(KEWConstants.ACTION_TAKEN_COMPLETED_CD, rh, principal, annotation);
 48  0
     }
 49  
 
 50  
     /* (non-Javadoc)
 51  
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#getActionPerformedCode()
 52  
      */
 53  
     @Override
 54  
     public String getActionPerformedCode() {
 55  0
         return KEWConstants.ACTION_TAKEN_ROUTED_CD;
 56  
     }
 57  
 
 58  
     /* (non-Javadoc)
 59  
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#isActionCompatibleRequest(java.util.List)
 60  
      */
 61  
     @Override
 62  
     public String validateActionRules() {
 63  
             // check state before checking kim
 64  0
         if (!getRouteHeader().isValidActionToTake(getActionPerformedCode())) {
 65  0
             return "Document is not in a state to be routed";
 66  
         }
 67  0
             if (! KEWServiceLocator.getDocumentTypePermissionService().canRoute(getPrincipal().getPrincipalId(), getRouteHeader())) {
 68  0
                     return "User is not authorized to Route document";
 69  
             }
 70  0
         return "";
 71  
     }
 72  
 
 73  
     @Override
 74  
     public String validateActionRules(List<ActionRequestValue> actionRequests) {
 75  0
             return validateActionRules();
 76  
     }
 77  
     
 78  
     /**
 79  
      * Record the routing action. To route a document, it must be in the proper state. Previous requests and actions have no bearing on the outcome of this action, unless the
 80  
      * @throws org.kuali.rice.kew.exception.InvalidActionTakenException
 81  
      */
 82  
     public void recordAction() throws InvalidActionTakenException {
 83  0
         MDC.put("docId", getRouteHeader().getDocumentId());
 84  0
         updateSearchableAttributesIfPossible();
 85  
 
 86  0
         LOG.debug("Routing document : " + annotation);
 87  
 
 88  0
         LOG.debug("Checking to see if the action is legal");
 89  0
         String errorMessage = validateActionRules();
 90  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
 91  0
             throw new InvalidActionTakenException(errorMessage);
 92  
         }
 93  
 
 94  
 
 95  
         // we want to check that the "RouteDocument" command is valid here, not the "Complete" command (which is in our Action's action taken code)
 96  0
         LOG.debug("Record the routing action");
 97  0
         ActionTakenValue actionTaken = saveActionTaken();
 98  
 
 99  
         //TODO this will get all pending AR's even if they haven't been in an action list... This seems bad
 100  0
         List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId());
 101  0
         LOG.debug("Deactivate all pending action requests");
 102  
         // deactivate any requests for the user that routed the document.
 103  0
         for (ActionRequestValue actionRequest : actionRequests)
 104  
         {
 105  
             // requests generated to the user who is routing the document should be deactivated
 106  0
             if ((getPrincipal().getPrincipalId().equals(actionRequest.getPrincipalId())) && (actionRequest.isActive()))
 107  
             {
 108  0
                 getActionRequestService().deactivateRequest(actionTaken, actionRequest);
 109  
             }
 110  
             // requests generated by a save action should be deactivated
 111  0
             else if (KEWConstants.SAVED_REQUEST_RESPONSIBILITY_ID.equals(actionRequest.getResponsibilityId()))
 112  
             {
 113  0
                 getActionRequestService().deactivateRequest(actionTaken, actionRequest);
 114  
             }
 115  
         }
 116  
 
 117  0
             notifyActionTaken(actionTaken);
 118  
 
 119  
             try {
 120  0
                 String oldStatus = getRouteHeader().getDocRouteStatus();
 121  0
                 getRouteHeader().markDocumentEnroute();
 122  
                 
 123  0
                 if (((Process)getRouteHeader().getDocumentType().getProcesses().get(0)).getInitialRouteNode() == null) {
 124  0
                     getRouteHeader().markDocumentProcessed();
 125  0
                     getRouteHeader().markDocumentFinalized();
 126  
                 }
 127  
 
 128  0
                 getRouteHeader().setRoutedByUserWorkflowId(getPrincipal().getPrincipalId());
 129  
 
 130  0
                 String newStatus = getRouteHeader().getDocRouteStatus();
 131  0
                 notifyStatusChange(newStatus, oldStatus);
 132  0
                 KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader());
 133  0
             } catch (WorkflowException ex) {
 134  0
                 LOG.warn(ex, ex);
 135  0
                     throw new InvalidActionTakenException(ex.getMessage());
 136  0
             }
 137  
 
 138  0
     }
 139  
 }