1 | |
package org.kuali.rice.krms.api.repository.agenda; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
import java.util.Collection; |
5 | |
import java.util.Collections; |
6 | |
import java.util.HashMap; |
7 | |
import java.util.Map; |
8 | |
|
9 | |
import javax.xml.bind.annotation.XmlAccessType; |
10 | |
import javax.xml.bind.annotation.XmlAccessorType; |
11 | |
import javax.xml.bind.annotation.XmlAnyElement; |
12 | |
import javax.xml.bind.annotation.XmlElement; |
13 | |
import javax.xml.bind.annotation.XmlRootElement; |
14 | |
import javax.xml.bind.annotation.XmlType; |
15 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
16 | |
|
17 | |
import org.apache.commons.lang.StringUtils; |
18 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
19 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
20 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
21 | |
import org.kuali.rice.core.api.CoreConstants; |
22 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
23 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
24 | |
import org.kuali.rice.core.util.jaxb.MapStringStringAdapter; |
25 | |
import org.kuali.rice.krms.api.repository.context.ContextDefinitionContract; |
26 | |
import org.kuali.rice.krms.api.repository.context.ContextDefinition.Builder; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
@XmlRootElement(name = AgendaDefinition.Constants.ROOT_ELEMENT_NAME) |
36 | |
@XmlAccessorType(XmlAccessType.NONE) |
37 | |
@XmlType(name = AgendaDefinition.Constants.TYPE_NAME, propOrder = { |
38 | |
AgendaDefinition.Elements.AGENDA_ID, |
39 | |
AgendaDefinition.Elements.NAME, |
40 | |
AgendaDefinition.Elements.NAMESPACE_CODE, |
41 | |
AgendaDefinition.Elements.TYPE_ID, |
42 | |
AgendaDefinition.Elements.CONTEXT_ID, |
43 | |
AgendaDefinition.Elements.ACTIVE, |
44 | |
AgendaDefinition.Elements.FIRST_ITEM_ID, |
45 | |
AgendaDefinition.Elements.ATTRIBUTES, |
46 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
47 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
48 | |
}) |
49 | 2 | public final class AgendaDefinition implements AgendaDefinitionContract, ModelObjectComplete{ |
50 | |
private static final long serialVersionUID = 2783959459503209577L; |
51 | |
|
52 | |
@XmlElement(name = Elements.AGENDA_ID, required = false) |
53 | |
private final String id; |
54 | |
|
55 | |
@XmlElement(name = Elements.NAME, required = true) |
56 | |
private final String name; |
57 | |
|
58 | |
@XmlElement(name = Elements.NAMESPACE_CODE, required = true) |
59 | |
private final String namespaceCode; |
60 | |
|
61 | |
@XmlElement(name = Elements.TYPE_ID, required = false) |
62 | |
private final String typeId; |
63 | |
|
64 | |
@XmlElement(name = Elements.CONTEXT_ID, required = true) |
65 | |
private final String contextId; |
66 | |
|
67 | |
@XmlElement(name = Elements.ACTIVE, required = false) |
68 | |
private final boolean active; |
69 | |
|
70 | |
@XmlElement(name = Elements.FIRST_ITEM_ID, required = false) |
71 | |
private final String firstItemId; |
72 | |
|
73 | |
@XmlElement(name = Elements.ATTRIBUTES, required = false) |
74 | |
@XmlJavaTypeAdapter(value = MapStringStringAdapter.class) |
75 | |
private final Map<String, String> attributes; |
76 | |
|
77 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
78 | |
private final Long versionNumber; |
79 | |
|
80 | 5 | @SuppressWarnings("unused") |
81 | |
@XmlAnyElement |
82 | |
private final Collection<org.w3c.dom.Element> _futureElements = null; |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | 3 | private AgendaDefinition() { |
89 | 3 | this.id = null; |
90 | 3 | this.name = null; |
91 | 3 | this.namespaceCode = null; |
92 | 3 | this.typeId = null; |
93 | 3 | this.contextId = null; |
94 | 3 | this.active = false; |
95 | 3 | this.firstItemId = null; |
96 | 3 | this.attributes = null; |
97 | 3 | this.versionNumber = null; |
98 | 3 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | 2 | private AgendaDefinition(Builder builder) { |
107 | 2 | this.id = builder.getId(); |
108 | 2 | this.name = builder.getName(); |
109 | 2 | this.namespaceCode = builder.getNamespaceCode(); |
110 | 2 | this.typeId = builder.getTypeId(); |
111 | 2 | this.contextId = builder.getContextId(); |
112 | 2 | this.active = builder.isActive(); |
113 | 2 | this.firstItemId = builder.getFirstItemId(); |
114 | 2 | if (builder.getAttributes() != null){ |
115 | 2 | this.attributes = Collections.unmodifiableMap(new HashMap<String, String>(builder.getAttributes())); |
116 | |
} else { |
117 | 0 | this.attributes = null; |
118 | |
} |
119 | 2 | this.versionNumber = builder.getVersionNumber(); |
120 | 2 | } |
121 | |
|
122 | |
@Override |
123 | |
public String getId() { |
124 | 1 | return this.id; |
125 | |
} |
126 | |
|
127 | |
@Override |
128 | |
public String getName() { |
129 | 0 | return this.name; |
130 | |
} |
131 | |
|
132 | |
@Override |
133 | |
public String getNamespaceCode() { |
134 | 0 | return this.namespaceCode; |
135 | |
} |
136 | |
|
137 | |
@Override |
138 | |
public String getTypeId() { |
139 | 0 | return this.typeId; |
140 | |
} |
141 | |
|
142 | |
@Override |
143 | |
public String getContextId(){ |
144 | 0 | return this.contextId; |
145 | |
} |
146 | |
|
147 | |
@Override |
148 | |
public boolean isActive() { |
149 | 0 | return this.active; |
150 | |
} |
151 | |
|
152 | |
@Override |
153 | |
public String getFirstItemId(){ |
154 | 0 | return this.firstItemId; |
155 | |
} |
156 | |
|
157 | |
@Override |
158 | |
public Map<String, String> getAttributes() { |
159 | 0 | return this.attributes; |
160 | |
} |
161 | |
|
162 | |
@Override |
163 | |
public Long getVersionNumber() { |
164 | 0 | return versionNumber; |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | 2 | public static class Builder implements AgendaDefinitionContract, ModelBuilder, Serializable { |
171 | |
|
172 | |
private static final long serialVersionUID = -8862851720709537839L; |
173 | |
|
174 | |
private String id; |
175 | |
private String name; |
176 | |
private String namespaceCode; |
177 | |
private String typeId; |
178 | |
private String contextId; |
179 | |
private boolean active; |
180 | |
private String firstItemId; |
181 | |
private Map<String, String> attributes; |
182 | |
private Long versionNumber; |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | 21 | private Builder(String id, String name, String namespaceCode, String typeId, String contextId) { |
188 | 21 | setId(id); |
189 | 19 | setName(name); |
190 | 15 | setNamespaceCode(namespaceCode); |
191 | 12 | setTypeId(typeId); |
192 | 9 | setContextId(contextId); |
193 | 6 | setActive(true); |
194 | 6 | setAttributes(new HashMap<String, String>()); |
195 | 6 | } |
196 | |
|
197 | |
public static Builder create(String id, String name, String namespaceCode, String typeId, String contextId){ |
198 | 21 | return new Builder(id, name, namespaceCode, typeId, contextId); |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
public static Builder create(AgendaDefinitionContract contract) { |
207 | 0 | if (contract == null) { |
208 | 0 | throw new IllegalArgumentException("contract is null"); |
209 | |
} |
210 | 0 | Builder builder = new Builder(contract.getId(), contract.getName(), |
211 | |
contract.getNamespaceCode(), contract.getTypeId(), contract.getContextId()); |
212 | 0 | builder.setActive(contract.isActive()); |
213 | 0 | builder.setFirstItemId( contract.getFirstItemId() ); |
214 | 0 | if (contract.getAttributes() != null) { |
215 | 0 | builder.setAttributes(new HashMap<String, String>(contract.getAttributes())); |
216 | |
} |
217 | 0 | builder.setVersionNumber(contract.getVersionNumber()); |
218 | 0 | return builder; |
219 | |
} |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
public void setId(String agendaId) { |
229 | 21 | if (agendaId != null && StringUtils.isBlank(agendaId)) { |
230 | 2 | throw new IllegalArgumentException("agenda ID must be null or non-blank"); |
231 | |
} |
232 | 19 | this.id = agendaId; |
233 | 19 | } |
234 | |
|
235 | |
public void setName(String name) { |
236 | 19 | if (StringUtils.isBlank(name)) { |
237 | 4 | throw new IllegalArgumentException("name is blank"); |
238 | |
} |
239 | 15 | this.name = name; |
240 | 15 | } |
241 | |
|
242 | |
public void setNamespaceCode(String namespaceCode) { |
243 | 15 | if (StringUtils.isBlank(namespaceCode)) { |
244 | 3 | throw new IllegalArgumentException("namespace is blank"); |
245 | |
} |
246 | 12 | this.namespaceCode = namespaceCode; |
247 | 12 | } |
248 | |
|
249 | |
public void setTypeId(String typeId) { |
250 | 12 | if (StringUtils.isBlank(typeId)) { |
251 | 3 | throw new IllegalArgumentException("KRMS type id is blank"); |
252 | |
} |
253 | 9 | this.typeId = typeId; |
254 | 9 | } |
255 | |
|
256 | |
public void setContextId(String contextId) { |
257 | 9 | if (StringUtils.isBlank(contextId)) { |
258 | 3 | throw new IllegalArgumentException("context id is blank"); |
259 | |
} |
260 | 6 | this.contextId = contextId; |
261 | 6 | } |
262 | |
|
263 | |
public void setActive(boolean active) { |
264 | 6 | this.active = active; |
265 | 6 | } |
266 | |
|
267 | |
public void setFirstItemId(String firstItemId) { |
268 | 4 | this.firstItemId = firstItemId; |
269 | 4 | } |
270 | |
|
271 | |
public void setAttributes(Map<String, String> attributes){ |
272 | 9 | if (attributes == null){ |
273 | 0 | this.attributes = Collections.emptyMap(); |
274 | |
} |
275 | 9 | this.attributes = Collections.unmodifiableMap(attributes); |
276 | 9 | } |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
public void setVersionNumber(Long versionNumber){ |
289 | 0 | this.versionNumber = versionNumber; |
290 | 0 | } |
291 | |
|
292 | |
@Override |
293 | |
public String getId() { |
294 | 2 | return id; |
295 | |
} |
296 | |
|
297 | |
@Override |
298 | |
public String getName() { |
299 | 2 | return name; |
300 | |
} |
301 | |
|
302 | |
@Override |
303 | |
public String getNamespaceCode() { |
304 | 2 | return namespaceCode; |
305 | |
} |
306 | |
|
307 | |
@Override |
308 | |
public String getTypeId() { |
309 | 2 | return typeId; |
310 | |
} |
311 | |
|
312 | |
@Override |
313 | |
public String getContextId() { |
314 | 2 | return contextId; |
315 | |
} |
316 | |
|
317 | |
@Override |
318 | |
public boolean isActive() { |
319 | 2 | return active; |
320 | |
} |
321 | |
|
322 | |
@Override |
323 | |
public String getFirstItemId() { |
324 | 2 | return firstItemId; |
325 | |
} |
326 | |
|
327 | |
@Override |
328 | |
public Map<String, String> getAttributes() { |
329 | 4 | return attributes; |
330 | |
} |
331 | |
|
332 | |
@Override |
333 | |
public Long getVersionNumber() { |
334 | 2 | return versionNumber; |
335 | |
} |
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
@Override |
343 | |
public AgendaDefinition build() { |
344 | 2 | return new AgendaDefinition(this); |
345 | |
} |
346 | |
|
347 | |
} |
348 | |
@Override |
349 | |
public int hashCode() { |
350 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
351 | |
} |
352 | |
|
353 | |
@Override |
354 | |
public boolean equals(Object obj) { |
355 | 1 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
356 | |
} |
357 | |
|
358 | |
@Override |
359 | |
public String toString() { |
360 | 0 | return ToStringBuilder.reflectionToString(this); |
361 | |
} |
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | 0 | public static class Constants { |
367 | |
final static String ROOT_ELEMENT_NAME = "agenda"; |
368 | |
final static String TYPE_NAME = "AgendaType"; |
369 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { "_furutreElements" }; |
370 | |
public final static String EVENT = "Event"; |
371 | |
} |
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | 0 | public static class Elements { |
378 | |
final static String AGENDA_ID = "id"; |
379 | |
final static String NAME = "name"; |
380 | |
final static String NAMESPACE_CODE = "namespaceCode"; |
381 | |
final static String TYPE_ID = "typeId"; |
382 | |
final static String CONTEXT_ID = "contextId"; |
383 | |
final static String ACTIVE = "active"; |
384 | |
final static String FIRST_ITEM_ID = "firstItemId"; |
385 | |
final static String ATTRIBUTES = "attributes"; |
386 | |
final static String ATTRIBUTE = "attribute"; |
387 | |
} |
388 | |
|
389 | |
} |