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