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 @XmlRootElement(name = ActionDefinition.Constants.ROOT_ELEMENT_NAME)
45 @XmlAccessorType(XmlAccessType.NONE)
46 @XmlType(name = ActionDefinition.Constants.TYPE_NAME, propOrder = {
47 ActionDefinition.Elements.ID,
48 ActionDefinition.Elements.NAME,
49 ActionDefinition.Elements.NAMESPACE,
50 ActionDefinition.Elements.DESC,
51 ActionDefinition.Elements.TYPE_ID,
52 ActionDefinition.Elements.RULE_ID,
53 ActionDefinition.Elements.SEQUENCE_NUMBER,
54 ActionDefinition.Elements.ATTRIBUTES,
55 CoreConstants.CommonElements.VERSION_NUMBER,
56 CoreConstants.CommonElements.FUTURE_ELEMENTS
57 })
58 public final class ActionDefinition extends AbstractDataTransferObject implements ActionDefinitionContract {
59 private static final long serialVersionUID = 2783959459503209577L;
60
61 @XmlElement(name = Elements.ID, required=true)
62 private String id;
63 @XmlElement(name = Elements.NAME, required=true)
64 private String name;
65 @XmlElement(name = Elements.NAMESPACE, required=true)
66 private String namespace;
67 @XmlElement(name = Elements.DESC, required=true)
68 private String description;
69 @XmlElement(name = Elements.TYPE_ID, required=true)
70 private String typeId;
71 @XmlElement(name = Elements.RULE_ID, required=true)
72 private String ruleId;
73 @XmlElement(name = Elements.SEQUENCE_NUMBER, required=true)
74 private Integer sequenceNumber;
75
76 @XmlElement(name = Elements.ATTRIBUTES, required = false)
77 @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
78 private final Map<String, String> attributes;
79
80 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
81 private final Long versionNumber;
82
83 @SuppressWarnings("unused")
84 @XmlAnyElement
85 private final Collection<org.w3c.dom.Element> _futureElements = null;
86
87
88
89
90
91
92 private ActionDefinition() {
93 this.id = null;
94 this.name = null;
95 this.namespace = null;
96 this.description = null;
97 this.typeId = null;
98 this.ruleId = null;
99 this.sequenceNumber = null;
100 this.attributes = null;
101 this.versionNumber = null;
102 }
103
104
105
106
107
108
109
110 private ActionDefinition(Builder builder) {
111 this.id = builder.getId();
112 this.name = builder.getName();
113 this.namespace = builder.getNamespace();
114 this.description = builder.getDescription();
115 this.typeId = builder.getTypeId();
116 this.ruleId = builder.getRuleId();
117 this.sequenceNumber = builder.getSequenceNumber();
118 if (builder.attributes != null){
119 this.attributes = Collections.unmodifiableMap(builder.getAttributes());
120 } else {
121 this.attributes = null;
122 }
123 this.versionNumber = builder.getVersionNumber();
124 }
125
126 @Override
127 public String getId() {
128 return this.id;
129 }
130
131 @Override
132 public String getName() {
133 return this.name;
134 }
135
136 @Override
137 public String getNamespace() {
138 return this.namespace;
139 }
140
141 @Override
142 public String getDescription() {
143 return this.description;
144 }
145
146 @Override
147 public String getTypeId() {
148 return this.typeId;
149 }
150
151 @Override
152 public String getRuleId() {
153 return this.ruleId;
154 }
155
156 @Override
157 public Integer getSequenceNumber() {
158 return this.sequenceNumber;
159 }
160
161 @Override
162 public Map<String, String> getAttributes() {
163 return this.attributes;
164 }
165
166 @Override
167 public Long getVersionNumber() {
168 return versionNumber;
169 }
170
171
172
173
174 public static class Builder implements ActionDefinitionContract, ModelBuilder, Serializable {
175 private static final long serialVersionUID = -6773634512570180267L;
176
177 private String id;
178 private String name;
179 private String namespace;
180 private String description;
181 private String typeId;
182 private String ruleId;
183 private Integer sequenceNumber;
184 private Map<String, String> attributes;
185 private Long versionNumber;
186
187
188
189
190 private Builder(String actionId, String name, String namespace, String typeId, String ruleId, Integer sequenceNumber) {
191 setId(actionId);
192 setName(name);
193 setNamespace(namespace);
194 setTypeId(typeId);
195 setRuleId(ruleId);
196 setSequenceNumber(sequenceNumber);
197 setAttributes(new HashMap<String, String>());
198 }
199
200 public static Builder create(String actionId, String name, String namespace, String typeId, String ruleId, Integer sequenceNumber){
201 return new Builder(actionId, name, namespace, typeId, ruleId, sequenceNumber);
202 }
203
204
205
206
207
208
209 public static Builder create(ActionDefinitionContract contract) {
210 if (contract == null) {
211 throw new IllegalArgumentException("contract is null");
212 }
213 Builder builder = new Builder(contract.getId(), contract.getName(),
214 contract.getNamespace(), contract.getTypeId(), contract.getRuleId(),
215 contract.getSequenceNumber());
216 builder.setDescription(contract.getDescription());
217 if (contract.getAttributes() != null){
218 builder.setAttributes(new HashMap<String, String>(contract.getAttributes()));
219 }
220 builder.setVersionNumber(contract.getVersionNumber());
221 return builder;
222 }
223
224
225
226
227
228
229
230
231 public void setId(String actionId) {
232 if (actionId != null && StringUtils.isBlank(actionId)) {
233 throw new IllegalArgumentException("action ID must be null or non-blank");
234 }
235 this.id = actionId;
236 }
237
238
239 public void setName(String name) {
240 if (StringUtils.isBlank(name)) {
241 throw new IllegalArgumentException("name is blank");
242 }
243 this.name = name;
244 }
245
246 public void setNamespace(String namespace) {
247 if (StringUtils.isBlank(namespace)) {
248 throw new IllegalArgumentException("namespace is blank");
249 }
250 this.namespace = namespace;
251 }
252
253 public void setDescription(String desc) {
254 this.description = desc;
255 }
256
257 public void setTypeId(String typeId) {
258 if (StringUtils.isBlank(typeId)) {
259 throw new IllegalArgumentException("KRMS type id is blank");
260 }
261 this.typeId = typeId;
262 }
263
264 public void setRuleId(String ruleId) {
265 if (StringUtils.isBlank(ruleId)) {
266 throw new IllegalArgumentException("rule id is blank");
267 }
268 this.ruleId = ruleId;
269 }
270
271 public void setSequenceNumber(Integer sequenceNumber) {
272 if (sequenceNumber == null) {
273 throw new IllegalArgumentException("sequence number is null");
274 }
275 this.sequenceNumber = sequenceNumber;
276 }
277
278 public void setAttributes(Map<String, String> attributes){
279 if (attributes == null){
280 this.attributes = Collections.emptyMap();
281 }
282 this.attributes = Collections.unmodifiableMap(attributes);
283 }
284
285 public void setVersionNumber(Long versionNumber){
286 this.versionNumber = versionNumber;
287 }
288
289 @Override
290 public String getId() {
291 return id;
292 }
293
294 @Override
295 public String getName() {
296 return name;
297 }
298
299 @Override
300 public String getNamespace() {
301 return namespace;
302 }
303
304 @Override
305 public String getDescription() {
306 return description;
307 }
308
309 @Override
310 public String getTypeId() {
311 return typeId;
312 }
313
314 @Override
315 public String getRuleId() {
316 return ruleId;
317 }
318
319 @Override
320 public Integer getSequenceNumber() {
321 return sequenceNumber;
322 }
323
324 @Override
325 public Map<String, String> getAttributes() {
326 return attributes;
327 }
328
329 @Override
330 public Long getVersionNumber() {
331 return versionNumber;
332 }
333
334
335
336
337
338
339 @Override
340 public ActionDefinition build() {
341 return new ActionDefinition(this);
342 }
343
344 }
345
346
347
348
349 static class Constants {
350 final static String ROOT_ELEMENT_NAME = "action";
351 final static String TYPE_NAME = "ActionType";
352 }
353
354
355
356
357
358 public static class Elements {
359 final static String ID = "id";
360 final static String NAME = "name";
361 final static String NAMESPACE = "namespace";
362 final static String DESC = "description";
363 final static String TYPE_ID = "typeId";
364 final static String RULE_ID = "ruleId";
365 final static String SEQUENCE_NUMBER = "sequenceNumber";
366 final static String ATTRIBUTES = "attributes";
367 }
368
369 }