Coverage Report - org.kuali.rice.kew.actions.SuperUserApproveEvent
 
Classes in this File Line Coverage Branch Coverage Complexity
SuperUserApproveEvent
0%
0/42
0%
0/10
2.6
 
 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.apache.log4j.Logger;
 19  
 import org.kuali.rice.kew.actionrequest.ActionRequestFactory;
 20  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 21  
 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
 22  
 import org.kuali.rice.kew.api.exception.InvalidActionTakenException;
 23  
 import org.kuali.rice.kew.api.exception.WorkflowException;
 24  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 25  
 import org.kuali.rice.kew.engine.BlanketApproveEngine;
 26  
 import org.kuali.rice.kew.engine.OrchestrationConfig;
 27  
 import org.kuali.rice.kew.engine.RouteContext;
 28  
 import org.kuali.rice.kew.engine.OrchestrationConfig.EngineCapability;
 29  
 import org.kuali.rice.kew.engine.node.RequestsNode;
 30  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
 31  
 import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl;
 32  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 33  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 34  
 import org.kuali.rice.kew.api.KewApiConstants;
 35  
 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
 36  
 
 37  
 
 38  
 import java.util.ArrayList;
 39  
 import java.util.HashSet;
 40  
 import java.util.List;
 41  
 
 42  
 
 43  
 /**
 44  
  * Does a super user approve action.
 45  
  *
 46  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 47  
  *
 48  
  */
 49  
 public class SuperUserApproveEvent extends SuperUserActionTakenEvent {
 50  
 
 51  0
         private static final Logger LOG = Logger.getLogger(SuperUserApproveEvent.class);
 52  
 
 53  
     public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
 54  0
         super(KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD, routeHeader, principal);
 55  0
         this.superUserAction = KewApiConstants.SUPER_USER_APPROVE;
 56  0
     }
 57  
 
 58  
     public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor) {
 59  0
         super(KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD, routeHeader, principal, annotation, runPostProcessor);
 60  0
         this.superUserAction = KewApiConstants.SUPER_USER_APPROVE;
 61  0
     }
 62  
 
 63  
         public void recordAction() throws InvalidActionTakenException {
 64  
                 // TODO: this is used because calling this code from SuperUserAction without
 65  
         // it causes an optimistic lock
 66  0
                 setRouteHeader(KEWServiceLocator.getRouteHeaderService().getRouteHeader(getDocumentId(), true));
 67  
 
 68  0
                 DocumentType docType = getRouteHeader().getDocumentType();
 69  
 
 70  0
         String errorMessage = super.validateActionRules();
 71  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
 72  0
             LOG.info("User not authorized");
 73  0
             List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>();
 74  0
             errors.add(new WorkflowServiceErrorImpl(errorMessage, AUTHORIZATION));
 75  0
             throw new WorkflowServiceErrorException(errorMessage, errors);
 76  
         }
 77  
 
 78  0
         ActionTakenValue actionTaken = saveActionTaken();
 79  
 
 80  0
                 notifyActionTaken(actionTaken);
 81  
 
 82  0
                 if (getRouteHeader().isInException() || getRouteHeader().isStateInitiated()) {
 83  0
                         LOG.debug("Moving document back to Enroute");
 84  0
                         String oldStatus = getRouteHeader().getDocRouteStatus();
 85  0
                         getRouteHeader().markDocumentEnroute();
 86  0
                         String newStatus = getRouteHeader().getDocRouteStatus();
 87  0
                         notifyStatusChange(newStatus, oldStatus);
 88  0
                         KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader());
 89  
                 }
 90  
 
 91  0
                 OrchestrationConfig config = new OrchestrationConfig(EngineCapability.BLANKET_APPROVAL, new HashSet<String>(), actionTaken, docType.getSuperUserApproveNotificationPolicy().getPolicyValue(), isRunPostProcessorLogic());
 92  0
                 RequestsNode.setSupressPolicyErrors(RouteContext.getCurrentRouteContext());
 93  
                 try {
 94  0
                         completeAnyOutstandingCompleteApproveRequests(actionTaken, docType.getSuperUserApproveNotificationPolicy().getPolicyValue());
 95  0
                         BlanketApproveEngine blanketApproveEngine = KEWServiceLocator.getWorkflowEngineFactory().newEngine(config);
 96  0
                         blanketApproveEngine.process(getRouteHeader().getDocumentId(), null);
 97  0
                 } catch (Exception e) {
 98  0
                         LOG.error("Failed to orchestrate the document to SuperUserApproved.", e);
 99  0
                         throw new InvalidActionTakenException("Failed to orchestrate the document to SuperUserApproved.", e);
 100  0
                 }
 101  
 
 102  0
         }
 103  
 
 104  
         @SuppressWarnings("unchecked")
 105  
         protected void completeAnyOutstandingCompleteApproveRequests(ActionTakenValue actionTaken, boolean sendNotifications) throws Exception {
 106  0
                 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, getDocumentId());
 107  0
                 actionRequests.addAll(KEWServiceLocator.getActionRequestService().findPendingByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_COMPLETE_REQ, getDocumentId()));
 108  0
                 for (ActionRequestValue actionRequest : actionRequests) {
 109  0
                         KEWServiceLocator.getActionRequestService().deactivateRequest(actionTaken, actionRequest);
 110  
                 }
 111  0
                 if (sendNotifications) {
 112  0
                         new ActionRequestFactory(this.getRouteHeader()).generateNotifications(actionRequests, getPrincipal(), this.findDelegatorForActionRequests(actionRequests), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD);
 113  
                 }
 114  0
         }
 115  
 
 116  
         protected void markDocument() throws WorkflowException {
 117  
                 // do nothing since we are overriding the entire behavior
 118  0
         }
 119  
 }