Coverage Report - org.kuali.rice.kew.actions.SuperUserActionTakenEvent
 
Classes in this File Line Coverage Branch Coverage Complexity
SuperUserActionTakenEvent
0%
0/40
0%
0/8
1.889
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.actions;
 17  
 
 18  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 19  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 20  
 import org.kuali.rice.kew.api.exception.InvalidActionTakenException;
 21  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 22  
 import org.kuali.rice.kew.api.exception.WorkflowException;
 23  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
 24  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl;
 25  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 26  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 27  
 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
 28  
 
 29  
 
 30  
 import java.util.ArrayList;
 31  
 import java.util.List;
 32  
 
 33  
 
 34  
 /**
 35  
  * Super class for all super user action takens.
 36  
  *
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  
 public abstract class SuperUserActionTakenEvent extends ActionTakenEvent {
 40  
 
 41  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserActionTakenEvent.class);
 42  
 
 43  
     protected String superUserAction;
 44  
     //protected DocumentRouteStatusChange event;
 45  
     private ActionRequestValue actionRequest;
 46  0
     public static String AUTHORIZATION = "general.routing.superuser.notAuthorized";
 47  
 
 48  
     public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
 49  0
         super(actionTakenCode, routeHeader, principal);
 50  0
     }
 51  
 
 52  
     public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor) {
 53  0
         super(actionTakenCode, routeHeader, principal, annotation, runPostProcessor);
 54  0
     }
 55  
 
 56  
     /* (non-Javadoc)
 57  
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#validateActionRules()
 58  
      */
 59  
     @Override
 60  
     public String validateActionRules() {
 61  0
         DocumentType docType = getRouteHeader().getDocumentType();
 62  0
         if (!KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(getPrincipal().getPrincipalId(), docType)) {
 63  0
             return "User not authorized for super user action";
 64  
         }
 65  0
         return "";
 66  
     }
 67  
 
 68  
     @Override
 69  
     public String validateActionRules(List<ActionRequestValue> actionRequests) {
 70  0
             return validateActionRules();
 71  
     }
 72  
 
 73  
     public void recordAction() throws InvalidActionTakenException {
 74  
 
 75  0
         String errorMessage = validateActionRules();
 76  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
 77  0
             LOG.info("User not authorized");
 78  0
             List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>();
 79  0
             errors.add(new WorkflowServiceErrorImpl(errorMessage, AUTHORIZATION));
 80  0
             throw new WorkflowServiceErrorException(errorMessage, errors);
 81  
         }
 82  
 
 83  0
         processActionRequests();
 84  
 
 85  
         try {
 86  0
                 String oldStatus = getRouteHeader().getDocRouteStatus();
 87  
                 //if the document is initiated then set it enroute so we can transition to any other status
 88  0
                 if (getRouteHeader().isStateInitiated()) {
 89  0
                         getRouteHeader().markDocumentEnroute();
 90  0
                         notifyStatusChange(getRouteHeader().getDocRouteStatus(), oldStatus);
 91  
                 }
 92  0
             markDocument();
 93  0
             String newStatus = getRouteHeader().getDocRouteStatus();
 94  0
             notifyStatusChange(newStatus, oldStatus);
 95  0
         } catch (Exception ex) {
 96  0
             LOG.error("Caught Exception talking to post processor", ex);
 97  0
             throw new RuntimeException(ex.getMessage());
 98  0
         }
 99  
 
 100  0
     }
 101  
 
 102  
     protected abstract void markDocument() throws WorkflowException;
 103  
 
 104  
     protected void processActionRequests() throws InvalidActionTakenException {
 105  0
         LOG.debug("Processing pending action requests");
 106  
 
 107  0
         ActionTakenValue actionTaken = saveActionTaken();
 108  
 
 109  0
         List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId());
 110  
 
 111  0
         for (ActionRequestValue actionRequest : actionRequests)
 112  
         {
 113  0
             getActionRequestService().deactivateRequest(actionTaken, actionRequest);
 114  
         }
 115  
 
 116  0
         notifyActionTaken(actionTaken);
 117  0
     }
 118  
 
 119  
     public ActionRequestValue getActionRequest() {
 120  0
         return actionRequest;
 121  
     }
 122  
 
 123  
     public void setActionRequest(ActionRequestValue actionRequest) {
 124  0
         this.actionRequest = actionRequest;
 125  0
     }
 126  
 
 127  
 }