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.ActionRequestValue; |
21 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
22 | |
import org.kuali.rice.kew.doctype.DocumentTypePolicy; |
23 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
24 | |
import org.kuali.rice.kew.exception.ResourceUnavailableException; |
25 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
26 | |
import org.kuali.rice.kew.util.KEWConstants; |
27 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
28 | |
|
29 | |
|
30 | |
import java.util.Iterator; |
31 | |
import java.util.List; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public class ClearFYIAction extends ActionTakenEvent { |
46 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ClearFYIAction.class); |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public ClearFYIAction(DocumentRouteHeaderValue rh, PrincipalContract principal) { |
55 | 0 | super(KEWConstants.ACTION_TAKEN_FYI_CD, rh, principal); |
56 | 0 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public ClearFYIAction(DocumentRouteHeaderValue rh, PrincipalContract principal, String annotation) { |
67 | 0 | super(KEWConstants.ACTION_TAKEN_FYI_CD, rh, principal, annotation); |
68 | 0 | } |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public String validateActionRules() { |
75 | 0 | return validateActionRules(getActionRequestService().findAllPendingRequests(routeHeader.getDocumentId())); |
76 | |
} |
77 | |
|
78 | |
public String validateActionRules(List<ActionRequestValue> actionRequests) { |
79 | 0 | if (!getRouteHeader().isValidActionToTake(getActionPerformedCode())) { |
80 | 0 | return "Document is not in a state to have FYI processed"; |
81 | |
} |
82 | 0 | List<ActionRequestValue> filteredActionRequests = filterActionRequestsByCode(actionRequests, KEWConstants.ACTION_REQUEST_FYI_REQ); |
83 | 0 | if (!isActionCompatibleRequest(filteredActionRequests)) { |
84 | 0 | return "No request for the user is compatible " + "with the ClearFYI action"; |
85 | |
} |
86 | 0 | return ""; |
87 | |
} |
88 | |
|
89 | |
public boolean isActionCompatibleRequest(List requests) { |
90 | |
|
91 | |
|
92 | 0 | if (routeHeader.isStateInitiated() || routeHeader.isStateSaved()) { |
93 | 0 | return true; |
94 | |
} |
95 | |
|
96 | 0 | boolean actionCompatible = false; |
97 | 0 | Iterator ars = requests.iterator(); |
98 | 0 | ActionRequestValue actionRequest = null; |
99 | |
|
100 | 0 | while (ars.hasNext()) { |
101 | 0 | actionRequest = (ActionRequestValue) ars.next(); |
102 | |
|
103 | |
|
104 | 0 | if (KEWConstants.ACTION_REQUEST_FYI_REQ.equals(actionRequest.getActionRequested())) { |
105 | 0 | actionCompatible = true; |
106 | 0 | break; |
107 | |
} |
108 | |
} |
109 | |
|
110 | 0 | return actionCompatible; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public void recordAction() throws InvalidActionTakenException { |
120 | 0 | MDC.put("docId", getRouteHeader().getDocumentId()); |
121 | 0 | updateSearchableAttributesIfPossible(); |
122 | |
|
123 | 0 | LOG.debug("Clear FYI for document : " + annotation); |
124 | 0 | LOG.debug("Checking to see if the action is legal"); |
125 | |
|
126 | 0 | List actionRequests = getActionRequestService().findAllValidRequests(getPrincipal().getPrincipalId(), getDocumentId(), KEWConstants.ACTION_REQUEST_FYI_REQ); |
127 | 0 | if (actionRequests == null || actionRequests.isEmpty()) { |
128 | 0 | DocumentTypePolicy allowUnrequested = getRouteHeader().getDocumentType().getAllowUnrequestedActionPolicy(); |
129 | 0 | if (allowUnrequested != null) { |
130 | 0 | if (!allowUnrequested.getPolicyValue()) { |
131 | 0 | throw new InvalidActionTakenException("No request for the user is compatible " + "with the ClearFYI action. " + "Doctype policy ALLOW_UNREQUESTED_ACTION is set to false and someone else likely just took action on the document."); |
132 | |
} |
133 | |
} |
134 | |
} |
135 | |
|
136 | 0 | String errorMessage = validateActionRules(actionRequests); |
137 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
138 | 0 | throw new InvalidActionTakenException(errorMessage); |
139 | |
} |
140 | |
|
141 | 0 | ActionTakenValue actionTaken = saveActionTaken(findDelegatorForActionRequests(actionRequests)); |
142 | |
|
143 | 0 | LOG.debug("Deactivate all pending action requests"); |
144 | 0 | getActionRequestService().deactivateRequests(actionTaken, actionRequests); |
145 | 0 | notifyActionTaken(actionTaken); |
146 | 0 | } |
147 | |
} |