Coverage Report - org.kuali.rice.kew.actions.SuperUserNodeApproveEvent
 
Classes in this File Line Coverage Branch Coverage Complexity
SuperUserNodeApproveEvent
0%
0/39
0%
0/8
3.25
 
 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.actiontaken.ActionTakenValue;
 20  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 21  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 22  
 import org.kuali.rice.kew.engine.BlanketApproveEngine;
 23  
 import org.kuali.rice.kew.engine.OrchestrationConfig;
 24  
 import org.kuali.rice.kew.exception.*;
 25  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 26  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 27  
 import org.kuali.rice.kew.util.KEWConstants;
 28  
 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
 29  
 
 30  
 
 31  
 import java.util.ArrayList;
 32  
 import java.util.Collections;
 33  
 import java.util.List;
 34  
 
 35  
 
 36  
 /**
 37  
  * Does a node level super user approve action.  All approve/complete requests outstanding for
 38  
  * this node are satisfied by this action.
 39  
  *
 40  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 41  
  *
 42  
  */
 43  
 public class SuperUserNodeApproveEvent extends SuperUserActionTakenEvent {
 44  
 
 45  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserNodeApproveEvent.class);
 46  
     private String nodeName;
 47  
 
 48  
     public SuperUserNodeApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
 49  0
         super(KEWConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, routeHeader, principal);
 50  0
         this.superUserAction = KEWConstants.SUPER_USER_ROUTE_LEVEL_APPROVE;
 51  0
     }
 52  
 
 53  
     public SuperUserNodeApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor, String nodeName) {
 54  0
         super(KEWConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, routeHeader, principal, annotation, runPostProcessor);
 55  0
         this.superUserAction = KEWConstants.SUPER_USER_ROUTE_LEVEL_APPROVE;
 56  0
         this.nodeName = nodeName;
 57  0
     }
 58  
 
 59  
     public void recordAction() throws InvalidActionTakenException {
 60  
 
 61  0
         if (org.apache.commons.lang.StringUtils.isEmpty(nodeName)) {
 62  0
             throw new InvalidActionTakenException("No approval node name set");
 63  
         }
 64  
 
 65  0
         DocumentType docType = getRouteHeader().getDocumentType();
 66  
 
 67  0
         String errorMessage = super.validateActionRules();
 68  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
 69  0
             LOG.info("User not authorized");
 70  0
             List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>();
 71  0
             errors.add(new WorkflowServiceErrorImpl(errorMessage, SuperUserActionTakenEvent.AUTHORIZATION));
 72  0
             throw new WorkflowServiceErrorException(errorMessage, errors);
 73  
         }
 74  
 
 75  0
         ActionTakenValue actionTaken = saveActionTaken();
 76  
 
 77  0
         notifyActionTaken(actionTaken);
 78  
 
 79  0
             if (getRouteHeader().isInException()) {
 80  0
                 LOG.debug("Moving document back to Enroute from Exception");
 81  0
                 String oldStatus = getRouteHeader().getDocRouteStatus();
 82  0
                 getRouteHeader().markDocumentEnroute();
 83  0
                 String newStatus = getRouteHeader().getDocRouteStatus();
 84  0
                 notifyStatusChange(newStatus, oldStatus);
 85  0
                 KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader());
 86  
             }
 87  
 
 88  0
             OrchestrationConfig config = new OrchestrationConfig();
 89  0
             config.setCause(actionTaken);
 90  0
             config.setDestinationNodeNames(Collections.singleton(nodeName));
 91  0
             config.setSendNotifications(docType.getSuperUserApproveNotificationPolicy().getPolicyValue());
 92  
             try {
 93  0
                     BlanketApproveEngine blanketApproveEngine = KEWServiceLocator.getBlanketApproveEngineFactory().newEngine(config, isRunPostProcessorLogic());
 94  0
                             blanketApproveEngine.process(getRouteHeader().getDocumentId(), null);
 95  0
             } catch (Exception e) {
 96  0
                     if (e instanceof RuntimeException) {
 97  0
                         throw (RuntimeException)e;
 98  
                 } else {
 99  0
                         throw new WorkflowRuntimeException(e.toString(), e);
 100  
                 }
 101  0
             }
 102  
 
 103  
         //queueDocument();
 104  0
     }
 105  
 
 106  
     protected void markDocument() throws WorkflowException {
 107  
         // do nothing since we are overriding the entire behavior
 108  0
     }
 109  
 
 110  
 
 111  
 
 112  
 
 113  
 
 114  
 }