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 java.io.Serializable;
19 import java.util.Collection;
20 import java.util.Map;
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlAnyElement;
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlType;
27 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
28
29 import org.apache.commons.lang.StringUtils;
30 import org.kuali.rice.core.api.CoreConstants;
31 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
32 import org.kuali.rice.core.api.mo.ModelBuilder;
33 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
34 import org.kuali.rice.kew.api.extension.ExtensionDefinition;
35 import org.w3c.dom.Element;
36
37 @XmlRootElement(name = RuleTemplateAttribute.Constants.ROOT_ELEMENT_NAME)
38 @XmlAccessorType(XmlAccessType.NONE)
39 @XmlType(name = RuleTemplateAttribute.Constants.TYPE_NAME, propOrder = {
40 RuleTemplateAttribute.Elements.DEFAULT_VALUE,
41 RuleTemplateAttribute.Elements.RULE_TEMPLATE_ID,
42 RuleTemplateAttribute.Elements.REQUIRED,
43 RuleTemplateAttribute.Elements.DISPLAY_ORDER,
44 RuleTemplateAttribute.Elements.RULE_ATTRIBUTE,
45 RuleTemplateAttribute.Elements.RULE_EXTENSIONS,
46 RuleTemplateAttribute.Elements.ID,
47 CoreConstants.CommonElements.VERSION_NUMBER,
48 CoreConstants.CommonElements.OBJECT_ID,
49 RuleTemplateAttribute.Elements.ACTIVE,
50 CoreConstants.CommonElements.FUTURE_ELEMENTS
51 })
52 public final class RuleTemplateAttribute
53 extends AbstractDataTransferObject
54 implements RuleTemplateAttributeContract,
55 Comparable<RuleTemplateAttribute>
56 {
57
58 @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
59 private final String defaultValue;
60 @XmlElement(name = Elements.RULE_TEMPLATE_ID, required = true)
61 private final String ruleTemplateId;
62 @XmlElement(name = Elements.REQUIRED, required = true)
63 private final boolean required;
64 @XmlElement(name = Elements.DISPLAY_ORDER, required = true)
65 private final Integer displayOrder;
66 @XmlElement(name = Elements.RULE_ATTRIBUTE, required = true)
67 private final ExtensionDefinition ruleAttribute;
68 @XmlElement(name = Elements.RULE_EXTENSIONS, required = false)
69 @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
70 private final Map<String, String> ruleExtensionMap;
71 @XmlElement(name = Elements.ID, required = false)
72 private final String id;
73 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
74 private final Long versionNumber;
75 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
76 private final String objectId;
77 @XmlElement(name = Elements.ACTIVE, required = true)
78 private final boolean active;
79 @SuppressWarnings("unused")
80 @XmlAnyElement
81 private final Collection<Element> _futureElements = null;
82
83
84
85
86
87 private RuleTemplateAttribute() {
88 this.defaultValue = null;
89 this.ruleTemplateId = null;
90 this.required = false;
91 this.displayOrder = null;
92 this.ruleAttribute = null;
93 this.ruleExtensionMap = null;
94 this.id = null;
95 this.versionNumber = null;
96 this.objectId = null;
97 this.active = false;
98 }
99
100 private RuleTemplateAttribute(Builder builder) {
101 this.defaultValue = builder.getDefaultValue();
102 this.ruleTemplateId = builder.getRuleTemplateId();
103 this.required = builder.isRequired();
104 this.displayOrder = builder.getDisplayOrder();
105 this.ruleAttribute = builder.getRuleAttribute() == null ? null : builder.getRuleAttribute().build();
106 this.ruleExtensionMap = builder.getRuleExtensionMap();
107 this.id = builder.getId();
108 this.versionNumber = builder.getVersionNumber();
109 this.objectId = builder.getObjectId();
110 this.active = builder.isActive();
111 }
112
113 @Override
114 public String getDefaultValue() {
115 return this.defaultValue;
116 }
117
118 @Override
119 public String getRuleTemplateId() {
120 return this.ruleTemplateId;
121 }
122
123 @Override
124 public boolean isRequired() {
125 return this.required;
126 }
127
128 @Override
129 public Integer getDisplayOrder() {
130 return this.displayOrder;
131 }
132
133 @Override
134 public ExtensionDefinition getRuleAttribute() {
135 return this.ruleAttribute;
136 }
137
138 @Override
139 public Map<String, String> getRuleExtensionMap() {
140 return this.ruleExtensionMap;
141 }
142
143 @Override
144 public String getId() {
145 return this.id;
146 }
147
148 @Override
149 public Long getVersionNumber() {
150 return this.versionNumber;
151 }
152
153 @Override
154 public String getObjectId() {
155 return this.objectId;
156 }
157
158 @Override
159 public boolean isActive() {
160 return this.active;
161 }
162
163 public int compareTo(RuleTemplateAttribute ruleTemplateAttribute) {
164 if ((this.getDisplayOrder() != null) && (ruleTemplateAttribute.getDisplayOrder() != null)) {
165 return this.getDisplayOrder().compareTo(ruleTemplateAttribute.getDisplayOrder());
166 }
167 return 0;
168 }
169
170
171
172
173
174
175 public final static class Builder
176 implements Serializable, ModelBuilder, RuleTemplateAttributeContract
177 {
178
179 private String defaultValue;
180 private String ruleTemplateId;
181 private boolean required;
182 private Integer displayOrder;
183 private ExtensionDefinition.Builder ruleAttribute;
184 private Map<String, String> ruleExtensionMap;
185 private String id;
186 private Long versionNumber;
187 private String objectId;
188 private boolean active;
189
190 private Builder(String ruleTemplateId,
191 ExtensionDefinition.Builder ruleAttribute,
192 boolean required,
193 Integer displayOrder) {
194 setActive(true);
195 setRuleTemplateId(ruleTemplateId);
196 setRuleAttribute(ruleAttribute);
197 setRequired(required);
198 setDisplayOrder(displayOrder);
199 }
200
201 public static Builder create(String ruleTemplateId,
202 ExtensionDefinition.Builder ruleAttribute,
203 boolean required,
204 Integer displayOrder) {
205 return new Builder(ruleTemplateId, ruleAttribute, required, displayOrder);
206 }
207
208 public static Builder create(RuleTemplateAttributeContract contract) {
209 if (contract == null) {
210 throw new IllegalArgumentException("contract was null");
211 }
212 Builder builder = create(contract.getRuleTemplateId(),
213 contract.getRuleAttribute() == null ? null : ExtensionDefinition.Builder.create(contract.getRuleAttribute()),
214 contract.isRequired(),
215 contract.getDisplayOrder());
216 builder.setDefaultValue(contract.getDefaultValue());
217 builder.setRuleExtensionMap(contract.getRuleExtensionMap());
218 builder.setId(contract.getId());
219 builder.setVersionNumber(contract.getVersionNumber());
220 builder.setObjectId(contract.getObjectId());
221 builder.setActive(contract.isActive());
222 return builder;
223 }
224
225 @Override
226 public RuleTemplateAttribute build() {
227 return new RuleTemplateAttribute(this);
228 }
229
230 @Override
231 public String getDefaultValue() {
232 return this.defaultValue;
233 }
234
235 @Override
236 public String getRuleTemplateId() {
237 return this.ruleTemplateId;
238 }
239
240 @Override
241 public boolean isRequired() {
242 return this.required;
243 }
244
245 @Override
246 public Integer getDisplayOrder() {
247 return this.displayOrder;
248 }
249
250 @Override
251 public ExtensionDefinition.Builder getRuleAttribute() {
252 return this.ruleAttribute;
253 }
254
255 @Override
256 public Map<String, String> getRuleExtensionMap() {
257 return this.ruleExtensionMap;
258 }
259
260 @Override
261 public String getId() {
262 return this.id;
263 }
264
265 @Override
266 public Long getVersionNumber() {
267 return this.versionNumber;
268 }
269
270 @Override
271 public String getObjectId() {
272 return this.objectId;
273 }
274
275 @Override
276 public boolean isActive() {
277 return this.active;
278 }
279
280 public void setDefaultValue(String defaultValue) {
281 this.defaultValue = defaultValue;
282 }
283
284 public void setRuleTemplateId(String ruleTemplateId) {
285 if (StringUtils.isBlank(ruleTemplateId)) {
286 throw new IllegalArgumentException("ruleTemplateId was null or blank");
287 }
288 this.ruleTemplateId = ruleTemplateId;
289 }
290
291 public void setRequired(boolean required) {
292 this.required = required;
293 }
294
295 public void setDisplayOrder(Integer displayOrder) {
296 if (displayOrder == null) {
297 throw new IllegalArgumentException("displayOrder was null");
298 }
299 this.displayOrder = displayOrder;
300 }
301
302 public void setRuleAttribute(ExtensionDefinition.Builder ruleAttribute) {
303 if (ruleAttribute == null) {
304 throw new IllegalArgumentException("ruleAttribute was null");
305 }
306 this.ruleAttribute = ruleAttribute;
307 }
308
309 public void setRuleExtensionMap(Map<String, String> ruleExtensionMap) {
310 this.ruleExtensionMap = ruleExtensionMap;
311 }
312
313 public void setId(String id) {
314 if (StringUtils.isWhitespace(id)) {
315 throw new IllegalArgumentException("id was whitespace");
316 }
317 this.id = id;
318 }
319
320 public void setVersionNumber(Long versionNumber) {
321 this.versionNumber = versionNumber;
322 }
323
324 public void setObjectId(String objectId) {
325 this.objectId = objectId;
326 }
327
328 public void setActive(boolean active) {
329 this.active = active;
330 }
331
332 }
333
334
335
336
337
338
339 static class Constants {
340
341 final static String ROOT_ELEMENT_NAME = "ruleTemplateAttribute";
342 final static String TYPE_NAME = "RuleTemplateAttributeType";
343
344 }
345
346
347
348
349
350
351 static class Elements {
352
353 final static String DEFAULT_VALUE = "defaultValue";
354 final static String RULE_TEMPLATE_ID = "ruleTemplateId";
355 final static String RULE_ATTRIBUTE_ID = "ruleAttributeId";
356 final static String REQUIRED = "required";
357 final static String DISPLAY_ORDER = "displayOrder";
358 final static String RULE_ATTRIBUTE = "ruleAttribute";
359 final static String RULE_EXTENSIONS = "ruleExtensionMap";
360 final static String ID = "id";
361 final static String ACTIVE = "active";
362
363 }
364
365 }