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.Iterator;
021: import java.util.List;
022:
023: import edu.iu.uis.eden.WorkflowServiceErrorException;
024: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
025: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
026: import edu.iu.uis.eden.doctype.DocumentType;
027: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
028: import edu.iu.uis.eden.exception.InvalidActionTakenException;
029: import edu.iu.uis.eden.exception.WorkflowException;
030: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
031: import edu.iu.uis.eden.user.WorkflowUser;
032: import edu.iu.uis.eden.util.Utilities;
033:
034: /**
035: * Super class for all super user action takens.
036: *
037: * @author rkirkend
038: * @author seiffert
039: */
040: public abstract class SuperUserActionTakenEvent extends
041: ActionTakenEvent {
042:
043: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
044: .getLogger(SuperUserActionTakenEvent.class);
045:
046: protected String super UserAction;
047: //protected DocumentRouteStatusChange event;
048: private ActionRequestValue actionRequest;
049: public static String AUTHORIZATION = "general.routing.superuser.notAuthorized";
050:
051: public SuperUserActionTakenEvent(
052: DocumentRouteHeaderValue routeHeader, WorkflowUser user) {
053: super (routeHeader, user);
054: }
055:
056: public SuperUserActionTakenEvent(
057: DocumentRouteHeaderValue routeHeader, WorkflowUser user,
058: String annotation) {
059: super (routeHeader, user, annotation);
060: }
061:
062: /* (non-Javadoc)
063: * @see edu.iu.uis.eden.actions.ActionTakenEvent#validateActionRules()
064: */
065: @Override
066: public String validateActionRules()
067: throws EdenUserNotFoundException {
068: DocumentType docType = getRouteHeader().getDocumentType();
069: if (!docType.isSuperUser(getUser())) {
070: return "User not authorized for super user action";
071: }
072: return "";
073: }
074:
075: public void recordAction() throws InvalidActionTakenException,
076: EdenUserNotFoundException {
077: checkLocking();
078:
079: String errorMessage = validateActionRules();
080: if (!Utilities.isEmpty(errorMessage)) {
081: LOG.info("User not authorized");
082: List errors = new ArrayList();
083: errors.add(new WorkflowServiceErrorImpl(errorMessage,
084: AUTHORIZATION));
085: throw new WorkflowServiceErrorException(errorMessage,
086: errors);
087: }
088:
089: // DocumentType docType = getRouteHeader().getDocumentType();
090: // if (!docType.isSuperUser(getUser())) {
091: // LOG.info("User not authorized");
092: // List errors = new ArrayList();
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: processActionRequests();
098:
099: try {
100: String oldStatus = getRouteHeader().getDocRouteStatus();
101: //if the document is initiated then set it enroute so we can transition to any other status
102: if (getRouteHeader().isStateInitiated()) {
103: getRouteHeader().markDocumentEnroute();
104: notifyStatusChange(
105: getRouteHeader().getDocRouteStatus(), oldStatus);
106: }
107: markDocument();
108: String newStatus = getRouteHeader().getDocRouteStatus();
109: notifyStatusChange(newStatus, oldStatus);
110: } catch (Exception ex) {
111: LOG.error("Caught Exception talking to post processor", ex);
112: throw new RuntimeException(ex.getMessage());
113: }
114:
115: queueDocument();
116: }
117:
118: protected abstract void markDocument() throws WorkflowException;
119:
120: protected void processActionRequests()
121: throws InvalidActionTakenException,
122: EdenUserNotFoundException {
123: LOG.debug("Processing pending action requests");
124:
125: saveActionTaken();
126:
127: List actionRequests = getActionRequestService()
128: .findPendingByDoc(getRouteHeaderId());
129:
130: for (Iterator iter = actionRequests.iterator(); iter.hasNext();) {
131: ActionRequestValue actionRequest = (ActionRequestValue) iter
132: .next();
133: getActionRequestService().deactivateRequest(actionTaken,
134: actionRequest);
135: }
136: }
137:
138: public ActionRequestValue getActionRequest() {
139: return actionRequest;
140: }
141:
142: public void setActionRequest(ActionRequestValue actionRequest) {
143: this.actionRequest = actionRequest;
144: }
145: }
|