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.actionrequest.Recipient; |
22 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
23 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
24 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
25 | |
import org.kuali.rice.kew.util.KEWConstants; |
26 | |
import org.kuali.rice.kim.api.entity.principal.PrincipalContract; |
27 | |
|
28 | |
|
29 | |
import java.util.ArrayList; |
30 | |
import java.util.List; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class RevokeAdHocAction extends ActionTakenEvent { |
39 | |
|
40 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RevokeAdHocAction.class); |
41 | |
|
42 | |
private AdHocRevoke revoke; |
43 | |
|
44 | |
public RevokeAdHocAction(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) { |
45 | 0 | super(KEWConstants.ACTION_TAKEN_ADHOC_REVOKED_CD, routeHeader, principal); |
46 | 0 | } |
47 | |
|
48 | |
public RevokeAdHocAction(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, AdHocRevoke revoke, String annotation) { |
49 | 0 | super(KEWConstants.ACTION_TAKEN_ADHOC_REVOKED_CD, routeHeader, principal, annotation); |
50 | 0 | this.revoke = revoke; |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@Override |
57 | |
public String validateActionRules() { |
58 | 0 | if (!getRouteHeader().isValidActionToTake(getActionPerformedCode())) { |
59 | 0 | return "Revoke adhoc request is not valid on this document"; |
60 | |
} |
61 | 0 | return ""; |
62 | |
} |
63 | |
|
64 | |
@Override |
65 | |
public String validateActionRules(List<ActionRequestValue> actionRequests) { |
66 | 0 | return validateActionRules(); |
67 | |
} |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public void recordAction() throws InvalidActionTakenException { |
79 | 0 | MDC.put("docId", getRouteHeader().getDocumentId()); |
80 | 0 | updateSearchableAttributesIfPossible(); |
81 | |
|
82 | 0 | String errorMessage = validateActionRules(); |
83 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
84 | 0 | throw new InvalidActionTakenException(errorMessage); |
85 | |
} |
86 | |
|
87 | 0 | LOG.debug("Revoking adhoc request : " + annotation); |
88 | |
|
89 | 0 | List<ActionRequestValue> requestsToRevoke = new ArrayList<ActionRequestValue>(); |
90 | 0 | List<ActionRequestValue> actionRequests = getActionRequestService().findPendingRootRequestsByDocId(getDocumentId()); |
91 | 0 | for (ActionRequestValue actionRequest : actionRequests) |
92 | |
{ |
93 | 0 | if (revoke.matchesActionRequest(actionRequest)) |
94 | |
{ |
95 | 0 | requestsToRevoke.add(actionRequest); |
96 | |
} |
97 | |
} |
98 | 0 | if (requestsToRevoke.isEmpty() && revoke.getActionRequestId() != null) { |
99 | 0 | throw new InvalidActionTakenException("Failed to revoke action request with id " + revoke.getActionRequestId() + |
100 | |
". ID does not represent a valid ad hoc request!"); |
101 | |
} |
102 | |
|
103 | 0 | Recipient delegator = findDelegatorForActionRequests(actionRequests); |
104 | 0 | LOG.debug("Record the revoke action"); |
105 | 0 | ActionTakenValue actionTaken = saveActionTaken(delegator); |
106 | |
|
107 | 0 | LOG.debug("Revoke all matching action requests, number of matching requests: " + requestsToRevoke.size()); |
108 | 0 | getActionRequestService().deactivateRequests(actionTaken, requestsToRevoke); |
109 | 0 | notifyActionTaken(actionTaken); |
110 | |
|
111 | 0 | } |
112 | |
|
113 | |
} |