001 /* 002 * Copyright 2005-2007 The Kuali Foundation 003 * 004 * 005 * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in 006 * compliance with the License. You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS 011 * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 012 * language governing permissions and limitations under the License. 013 */ 014 package org.kuali.rice.kew.actions.asyncservices; 015 016 import java.util.ArrayList; 017 import java.util.List; 018 019 import org.apache.log4j.Logger; 020 import org.kuali.rice.core.reflect.DataDefinition; 021 import org.kuali.rice.kew.actions.ActionTakenEvent; 022 import org.kuali.rice.kew.exception.WorkflowRuntimeException; 023 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; 024 import org.kuali.rice.kew.service.KEWServiceLocator; 025 import org.kuali.rice.kim.bo.entity.KimPrincipal; 026 027 028 /** 029 * Service for doing the actual work of a mass action in the action list. Represents a single action on a single document. 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033 public class ActionInvocationProcessor implements ActionInvocationService { // implements RouteQueueProcessor { 034 035 private static final Logger LOG = Logger.getLogger(ActionInvocationProcessor.class); 036 037 public void invokeAction(String principalId, Long documentId, ActionInvocation invocation) { 038 039 KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId, true); 040 DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); 041 042 KimPrincipal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId); 043 List<DataDefinition> parameters = new ArrayList<DataDefinition>(); 044 parameters.add(new DataDefinition(document)); 045 parameters.add(new DataDefinition(principal)); 046 parameters.add(new DataDefinition("")); 047 ActionTakenEvent action; 048 try { 049 action = KEWServiceLocator.getActionRegistry().createAction(invocation.getActionCode(), parameters); 050 if (!document.isValidActionToTake(invocation.getActionCode())) { 051 LOG.warn("Action " + invocation.getActionCode() + " is not a valid action to take against document " + document.getRouteHeaderId() + " by principal with name '" + principal.getPrincipalName() + "'"); 052 return; 053 } else if (!KEWServiceLocator.getActionRegistry().getValidActions(principal, document).getActionTakenCodes().contains(action.getActionTakenCode())) { 054 LOG.warn("Action " + action.getActionTakenCode() + " is not valid for document " + document.getRouteHeaderId() + " by principal with name '" + principal.getPrincipalName() + "'"); 055 return; 056 } 057 action.performAction(); 058 } catch (Exception e) { 059 throw new WorkflowRuntimeException(e); 060 } 061 062 } 063 064 }