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.Collections;
021: import java.util.HashMap;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.log4j.Logger;
027: import org.kuali.rice.definition.DataDefinition;
028: import org.kuali.rice.definition.ObjectDefinition;
029: import org.kuali.rice.resourceloader.ObjectDefinitionResolver;
030:
031: import edu.iu.uis.eden.EdenConstants;
032: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
033: import edu.iu.uis.eden.exception.ResourceUnavailableException;
034: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
035: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
036: import edu.iu.uis.eden.user.WorkflowUser;
037: import edu.iu.uis.eden.util.ClassLoaderUtils;
038:
039: /**
040: * A simple implementation of an ActionRegistry which includes all of the default Workflow Actions.
041: *
042: * @author ewestfal
043: */
044: public class ActionRegistryImpl implements ActionRegistry {
045: private static final Logger LOG = Logger
046: .getLogger(ActionRegistryImpl.class);
047:
048: private static Map actionMap = new HashMap();
049: static {
050: actionMap.put(EdenConstants.ACTION_TAKEN_ACKNOWLEDGED_CD,
051: AcknowledgeAction.class.getName());
052: actionMap.put(EdenConstants.ACTION_TAKEN_ADHOC_CD,
053: AdHocAction.class.getName());
054: actionMap.put(EdenConstants.ACTION_TAKEN_ADHOC_REVOKED_CD,
055: RevokeAdHocAction.class.getName());
056: actionMap.put(EdenConstants.ACTION_TAKEN_APPROVED_CD,
057: ApproveAction.class.getName());
058: actionMap.put(EdenConstants.ACTION_TAKEN_BLANKET_APPROVE_CD,
059: BlanketApproveAction.class.getName());
060: actionMap.put(EdenConstants.ACTION_TAKEN_CANCELED_CD,
061: CancelAction.class.getName());
062: actionMap.put(EdenConstants.ACTION_TAKEN_COMPLETED_CD,
063: CompleteAction.class.getName());
064: actionMap.put(EdenConstants.ACTION_TAKEN_ROUTED_CD,
065: RouteDocumentAction.class.getName());
066: actionMap.put(EdenConstants.ACTION_TAKEN_DENIED_CD,
067: DisapproveAction.class.getName());
068: actionMap.put(EdenConstants.ACTION_TAKEN_FYI_CD,
069: ClearFYIAction.class.getName());
070: actionMap.put(
071: EdenConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD,
072: LogDocumentActionAction.class.getName());
073: actionMap.put(EdenConstants.ACTION_TAKEN_MOVE_CD,
074: MoveDocumentAction.class.getName());
075: actionMap.put(
076: EdenConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD,
077: TakeWorkgroupAuthority.class.getName());
078: actionMap
079: .put(
080: EdenConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD,
081: ReleaseWorkgroupAuthority.class.getName());
082: actionMap.put(
083: EdenConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS_CD,
084: ReturnToPreviousNodeAction.class.getName());
085: actionMap.put(EdenConstants.ACTION_TAKEN_SAVED_CD,
086: SaveActionEvent.class.getName());
087: //actionMap.put(EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD, SuperUserActionRequestAcknowledgeEvent.class.getName());
088: actionMap
089: .put(
090: EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED_CD,
091: SuperUserActionRequestApproveEvent.class
092: .getName());
093: //actionMap.put(EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED_CD, SuperUserActionRequestCompleteEvent.class.getName());
094: //actionMap.put(EdenConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD, SuperUserActionRequestFYIEvent.class.getName());
095: actionMap.put(EdenConstants.ACTION_TAKEN_SU_APPROVED_CD,
096: SuperUserApproveEvent.class.getName());
097: actionMap.put(EdenConstants.ACTION_TAKEN_SU_CANCELED_CD,
098: SuperUserCancelEvent.class.getName());
099: actionMap.put(EdenConstants.ACTION_TAKEN_SU_DISAPPROVED_CD,
100: SuperUserDisapproveEvent.class.getName());
101: actionMap.put(
102: EdenConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS_CD,
103: SuperUserReturnToPreviousNodeAction.class.getName());
104: actionMap.put(
105: EdenConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD,
106: SuperUserNodeApproveEvent.class.getName());
107: }
108:
109: public void registerAction(String actionCode, String actionClass) {
110: if (actionClass == null) {
111: throw new IllegalArgumentException(
112: "Action Code '"
113: + actionCode
114: + "' cannot be registered with a null action class.");
115: }
116: if (actionMap.containsKey(actionCode)) {
117: throw new WorkflowRuntimeException(
118: "Action Code is already in use. ["
119: + actionCode
120: + ", "
121: + actionClass
122: + "]. "
123: + "Please unregister the existing implementation first.");
124: }
125: actionMap.put(actionCode, actionClass);
126: }
127:
128: public void unregisterAction(String actionCode) {
129: actionMap.remove(actionCode);
130: }
131:
132: public Map getActionMap() {
133: return Collections.synchronizedMap(actionMap);
134: }
135:
136: /* (non-Javadoc)
137: * @see edu.iu.uis.eden.actions.ActionRegistry#createAction(java.lang.String, java.util.List)
138: */
139: public ActionTakenEvent createAction(String actionCode,
140: List parameters) throws ResourceUnavailableException {
141: String actionClassName = (String) actionMap.get(actionCode);
142: if (actionClassName == null) {
143: throw new IllegalArgumentException(
144: "No action has been registered for the given action code of '"
145: + actionCode + "'.");
146: }
147: ObjectDefinition actionDefinition = new ObjectDefinition(
148: actionClassName);
149: if (parameters != null && !parameters.isEmpty()) {
150: actionDefinition.setConstructorParameters(parameters);
151: }
152: try {
153: //ActionTakenEvent actionTaken = (ActionTakenEvent)GlobalResourceLoader.getResourceLoader().getObject(actionDefinition);
154: // TODO ActionTakenEvent is not an interface so we can't fetch them through the GlobalResourceLoader, for now, just use
155: // the ObjectDefinitionResolver
156: ActionTakenEvent actionTaken = (ActionTakenEvent) ObjectDefinitionResolver
157: .createObject(actionDefinition, ClassLoaderUtils
158: .getDefaultClassLoader(), false);
159: if (actionTaken == null) {
160: // TODO the exception handling here is a bit wonky
161: throw new ResourceUnavailableException(
162: "Could not locate action taken class '"
163: + actionClassName + "'");
164: }
165: return actionTaken;
166: } catch (Exception e) {
167: LOG
168: .debug("createAction() Exception thrown while working with action class name '"
169: + actionClassName + "'");
170: if (e instanceof ResourceUnavailableException) {
171: throw (ResourceUnavailableException) e;
172: }
173: throw new ResourceUnavailableException(e);
174: }
175: }
176:
177: /* (non-Javadoc)
178: * @see edu.iu.uis.eden.actions.ActionValidationService#getValidActions(edu.iu.uis.eden.user.WorkflowUser, edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue)
179: */
180: public ValidActions getValidActions(WorkflowUser user,
181: DocumentRouteHeaderValue document)
182: throws ResourceUnavailableException,
183: EdenUserNotFoundException {
184: ValidActions validActions = new ValidActions();
185: for (Iterator iter = actionMap.keySet().iterator(); iter
186: .hasNext();) {
187: String actionTakenCode = (String) iter.next();
188: List<Object> parameters = new ArrayList<Object>();
189: parameters.add(new DataDefinition(document));
190: parameters.add(new DataDefinition(user));
191: ActionTakenEvent actionEvent = createAction(
192: actionTakenCode, parameters);
193: if (actionEvent.isActionValid()) {
194: validActions.addActionTakenCode(actionTakenCode);
195: }
196: }
197: return validActions;
198: }
199: }
|