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