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