1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.api.rule; |
17 | |
|
18 | |
import org.apache.commons.collections.CollectionUtils; |
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.joda.time.DateTime; |
21 | |
import org.kuali.rice.core.api.CoreConstants; |
22 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
23 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
24 | |
import org.kuali.rice.kew.api.KewApiConstants; |
25 | |
import org.w3c.dom.Element; |
26 | |
|
27 | |
import javax.xml.bind.annotation.XmlAccessType; |
28 | |
import javax.xml.bind.annotation.XmlAccessorType; |
29 | |
import javax.xml.bind.annotation.XmlAnyElement; |
30 | |
import javax.xml.bind.annotation.XmlElement; |
31 | |
import javax.xml.bind.annotation.XmlRootElement; |
32 | |
import javax.xml.bind.annotation.XmlType; |
33 | |
import java.io.Serializable; |
34 | |
import java.util.ArrayList; |
35 | |
import java.util.Collection; |
36 | |
import java.util.Collections; |
37 | |
import java.util.HashMap; |
38 | |
import java.util.List; |
39 | |
import java.util.Map; |
40 | |
|
41 | 0 | @XmlRootElement(name = Rule.Constants.ROOT_ELEMENT_NAME) |
42 | |
@XmlAccessorType(XmlAccessType.NONE) |
43 | |
@XmlType(name = Rule.Constants.TYPE_NAME, propOrder = { |
44 | |
Rule.Elements.ID, |
45 | |
Rule.Elements.NAME, |
46 | |
Rule.Elements.RULE_TEMPLATE, |
47 | |
Rule.Elements.ACTIVE, |
48 | |
Rule.Elements.DESCRIPTION, |
49 | |
Rule.Elements.DOC_TYPE_NAME, |
50 | |
Rule.Elements.FROM_DATE, |
51 | |
Rule.Elements.TO_DATE, |
52 | |
Rule.Elements.FORCE_ACTION, |
53 | |
Rule.Elements.PREVIOUS_VERSION_ID, |
54 | |
Rule.Elements.RULE_RESPONSIBILITIES, |
55 | |
Rule.Elements.RULE_EXTENSIONS, |
56 | |
Rule.Elements.RULE_TEMPLATE_NAME, |
57 | |
Rule.Elements.RULE_EXPRESSION_DEF, |
58 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
59 | |
}) |
60 | 0 | public final class Rule |
61 | |
extends AbstractDataTransferObject |
62 | |
implements RuleContract |
63 | |
{ |
64 | |
@XmlElement(name = Elements.ID, required = false) |
65 | |
private final String id; |
66 | |
@XmlElement(name = Elements.NAME, required = false) |
67 | |
private final String name; |
68 | |
@XmlElement(name = Elements.RULE_TEMPLATE, required = false) |
69 | |
private final RuleTemplate ruleTemplate; |
70 | |
@XmlElement(name = Elements.ACTIVE, required = false) |
71 | |
private final boolean active; |
72 | |
@XmlElement(name = Elements.DESCRIPTION, required = false) |
73 | |
private final String description; |
74 | |
@XmlElement(name = Elements.DOC_TYPE_NAME, required = false) |
75 | |
private final String docTypeName; |
76 | |
@XmlElement(name = Elements.FROM_DATE, required = false) |
77 | |
private final DateTime fromDate; |
78 | |
@XmlElement(name = Elements.TO_DATE, required = false) |
79 | |
private final DateTime toDate; |
80 | |
@XmlElement(name = Elements.FORCE_ACTION, required = false) |
81 | |
private final boolean forceAction; |
82 | |
@XmlElement(name = Elements.PREVIOUS_VERSION_ID, required = false) |
83 | |
private final String previousRuleId; |
84 | |
@XmlElement(name = Elements.RULE_RESPONSIBILITIES, required = false) |
85 | |
private final List<RuleResponsibility> ruleResponsibilities; |
86 | |
@XmlElement(name = Elements.RULE_EXTENSIONS, required = false) |
87 | |
private final List<RuleExtension> ruleExtensions; |
88 | |
@XmlElement(name = Elements.RULE_TEMPLATE_NAME, required = false) |
89 | |
private final String ruleTemplateName; |
90 | |
@XmlElement(name = Elements.RULE_EXPRESSION_DEF, required = false) |
91 | |
private final RuleExpression ruleExpressionDef; |
92 | 0 | @SuppressWarnings("unused") |
93 | |
@XmlAnyElement |
94 | |
private final Collection<Element> _futureElements = null; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 0 | private Rule() { |
101 | 0 | this.id = null; |
102 | 0 | this.name = null; |
103 | 0 | this.ruleTemplate = null; |
104 | 0 | this.active = false; |
105 | 0 | this.description = null; |
106 | 0 | this.docTypeName = null; |
107 | 0 | this.fromDate = null; |
108 | 0 | this.toDate = null; |
109 | 0 | this.forceAction = false; |
110 | 0 | this.ruleResponsibilities = null; |
111 | 0 | this.ruleExtensions = null; |
112 | 0 | this.ruleTemplateName = null; |
113 | 0 | this.ruleExpressionDef = null; |
114 | 0 | this.previousRuleId = null; |
115 | 0 | } |
116 | |
|
117 | 0 | private Rule(Builder builder) { |
118 | 0 | this.id = builder.getId(); |
119 | 0 | this.name = builder.getName(); |
120 | 0 | this.ruleTemplate = builder.getRuleTemplate() == null ? null : builder.getRuleTemplate().build(); |
121 | 0 | this.active = builder.isActive(); |
122 | 0 | this.description = builder.getDescription(); |
123 | 0 | this.docTypeName = builder.getDocTypeName(); |
124 | 0 | this.fromDate = builder.getFromDate(); |
125 | 0 | this.toDate = builder.getToDate(); |
126 | 0 | this.forceAction = builder.isForceAction(); |
127 | 0 | if (CollectionUtils.isNotEmpty(builder.getRuleResponsibilities())) { |
128 | 0 | List<RuleResponsibility> responsibilities = new ArrayList<RuleResponsibility>(); |
129 | 0 | for (RuleResponsibility.Builder b : builder.getRuleResponsibilities()) { |
130 | 0 | responsibilities.add(b.build()); |
131 | |
} |
132 | 0 | this.ruleResponsibilities = responsibilities; |
133 | 0 | } else { |
134 | 0 | this.ruleResponsibilities = Collections.emptyList(); |
135 | |
} |
136 | 0 | if (CollectionUtils.isNotEmpty(builder.getRuleExtensions())) { |
137 | 0 | List<RuleExtension> extensions = new ArrayList<RuleExtension>(); |
138 | 0 | for (RuleExtension.Builder b : builder.getRuleExtensions()) { |
139 | 0 | extensions.add(b.build()); |
140 | |
} |
141 | 0 | this.ruleExtensions = extensions; |
142 | 0 | } else { |
143 | 0 | this.ruleExtensions = Collections.emptyList(); |
144 | |
} |
145 | 0 | this.ruleTemplateName = builder.getRuleTemplateName(); |
146 | 0 | this.ruleExpressionDef = builder.getRuleExpressionDef() == null ? null : builder.getRuleExpressionDef().build(); |
147 | 0 | this.previousRuleId = builder.getPreviousRuleId(); |
148 | 0 | } |
149 | |
|
150 | |
@Override |
151 | |
public String getId() { |
152 | 0 | return this.id; |
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public String getName() { |
157 | 0 | return this.name; |
158 | |
} |
159 | |
|
160 | |
@Override |
161 | |
public RuleTemplate getRuleTemplate() { |
162 | 0 | return this.ruleTemplate; |
163 | |
} |
164 | |
|
165 | |
@Override |
166 | |
public boolean isActive() { |
167 | 0 | return this.active; |
168 | |
} |
169 | |
|
170 | |
@Override |
171 | |
public String getDescription() { |
172 | 0 | return this.description; |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
public String getPreviousRuleId() { |
177 | 0 | return this.previousRuleId; |
178 | |
} |
179 | |
|
180 | |
@Override |
181 | |
public String getDocTypeName() { |
182 | 0 | return this.docTypeName; |
183 | |
} |
184 | |
|
185 | |
@Override |
186 | |
public DateTime getFromDate() { |
187 | 0 | return this.fromDate; |
188 | |
} |
189 | |
|
190 | |
@Override |
191 | |
public DateTime getToDate() { |
192 | 0 | return this.toDate; |
193 | |
} |
194 | |
|
195 | |
@Override |
196 | |
public boolean isForceAction() { |
197 | 0 | return this.forceAction; |
198 | |
} |
199 | |
|
200 | |
@Override |
201 | |
public List<RuleResponsibility> getRuleResponsibilities() { |
202 | 0 | return this.ruleResponsibilities; |
203 | |
} |
204 | |
|
205 | |
@Override |
206 | |
public List<RuleExtension> getRuleExtensions() { |
207 | 0 | return this.ruleExtensions; |
208 | |
} |
209 | |
|
210 | |
public Map<String, String> getRuleExtensionMap() { |
211 | 0 | Map<String, String> extensions = new HashMap<String, String>(); |
212 | 0 | for (RuleExtension ext : this.getRuleExtensions()) { |
213 | 0 | extensions.putAll(ext.getExtensionValuesMap()); |
214 | |
} |
215 | 0 | return Collections.unmodifiableMap(extensions); |
216 | |
} |
217 | |
|
218 | |
@Override |
219 | |
public String getRuleTemplateName() { |
220 | 0 | return this.ruleTemplateName; |
221 | |
} |
222 | |
|
223 | |
@Override |
224 | |
public RuleExpression getRuleExpressionDef() { |
225 | 0 | return this.ruleExpressionDef; |
226 | |
} |
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | 0 | public final static class Builder |
234 | |
implements Serializable, ModelBuilder, RuleContract |
235 | |
{ |
236 | |
private String id; |
237 | |
private String name; |
238 | |
private RuleTemplate.Builder ruleTemplate; |
239 | |
private boolean active; |
240 | |
private String description; |
241 | |
private String docTypeName; |
242 | |
private DateTime fromDate; |
243 | |
private DateTime toDate; |
244 | |
private boolean forceAction; |
245 | 0 | private List<RuleResponsibility.Builder> ruleResponsibilities = Collections.<RuleResponsibility.Builder>emptyList(); |
246 | 0 | private List<RuleExtension.Builder> ruleExtensions = Collections.emptyList(); |
247 | |
private String ruleTemplateName; |
248 | |
private String previousRuleId; |
249 | |
private RuleExpression.Builder ruleExpressionDef; |
250 | |
|
251 | 0 | private Builder() { |
252 | 0 | setActive(true); |
253 | 0 | } |
254 | |
|
255 | |
public static Builder create() { |
256 | 0 | return new Builder(); |
257 | |
} |
258 | |
|
259 | |
public static Builder create(RuleContract contract) { |
260 | 0 | if (contract == null) { |
261 | 0 | throw new IllegalArgumentException("contract was null"); |
262 | |
} |
263 | 0 | Builder builder = create(); |
264 | 0 | builder.setId(contract.getId()); |
265 | 0 | builder.setName(contract.getName()); |
266 | 0 | builder.setRuleTemplate( |
267 | |
contract.getRuleTemplate() == null ? null : RuleTemplate.Builder.create(contract.getRuleTemplate())); |
268 | 0 | builder.setActive(contract.isActive()); |
269 | 0 | builder.setDescription(contract.getDescription()); |
270 | 0 | builder.setDocTypeName(contract.getDocTypeName()); |
271 | 0 | builder.setFromDate(contract.getFromDate()); |
272 | 0 | builder.setToDate(contract.getToDate()); |
273 | 0 | builder.setForceAction(contract.isForceAction()); |
274 | 0 | builder.setPreviousRuleId(contract.getPreviousRuleId()); |
275 | 0 | if (CollectionUtils.isNotEmpty(contract.getRuleResponsibilities())) { |
276 | 0 | List<RuleResponsibility.Builder> responsibilityBuilders = new ArrayList<RuleResponsibility.Builder>(); |
277 | 0 | for (RuleResponsibilityContract c : contract.getRuleResponsibilities()) { |
278 | 0 | responsibilityBuilders.add(RuleResponsibility.Builder.create(c)); |
279 | |
} |
280 | 0 | builder.setRuleResponsibilities(responsibilityBuilders); |
281 | 0 | } else { |
282 | 0 | builder.setRuleResponsibilities(Collections.<RuleResponsibility.Builder>emptyList()); |
283 | |
} |
284 | 0 | if (CollectionUtils.isNotEmpty(contract.getRuleExtensions())) { |
285 | 0 | List<RuleExtension.Builder> extensionBuilders = new ArrayList<RuleExtension.Builder>(); |
286 | 0 | for (RuleExtensionContract c : contract.getRuleExtensions()) { |
287 | 0 | extensionBuilders.add(RuleExtension.Builder.create(c)); |
288 | |
} |
289 | 0 | builder.setRuleExtensions(extensionBuilders); |
290 | 0 | } else { |
291 | 0 | builder.setRuleExtensions(Collections.<RuleExtension.Builder>emptyList()); |
292 | |
} |
293 | 0 | builder.setRuleTemplateName(contract.getRuleTemplateName()); |
294 | 0 | if (contract.getRuleExpressionDef() != null) { |
295 | 0 | builder.setRuleExpressionDef(RuleExpression.Builder.create(contract.getRuleExpressionDef())); |
296 | |
} |
297 | 0 | return builder; |
298 | |
} |
299 | |
|
300 | |
public Rule build() { |
301 | 0 | return new Rule(this); |
302 | |
} |
303 | |
|
304 | |
@Override |
305 | |
public String getId() { |
306 | 0 | return this.id; |
307 | |
} |
308 | |
|
309 | |
@Override |
310 | |
public String getName() { |
311 | 0 | return this.name; |
312 | |
} |
313 | |
|
314 | |
@Override |
315 | |
public RuleTemplate.Builder getRuleTemplate() { |
316 | 0 | return this.ruleTemplate; |
317 | |
} |
318 | |
|
319 | |
@Override |
320 | |
public boolean isActive() { |
321 | 0 | return this.active; |
322 | |
} |
323 | |
|
324 | |
@Override |
325 | |
public String getDescription() { |
326 | 0 | return this.description; |
327 | |
} |
328 | |
|
329 | |
@Override |
330 | |
public String getDocTypeName() { |
331 | 0 | return this.docTypeName; |
332 | |
} |
333 | |
|
334 | |
@Override |
335 | |
public DateTime getFromDate() { |
336 | 0 | return this.fromDate; |
337 | |
} |
338 | |
|
339 | |
@Override |
340 | |
public DateTime getToDate() { |
341 | 0 | return this.toDate; |
342 | |
} |
343 | |
|
344 | |
@Override |
345 | |
public boolean isForceAction() { |
346 | 0 | return this.forceAction; |
347 | |
} |
348 | |
|
349 | |
@Override |
350 | |
public String getPreviousRuleId() { |
351 | 0 | return this.previousRuleId; |
352 | |
} |
353 | |
|
354 | |
@Override |
355 | |
public List<RuleResponsibility.Builder> getRuleResponsibilities() { |
356 | 0 | return this.ruleResponsibilities; |
357 | |
} |
358 | |
|
359 | |
@Override |
360 | |
public List<RuleExtension.Builder> getRuleExtensions() { |
361 | 0 | return this.ruleExtensions; |
362 | |
} |
363 | |
|
364 | |
@Override |
365 | |
public String getRuleTemplateName() { |
366 | 0 | return this.ruleTemplateName; |
367 | |
} |
368 | |
|
369 | |
@Override |
370 | |
public RuleExpression.Builder getRuleExpressionDef() { |
371 | 0 | return this.ruleExpressionDef; |
372 | |
} |
373 | |
|
374 | |
public void setId(String id) { |
375 | 0 | if (StringUtils.isWhitespace(id)) { |
376 | 0 | throw new IllegalArgumentException("id is blank"); |
377 | |
} |
378 | 0 | this.id = id; |
379 | 0 | } |
380 | |
|
381 | |
public void setName(String name) { |
382 | 0 | this.name = name; |
383 | 0 | } |
384 | |
public void setRuleTemplate(RuleTemplate.Builder ruleTemplate) { |
385 | 0 | this.ruleTemplate = ruleTemplate; |
386 | 0 | } |
387 | |
|
388 | |
public void setActive(boolean active) { |
389 | 0 | this.active = active; |
390 | 0 | } |
391 | |
|
392 | |
public void setDescription(String description) { |
393 | 0 | this.description = description; |
394 | 0 | } |
395 | |
|
396 | |
public void setDocTypeName(String docTypeName) { |
397 | 0 | this.docTypeName = docTypeName; |
398 | 0 | } |
399 | |
|
400 | |
public void setFromDate(DateTime fromDate) { |
401 | 0 | this.fromDate = fromDate; |
402 | 0 | } |
403 | |
|
404 | |
public void setToDate(DateTime toDate) { |
405 | 0 | this.toDate = toDate; |
406 | 0 | } |
407 | |
|
408 | |
public void setForceAction(boolean forceAction) { |
409 | 0 | this.forceAction = forceAction; |
410 | 0 | } |
411 | |
|
412 | |
public void setPreviousRuleId(String previousRuleId) { |
413 | 0 | this.previousRuleId = previousRuleId; |
414 | 0 | } |
415 | |
|
416 | |
public void setRuleResponsibilities(List<RuleResponsibility.Builder> ruleResponsibilities) { |
417 | 0 | this.ruleResponsibilities = Collections.unmodifiableList(ruleResponsibilities); |
418 | 0 | } |
419 | |
|
420 | |
public void setRuleExtensions(List<RuleExtension.Builder> ruleExtensions) { |
421 | 0 | this.ruleExtensions = Collections.unmodifiableList(ruleExtensions); |
422 | 0 | } |
423 | |
|
424 | |
public void setRuleTemplateName(String ruleTemplateName) { |
425 | 0 | this.ruleTemplateName = ruleTemplateName; |
426 | 0 | } |
427 | |
|
428 | |
public void setRuleExpressionDef(RuleExpression.Builder ruleExpressionDef) { |
429 | 0 | this.ruleExpressionDef = ruleExpressionDef; |
430 | 0 | } |
431 | |
|
432 | |
} |
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
|
439 | 0 | static class Constants { |
440 | |
|
441 | |
final static String ROOT_ELEMENT_NAME = "rule"; |
442 | |
final static String TYPE_NAME = "RuleType"; |
443 | |
|
444 | |
} |
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | 0 | static class Elements { |
452 | |
final static String ID = "id"; |
453 | |
final static String NAME = "name"; |
454 | |
final static String RULE_TEMPLATE = "ruleTemplate"; |
455 | |
final static String ACTIVE = "active"; |
456 | |
final static String DESCRIPTION = "description"; |
457 | |
final static String DOC_TYPE_NAME = "docTypeName"; |
458 | |
final static String FROM_DATE = "fromDate"; |
459 | |
final static String TO_DATE = "toDate"; |
460 | |
final static String FORCE_ACTION = "forceAction"; |
461 | |
final static String RULE_RESPONSIBILITIES = "ruleResponsibilities"; |
462 | |
final static String RULE_EXTENSIONS = "ruleExtensions"; |
463 | |
final static String RULE_TEMPLATE_NAME = "ruleTemplateName"; |
464 | |
final static String RULE_EXPRESSION_DEF = "ruleExpressionDef"; |
465 | |
final static String PREVIOUS_VERSION_ID = "previousRuleId"; |
466 | |
} |
467 | |
|
468 | 0 | public static class Cache { |
469 | |
public static final String NAME = KewApiConstants.Namespaces.KEW_NAMESPACE_2_0 + "/" + Rule.Constants.TYPE_NAME; |
470 | |
} |
471 | |
} |