Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WorkflowAttributeRuleExpression |
|
| 6.5;6.5 |
1 | /** | |
2 | * Copyright 2005-2011 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 org.kuali.rice.kew.engine.RouteContext; | |
19 | import org.kuali.rice.kew.routeheader.DocumentContent; | |
20 | import org.kuali.rice.kew.rule.bo.RuleAttribute; | |
21 | import org.kuali.rice.kew.rule.bo.RuleTemplateAttributeBo; | |
22 | import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute; | |
23 | import org.kuali.rice.kew.service.KEWServiceLocator; | |
24 | import org.kuali.rice.kew.api.KewApiConstants; | |
25 | ||
26 | import java.util.ArrayList; | |
27 | import java.util.List; | |
28 | ||
29 | ||
30 | /** | |
31 | * Standard rule expression implementation that evaluates the attributes associated with the rule definition | |
32 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
33 | */ | |
34 | 0 | class WorkflowAttributeRuleExpression implements RuleExpression { |
35 | ||
36 | public RuleExpressionResult evaluate(Rule rule, RouteContext context) { | |
37 | ||
38 | 0 | org.kuali.rice.kew.api.rule.Rule ruleDefinition = |
39 | org.kuali.rice.kew.api.rule.Rule.Builder.create(rule.getDefinition()).build(); | |
40 | 0 | boolean match = isMatch(ruleDefinition, context.getDocumentContent()); |
41 | 0 | if (match) { |
42 | 0 | return new RuleExpressionResult(rule, match, ruleDefinition.getRuleResponsibilities()); |
43 | } | |
44 | 0 | return new RuleExpressionResult(rule, match); |
45 | } | |
46 | ||
47 | public boolean isMatch(org.kuali.rice.kew.api.rule.Rule ruleDefinition, DocumentContent docContent) { | |
48 | 0 | if (ruleDefinition.getRuleTemplate() == null) { |
49 | // this can happen if neither rule template nor expression was specified in the rule definition | |
50 | // because WorkflowAttributeRuleExpression is the default expression implementation, we should | |
51 | // handle this here in order to support rules that fire unconditionally (and just return a statically | |
52 | // configured list of responsibilities) | |
53 | // the alternative is to either detect this situation in the rule xml parser or RuleImpl, and either substitute | |
54 | // a different RuleExpression implementation (a "default default" one) in the configuration, or at runtime, | |
55 | // that simply implements the one-liner of returning responsibilities. | |
56 | // doing this in the existing WorkflowAttributeRuleExpression implementation introduces the least change | |
57 | // or compatibilities issues, and avoids pushing compensating logic into RuleImpl | |
58 | 0 | return true; |
59 | } | |
60 | 0 | RuleBaseValues rule = KEWServiceLocator.getRuleService().getRuleByName(ruleDefinition.getName()); |
61 | 0 | for (RuleTemplateAttributeBo ruleTemplateAttribute : rule.getRuleTemplate().getActiveRuleTemplateAttributes()) { |
62 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
63 | 0 | continue; |
64 | } | |
65 | 0 | WorkflowRuleAttribute routingAttribute = (WorkflowRuleAttribute) ruleTemplateAttribute.getWorkflowAttribute(); |
66 | ||
67 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
68 | 0 | if (ruleAttribute.getType().equals(KewApiConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
69 | 0 | ((GenericXMLRuleAttribute) routingAttribute).setExtensionDefinition(RuleAttribute.to(ruleAttribute)); |
70 | } | |
71 | 0 | String className = ruleAttribute.getResourceDescriptor(); |
72 | 0 | List<RuleExtensionBo> editedRuleExtensions = new ArrayList(); |
73 | 0 | for (RuleExtensionBo extension : rule.getRuleExtensions()) { |
74 | 0 | if (extension.getRuleTemplateAttribute().getRuleAttribute().getResourceDescriptor().equals(className)) { |
75 | 0 | editedRuleExtensions.add(extension); |
76 | } | |
77 | } | |
78 | 0 | if (!routingAttribute.isMatch(docContent, editedRuleExtensions)) { |
79 | 0 | return false; |
80 | } | |
81 | 0 | } |
82 | 0 | return true; |
83 | } | |
84 | ||
85 | } |