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.List;
21
22 import org.apache.log4j.MDC;
23 import org.kuali.rice.kew.actionrequest.ActionRequestFactory;
24 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
25 import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
26 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
27 import org.kuali.rice.kew.doctype.bo.DocumentType;
28 import org.kuali.rice.kew.exception.InvalidActionTakenException;
29 import org.kuali.rice.kew.exception.WorkflowException;
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.util.KEWConstants;
35 import org.kuali.rice.kew.util.Utilities;
36 import org.kuali.rice.kim.bo.entity.KimPrincipal;
37
38
39
40
41
42
43
44 public class SuperUserActionRequestApproveEvent extends SuperUserActionTakenEvent {
45
46
47
48
49
50
51
52
53
54
55 private static final String UNDEFINED_ACTION_TAKEN_CODE = null;
56
57 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserActionRequestApproveEvent.class);
58 private Long actionRequestId;
59
60 public SuperUserActionRequestApproveEvent(DocumentRouteHeaderValue routeHeader, KimPrincipal principal) {
61 super(UNDEFINED_ACTION_TAKEN_CODE, routeHeader, principal);
62 this.superUserAction = KEWConstants.SUPER_USER_ACTION_REQUEST_APPROVE;
63 }
64
65 public SuperUserActionRequestApproveEvent(DocumentRouteHeaderValue routeHeader, KimPrincipal principal, Long actionRequestId, String annotation, boolean runPostProcessor) {
66 super(UNDEFINED_ACTION_TAKEN_CODE, routeHeader, principal, annotation, runPostProcessor);
67 this.superUserAction = KEWConstants.SUPER_USER_ACTION_REQUEST_APPROVE;
68 this.actionRequestId = actionRequestId;
69 }
70
71 public void setActionTaken() {
72 String actionRequestCode = "";
73
74 ActionRequestValue actionRequest = getActionRequestService().findByActionRequestId(actionRequestId);
75
76 setActionRequest(actionRequest);
77
78 actionRequestCode = actionRequest.getActionRequested();
79
80 if (KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(actionRequestCode)) {
81 this.setActionTakenCode(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED_CD);
82 } else if (KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(actionRequestCode)) {
83 this.setActionTakenCode(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED_CD);
84 } else if (KEWConstants.ACTION_REQUEST_FYI_REQ.equals(actionRequestCode)) {
85 this.setActionTakenCode(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD);
86 } else if (KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ.equals(actionRequestCode)) {
87 this.setActionTakenCode(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD);
88 } else {
89
90 LOG.error("Invalid SU delegation action request code: " + actionRequestCode);
91 throw new RuntimeException("Invalid SU delegation action request code: " + actionRequestCode);
92 }
93 }
94
95 protected void processActionRequests() throws InvalidActionTakenException {
96
97
98 DocumentType docType = getRouteHeader().getDocumentType();
99
100
101 String errorMessage = super.validateActionRules();
102 if (!Utilities.isEmpty(errorMessage)) {
103 LOG.info("User not authorized");
104 List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>();
105 errors.add(new WorkflowServiceErrorImpl(errorMessage, SuperUserActionTakenEvent.AUTHORIZATION));
106 throw new WorkflowServiceErrorException(errorMessage, errors);
107 }
108
109
110
111
112
113
114 this.setActionTaken();
115
116 MDC.put("docId", getRouteHeader().getRouteHeaderId());
117
118 LOG.debug("Super User Delegation Action on action request: " + annotation);
119 KimPrincipalRecipient superUserRecipient = null;
120 if (getActionRequest().getPrincipal() != null) {
121 superUserRecipient = new KimPrincipalRecipient(getActionRequest().getPrincipal());
122 }
123
124 ActionTakenValue actionTaken = this.saveActionTaken(superUserRecipient);
125
126 LOG.debug("Deactivate this action request");
127
128 ActionRequestValue request = getActionRequest();
129 getActionRequestService().deactivateRequest(actionTaken, request);
130 if (docType.getSuperUserApproveNotificationPolicy().getPolicyValue() && request.isApproveOrCompleteRequest()) {
131 KEWServiceLocator.getActionRequestService().activateRequest(
132 new ActionRequestFactory(this.getRouteHeader()).createNotificationRequest(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, request.getPrincipal(), this.getActionTakenCode(), getPrincipal(), null));
133 }
134 notifyActionTaken(actionTaken);
135
136 if (!(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD.equals(this.getActionTakenCode()) && KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD.equals(this.getActionTakenCode()))) {
137 if (getRouteHeader().isInException()) {
138 LOG.debug("Moving document back to Enroute from Exception");
139
140 String oldStatus = getRouteHeader().getDocRouteStatus();
141 this.getRouteHeader().markDocumentEnroute();
142
143 String newStatus = getRouteHeader().getDocRouteStatus();
144 this.notifyStatusChange(newStatus, oldStatus);
145 KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader());
146 }
147 else if (getRouteHeader().isStateSaved()) {
148 if (KEWConstants.SAVED_REQUEST_RESPONSIBILITY_ID.equals(request.getResponsibilityId())) {
149 LOG.debug("Moving document to Enroute from Saved because action request was request generated by save action");
150
151 String oldStatus = getRouteHeader().getDocRouteStatus();
152 this.getRouteHeader().markDocumentEnroute();
153 String newStatus = getRouteHeader().getDocRouteStatus();
154 this.notifyStatusChange(newStatus, oldStatus);
155 KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader());
156 }
157 }
158 }
159 }
160
161 public void recordAction() throws InvalidActionTakenException {
162 this.processActionRequests();
163 this.queueDocumentProcessing();
164 }
165
166 protected void markDocument() throws WorkflowException {
167 }
168 }