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 org.apache.log4j.MDC;
020:
021: import edu.iu.uis.eden.EdenConstants;
022: import edu.iu.uis.eden.KEWServiceLocator;
023: import edu.iu.uis.eden.actionrequests.ActionRequestFactory;
024: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
025: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
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: * Saves a document. Puts the document in the persons action list that saved the document.
035: * This can currently only be done by the initiator of the document.
036: *
037: * @author rkirkend
038: * @author ewestfal
039: * @author seiffert
040: *
041: */
042: public class SaveActionEvent extends ActionTakenEvent {
043:
044: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045: .getLogger(SaveActionEvent.class);
046:
047: private static final String RESPONSIBILITY_DESCRIPTION = "Initiator needs to complete document.";
048:
049: public SaveActionEvent(DocumentRouteHeaderValue routeHeader,
050: WorkflowUser user) {
051: super (routeHeader, user);
052: setActionTakenCode(EdenConstants.ACTION_TAKEN_SAVED_CD);
053: }
054:
055: public SaveActionEvent(DocumentRouteHeaderValue routeHeader,
056: WorkflowUser user, String annotation) {
057: super (routeHeader, user, annotation);
058: setActionTakenCode(EdenConstants.ACTION_TAKEN_SAVED_CD);
059: }
060:
061: /* (non-Javadoc)
062: * @see edu.iu.uis.eden.actions.ActionTakenEvent#requireInitiatorCheck()
063: */
064: @Override
065: protected boolean requireInitiatorCheck() {
066: return routeHeader.getDocumentType()
067: .getInitiatorMustSavePolicy().getPolicyValue()
068: .booleanValue();
069: }
070:
071: /* (non-Javadoc)
072: * @see edu.iu.uis.eden.actions.ActionTakenEvent#isActionCompatibleRequest(java.util.List)
073: */
074: @Override
075: public String validateActionRules()
076: throws EdenUserNotFoundException {
077: String super Error = super .validateActionTakenRules();
078: if (!Utilities.isEmpty(super Error)) {
079: return super Error;
080: }
081: if (!getRouteHeader().isValidActionToTake(
082: getActionPerformedCode())) {
083: return "Document is not in a state to be approved";
084: }
085: return "";
086: }
087:
088: public void recordAction() throws InvalidActionTakenException,
089: EdenUserNotFoundException {
090: MDC.put("docId", getRouteHeader().getRouteHeaderId());
091: checkLocking();
092: updateSearchableAttributesIfPossible();
093:
094: if (annotation == null) {
095: annotation = "";
096: }
097:
098: LOG.debug("Checking to see if the action is legal");
099: String errorMessage = validateActionRules();
100: if (!Utilities.isEmpty(errorMessage)) {
101: throw new InvalidActionTakenException(errorMessage);
102: }
103:
104: // if (getRouteHeader().isValidActionToTake(getActionTakenCode())) {
105: if (getRouteHeader().isStateInitiated()) {
106: LOG.debug("Record the save action");
107: saveActionTaken();
108: getRouteHeader().getActionRequests().add(
109: generateSaveRequest());
110: LOG.debug("Marking document saved");
111: try {
112: String oldStatus = getRouteHeader().getDocRouteStatus();
113: getRouteHeader().markDocumentSaved();
114: String newStatus = getRouteHeader().getDocRouteStatus();
115: notifyStatusChange(newStatus, oldStatus);
116: getRouteHeaderService().saveRouteHeader(routeHeader);
117: } catch (WorkflowException ex) {
118: LOG.warn(ex, ex);
119: throw new InvalidActionTakenException(ex.getMessage());
120: }
121: }
122: // } else {
123: // LOG.warn("Document not in state to be saved.");
124: // throw new InvalidActionTakenException("Document is not in a state to be saved");
125: // }
126: }
127:
128: protected ActionRequestValue generateSaveRequest()
129: throws EdenUserNotFoundException {
130: RouteNodeInstance intialNode = (RouteNodeInstance) KEWServiceLocator
131: .getRouteNodeService().getInitialNodeInstances(
132: routeHeaderId).get(0);
133: ActionRequestFactory arFactory = new ActionRequestFactory(
134: routeHeader, intialNode);
135: ActionRequestValue saveRequest = arFactory.createActionRequest(
136: EdenConstants.ACTION_REQUEST_COMPLETE_REQ, new Integer(
137: 0), getUser(), RESPONSIBILITY_DESCRIPTION,
138: EdenConstants.SAVED_REQUEST_RESPONSIBILITY_ID,
139: Boolean.TRUE, annotation);
140: // this.getActionRequestService().saveActionRequest(saveRequest);
141: this.getActionRequestService().activateRequest(saveRequest);
142: return saveRequest;
143: }
144:
145: }
|