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