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.WorkflowException;
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: * Action that puts the document in routing.
035: *
036: * @author rkirkend
037: * @author ewestfal
038: * @author seiffert
039: *
040: */
041: public class RouteDocumentAction extends ActionTakenEvent {
042: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
043: .getLogger(RouteDocumentAction.class);
044:
045: public RouteDocumentAction(DocumentRouteHeaderValue rh,
046: WorkflowUser user) {
047: super (rh, user);
048: setActionTakenCode(EdenConstants.ACTION_TAKEN_COMPLETED_CD);
049: }
050:
051: public RouteDocumentAction(DocumentRouteHeaderValue rh,
052: WorkflowUser user, String annotation) {
053: super (rh, user, annotation);
054: setActionTakenCode(EdenConstants.ACTION_TAKEN_COMPLETED_CD);
055: }
056:
057: /* (non-Javadoc)
058: * @see edu.iu.uis.eden.actions.ActionTakenEvent#getActionPerformedCode()
059: */
060: @Override
061: public String getActionPerformedCode() {
062: return EdenConstants.ACTION_TAKEN_ROUTED_CD;
063: }
064:
065: /* (non-Javadoc)
066: * @see edu.iu.uis.eden.actions.ActionTakenEvent#requireInitiatorCheck()
067: */
068: @Override
069: protected boolean requireInitiatorCheck() {
070: return routeHeader.getDocumentType()
071: .getInitiatorMustRoutePolicy().getPolicyValue()
072: .booleanValue();
073: }
074:
075: /* (non-Javadoc)
076: * @see edu.iu.uis.eden.actions.ActionTakenEvent#isActionCompatibleRequest(java.util.List)
077: */
078: @Override
079: public String validateActionRules()
080: throws EdenUserNotFoundException {
081: String super Error = super .validateActionTakenRules();
082: if (!Utilities.isEmpty(super Error)) {
083: return super Error;
084: }
085: if (!getRouteHeader().isValidActionToTake(
086: getActionPerformedCode())) {
087: return "Document is not in a state to be routed";
088: }
089: return "";
090: }
091:
092: /**
093: * Record the routing action. To route a document, it must be in the proper state. Previous requests and actions have no bearing on the outcome of this action, unless the
094: * @throws edu.iu.uis.eden.exception.InvalidActionTakenException
095: * @throws edu.iu.uis.eden.exception.EdenUserNotFoundException
096: */
097: public void recordAction()
098: throws edu.iu.uis.eden.exception.InvalidActionTakenException,
099: EdenUserNotFoundException {
100: MDC.put("docId", getRouteHeader().getRouteHeaderId());
101: checkLocking();
102: updateSearchableAttributesIfPossible();
103: // if (routeHeader.getDocumentType().getInitiatorMustRoutePolicy().getPolicyValue().booleanValue()) {
104: // super.recordAction();
105: // }
106:
107: if (annotation == null) {
108: annotation = "";
109: }
110:
111: LOG.debug("Routing document : " + annotation);
112:
113: LOG.debug("Checking to see if the action is legal");
114: String errorMessage = validateActionRules();
115: if (!Utilities.isEmpty(errorMessage)) {
116: throw new InvalidActionTakenException(errorMessage);
117: }
118:
119: // we want to check that the "RouteDocument" command is valid here, not the "Complete" command (which is in our Action's action taken code)
120: // if (getRouteHeader().isValidActionToTake(EdenConstants.ACTION_TAKEN_ROUTED_CD)) {
121: LOG.debug("Record the routing action");
122: saveActionTaken();
123:
124: //TODO this will get all pending AR's even if they haven't been in an action list... This seems bad
125: List actionRequests = getActionRequestService()
126: .findPendingByDoc(getRouteHeaderId());
127: LOG.debug("Deactivate all pending action requests");
128: // deactivate any requests for the user that routed the document.
129: for (Iterator iter = actionRequests.iterator(); iter.hasNext();) {
130: ActionRequestValue actionRequest = (ActionRequestValue) iter
131: .next();
132: // requests generated to the user who is routing the document should be deactivated
133: if ((getUser().getWorkflowId().equals(actionRequest
134: .getWorkflowId()))
135: && (actionRequest.isActive())) {
136: getActionRequestService().deactivateRequest(
137: actionTaken, actionRequest);
138: }
139: // requests generated by a save action should be deactivated
140: else if (EdenConstants.SAVED_REQUEST_RESPONSIBILITY_ID
141: .equals(actionRequest.getResponsibilityId())) {
142: getActionRequestService().deactivateRequest(
143: actionTaken, actionRequest);
144: }
145: }
146:
147: try {
148: String oldStatus = getRouteHeader().getDocRouteStatus();
149: getRouteHeader().markDocumentEnroute();
150: getRouteHeader().setRoutedByUserWorkflowId(
151: getUser().getWorkflowId());
152:
153: String newStatus = getRouteHeader().getDocRouteStatus();
154: notifyStatusChange(newStatus, oldStatus);
155: getRouteHeaderService().saveRouteHeader(getRouteHeader());
156: } catch (WorkflowException ex) {
157: LOG.warn(ex, ex);
158: throw new InvalidActionTakenException(ex.getMessage());
159: }
160: // } else {
161: // LOG.warn("Document not in state to be routed.");
162: // throw new InvalidActionTakenException("Document is not in a state to be routed");
163: // }
164: }
165: }
|