Coverage Report - org.kuali.rice.kew.actions.ActionRegistryImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionRegistryImpl
0%
0/64
0%
0/26
5.2
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.actions;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collections;
 21  
 import java.util.HashMap;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 import org.apache.commons.lang.StringUtils;
 27  
 import org.apache.log4j.Logger;
 28  
 import org.kuali.rice.core.api.reflect.DataDefinition;
 29  
 import org.kuali.rice.core.api.reflect.ObjectDefinition;
 30  
 import org.kuali.rice.core.api.reflect.DataDefinition;
 31  
 import org.kuali.rice.core.api.reflect.ObjectDefinition;
 32  
 import org.kuali.rice.core.framework.resourceloader.ObjectDefinitionResolver;
 33  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 34  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 35  
 import org.kuali.rice.kew.exception.ResourceUnavailableException;
 36  
 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
 37  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 38  
 import org.kuali.rice.kew.util.KEWConstants;
 39  
 import org.kuali.rice.kim.api.entity.principal.PrincipalContract;
 40  
 
 41  
 
 42  
 
 43  
 /**
 44  
  * A simple implementation of an ActionRegistry which includes all of the default Workflow Actions.
 45  
  *
 46  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 47  
  */
 48  0
 public class ActionRegistryImpl implements ActionRegistry {
 49  0
     private static final Logger LOG = Logger.getLogger(ActionRegistryImpl.class);
 50  
 
 51  0
         private static Map<String, String> actionMap = new HashMap<String, String>();
 52  
         static {
 53  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD, AcknowledgeAction.class.getName());
 54  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_ADHOC_CD, AdHocAction.class.getName());
 55  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_ADHOC_REVOKED_CD, RevokeAdHocAction.class.getName());
 56  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_APPROVED_CD, ApproveAction.class.getName());
 57  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD, BlanketApproveAction.class.getName());
 58  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_CANCELED_CD, CancelAction.class.getName());
 59  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_COMPLETED_CD, CompleteAction.class.getName());
 60  0
         actionMap.put(KEWConstants.ACTION_TAKEN_ROUTED_CD, RouteDocumentAction.class.getName());
 61  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_DENIED_CD, DisapproveAction.class.getName());
 62  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_FYI_CD, ClearFYIAction.class.getName());
 63  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, LogDocumentActionAction.class.getName());
 64  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_MOVE_CD, MoveDocumentAction.class.getName());
 65  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, TakeWorkgroupAuthority.class.getName());
 66  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, ReleaseWorkgroupAuthority.class.getName());
 67  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS_CD, ReturnToPreviousNodeAction.class.getName());
 68  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_SAVED_CD, SaveActionEvent.class.getName());
 69  
                 //actionMap.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD, SuperUserActionRequestAcknowledgeEvent.class.getName());
 70  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED_CD, SuperUserActionRequestApproveEvent.class.getName());
 71  
                 //actionMap.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED_CD, SuperUserActionRequestCompleteEvent.class.getName());
 72  
                 //actionMap.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD, SuperUserActionRequestFYIEvent.class.getName());
 73  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_SU_APPROVED_CD, SuperUserApproveEvent.class.getName());
 74  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_SU_CANCELED_CD, SuperUserCancelEvent.class.getName());
 75  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_SU_DISAPPROVED_CD, SuperUserDisapproveEvent.class.getName());
 76  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS_CD, SuperUserReturnToPreviousNodeAction.class.getName());
 77  0
                 actionMap.put(KEWConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, SuperUserNodeApproveEvent.class.getName());
 78  0
         }
 79  
 
 80  
         public void registerAction(String actionCode, String actionClass) {
 81  0
                 if (actionClass == null) {
 82  0
                         throw new IllegalArgumentException("Action Code '" + actionCode + "' cannot be registered with a null action class.");
 83  
                 }
 84  0
                 if (actionMap.containsKey(actionCode)) {
 85  0
                         throw new WorkflowRuntimeException("Action Code is already in use.  [" +
 86  
                                         actionCode + ", " + actionClass + "].  "+
 87  
                                         "Please unregister the existing implementation first.");
 88  
                 }
 89  0
                 actionMap.put(actionCode, actionClass);
 90  0
         }
 91  
 
 92  
         public void unregisterAction(String actionCode) {
 93  0
                 actionMap.remove(actionCode);
 94  0
         }
 95  
 
 96  
         public Map getActionMap() {
 97  0
                 return Collections.unmodifiableMap(actionMap);
 98  
         }
 99  
 
 100  
         /* (non-Javadoc)
 101  
          * @see org.kuali.rice.kew.actions.ActionRegistry#createAction(java.lang.String, java.util.List)
 102  
          */
 103  
         public ActionTakenEvent createAction(String actionCode, List<DataDefinition> parameters) throws ResourceUnavailableException {
 104  0
                 String actionClassName = actionMap.get(actionCode);
 105  0
                 if (actionClassName == null) {
 106  0
                         throw new IllegalArgumentException("No action has been registered for the given action code of '" + actionCode + "'.");
 107  
                 }
 108  0
                 ObjectDefinition actionDefinition = new ObjectDefinition(actionClassName);
 109  0
                 if (parameters != null && !parameters.isEmpty()) {
 110  0
                         actionDefinition.setConstructorParameters(parameters);
 111  
                 }
 112  
                 try {
 113  
                         //ActionTakenEvent actionTaken = (ActionTakenEvent)GlobalResourceLoader.getResourceLoader().getObject(actionDefinition);
 114  
                         // TODO ActionTakenEvent is not an interface so we can't fetch them through the GlobalResourceLoader, for now, just use
 115  
                         // the ObjectDefinitionResolver
 116  0
                         ActionTakenEvent actionTaken = (ActionTakenEvent) ObjectDefinitionResolver.createObject(actionDefinition, ClassLoaderUtils.getDefaultClassLoader(), false);
 117  0
                         if (actionTaken == null) {
 118  
                                 // TODO the exception handling here is a bit wonky
 119  0
                                 throw new ResourceUnavailableException("Could not locate action taken class '" + actionClassName + "'");
 120  
                         }
 121  0
                         return actionTaken;
 122  0
                 } catch (Exception e) {
 123  0
             LOG.debug("createAction() Exception thrown while working with action class name '" + actionClassName + "'");
 124  0
                         if (e instanceof ResourceUnavailableException) {
 125  0
                                 throw (ResourceUnavailableException)e;
 126  
                         }
 127  0
                         throw new ResourceUnavailableException(e);
 128  
                 }
 129  
         }
 130  
 
 131  
     /* (non-Javadoc)
 132  
      * @see org.kuali.rice.kew.actions.ActionValidationService#getValidActions(org.kuali.rice.kew.user.WorkflowUser, org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue)
 133  
      */
 134  
     public ValidActions getValidActions(PrincipalContract principal, DocumentRouteHeaderValue document) throws ResourceUnavailableException {
 135  0
         ValidActions validActions = new ValidActions();
 136  0
         ArrayList<ActionRequestValue> activeRequests = new ArrayList<ActionRequestValue>();
 137  0
         for ( ActionRequestValue ar : document.getActionRequests() ) {
 138  0
                 if ( (ar.getCurrentIndicator() != null && ar.getCurrentIndicator()) && StringUtils.equals( ar.getStatus(), KEWConstants.ACTION_REQUEST_ACTIVATED ) ) {
 139  0
                         activeRequests.add(ar);
 140  
                 }
 141  
         }
 142  0
         for (String actionTakenCode : actionMap.keySet())
 143  
         {
 144  0
             List<DataDefinition> parameters = new ArrayList<DataDefinition>();
 145  0
             parameters.add(new DataDefinition(document));
 146  0
             parameters.add(new DataDefinition(principal));
 147  0
             ActionTakenEvent actionEvent = createAction(actionTakenCode, parameters);
 148  0
             if (StringUtils.isEmpty(actionEvent.validateActionRules(activeRequests)))
 149  
             {
 150  0
                 validActions.addActionTakenCode(actionTakenCode);
 151  
             }
 152  0
         }
 153  0
         return validActions;
 154  
     }
 155  
 }