Coverage Report - org.kuali.rice.kew.impl.action.ActionInvocationQueueImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionInvocationQueueImpl
0%
0/29
0%
0/10
15
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.impl.action;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.apache.log4j.Logger;
 23  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 24  
 import org.kuali.rice.core.api.reflect.DataDefinition;
 25  
 import org.kuali.rice.kew.actions.ActionTakenEvent;
 26  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 27  
 import org.kuali.rice.kew.api.action.ActionInvocation;
 28  
 import org.kuali.rice.kew.api.action.ActionInvocationQueue;
 29  
 import org.kuali.rice.kew.api.exception.InvalidActionTakenException;
 30  
 import org.kuali.rice.kew.api.exception.ResourceUnavailableException;
 31  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 32  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 33  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 34  
 
 35  
 /**
 36  
  * Reference implementation of the ActionInvocationQueue.
 37  
  *
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  */
 40  0
 public class ActionInvocationQueueImpl implements ActionInvocationQueue {
 41  
 
 42  0
     private static final Logger LOG = Logger.getLogger(ActionInvocationQueueImpl.class);
 43  
 
 44  
     @Override
 45  
     public void invokeAction(String principalId, String documentId, ActionInvocation invocation) {
 46  0
         if (StringUtils.isBlank(principalId)) {
 47  0
             throw new RiceIllegalArgumentException("principalId is null or blank");
 48  
         }
 49  
 
 50  0
         if (StringUtils.isBlank(documentId)) {
 51  0
             throw new RiceIllegalArgumentException("documentId is null");
 52  
         }
 53  
 
 54  0
         if (invocation == null) {
 55  0
             throw new RiceIllegalArgumentException("invocation is null");
 56  
         }
 57  
 
 58  
 
 59  0
         KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId, true);
 60  0
         DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId);
 61  
 
 62  0
         Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId);
 63  0
         List<DataDefinition> parameters = new ArrayList<DataDefinition>();
 64  0
         parameters.add(new DataDefinition(document));
 65  0
         parameters.add(new DataDefinition(principal));
 66  0
         parameters.add(new DataDefinition(""));
 67  
 
 68  
         try {
 69  0
             final ActionTakenEvent action = KEWServiceLocator.getActionRegistry().createAction(invocation.getAction().getCode(), parameters);
 70  0
             if (!document.isValidActionToTake(invocation.getAction().getCode())) {
 71  0
                 LOG.warn("Action "
 72  
                         + invocation.getAction()
 73  
                         + " is not a valid action to take against document "
 74  
                         + document.getDocumentId()
 75  
                         + " by principal with name '"
 76  
                         + principal.getPrincipalName()
 77  
                         + "'");
 78  0
                 return;
 79  0
             } else if (!KEWServiceLocator.getActionRegistry().getValidActions(principal, document).getActionTakenCodes()
 80  
                     .contains(action.getActionTakenCode())) {
 81  0
                 LOG.warn("Action "
 82  
                         + action.getActionTakenCode()
 83  
                         + " is not valid for document "
 84  
                         + document.getDocumentId()
 85  
                         + " by principal with name '"
 86  
                         + principal.getPrincipalName()
 87  
                         + "'");
 88  0
                 return;
 89  
             }
 90  0
             action.performAction();
 91  0
         } catch (ResourceUnavailableException e) {
 92  0
             throw new WorkflowRuntimeException(e);
 93  0
         } catch (InvalidActionTakenException e) {
 94  0
             throw new WorkflowRuntimeException(e);
 95  0
         }
 96  
 
 97  0
     }
 98  
 
 99  
 }