1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.api.repository.agenda;
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 @XmlRootElement(name = AgendaDefinition.Constants.ROOT_ELEMENT_NAME)
46 @XmlAccessorType(XmlAccessType.NONE)
47 @XmlType(name = AgendaDefinition.Constants.TYPE_NAME, propOrder = {
48 AgendaDefinition.Elements.AGENDA_ID,
49 AgendaDefinition.Elements.NAME,
50 AgendaDefinition.Elements.TYPE_ID,
51 AgendaDefinition.Elements.CONTEXT_ID,
52 AgendaDefinition.Elements.ACTIVE,
53 AgendaDefinition.Elements.FIRST_ITEM_ID,
54 AgendaDefinition.Elements.ATTRIBUTES,
55 CoreConstants.CommonElements.VERSION_NUMBER,
56 CoreConstants.CommonElements.FUTURE_ELEMENTS
57 })
58 public final class AgendaDefinition extends AbstractDataTransferObject implements AgendaDefinitionContract {
59 private static final long serialVersionUID = 2783959459503209577L;
60
61 @XmlElement(name = Elements.AGENDA_ID, required = false)
62 private final String id;
63
64 @XmlElement(name = Elements.NAME, required = true)
65 private final String name;
66
67 @XmlElement(name = Elements.TYPE_ID, required = false)
68 private final String typeId;
69
70 @XmlElement(name = Elements.CONTEXT_ID, required = true)
71 private final String contextId;
72
73 @XmlElement(name = Elements.ACTIVE, required = false)
74 private final boolean active;
75
76 @XmlElement(name = Elements.FIRST_ITEM_ID, required = false)
77 private final String firstItemId;
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 private AgendaDefinition() {
95 this.id = null;
96 this.name = null;
97 this.typeId = null;
98 this.contextId = null;
99 this.active = true;
100 this.firstItemId = null;
101 this.attributes = null;
102 this.versionNumber = null;
103 }
104
105
106
107
108
109
110
111 private AgendaDefinition(Builder builder) {
112 this.id = builder.getId();
113 this.name = builder.getName();
114 this.typeId = builder.getTypeId();
115 this.contextId = builder.getContextId();
116 this.active = builder.isActive();
117 this.firstItemId = builder.getFirstItemId();
118 if (builder.getAttributes() != null){
119 this.attributes = Collections.unmodifiableMap(new HashMap<String, String>(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 getTypeId() {
138 return this.typeId;
139 }
140
141 @Override
142 public String getContextId(){
143 return this.contextId;
144 }
145
146 @Override
147 public boolean isActive() {
148 return this.active;
149 }
150
151 @Override
152 public String getFirstItemId(){
153 return this.firstItemId;
154 }
155
156
157
158
159
160
161
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 AgendaDefinitionContract, ModelBuilder, Serializable {
175
176 private static final long serialVersionUID = -8862851720709537839L;
177
178 private String id;
179 private String name;
180 private String typeId;
181 private String contextId;
182 private boolean active;
183 private String firstItemId;
184 private Map<String, String> attributes;
185 private Long versionNumber;
186
187
188
189
190 private Builder(String id, String name, String typeId, String contextId) {
191 setId(id);
192 setName(name);
193 setTypeId(typeId);
194 setContextId(contextId);
195 setActive(true);
196 setAttributes(new HashMap<String, String>());
197 }
198
199
200
201
202
203
204
205
206
207
208 public static Builder create(String id, String name, String typeId, String contextId){
209 return new Builder(id, name, typeId, contextId);
210 }
211
212
213
214
215
216
217
218
219 public static Builder create(AgendaDefinitionContract contract) {
220 if (contract == null) {
221 throw new IllegalArgumentException("contract is null");
222 }
223 Builder builder = new Builder(contract.getId(), contract.getName(), contract.getTypeId(), contract.getContextId());
224 builder.setActive(contract.isActive());
225 builder.setFirstItemId( contract.getFirstItemId() );
226 if (contract.getAttributes() != null) {
227 builder.setAttributes(new HashMap<String, String>(contract.getAttributes()));
228 }
229 builder.setVersionNumber(contract.getVersionNumber());
230 return builder;
231 }
232
233
234
235
236
237
238
239
240
241 public void setId(String agendaId) {
242 if (agendaId != null && StringUtils.isBlank(agendaId)) {
243 throw new IllegalArgumentException("agenda ID must be null or non-blank");
244 }
245 this.id = agendaId;
246 }
247
248
249
250
251
252
253
254 public void setName(String name) {
255 if (StringUtils.isBlank(name)) {
256 throw new IllegalArgumentException("name is blank");
257 }
258 this.name = name;
259 }
260
261
262
263
264
265 public void setTypeId(String typeId) {
266 this.typeId = typeId;
267 }
268
269
270
271
272
273
274
275 public void setContextId(String contextId) {
276 if (StringUtils.isBlank(contextId)) {
277 throw new IllegalArgumentException("context id is blank");
278 }
279 this.contextId = contextId;
280 }
281
282
283
284
285
286
287 public void setActive(boolean active) {
288 this.active = active;
289 }
290
291
292
293
294
295
296 public void setFirstItemId(String firstItemId) {
297 this.firstItemId = firstItemId;
298 }
299
300
301
302
303
304
305 public void setAttributes(Map<String, String> attributes){
306 if (attributes == null){
307 this.attributes = Collections.emptyMap();
308 } else {
309 this.attributes = Collections.unmodifiableMap(attributes);
310 }
311 }
312
313
314
315
316
317
318 public void setVersionNumber(Long versionNumber){
319 this.versionNumber = versionNumber;
320 }
321
322 @Override
323 public String getId() {
324 return id;
325 }
326
327 @Override
328 public String getName() {
329 return name;
330 }
331
332 @Override
333 public String getTypeId() {
334 return typeId;
335 }
336
337 @Override
338 public String getContextId() {
339 return contextId;
340 }
341
342 @Override
343 public boolean isActive() {
344 return active;
345 }
346
347 @Override
348 public String getFirstItemId() {
349 return firstItemId;
350 }
351
352 @Override
353 public Map<String, String> getAttributes() {
354 return attributes;
355 }
356
357 @Override
358 public Long getVersionNumber() {
359 return versionNumber;
360 }
361
362
363
364
365
366
367 @Override
368 public AgendaDefinition build() {
369 return new AgendaDefinition(this);
370 }
371
372 }
373
374
375
376
377 public static class Constants {
378 final static String ROOT_ELEMENT_NAME = "agenda";
379 final static String TYPE_NAME = "AgendaType";
380 final static String[] HASH_CODE_EQUALS_EXCLUDE = { "_futureElements" };
381 public final static String EVENT = "Event";
382 }
383
384
385
386
387
388 public static class Elements {
389 public final static String AGENDA_ID = "id";
390 final static String NAME = "name";
391 final static String TYPE_ID = "typeId";
392 final static String CONTEXT_ID = "contextId";
393 final static String ACTIVE = "active";
394 final static String FIRST_ITEM_ID = "firstItemId";
395 final static String ATTRIBUTES = "attributes";
396 final static String ATTRIBUTE = "attribute";
397 }
398
399 public static class Cache {
400 public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + AgendaDefinition.Constants.TYPE_NAME;
401 }
402 }