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.HashSet;
021: import java.util.List;
022:
023: import org.apache.log4j.Logger;
024:
025: import edu.iu.uis.eden.EdenConstants;
026: import edu.iu.uis.eden.KEWServiceLocator;
027: import edu.iu.uis.eden.WorkflowServiceErrorException;
028: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
029: import edu.iu.uis.eden.actionrequests.ActionRequestFactory;
030: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
031: import edu.iu.uis.eden.doctype.DocumentType;
032: import edu.iu.uis.eden.engine.BlanketApproveEngine;
033: import edu.iu.uis.eden.engine.OrchestrationConfig;
034: import edu.iu.uis.eden.engine.RouteContext;
035: import edu.iu.uis.eden.engine.node.RequestsNode;
036: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
037: import edu.iu.uis.eden.exception.InvalidActionTakenException;
038: import edu.iu.uis.eden.exception.WorkflowException;
039: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
040: import edu.iu.uis.eden.user.WorkflowUser;
041: import edu.iu.uis.eden.util.Utilities;
042:
043: /**
044: * Does a super user approve action.
045: *
046: * @author rkirkend
047: * @author ewestfal
048: *
049: */
050: public class SuperUserApproveEvent extends SuperUserActionTakenEvent {
051:
052: private static final Logger LOG = Logger
053: .getLogger(SuperUserApproveEvent.class);
054:
055: public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader,
056: WorkflowUser user) {
057: super (routeHeader, user);
058: setActionTakenCode(EdenConstants.ACTION_TAKEN_SU_APPROVED_CD);
059: this .super UserAction = EdenConstants.SUPER_USER_APPROVE;
060: }
061:
062: public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader,
063: WorkflowUser user, String annotation) {
064: super (routeHeader, user, annotation);
065: setActionTakenCode(EdenConstants.ACTION_TAKEN_SU_APPROVED_CD);
066: this .super UserAction = EdenConstants.SUPER_USER_APPROVE;
067: }
068:
069: public void recordAction() throws InvalidActionTakenException,
070: EdenUserNotFoundException {
071: // TODO: this is used because calling this code from SuperUserAction without
072: // it causes an optimistic lock
073: this .routeHeader = KEWServiceLocator.getRouteHeaderService()
074: .getRouteHeader(getRouteHeaderId(), true);
075:
076: checkLocking();
077:
078: DocumentType docType = getRouteHeader().getDocumentType();
079:
080: String errorMessage = super .validateActionRules();
081: if (!Utilities.isEmpty(errorMessage)) {
082: LOG.info("User not authorized");
083: List errors = new ArrayList();
084: errors.add(new WorkflowServiceErrorImpl(errorMessage,
085: AUTHORIZATION));
086: throw new WorkflowServiceErrorException(errorMessage,
087: errors);
088: }
089:
090: // if (!docType.isSuperUser(getUser())) {
091: // LOG.info("User not authorized");
092: // List<WorkflowServiceError> errors = new ArrayList<WorkflowServiceError>();
093: // errors.add(new WorkflowServiceErrorImpl("User not authorized for super user action", AUTHORIZATION));
094: // throw new WorkflowServiceErrorException("Super User Authorization Error", errors);
095: // }
096:
097: saveActionTaken();
098:
099: if (getRouteHeader().isInException()
100: || getRouteHeader().isStateInitiated()) {
101: LOG.debug("Moving document back to Enroute");
102: String oldStatus = getRouteHeader().getDocRouteStatus();
103: getRouteHeader().markDocumentEnroute();
104: String newStatus = getRouteHeader().getDocRouteStatus();
105: notifyStatusChange(newStatus, oldStatus);
106: getRouteHeaderService().saveRouteHeader(getRouteHeader());
107: }
108:
109: OrchestrationConfig config = new OrchestrationConfig();
110: config.setCause(actionTaken);
111: config.setDestinationNodeNames(new HashSet());
112: config.setSendNotifications(docType
113: .getSuperUserApproveNotificationPolicy()
114: .getPolicyValue().booleanValue());
115: RequestsNode.setSupressPolicyErrors(RouteContext
116: .getCurrentRouteContext());
117: try {
118: completeAnyOutstandingCompleteApproveRequets(docType
119: .getSuperUserApproveNotificationPolicy()
120: .getPolicyValue().booleanValue());
121: new BlanketApproveEngine(config).process(getRouteHeader()
122: .getRouteHeaderId(), null);
123: } catch (Exception e) {
124: LOG
125: .error(
126: "Failed to orchestrate the document to SuperUserApproved.",
127: e);
128: throw new InvalidActionTakenException(
129: "Failed to orchestrate the document to SuperUserApproved.",
130: e);
131: }
132:
133: }
134:
135: @SuppressWarnings("unchecked")
136: protected void completeAnyOutstandingCompleteApproveRequets(
137: boolean sendNotifications) throws Exception {
138: List<ActionRequestValue> actionRequests = KEWServiceLocator
139: .getActionRequestService()
140: .findPendingByActionRequestedAndDocId(
141: EdenConstants.ACTION_REQUEST_APPROVE_REQ,
142: routeHeaderId);
143: actionRequests.addAll(KEWServiceLocator
144: .getActionRequestService()
145: .findPendingByActionRequestedAndDocId(
146: EdenConstants.ACTION_REQUEST_COMPLETE_REQ,
147: routeHeaderId));
148: for (ActionRequestValue actionRequest : actionRequests) {
149: KEWServiceLocator.getActionRequestService()
150: .deactivateRequest(this .getActionTaken(),
151: actionRequest);
152: }
153: if (sendNotifications) {
154: new ActionRequestFactory(this .getRouteHeader())
155: .generateNotifications(
156: actionRequests,
157: this .getUser(),
158: this
159: .findDelegatorForActionRequests(actionRequests),
160: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ,
161: EdenConstants.ACTION_TAKEN_SU_APPROVED_CD);
162: }
163: }
164:
165: protected void markDocument() throws WorkflowException {
166: // do nothing since we are overriding the entire behavior
167: }
168: }
|