1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.actions;
18
19 import java.util.ArrayList;
20 import java.util.HashSet;
21 import java.util.List;
22
23 import org.apache.log4j.Logger;
24 import org.kuali.rice.kew.actionrequest.ActionRequestFactory;
25 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
26 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
27 import org.kuali.rice.kew.doctype.bo.DocumentType;
28 import org.kuali.rice.kew.engine.BlanketApproveEngine;
29 import org.kuali.rice.kew.engine.OrchestrationConfig;
30 import org.kuali.rice.kew.engine.RouteContext;
31 import org.kuali.rice.kew.engine.node.RequestsNode;
32 import org.kuali.rice.kew.exception.InvalidActionTakenException;
33 import org.kuali.rice.kew.exception.WorkflowException;
34 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
35 import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl;
36 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
37 import org.kuali.rice.kew.service.KEWServiceLocator;
38 import org.kuali.rice.kew.util.KEWConstants;
39 import org.kuali.rice.kew.util.Utilities;
40 import org.kuali.rice.kim.bo.entity.KimPrincipal;
41
42
43
44
45
46
47
48
49 public class SuperUserApproveEvent extends SuperUserActionTakenEvent {
50
51 private static final Logger LOG = Logger.getLogger(SuperUserApproveEvent.class);
52
53 public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader, KimPrincipal principal) {
54 super(KEWConstants.ACTION_TAKEN_SU_APPROVED_CD, routeHeader, principal);
55 this.superUserAction = KEWConstants.SUPER_USER_APPROVE;
56 }
57
58 public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader, KimPrincipal principal, String annotation, boolean runPostProcessor) {
59 super(KEWConstants.ACTION_TAKEN_SU_APPROVED_CD, routeHeader, principal, annotation, runPostProcessor);
60 this.superUserAction = KEWConstants.SUPER_USER_APPROVE;
61 }
62
63 public void recordAction() throws InvalidActionTakenException {
64
65
66 setRouteHeader(KEWServiceLocator.getRouteHeaderService().getRouteHeader(getRouteHeaderId(), true));
67
68 DocumentType docType = getRouteHeader().getDocumentType();
69
70 String errorMessage = super.validateActionRules();
71 if (!Utilities.isEmpty(errorMessage)) {
72 LOG.info("User not authorized");
73 List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>();
74 errors.add(new WorkflowServiceErrorImpl(errorMessage, AUTHORIZATION));
75 throw new WorkflowServiceErrorException(errorMessage, errors);
76 }
77
78 ActionTakenValue actionTaken = saveActionTaken();
79
80 notifyActionTaken(actionTaken);
81
82 if (getRouteHeader().isInException() || getRouteHeader().isStateInitiated()) {
83 LOG.debug("Moving document back to Enroute");
84 String oldStatus = getRouteHeader().getDocRouteStatus();
85 getRouteHeader().markDocumentEnroute();
86 String newStatus = getRouteHeader().getDocRouteStatus();
87 notifyStatusChange(newStatus, oldStatus);
88 KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader());
89 }
90
91 OrchestrationConfig config = new OrchestrationConfig();
92 config.setCause(actionTaken);
93 config.setDestinationNodeNames(new HashSet());
94 config.setSendNotifications(docType.getSuperUserApproveNotificationPolicy().getPolicyValue());
95 RequestsNode.setSupressPolicyErrors(RouteContext.getCurrentRouteContext());
96 try {
97 completeAnyOutstandingCompleteApproveRequests(actionTaken, docType.getSuperUserApproveNotificationPolicy().getPolicyValue());
98 new BlanketApproveEngine(config, isRunPostProcessorLogic()).process(getRouteHeader().getRouteHeaderId(), null);
99 } catch (Exception e) {
100 LOG.error("Failed to orchestrate the document to SuperUserApproved.", e);
101 throw new InvalidActionTakenException("Failed to orchestrate the document to SuperUserApproved.", e);
102 }
103
104 }
105
106 @SuppressWarnings("unchecked")
107 protected void completeAnyOutstandingCompleteApproveRequests(ActionTakenValue actionTaken, boolean sendNotifications) throws Exception {
108 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingByActionRequestedAndDocId(KEWConstants.ACTION_REQUEST_APPROVE_REQ, getRouteHeaderId());
109 actionRequests.addAll(KEWServiceLocator.getActionRequestService().findPendingByActionRequestedAndDocId(KEWConstants.ACTION_REQUEST_COMPLETE_REQ, getRouteHeaderId()));
110 for (ActionRequestValue actionRequest : actionRequests) {
111 KEWServiceLocator.getActionRequestService().deactivateRequest(actionTaken, actionRequest);
112 }
113 if (sendNotifications) {
114 new ActionRequestFactory(this.getRouteHeader()).generateNotifications(actionRequests, getPrincipal(), this.findDelegatorForActionRequests(actionRequests), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_TAKEN_SU_APPROVED_CD);
115 }
116 }
117
118 protected void markDocument() throws WorkflowException {
119
120 }
121 }