View Javadoc

1   /**
2    * Copyright 2005-2012 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  public class RouteModuleServiceImpl implements RouteModuleService, BeanFactoryAware {
38  
39      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          String routeMethodName = node.getRouteMethodName();
49          LOG.debug("Finding route module for routeMethodName="+routeMethodName+" at route level "+node.getRouteNodeName());
50          RouteModule routeModule = null;
51          // default to FlexRM module if the routeMethodName is null
52          if (node.isRulesEngineNode()) {
53              routeModule = getRulesEngineRouteModule();
54          } else if (node.isPeopleFlowNode()) {
55              routeModule = getPeopleFlowRouteModule();
56          } else if (routeMethodName == null || node.isFlexRM()) {
57              routeModule = getFlexRMRouteModule(routeMethodName);
58          } else {
59              routeModule = getRouteModule(routeMethodName);
60          }
61          return routeModule;
62      }
63  
64      public RouteModule findRouteModule(ActionRequestValue actionRequest) throws ResourceUnavailableException {
65      	if (!actionRequest.getResolveResponsibility()) {
66      		return new RoleRouteModule();
67      	}
68          if (actionRequest.getNodeInstance() == null) {
69              return null;
70          }
71          return findRouteModule(actionRequest.getNodeInstance().getRouteNode());
72      }
73  
74      private RouteModule getRouteModule(String routeMethodName) throws ResourceUnavailableException {
75          if (routeMethodName == null) {
76              return null;
77          } else if ("".equals(routeMethodName.trim()) || KewApiConstants.ROUTE_LEVEL_NO_ROUTE_MODULE.equals(routeMethodName)) {
78                  return null;
79          }
80          Object routeModule = GlobalResourceLoader.getObject(new ObjectDefinition(routeMethodName));//SpringServiceLocator.getExtensionService().getRouteModule(routeMethodName);
81          if (routeModule instanceof RouteModule) {
82              return (RouteModule)routeModule;
83          }
84          throw new WorkflowRuntimeException("Could not locate the Route Module with the given name: " + routeMethodName);
85      }
86  
87      private RouteModule getFlexRMRouteModule(String ruleTemplateName) {
88          return new FlexRMAdapter();
89      }
90  
91      public void setPeopleFlowRouteModule(RouteModule peopleFlowRouteModule) {
92          this.peopleFlowRouteModule = peopleFlowRouteModule;
93      }
94  
95      public RouteModule getPeopleFlowRouteModule() {
96          return peopleFlowRouteModule;
97      }
98  
99      public String getRulesEngineRouteModuleId() {
100         return rulesEngineRouteModuleId;
101     }
102 
103     public void setRulesEngineRouteModuleId(String rulesEngineRouteModuleId) {
104         this.rulesEngineRouteModuleId = rulesEngineRouteModuleId;
105     }
106 
107     @Override
108     public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
109         this.beanFactory = beanFactory;
110     }
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         if (rulesEngineRouteModule == null) {
117             // this should initialize the route module in spring
118             rulesEngineRouteModule = (RouteModule)beanFactory.getBean(getRulesEngineRouteModuleId());
119         }
120         return rulesEngineRouteModule;
121     }
122 
123 }