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 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 super(KEWConstants.ACTION_TAKEN_FYI_CD, rh, principal);
56 }
57
58
59
60
61
62
63
64
65
66 public ClearFYIAction(DocumentRouteHeaderValue rh, PrincipalContract principal, String annotation) {
67 super(KEWConstants.ACTION_TAKEN_FYI_CD, rh, principal, annotation);
68 }
69
70
71
72
73
74 public String validateActionRules() {
75 return validateActionRules(getActionRequestService().findAllPendingRequests(routeHeader.getDocumentId()));
76 }
77
78 public String validateActionRules(List<ActionRequestValue> actionRequests) {
79 if (!getRouteHeader().isValidActionToTake(getActionPerformedCode())) {
80 return "Document is not in a state to have FYI processed";
81 }
82 List<ActionRequestValue> filteredActionRequests = filterActionRequestsByCode(actionRequests, KEWConstants.ACTION_REQUEST_FYI_REQ);
83 if (!isActionCompatibleRequest(filteredActionRequests)) {
84 return "No request for the user is compatible " + "with the ClearFYI action";
85 }
86 return "";
87 }
88
89 public boolean isActionCompatibleRequest(List requests) {
90
91
92 if (routeHeader.isStateInitiated() || routeHeader.isStateSaved()) {
93 return true;
94 }
95
96 boolean actionCompatible = false;
97 Iterator ars = requests.iterator();
98 ActionRequestValue actionRequest = null;
99
100 while (ars.hasNext()) {
101 actionRequest = (ActionRequestValue) ars.next();
102
103
104 if (KEWConstants.ACTION_REQUEST_FYI_REQ.equals(actionRequest.getActionRequested())) {
105 actionCompatible = true;
106 break;
107 }
108 }
109
110 return actionCompatible;
111 }
112
113
114
115
116
117
118
119 public void recordAction() throws InvalidActionTakenException {
120 MDC.put("docId", getRouteHeader().getDocumentId());
121 updateSearchableAttributesIfPossible();
122
123 LOG.debug("Clear FYI for document : " + annotation);
124 LOG.debug("Checking to see if the action is legal");
125
126 List actionRequests = getActionRequestService().findAllValidRequests(getPrincipal().getPrincipalId(), getDocumentId(), KEWConstants.ACTION_REQUEST_FYI_REQ);
127 if (actionRequests == null || actionRequests.isEmpty()) {
128 DocumentTypePolicy allowUnrequested = getRouteHeader().getDocumentType().getAllowUnrequestedActionPolicy();
129 if (allowUnrequested != null) {
130 if (!allowUnrequested.getPolicyValue()) {
131 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 String errorMessage = validateActionRules(actionRequests);
137 if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) {
138 throw new InvalidActionTakenException(errorMessage);
139 }
140
141 ActionTakenValue actionTaken = saveActionTaken(findDelegatorForActionRequests(actionRequests));
142
143 LOG.debug("Deactivate all pending action requests");
144 getActionRequestService().deactivateRequests(actionTaken, actionRequests);
145 notifyActionTaken(actionTaken);
146 }
147 }