View Javadoc

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