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.repository.context.ContextDefinitionContract;
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 @Override
157 public Map<String, String> getAttributes() {
158 return this.attributes;
159 }
160
161 @Override
162 public Long getVersionNumber() {
163 return versionNumber;
164 }
165
166
167
168
169 public static class Builder implements AgendaDefinitionContract, ModelBuilder, Serializable {
170
171 private static final long serialVersionUID = -8862851720709537839L;
172
173 private String id;
174 private String name;
175 private String typeId;
176 private String contextId;
177 private boolean active;
178 private String firstItemId;
179 private Map<String, String> attributes;
180 private Long versionNumber;
181
182
183
184
185 private Builder(String id, String name, String typeId, String contextId) {
186 setId(id);
187 setName(name);
188 setTypeId(typeId);
189 setContextId(contextId);
190 setActive(true);
191 setAttributes(new HashMap<String, String>());
192 }
193
194 public static Builder create(String id, String name, String typeId, String contextId){
195 return new Builder(id, name, typeId, contextId);
196 }
197
198
199
200
201
202
203 public static Builder create(AgendaDefinitionContract contract) {
204 if (contract == null) {
205 throw new IllegalArgumentException("contract is null");
206 }
207 Builder builder = new Builder(contract.getId(), contract.getName(), contract.getTypeId(), contract.getContextId());
208 builder.setActive(contract.isActive());
209 builder.setFirstItemId( contract.getFirstItemId() );
210 if (contract.getAttributes() != null) {
211 builder.setAttributes(new HashMap<String, String>(contract.getAttributes()));
212 }
213 builder.setVersionNumber(contract.getVersionNumber());
214 return builder;
215 }
216
217
218
219
220
221
222
223
224 public void setId(String agendaId) {
225 if (agendaId != null && StringUtils.isBlank(agendaId)) {
226 throw new IllegalArgumentException("agenda ID must be null or non-blank");
227 }
228 this.id = agendaId;
229 }
230
231 public void setName(String name) {
232 if (StringUtils.isBlank(name)) {
233 throw new IllegalArgumentException("name is blank");
234 }
235 this.name = name;
236 }
237
238 public void setTypeId(String typeId) {
239 this.typeId = typeId;
240 }
241
242 public void setContextId(String contextId) {
243 if (StringUtils.isBlank(contextId)) {
244 throw new IllegalArgumentException("context id is blank");
245 }
246 this.contextId = contextId;
247 }
248
249 public void setActive(boolean active) {
250 this.active = active;
251 }
252
253 public void setFirstItemId(String firstItemId) {
254 this.firstItemId = firstItemId;
255 }
256
257 public void setAttributes(Map<String, String> attributes){
258 if (attributes == null){
259 this.attributes = Collections.emptyMap();
260 }
261 this.attributes = Collections.unmodifiableMap(attributes);
262 }
263
264
265
266
267
268
269
270
271
272
273
274 public void setVersionNumber(Long versionNumber){
275 this.versionNumber = versionNumber;
276 }
277
278 @Override
279 public String getId() {
280 return id;
281 }
282
283 @Override
284 public String getName() {
285 return name;
286 }
287
288 @Override
289 public String getTypeId() {
290 return typeId;
291 }
292
293 @Override
294 public String getContextId() {
295 return contextId;
296 }
297
298 @Override
299 public boolean isActive() {
300 return active;
301 }
302
303 @Override
304 public String getFirstItemId() {
305 return firstItemId;
306 }
307
308 @Override
309 public Map<String, String> getAttributes() {
310 return attributes;
311 }
312
313 @Override
314 public Long getVersionNumber() {
315 return versionNumber;
316 }
317
318
319
320
321
322
323 @Override
324 public AgendaDefinition build() {
325 return new AgendaDefinition(this);
326 }
327
328 }
329
330
331
332
333 public static class Constants {
334 final static String ROOT_ELEMENT_NAME = "agenda";
335 final static String TYPE_NAME = "AgendaType";
336 final static String[] HASH_CODE_EQUALS_EXCLUDE = { "_futureElements" };
337 public final static String EVENT = "Event";
338 }
339
340
341
342
343
344 public static class Elements {
345 final static String AGENDA_ID = "id";
346 final static String NAME = "name";
347 final static String TYPE_ID = "typeId";
348 final static String CONTEXT_ID = "contextId";
349 final static String ACTIVE = "active";
350 final static String FIRST_ITEM_ID = "firstItemId";
351 final static String ATTRIBUTES = "attributes";
352 final static String ATTRIBUTE = "attribute";
353 }
354
355 }