Clover Coverage Report - Implementation 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
17   81   5   8.5
6   44   0.29   2
2     2.5  
1    
 
  NamedRuleSelector       Line # 38 17 0% 5 25 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2007 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.rule;
17   
18    import java.sql.Timestamp;
19    import java.util.ArrayList;
20    import java.util.List;
21    import java.util.Map;
22   
23    import org.kuali.rice.kew.engine.RouteContext;
24    import org.kuali.rice.kew.engine.node.NodeState;
25    import org.kuali.rice.kew.engine.node.RouteNode;
26    import org.kuali.rice.kew.engine.node.RouteNodeInstance;
27    import org.kuali.rice.kew.exception.WorkflowException;
28    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
29    import org.kuali.rice.kew.service.KEWServiceLocator;
30    import org.kuali.rice.kew.util.KEWConstants;
31    import org.kuali.rice.kew.util.Utilities;
32   
33   
34    /**
35    * Rule selector that select a rule based on configured rule name
36    * @author Kuali Rice Team (rice.collab@kuali.org)
37    */
 
38    public class NamedRuleSelector implements RuleSelector {
39    /**
40    * The route node config param consulted to determine the rule name to select
41    */
42    public static final String RULE_NAME_CFG_KEY = "ruleName";
43   
44    /**
45    * @return the name of the rule that should be selected
46    */
 
47  0 toggle protected String getName(RouteContext context, DocumentRouteHeaderValue routeHeader,
48    RouteNodeInstance nodeInstance, String selectionCriterion, Timestamp effectiveDate) throws WorkflowException {
49  0 String ruleName = null;
50  0 RouteNode routeNodeDef = nodeInstance.getRouteNode();
51    // first check to see if there is a rule name configured on the node instance
52  0 NodeState ns = nodeInstance.getNodeState(KEWConstants.RULE_NAME_NODE_STATE_KEY);
53  0 if (ns != null) {
54  0 ruleName = ns.getValue();
55    } else {
56    // otherwise check the node def
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  0 toggle public List<Rule> selectRules(RouteContext context, DocumentRouteHeaderValue routeHeader,
64    RouteNodeInstance nodeInstance, String selectionCriterion, Timestamp effectiveDate) throws WorkflowException {
65   
66  0 String ruleName = getName(context, routeHeader, nodeInstance, selectionCriterion, effectiveDate);
67   
68  0 if (ruleName == null) {
69  0 throw new WorkflowException("No 'ruleName' configuration parameter present on route node definition: " + nodeInstance.getRouteNode());
70    }
71   
72  0 RuleBaseValues ruleDef = KEWServiceLocator.getRuleService().getRuleByName(ruleName);
73  0 if (ruleDef == null) {
74  0 throw new WorkflowException("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    }