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 | 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 | |
|
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)); |
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 | |
|
114 | |
|
115 | |
protected RouteModule getRulesEngineRouteModule() { |
116 | 0 | if (rulesEngineRouteModule == null) { |
117 | |
|
118 | 0 | rulesEngineRouteModule = (RouteModule)beanFactory.getBean(getRulesEngineRouteModuleId()); |
119 | |
} |
120 | 0 | return rulesEngineRouteModule; |
121 | |
} |
122 | |
|
123 | |
} |