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.Iterator;
020: import java.util.List;
021:
022: import org.apache.log4j.MDC;
023:
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
026: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
027: import edu.iu.uis.eden.exception.InvalidActionTakenException;
028: import edu.iu.uis.eden.exception.ResourceUnavailableException;
029: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
030: import edu.iu.uis.eden.user.WorkflowUser;
031: import edu.iu.uis.eden.util.Utilities;
032:
033: /**
034: *
035: * ClearFYIAction deactivates the user requests.
036: *
037: * The routeheader is first checked to make sure the action is valid for the document.
038: * Next the user is checked to make sure he/she has not taken a previous action on this
039: * document at the actions responsibility or below. Any requests related to this user
040: * are deactivated.
041: *
042: * @author rkirkend
043: * @author ewestfal
044: * @author seiffert
045: */
046: public class ClearFYIAction extends ActionTakenEvent {
047: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
048: .getLogger(ClearFYIAction.class);
049:
050: /**
051: * @param rh
052: * RouteHeader for the document upon which the action is taken.
053: * @param user
054: * User taking the action.
055: */
056: public ClearFYIAction(DocumentRouteHeaderValue rh, WorkflowUser user) {
057: super (rh, user);
058: setActionTakenCode(EdenConstants.ACTION_TAKEN_FYI_CD);
059: }
060:
061: /**
062: * @param rh
063: * RouteHeader for the document upon which the action is taken.
064: * @param user
065: * User taking the action.
066: * @param annotation
067: * User comment on the action taken
068: */
069: public ClearFYIAction(DocumentRouteHeaderValue rh,
070: WorkflowUser user, String annotation) {
071: super (rh, user, annotation);
072: setActionTakenCode(EdenConstants.ACTION_TAKEN_FYI_CD);
073: }
074:
075: /* (non-Javadoc)
076: * @see edu.iu.uis.eden.actions.ActionTakenEvent#requireInitiatorCheck()
077: */
078: @Override
079: protected boolean requireInitiatorCheck() {
080: return false;
081: }
082:
083: /**
084: * Method to check if the Action is currently valid on the given document
085: * @return returns an error message to give system better identifier for problem
086: */
087: public String validateActionRules()
088: throws EdenUserNotFoundException {
089: return validateActionRules(getActionRequestService()
090: .findAllValidRequests(getUser(),
091: routeHeader.getRouteHeaderId(),
092: EdenConstants.ACTION_REQUEST_FYI_REQ));
093: }
094:
095: private String validateActionRules(List actionRequests)
096: throws EdenUserNotFoundException {
097: String super Error = super .validateActionTakenRules();
098: if (!Utilities.isEmpty(super Error)) {
099: return super Error;
100: }
101: if (!getRouteHeader().isValidActionToTake(
102: getActionPerformedCode())) {
103: return "Document is not in a state to have FYI processed";
104: }
105: if (!isActionCompatibleRequest(actionRequests)) {
106: return "No request for the user is compatible "
107: + "with the ClearFYI action";
108: }
109: return "";
110: }
111:
112: public boolean isActionCompatibleRequest(List requests)
113: throws EdenUserNotFoundException {
114:
115: // can always cancel saved or initiated document
116: if (routeHeader.isStateInitiated()
117: || routeHeader.isStateSaved()) {
118: return true;
119: }
120:
121: boolean actionCompatible = false;
122: Iterator ars = requests.iterator();
123: ActionRequestValue actionRequest = null;
124:
125: while (ars.hasNext()) {
126: actionRequest = (ActionRequestValue) ars.next();
127:
128: //FYI request matches all but deny and cancel
129: if (EdenConstants.ACTION_REQUEST_FYI_REQ
130: .equals(actionRequest.getActionRequested())) {
131: actionCompatible = true;
132: break;
133: }
134: }
135:
136: return actionCompatible;
137: }
138:
139: /**
140: * Processes the clear FYI action. - Checks to make sure the document status allows the action. - Checks that the user has not taken a previous action. - Deactivates the pending requests for this user
141: *
142: * @throws InvalidActionTakenException
143: * @throws ResourceUnavailableException
144: */
145: public void recordAction() throws InvalidActionTakenException,
146: EdenUserNotFoundException {
147: MDC.put("docId", getRouteHeader().getRouteHeaderId());
148: checkLocking();
149: updateSearchableAttributesIfPossible();
150:
151: LOG.debug("Clear FYI for document : " + annotation);
152: LOG.debug("Checking to see if the action is legal");
153:
154: List actionRequests = getActionRequestService()
155: .findAllValidRequests(getUser(), getRouteHeaderId(),
156: EdenConstants.ACTION_REQUEST_FYI_REQ);
157: String errorMessage = validateActionRules(actionRequests);
158: if (!Utilities.isEmpty(errorMessage)) {
159: throw new InvalidActionTakenException(errorMessage);
160: }
161:
162: // if (!getRouteHeader().isValidActionToTake(getActionTakenCode())) {
163: // LOG.warn("Document not in state to have FYI processed.");
164: // throw new InvalidActionTakenException("Document is not in a state to have FYI processed");
165: // }
166: //
167: // List actionRequests = getActionRequestService().findAllValidRequests(getUser(), getRouteHeaderId(), EdenConstants.ACTION_REQUEST_FYI_REQ);
168: // if (!isActionCompatibleRequest(actionRequests, getActionTakenCode())) {
169: // throw new InvalidActionTakenException("No request for the user is compatible with the ClearFYI Action");
170: // }
171:
172: saveActionTaken(findDelegatorForActionRequests(actionRequests));
173:
174: LOG.debug("Deactivate all pending action requests");
175: getActionRequestService().deactivateRequests(actionTaken,
176: actionRequests);
177: notifyActionTaken(this.actionTaken);
178: }
179: }
|