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 org.apache.log4j.MDC;
023:
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.WorkflowServiceErrorException;
027: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
028: import edu.iu.uis.eden.actionrequests.ActionRequestFactory;
029: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
030: import edu.iu.uis.eden.doctype.DocumentType;
031: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
032: import edu.iu.uis.eden.exception.InvalidActionTakenException;
033: import edu.iu.uis.eden.exception.WorkflowException;
034: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
035: import edu.iu.uis.eden.user.WorkflowUser;
036: import edu.iu.uis.eden.util.Utilities;
037:
038: /**
039: * Super user Approves a single action request.
040: *
041: * @author rkirkend
042: * @author temay
043: */
044: public class SuperUserActionRequestApproveEvent extends
045: SuperUserActionTakenEvent {
046: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
047: .getLogger(SuperUserActionRequestApproveEvent.class);
048: private Long actionRequestId;
049:
050: public SuperUserActionRequestApproveEvent(
051: DocumentRouteHeaderValue routeHeader, WorkflowUser user) {
052: super (routeHeader, user);
053: this .super UserAction = EdenConstants.SUPER_USER_ACTION_REQUEST_APPROVE;
054: }
055:
056: public SuperUserActionRequestApproveEvent(
057: DocumentRouteHeaderValue routeHeader, WorkflowUser user,
058: Long actionRequestId, String annotation) {
059: super (routeHeader, user, annotation);
060: this .super UserAction = EdenConstants.SUPER_USER_ACTION_REQUEST_APPROVE;
061: this .actionRequestId = actionRequestId;
062: }
063:
064: public void setActionTaken() {
065: String actionRequestCode = "";
066:
067: ActionRequestValue actionRequest = getActionRequestService()
068: .findByActionRequestId(actionRequestId);
069:
070: setActionRequest(actionRequest);
071:
072: actionRequestCode = actionRequest.getActionRequested();
073: //This has been set up for all of the actions, but this class only does approvals
074: if (EdenConstants.ACTION_REQUEST_APPROVE_REQ
075: .equals(actionRequestCode)) {
076: this
077: .setActionTakenCode(EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED_CD);
078: } else if (EdenConstants.ACTION_REQUEST_COMPLETE_REQ
079: .equals(actionRequestCode)) {
080: this
081: .setActionTakenCode(EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED_CD);
082: } else if (EdenConstants.ACTION_REQUEST_FYI_REQ
083: .equals(actionRequestCode)) {
084: this
085: .setActionTakenCode(EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD);
086: } else if (EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ
087: .equals(actionRequestCode)) {
088: this
089: .setActionTakenCode(EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD);
090: } else {
091: //TODO this should be checked
092: LOG.error("Invalid SU delegation action request code: "
093: + actionRequestCode);
094: throw new RuntimeException(
095: "Invalid SU delegation action request code: "
096: + actionRequestCode);
097: }
098: }
099:
100: protected void processActionRequests()
101: throws InvalidActionTakenException,
102: EdenUserNotFoundException {
103: //this method has been written to process all of the actions though only approvals are currently processed
104:
105: DocumentType docType = getRouteHeader().getDocumentType();
106: // boolean userAuthorized = getDocumentTypeService().verifySUAuthority(docType, getUser());
107:
108: String errorMessage = super .validateActionRules();
109: if (!Utilities.isEmpty(errorMessage)) {
110: LOG.info("User not authorized");
111: List errors = new ArrayList();
112: errors.add(new WorkflowServiceErrorImpl(errorMessage,
113: SuperUserActionTakenEvent.AUTHORIZATION));
114: throw new WorkflowServiceErrorException(errorMessage,
115: errors);
116: }
117: // if (!docType.isSuperUser(getUser())) {
118: // List errors = new ArrayList();
119: // errors.add(new WorkflowServiceErrorImpl("User not authorized for super user action", SuperUserActionTakenEvent.AUTHORIZATION));
120: // throw new WorkflowServiceErrorException("Super User Authorization Error", errors);
121: // }
122:
123: this .setActionTaken();
124:
125: MDC.put("docId", getRouteHeader().getRouteHeaderId());
126:
127: if (annotation == null) {
128: annotation = "";
129: }
130:
131: LOG.debug("Super User Delegation Action on action request: "
132: + annotation);
133: this .saveActionTaken(getActionRequest().getWorkflowUser());
134:
135: LOG.debug("Deactivate this action request");
136:
137: ActionRequestValue request = getActionRequest();
138: getActionRequestService().deactivateRequest(actionTaken,
139: request);
140: if (docType.getSuperUserApproveNotificationPolicy()
141: .getPolicyValue().booleanValue()
142: && request.isApproveOrCompleteRequest()) {
143: KEWServiceLocator
144: .getActionRequestService()
145: .activateRequest(
146: new ActionRequestFactory(this
147: .getRouteHeader())
148: .createNotificationRequest(
149: EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ,
150: request.getWorkflowUser(),
151: this .getActionTakenCode(),
152: this .getUser(), null));
153: }
154: notifyActionTaken(this .actionTaken);
155:
156: if (!(EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD
157: .equals(this .getActionTakenCode()) && EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD
158: .equals(this .getActionTakenCode()))) {
159: if (getRouteHeader().isInException()) {
160: LOG
161: .debug("Moving document back to Enroute from Exception");
162:
163: String oldStatus = getRouteHeader().getDocRouteStatus();
164: this .getRouteHeader().markDocumentEnroute();
165:
166: String newStatus = getRouteHeader().getDocRouteStatus();
167: this .notifyStatusChange(newStatus, oldStatus);
168: getRouteHeaderService().saveRouteHeader(
169: getRouteHeader());
170: }
171: }
172: }
173:
174: public void recordAction() throws InvalidActionTakenException,
175: EdenUserNotFoundException {
176: checkLocking();
177: this .processActionRequests();
178: this .queueDocument();
179: }
180:
181: protected void markDocument() throws WorkflowException {
182: }
183: }
|