1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.api.repository.action;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.CoreConstants;
20 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
21 import org.kuali.rice.core.api.mo.ModelBuilder;
22 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
23
24 import javax.xml.bind.annotation.XmlAccessType;
25 import javax.xml.bind.annotation.XmlAccessorType;
26 import javax.xml.bind.annotation.XmlAnyElement;
27 import javax.xml.bind.annotation.XmlElement;
28 import javax.xml.bind.annotation.XmlRootElement;
29 import javax.xml.bind.annotation.XmlType;
30 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
31 import java.io.Serializable;
32 import java.util.Collection;
33 import java.util.Collections;
34 import java.util.HashMap;
35 import java.util.Map;
36
37
38
39
40
41
42
43
44
45
46
47 @XmlRootElement(name = ActionDefinition.Constants.ROOT_ELEMENT_NAME)
48 @XmlAccessorType(XmlAccessType.NONE)
49 @XmlType(name = ActionDefinition.Constants.TYPE_NAME, propOrder = {
50 ActionDefinition.Elements.ID,
51 ActionDefinition.Elements.NAME,
52 ActionDefinition.Elements.NAMESPACE,
53 ActionDefinition.Elements.DESC,
54 ActionDefinition.Elements.TYPE_ID,
55 ActionDefinition.Elements.RULE_ID,
56 ActionDefinition.Elements.SEQUENCE_NUMBER,
57 ActionDefinition.Elements.ATTRIBUTES,
58 CoreConstants.CommonElements.VERSION_NUMBER,
59 CoreConstants.CommonElements.FUTURE_ELEMENTS
60 })
61 public final class ActionDefinition extends AbstractDataTransferObject implements ActionDefinitionContract {
62 private static final long serialVersionUID = 2783959459503209577L;
63
64 @XmlElement(name = Elements.ID, required=true)
65 private String id;
66 @XmlElement(name = Elements.NAME, required=true)
67 private String name;
68 @XmlElement(name = Elements.NAMESPACE, required=true)
69 private String namespace;
70 @XmlElement(name = Elements.DESC, required=true)
71 private String description;
72 @XmlElement(name = Elements.TYPE_ID, required=true)
73 private String typeId;
74 @XmlElement(name = Elements.RULE_ID, required=true)
75 private String ruleId;
76 @XmlElement(name = Elements.SEQUENCE_NUMBER, required=true)
77 private Integer sequenceNumber;
78
79 @XmlElement(name = Elements.ATTRIBUTES, required = false)
80 @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
81 private final Map<String, String> attributes;
82
83 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
84 private final Long versionNumber;
85
86 @SuppressWarnings("unused")
87 @XmlAnyElement
88 private final Collection<org.w3c.dom.Element> _futureElements = null;
89
90
91
92
93
94
95 private ActionDefinition() {
96 this.id = null;
97 this.name = null;
98 this.namespace = null;
99 this.description = null;
100 this.typeId = null;
101 this.ruleId = null;
102 this.sequenceNumber = null;
103 this.attributes = null;
104 this.versionNumber = null;
105 }
106
107
108
109
110
111
112
113 private ActionDefinition(Builder builder) {
114 this.id = builder.getId();
115 this.name = builder.getName();
116 this.namespace = builder.getNamespace();
117 this.description = builder.getDescription();
118 this.typeId = builder.getTypeId();
119 this.ruleId = builder.getRuleId();
120 this.sequenceNumber = builder.getSequenceNumber();
121 if (builder.attributes != null){
122 this.attributes = Collections.unmodifiableMap(builder.getAttributes());
123 } else {
124 this.attributes = null;
125 }
126 this.versionNumber = builder.getVersionNumber();
127 }
128
129 @Override
130 public String getId() {
131 return this.id;
132 }
133
134 @Override
135 public String getName() {
136 return this.name;
137 }
138
139 @Override
140 public String getNamespace() {
141 return this.namespace;
142 }
143
144 @Override
145 public String getDescription() {
146 return this.description;
147 }
148
149 @Override
150 public String getTypeId() {
151 return this.typeId;
152 }
153
154 @Override
155 public String getRuleId() {
156 return this.ruleId;
157 }
158
159 @Override
160 public Integer getSequenceNumber() {
161 return this.sequenceNumber;
162 }
163
164
165
166
167
168
169
170 @Override
171 public Map<String, String> getAttributes() {
172 return this.attributes;
173 }
174
175 @Override
176 public Long getVersionNumber() {
177 return versionNumber;
178 }
179
180
181
182
183 public static class Builder implements ActionDefinitionContract, ModelBuilder, Serializable {
184 private static final long serialVersionUID = -6773634512570180267L;
185
186 private String id;
187 private String name;
188 private String namespace;
189 private String description;
190 private String typeId;
191 private String ruleId;
192 private Integer sequenceNumber;
193 private Map<String, String> attributes;
194 private Long versionNumber;
195
196
197
198
199
200
201
202
203
204
205
206 private Builder(String actionId, String name, String namespace, String typeId, String ruleId, Integer sequenceNumber) {
207 setId(actionId);
208 setName(name);
209 setNamespace(namespace);
210 setTypeId(typeId);
211 setRuleId(ruleId);
212 setSequenceNumber(sequenceNumber);
213 setAttributes(new HashMap<String, String>());
214 }
215
216
217
218
219
220
221
222
223
224
225
226
227 public static Builder create(String actionId, String name, String namespace, String typeId, String ruleId, Integer sequenceNumber){
228 return new Builder(actionId, name, namespace, typeId, ruleId, sequenceNumber);
229 }
230
231
232
233
234
235
236
237 public static Builder create(ActionDefinitionContract contract) {
238 if (contract == null) {
239 throw new IllegalArgumentException("contract is null");
240 }
241 Builder builder = new Builder(contract.getId(), contract.getName(),
242 contract.getNamespace(), contract.getTypeId(), contract.getRuleId(),
243 contract.getSequenceNumber());
244 builder.setDescription(contract.getDescription());
245 if (contract.getAttributes() != null){
246 builder.setAttributes(new HashMap<String, String>(contract.getAttributes()));
247 }
248 builder.setVersionNumber(contract.getVersionNumber());
249 return builder;
250 }
251
252
253
254
255
256
257
258 public void setId(String actionId) {
259 if (actionId != null && StringUtils.isBlank(actionId)) {
260 throw new IllegalArgumentException("action ID must be null or non-blank");
261 }
262 this.id = actionId;
263 }
264
265
266
267
268
269
270
271
272 public void setName(String name) {
273 if (StringUtils.isBlank(name)) {
274 throw new IllegalArgumentException("name is blank");
275 }
276 this.name = name;
277 }
278
279
280
281
282
283
284
285 public void setNamespace(String namespace) {
286 if (StringUtils.isBlank(namespace)) {
287 throw new IllegalArgumentException("namespace is blank");
288 }
289 this.namespace = namespace;
290 }
291
292
293
294
295
296
297 public void setDescription(String desc) {
298 this.description = desc;
299 }
300
301
302
303
304
305
306
307 public void setTypeId(String typeId) {
308 if (StringUtils.isBlank(typeId)) {
309 throw new IllegalArgumentException("KRMS type id is blank");
310 }
311 this.typeId = typeId;
312 }
313
314
315
316
317
318
319
320 public void setRuleId(String ruleId) {
321 if (StringUtils.isBlank(ruleId)) {
322 throw new IllegalArgumentException("rule id is blank");
323 }
324 this.ruleId = ruleId;
325 }
326
327
328
329
330
331
332
333 public void setSequenceNumber(Integer sequenceNumber) {
334 if (sequenceNumber == null) {
335 throw new IllegalArgumentException("sequence number is null");
336 }
337 this.sequenceNumber = sequenceNumber;
338 }
339
340
341
342
343
344
345 public void setAttributes(Map<String, String> attributes){
346 if (attributes == null){
347 this.attributes = Collections.emptyMap();
348 }
349 this.attributes = Collections.unmodifiableMap(attributes);
350 }
351
352
353
354
355
356
357 public void setVersionNumber(Long versionNumber){
358 this.versionNumber = versionNumber;
359 }
360
361 @Override
362 public String getId() {
363 return id;
364 }
365
366 @Override
367 public String getName() {
368 return name;
369 }
370
371 @Override
372 public String getNamespace() {
373 return namespace;
374 }
375
376 @Override
377 public String getDescription() {
378 return description;
379 }
380
381 @Override
382 public String getTypeId() {
383 return typeId;
384 }
385
386 @Override
387 public String getRuleId() {
388 return ruleId;
389 }
390
391 @Override
392 public Integer getSequenceNumber() {
393 return sequenceNumber;
394 }
395
396 @Override
397 public Map<String, String> getAttributes() {
398 return attributes;
399 }
400
401 @Override
402 public Long getVersionNumber() {
403 return versionNumber;
404 }
405
406
407
408
409
410
411 @Override
412 public ActionDefinition build() {
413 return new ActionDefinition(this);
414 }
415
416 }
417
418
419
420
421 static class Constants {
422 final static String ROOT_ELEMENT_NAME = "action";
423 final static String TYPE_NAME = "ActionType";
424 }
425
426
427
428
429
430 public static class Elements {
431 final static String ID = "id";
432 final static String NAME = "name";
433 final static String NAMESPACE = "namespace";
434 final static String DESC = "description";
435 final static String TYPE_ID = "typeId";
436 final static String RULE_ID = "ruleId";
437 final static String SEQUENCE_NUMBER = "sequenceNumber";
438 final static String ATTRIBUTES = "attributes";
439 }
440
441 }