001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.actions;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.apache.log4j.MDC;
024:
025: import edu.iu.uis.eden.EdenConstants;
026: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
027: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
028: import edu.iu.uis.eden.exception.InvalidActionTakenException;
029: import edu.iu.uis.eden.exception.ResourceUnavailableException;
030: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
031: import edu.iu.uis.eden.user.Recipient;
032: import edu.iu.uis.eden.user.WorkflowUser;
033: import edu.iu.uis.eden.util.Utilities;
034:
035: /**
036: * The RevokeAdHocApprove revokes the specified AdHoc requests.
037: *
038: * @author ewestfal
039: */
040: public class RevokeAdHocAction extends ActionTakenEvent {
041:
042: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
043: .getLogger(RevokeAdHocAction.class);
044:
045: private AdHocRevoke revoke;
046:
047: public RevokeAdHocAction(DocumentRouteHeaderValue routeHeader,
048: WorkflowUser user) {
049: super (routeHeader, user);
050: setActionTakenCode(EdenConstants.ACTION_TAKEN_ADHOC_REVOKED_CD);
051: }
052:
053: public RevokeAdHocAction(DocumentRouteHeaderValue routeHeader,
054: WorkflowUser user, AdHocRevoke revoke, String annotation) {
055: super (routeHeader, user, annotation);
056: this .revoke = revoke;
057: setActionTakenCode(EdenConstants.ACTION_TAKEN_ADHOC_REVOKED_CD);
058: }
059:
060: /* (non-Javadoc)
061: * @see edu.iu.uis.eden.actions.ActionTakenEvent#isActionCompatibleRequest(java.util.List)
062: */
063: @Override
064: public String validateActionRules()
065: throws EdenUserNotFoundException {
066: String super Error = super .validateActionTakenRules();
067: if (!Utilities.isEmpty(super Error)) {
068: return super Error;
069: }
070: if (!getRouteHeader().isValidActionToTake(
071: getActionPerformedCode())) {
072: return "Revoke adhoc request is not valid on this document";
073: }
074: return "";
075: }
076:
077: /**
078: * Records the approve action.
079: * - Checks to make sure the document status allows the action.
080: * - Checks that the user has not taken a previous action.
081: * - Deactivates the pending requests for this user
082: * - Records the action
083: *
084: * @throws InvalidActionTakenException
085: * @throws EdenUserNotFoundException
086: */
087: public void recordAction() throws InvalidActionTakenException,
088: EdenUserNotFoundException {
089: MDC.put("docId", getRouteHeader().getRouteHeaderId());
090: checkLocking();
091: updateSearchableAttributesIfPossible();
092:
093: String errorMessage = validateActionRules();
094: if (!Utilities.isEmpty(errorMessage)) {
095: throw new InvalidActionTakenException(errorMessage);
096: }
097: // if (! routeHeader.isValidActionToTake(getActionTakenCode())) {
098: // LOG.warn("RevokeAdHocRequest action is not valid on this document.");
099: // throw new InvalidActionTakenException("Revoke adhoc request is not valid on this document.");
100: // }
101:
102: LOG.debug("Revoking adhoc request : " + annotation);
103:
104: List requestsToRevoke = new ArrayList();
105: List actionRequests = getActionRequestService()
106: .findPendingRootRequestsByDocId(getRouteHeaderId());
107: for (Iterator iterator = actionRequests.iterator(); iterator
108: .hasNext();) {
109: ActionRequestValue actionRequest = (ActionRequestValue) iterator
110: .next();
111: if (revoke.matchesActionRequest(actionRequest)) {
112: requestsToRevoke.add(actionRequest);
113: }
114: }
115: if (requestsToRevoke.isEmpty()
116: && revoke.getActionRequestId() != null) {
117: throw new InvalidActionTakenException(
118: "Failed to revoke action request with id "
119: + revoke.getActionRequestId()
120: + ". ID does not represent a valid ad hoc request!");
121: }
122:
123: Recipient delegator = findDelegatorForActionRequests(actionRequests);
124: LOG.debug("Record the revoke action");
125: saveActionTaken(delegator);
126:
127: LOG
128: .debug("Revoke all matching action requests, number of matching requests: "
129: + requestsToRevoke.size());
130: getActionRequestService().deactivateRequests(actionTaken,
131: requestsToRevoke);
132: notifyActionTaken(this.actionTaken);
133:
134: }
135:
136: }
|