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