Coverage Report - org.kuali.rice.kew.routemodule.service.impl.RouteModuleServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteModuleServiceImpl
0%
0/38
0%
0/22
2.7
 
 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.routemodule.service.impl;
 17  
 
 18  
 import org.apache.log4j.Logger;
 19  
 import org.kuali.rice.core.api.reflect.ObjectDefinition;
 20  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 21  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 22  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 23  
 import org.kuali.rice.kew.api.exception.ResourceUnavailableException;
 24  
 import org.kuali.rice.kew.engine.node.RouteNode;
 25  
 import org.kuali.rice.kew.role.RoleRouteModule;
 26  
 import org.kuali.rice.kew.routemodule.FlexRMAdapter;
 27  
 import org.kuali.rice.kew.routemodule.RouteModule;
 28  
 import org.kuali.rice.kew.routemodule.service.RouteModuleService;
 29  
 import org.kuali.rice.kew.api.KewApiConstants;
 30  
 import org.springframework.beans.BeansException;
 31  
 import org.springframework.beans.factory.BeanFactory;
 32  
 import org.springframework.beans.factory.BeanFactoryAware;
 33  
 
 34  
 /**
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  0
 public class RouteModuleServiceImpl implements RouteModuleService, BeanFactoryAware {
 38  
 
 39  0
     private static final Logger LOG = Logger.getLogger(RouteModuleServiceImpl.class);
 40  
 
 41  
     private BeanFactory beanFactory;
 42  
     private String rulesEngineRouteModuleId;
 43  
 
 44  
     private RouteModule peopleFlowRouteModule;
 45  
     private volatile RouteModule rulesEngineRouteModule;
 46  
 
 47  
     public RouteModule findRouteModule(RouteNode node) throws ResourceUnavailableException {
 48  0
         String routeMethodName = node.getRouteMethodName();
 49  0
         LOG.debug("Finding route module for routeMethodName="+routeMethodName+" at route level "+node.getRouteNodeName());
 50  0
         RouteModule routeModule = null;
 51  
         // default to FlexRM module if the routeMethodName is null
 52  0
         if (node.isRulesEngineNode()) {
 53  0
             routeModule = getRulesEngineRouteModule();
 54  0
         } else if (node.isPeopleFlowNode()) {
 55  0
             routeModule = getPeopleFlowRouteModule();
 56  0
         } else if (routeMethodName == null || node.isFlexRM()) {
 57  0
             routeModule = getFlexRMRouteModule(routeMethodName);
 58  
         } else {
 59  0
             routeModule = getRouteModule(routeMethodName);
 60  
         }
 61  0
         return routeModule;
 62  
     }
 63  
 
 64  
     public RouteModule findRouteModule(ActionRequestValue actionRequest) throws ResourceUnavailableException {
 65  0
             if (!actionRequest.getResolveResponsibility()) {
 66  0
                     return new RoleRouteModule();
 67  
             }
 68  0
         if (actionRequest.getNodeInstance() == null) {
 69  0
             return null;
 70  
         }
 71  0
         return findRouteModule(actionRequest.getNodeInstance().getRouteNode());
 72  
     }
 73  
 
 74  
     private RouteModule getRouteModule(String routeMethodName) throws ResourceUnavailableException {
 75  0
         if (routeMethodName == null) {
 76  0
             return null;
 77  0
         } else if ("".equals(routeMethodName.trim()) || KewApiConstants.ROUTE_LEVEL_NO_ROUTE_MODULE.equals(routeMethodName)) {
 78  0
                 return null;
 79  
         }
 80  0
         Object routeModule = GlobalResourceLoader.getObject(new ObjectDefinition(routeMethodName));//SpringServiceLocator.getExtensionService().getRouteModule(routeMethodName);
 81  0
         if (routeModule instanceof RouteModule) {
 82  0
             return (RouteModule)routeModule;
 83  
         }
 84  0
         throw new WorkflowRuntimeException("Could not locate the Route Module with the given name: " + routeMethodName);
 85  
     }
 86  
 
 87  
     private RouteModule getFlexRMRouteModule(String ruleTemplateName) {
 88  0
         return new FlexRMAdapter();
 89  
     }
 90  
 
 91  
     public void setPeopleFlowRouteModule(RouteModule peopleFlowRouteModule) {
 92  0
         this.peopleFlowRouteModule = peopleFlowRouteModule;
 93  0
     }
 94  
 
 95  
     public RouteModule getPeopleFlowRouteModule() {
 96  0
         return peopleFlowRouteModule;
 97  
     }
 98  
 
 99  
     public String getRulesEngineRouteModuleId() {
 100  0
         return rulesEngineRouteModuleId;
 101  
     }
 102  
 
 103  
     public void setRulesEngineRouteModuleId(String rulesEngineRouteModuleId) {
 104  0
         this.rulesEngineRouteModuleId = rulesEngineRouteModuleId;
 105  0
     }
 106  
 
 107  
     @Override
 108  
     public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
 109  0
         this.beanFactory = beanFactory;
 110  0
     }
 111  
 
 112  
     /**
 113  
      * Loaded lazily by id so as not to introduce a runtime dependency on KRMS when it is not in use.
 114  
      */
 115  
     protected RouteModule getRulesEngineRouteModule() {
 116  0
         if (rulesEngineRouteModule == null) {
 117  
             // this should initialize the route module in spring
 118  0
             rulesEngineRouteModule = (RouteModule)beanFactory.getBean(getRulesEngineRouteModuleId());
 119  
         }
 120  0
         return rulesEngineRouteModule;
 121  
     }
 122  
 
 123  
 }