1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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));
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
114
115 protected RouteModule getRulesEngineRouteModule() {
116 if (rulesEngineRouteModule == null) {
117
118 rulesEngineRouteModule = (RouteModule)beanFactory.getBean(getRulesEngineRouteModuleId());
119 }
120 return rulesEngineRouteModule;
121 }
122
123 }