1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.rule; |
17 | |
|
18 | |
import org.kuali.rice.core.api.exception.RiceIllegalStateException; |
19 | |
import org.kuali.rice.kew.api.KewApiServiceLocator; |
20 | |
import org.kuali.rice.kew.engine.RouteContext; |
21 | |
import org.kuali.rice.kew.engine.node.NodeState; |
22 | |
import org.kuali.rice.kew.engine.node.RouteNode; |
23 | |
import org.kuali.rice.kew.engine.node.RouteNodeInstance; |
24 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
25 | |
import org.kuali.rice.kew.api.KewApiConstants; |
26 | |
import org.kuali.rice.kew.util.Utilities; |
27 | |
|
28 | |
import java.sql.Timestamp; |
29 | |
import java.util.ArrayList; |
30 | |
import java.util.List; |
31 | |
import java.util.Map; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class NamedRuleSelector implements RuleSelector { |
39 | |
|
40 | |
|
41 | |
|
42 | |
public static final String RULE_NAME_CFG_KEY = "ruleName"; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
protected String getName(RouteContext context, DocumentRouteHeaderValue routeHeader, |
48 | |
RouteNodeInstance nodeInstance, String selectionCriterion, Timestamp effectiveDate) { |
49 | 0 | String ruleName = null; |
50 | 0 | RouteNode routeNodeDef = nodeInstance.getRouteNode(); |
51 | |
|
52 | 0 | NodeState ns = nodeInstance.getNodeState(KewApiConstants.RULE_NAME_NODE_STATE_KEY); |
53 | 0 | if (ns != null) { |
54 | 0 | ruleName = ns.getValue(); |
55 | |
} else { |
56 | |
|
57 | 0 | Map<String, String> routeNodeConfig = Utilities.getKeyValueCollectionAsMap(routeNodeDef.getConfigParams()); |
58 | 0 | ruleName = routeNodeConfig.get(RULE_NAME_CFG_KEY); |
59 | |
} |
60 | 0 | return ruleName; |
61 | |
} |
62 | |
|
63 | |
public List<Rule> selectRules(RouteContext context, DocumentRouteHeaderValue routeHeader, |
64 | |
RouteNodeInstance nodeInstance, String selectionCriterion, Timestamp effectiveDate) { |
65 | |
|
66 | 0 | String ruleName = getName(context, routeHeader, nodeInstance, selectionCriterion, effectiveDate); |
67 | |
|
68 | 0 | if (ruleName == null) { |
69 | 0 | throw new RiceIllegalStateException("No 'ruleName' configuration parameter present on route node definition: " + nodeInstance.getRouteNode()); |
70 | |
} |
71 | |
|
72 | 0 | org.kuali.rice.kew.api.rule.Rule ruleDef = KewApiServiceLocator.getRuleService().getRuleByName(ruleName); |
73 | 0 | if (ruleDef == null) { |
74 | 0 | throw new RiceIllegalStateException("No rule found with name '" + ruleName + "'"); |
75 | |
} |
76 | |
|
77 | 0 | List<Rule> rules = new ArrayList<Rule>(1); |
78 | 0 | rules.add(new RuleImpl(ruleDef)); |
79 | 0 | return rules; |
80 | |
} |
81 | |
} |