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.List;
021:
022: import edu.iu.uis.eden.EdenConstants;
023: import edu.iu.uis.eden.WorkflowServiceErrorException;
024: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
025: import edu.iu.uis.eden.doctype.DocumentType;
026: import edu.iu.uis.eden.engine.BlanketApproveEngine;
027: import edu.iu.uis.eden.engine.OrchestrationConfig;
028: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
029: import edu.iu.uis.eden.exception.InvalidActionTakenException;
030: import edu.iu.uis.eden.exception.WorkflowException;
031: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
032: import edu.iu.uis.eden.user.WorkflowUser;
033: import edu.iu.uis.eden.util.Utilities;
034:
035: /**
036: * Does a node level super user approve action. All approve/complete requests outstanding for
037: * this node are satisfied by this action.
038: *
039: * @author ewestfal
040: * @author rkirkend
041: *
042: */
043: public class SuperUserNodeApproveEvent extends
044: SuperUserActionTakenEvent {
045:
046: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
047: .getLogger(SuperUserNodeApproveEvent.class);
048: private String nodeName;
049:
050: public SuperUserNodeApproveEvent(
051: DocumentRouteHeaderValue routeHeader, WorkflowUser user) {
052: super (routeHeader, user);
053: setActionTakenCode(EdenConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD);
054: this .super UserAction = EdenConstants.SUPER_USER_ROUTE_LEVEL_APPROVE;
055: }
056:
057: public SuperUserNodeApproveEvent(
058: DocumentRouteHeaderValue routeHeader, WorkflowUser user,
059: String annotation, String nodeName) {
060: super (routeHeader, user, annotation);
061: setActionTakenCode(EdenConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD);
062: this .super UserAction = EdenConstants.SUPER_USER_ROUTE_LEVEL_APPROVE;
063: this .nodeName = nodeName;
064: }
065:
066: public void recordAction() throws InvalidActionTakenException,
067: EdenUserNotFoundException {
068: checkLocking();
069:
070: if (Utilities.isEmpty(nodeName)) {
071: throw new InvalidActionTakenException(
072: "No approval node name set");
073: }
074:
075: DocumentType docType = getRouteHeader().getDocumentType();
076:
077: String errorMessage = super .validateActionRules();
078: if (!Utilities.isEmpty(errorMessage)) {
079: LOG.info("User not authorized");
080: List errors = new ArrayList();
081: errors.add(new WorkflowServiceErrorImpl(errorMessage,
082: SuperUserActionTakenEvent.AUTHORIZATION));
083: throw new WorkflowServiceErrorException(errorMessage,
084: errors);
085: }
086: // if (!docType.isSuperUser(getUser())) {
087: // LOG.info("User not authorized");
088: // List errors = new ArrayList();
089: // errors.add(new WorkflowServiceErrorImpl("User not authorized for super user action", AUTHORIZATION));
090: // throw new WorkflowServiceErrorException("Super User Authorization Error", errors);
091: // }
092:
093: saveActionTaken();
094:
095: if (getRouteHeader().isInException()) {
096: LOG.debug("Moving document back to Enroute from Exception");
097: String oldStatus = getRouteHeader().getDocRouteStatus();
098: getRouteHeader().markDocumentEnroute();
099: String newStatus = getRouteHeader().getDocRouteStatus();
100: notifyStatusChange(newStatus, oldStatus);
101: getRouteHeaderService().saveRouteHeader(getRouteHeader());
102: }
103:
104: OrchestrationConfig config = new OrchestrationConfig();
105: config.setCause(actionTaken);
106: config.setDestinationNodeNames(Utilities.asSet(nodeName));
107: config.setSendNotifications(docType
108: .getSuperUserApproveNotificationPolicy()
109: .getPolicyValue().booleanValue());
110: try {
111: new BlanketApproveEngine(config).process(getRouteHeader()
112: .getRouteHeaderId(), null);
113: } catch (Exception e) {
114: throw new InvalidActionTakenException(
115: "Failed to orchestrate the document through super user node approve.",
116: e);
117: }
118:
119: //queueDocument();
120: }
121:
122: protected void markDocument() throws WorkflowException {
123: // do nothing since we are overriding the entire behavior
124: }
125:
126: }
|