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.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
32
33
34 class WorkflowAttributeRuleExpression implements RuleExpression {
35
36 public RuleExpressionResult evaluate(Rule rule, RouteContext context) {
37
38 org.kuali.rice.kew.api.rule.Rule ruleDefinition =
39 org.kuali.rice.kew.api.rule.Rule.Builder.create(rule.getDefinition()).build();
40 boolean match = isMatch(ruleDefinition, context.getDocumentContent());
41 if (match) {
42 return new RuleExpressionResult(rule, match, ruleDefinition.getRuleResponsibilities());
43 }
44 return new RuleExpressionResult(rule, match);
45 }
46
47 public boolean isMatch(org.kuali.rice.kew.api.rule.Rule ruleDefinition, DocumentContent docContent) {
48 if (ruleDefinition.getRuleTemplate() == null) {
49
50
51
52
53
54
55
56
57
58 return true;
59 }
60 RuleBaseValues rule = KEWServiceLocator.getRuleService().getRuleByName(ruleDefinition.getName());
61 for (RuleTemplateAttributeBo ruleTemplateAttribute : rule.getRuleTemplate().getActiveRuleTemplateAttributes()) {
62 if (!ruleTemplateAttribute.isWorkflowAttribute()) {
63 continue;
64 }
65 WorkflowRuleAttribute routingAttribute = (WorkflowRuleAttribute) ruleTemplateAttribute.getWorkflowAttribute();
66
67 RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
68 if (ruleAttribute.getType().equals(KewApiConstants.RULE_XML_ATTRIBUTE_TYPE)) {
69 ((GenericXMLRuleAttribute) routingAttribute).setExtensionDefinition(RuleAttribute.to(ruleAttribute));
70 }
71 String className = ruleAttribute.getResourceDescriptor();
72 List<RuleExtensionBo> editedRuleExtensions = new ArrayList();
73 for (RuleExtensionBo extension : rule.getRuleExtensions()) {
74 if (extension.getRuleTemplateAttribute().getRuleAttribute().getResourceDescriptor().equals(className)) {
75 editedRuleExtensions.add(extension);
76 }
77 }
78 if (!routingAttribute.isMatch(docContent, editedRuleExtensions)) {
79 return false;
80 }
81 }
82 return true;
83 }
84
85 }