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 java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Map;
22
23 import javax.xml.xpath.XPathExpressionException;
24
25 import org.apache.commons.lang.ObjectUtils;
26 import org.apache.log4j.Logger;
27 import org.kuali.rice.kew.api.rule.RuleExtension;
28 import org.kuali.rice.kew.routeheader.DocumentContent;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 public abstract class GenericWorkflowAttribute extends AbstractWorkflowAttribute {
58 protected final Logger log = Logger.getLogger(getClass());
59 protected final String attributeName;
60 protected final GenericAttributeContent content;
61
62 public GenericWorkflowAttribute() {
63 this(null);
64 }
65
66 public GenericWorkflowAttribute(String uniqueName) {
67 if (uniqueName != null) {
68 this.attributeName = uniqueName;
69 } else {
70 this.attributeName = getClass().getName();
71 }
72 content = new GenericAttributeContent(attributeName);
73 }
74
75
76
77
78
79 public abstract Map<String, String> getProperties();
80
81
82
83
84 public String getDocContent() {
85 String dc = content.generateContent(getProperties());
86
87 return dc;
88 }
89
90 public boolean isMatch(DocumentContent docContent, List<RuleExtension> ruleExtensions) {
91 log.info("isMatch: " + docContent + " " + ruleExtensions);
92 try {
93
94 List<Map<String, String>> propertiesList = content.parseContent(docContent.getAttributeContent());
95
96 return isMatch(propertiesList, ruleExtensions);
97 } catch (XPathExpressionException xpee) {
98 String message = "Error parsing attribute '" + attributeName + "' content: " + docContent.getDocContent();
99 log.error(message, xpee);
100 throw new RuntimeException(xpee);
101 }
102 }
103
104
105
106
107
108
109
110 protected boolean isMatch(List<Map<String, String>> propertiesList, List<RuleExtension> ruleExtensions) {
111 for (Map<String, String> properties: propertiesList) {
112 return isMatch(properties, ruleExtensions);
113 }
114 return false;
115 }
116
117
118
119
120
121
122
123
124 protected boolean isMatch(Map<String, String> properties, List<RuleExtension> ruleExtensions) {
125 for (RuleExtension ruleExtension: ruleExtensions) {
126 for (Map.Entry<String, String> ruleExtensionValue: ruleExtension.getExtensionValuesMap().entrySet()) {
127 if (!ObjectUtils.equals(ruleExtensionValue.getValue(), properties.get(ruleExtensionValue.getKey()))) {
128 return false;
129 }
130 }
131 }
132 return true;
133 }
134
135
136
137
138
139
140
141 public List validateRoutingData(Map paramMap) {
142 return Collections.EMPTY_LIST;
143 }
144 public List validateRuleData(Map paramMap) {
145 return Collections.EMPTY_LIST;
146 }
147
148
149
150
151
152
153
154
155
156
157 public List<RuleExtensionValue> getRuleExtensionValues() {
158 log.info("getRuleExtensionValues");
159 List<RuleExtensionValue> exts = new ArrayList<RuleExtensionValue>();
160 Map<String, String> props = getProperties();
161 if (props != null) {
162 for (Map.Entry<String, String> entry: props.entrySet()) {
163 if (entry.getValue() != null) {
164 RuleExtensionValue ruleVal = new RuleExtensionValue();
165 ruleVal.setKey(entry.getKey());
166 ruleVal.setValue(entry.getValue());
167 exts.add(ruleVal);
168 }
169 }
170 }
171 return exts;
172 }
173 }