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.routeheader.DocumentContent;
28
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 public abstract class GenericWorkflowAttribute extends AbstractWorkflowAttribute {
57 protected final Logger log = Logger.getLogger(getClass());
58 protected final String attributeName;
59 protected final GenericAttributeContent content;
60
61 public GenericWorkflowAttribute() {
62 this(null);
63 }
64
65 public GenericWorkflowAttribute(String uniqueName) {
66 if (uniqueName != null) {
67 this.attributeName = uniqueName;
68 } else {
69 this.attributeName = getClass().getName();
70 }
71 content = new GenericAttributeContent(attributeName);
72 }
73
74
75
76
77
78 public abstract Map<String, String> getProperties();
79
80
81
82
83 public String getDocContent() {
84 String dc = content.generateContent(getProperties());
85
86 return dc;
87 }
88
89 public boolean isMatch(DocumentContent docContent, List<RuleExtensionBo> ruleExtensions) {
90 log.info("isMatch: " + docContent + " " + ruleExtensions);
91 try {
92
93 List<Map<String, String>> propertiesList = content.parseContent(docContent.getAttributeContent());
94
95 return isMatch(propertiesList, ruleExtensions);
96 } catch (XPathExpressionException xpee) {
97 String message = "Error parsing attribute '" + attributeName + "' content: " + docContent.getDocContent();
98 log.error(message, xpee);
99 throw new RuntimeException(xpee);
100 }
101 }
102
103
104
105
106
107
108
109 protected boolean isMatch(List<Map<String, String>> propertiesList, List<RuleExtensionBo> ruleExtensions) {
110 for (Map<String, String> properties: propertiesList) {
111 return isMatch(properties, ruleExtensions);
112 }
113 return false;
114 }
115
116
117
118
119
120
121
122
123 protected boolean isMatch(Map<String, String> properties, List<RuleExtensionBo> ruleExtensions) {
124 for (RuleExtensionBo ruleExtension: ruleExtensions) {
125 for (RuleExtensionValue ruleExtensionValue: ruleExtension.getExtensionValues()) {
126 if (!ObjectUtils.equals(ruleExtensionValue.getValue(), properties.get(ruleExtensionValue.getKey()))) {
127 return false;
128 }
129 }
130 }
131 return true;
132 }
133
134
135
136
137
138
139
140 public List validateRoutingData(Map paramMap) {
141 return Collections.EMPTY_LIST;
142 }
143 public List validateRuleData(Map paramMap) {
144 return Collections.EMPTY_LIST;
145 }
146
147
148
149
150
151
152
153
154
155
156 public List<RuleExtensionValue> getRuleExtensionValues() {
157 log.info("getRuleExtensionValues");
158 List<RuleExtensionValue> exts = new ArrayList<RuleExtensionValue>();
159 Map<String, String> props = getProperties();
160 if (props != null) {
161 for (Map.Entry<String, String> entry: props.entrySet()) {
162 if (entry.getValue() != null) {
163 RuleExtensionValue ruleVal = new RuleExtensionValue();
164 ruleVal.setKey(entry.getKey());
165 ruleVal.setValue(entry.getValue());
166 exts.add(ruleVal);
167 }
168 }
169 }
170 return exts;
171 }
172 }