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-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 org.kuali.rice.kew.actionrequest.ActionRequestValue;
 20  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 21  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 22  
 import org.kuali.rice.kew.exception.InvalidActionTakenException;
 23  
 import org.kuali.rice.kew.exception.WorkflowException;
 24  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
 25  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl;
 26  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 27  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 28  
 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
 29  
 
 30  
 
 31  
 import java.util.ArrayList;
 32  
 import java.util.List;
 33  
 
 34  
 
 35  
 /**
 36  
  * Super class for all super user action takens.
 37  
  *
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  */
 40  
 public abstract class SuperUserActionTakenEvent extends ActionTakenEvent {
 41  
 
 42  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserActionTakenEvent.class);
 43  
 
 44  
     protected String superUserAction;
 45  
     //protected DocumentRouteStatusChange event;
 46  
     private ActionRequestValue actionRequest;
 47  0
     public static String AUTHORIZATION = "general.routing.superuser.notAuthorized";
 48  
 
 49  
     public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
 50  0
         super(actionTakenCode, routeHeader, principal);
 51  0
     }
 52  
 
 53  
     public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor) {
 54  0
         super(actionTakenCode, routeHeader, principal, annotation, runPostProcessor);
 55  0
     }
 56  
 
 57  
     /* (non-Javadoc)
 58  
      * @see org.kuali.rice.kew.actions.ActionTakenEvent#validateActionRules()
 59  
      */
 60  
     @Override
 61  
     public String validateActionRules() {
 62  0
         DocumentType docType = getRouteHeader().getDocumentType();
 63  0
         if (!KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(getPrincipal().getPrincipalId(), docType)) {
 64  0
             return "User not authorized for super user action";
 65  
         }
 66  0
         return "";
 67  
     }
 68  
 
 69  
     @Override
 70  
     public String validateActionRules(List<ActionRequestValue> actionRequests) {
 71  0
             return validateActionRules();
 72  
     }
 73  
 
 74  
     public void recordAction() throws InvalidActionTakenException {
 75  
 
 76  0
         String errorMessage = validateActionRules();
 77  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
 78  0
             LOG.info("User not authorized");
 79  0
             List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>();
 80  0
             errors.add(new WorkflowServiceErrorImpl(errorMessage, AUTHORIZATION));
 81  0
             throw new WorkflowServiceErrorException(errorMessage, errors);
 82  
         }
 83  
 
 84  0
         processActionRequests();
 85  
 
 86  
         try {
 87  0
                 String oldStatus = getRouteHeader().getDocRouteStatus();
 88  
                 //if the document is initiated then set it enroute so we can transition to any other status
 89  0
                 if (getRouteHeader().isStateInitiated()) {
 90  0
                         getRouteHeader().markDocumentEnroute();
 91  0
                         notifyStatusChange(getRouteHeader().getDocRouteStatus(), oldStatus);
 92  
                 }
 93  0
             markDocument();
 94  0
             String newStatus = getRouteHeader().getDocRouteStatus();
 95  0
             notifyStatusChange(newStatus, oldStatus);
 96  0
         } catch (Exception ex) {
 97  0
             LOG.error("Caught Exception talking to post processor", ex);
 98  0
             throw new RuntimeException(ex.getMessage());
 99  0
         }
 100  
 
 101  0
     }
 102  
 
 103  
     protected abstract void markDocument() throws WorkflowException;
 104  
 
 105  
     protected void processActionRequests() throws InvalidActionTakenException {
 106  0
         LOG.debug("Processing pending action requests");
 107  
 
 108  0
         ActionTakenValue actionTaken = saveActionTaken();
 109  
 
 110  0
         List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId());
 111  
 
 112  0
         for (ActionRequestValue actionRequest : actionRequests)
 113  
         {
 114  0
             getActionRequestService().deactivateRequest(actionTaken, actionRequest);
 115  
         }
 116  
 
 117  0
         notifyActionTaken(actionTaken);
 118  0
     }
 119  
 
 120  
     public ActionRequestValue getActionRequest() {
 121  0
         return actionRequest;
 122  
     }
 123  
 
 124  
     public void setActionRequest(ActionRequestValue actionRequest) {
 125  0
         this.actionRequest = actionRequest;
 126  0
     }
 127  
 
 128  
 }