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