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