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 | 0 | 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 | 0 | @SuppressWarnings("unused") |
87 | |
@XmlAnyElement |
88 | |
private final Collection<org.w3c.dom.Element> _futureElements = null; |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | 0 | private AgendaDefinition() { |
95 | 0 | this.id = null; |
96 | 0 | this.name = null; |
97 | 0 | this.typeId = null; |
98 | 0 | this.contextId = null; |
99 | 0 | this.active = false; |
100 | 0 | this.firstItemId = null; |
101 | 0 | this.attributes = null; |
102 | 0 | this.versionNumber = null; |
103 | 0 | } |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | 0 | private AgendaDefinition(Builder builder) { |
112 | 0 | this.id = builder.getId(); |
113 | 0 | this.name = builder.getName(); |
114 | 0 | this.typeId = builder.getTypeId(); |
115 | 0 | this.contextId = builder.getContextId(); |
116 | 0 | this.active = builder.isActive(); |
117 | 0 | this.firstItemId = builder.getFirstItemId(); |
118 | 0 | if (builder.getAttributes() != null){ |
119 | 0 | this.attributes = Collections.unmodifiableMap(new HashMap<String, String>(builder.getAttributes())); |
120 | |
} else { |
121 | 0 | this.attributes = null; |
122 | |
} |
123 | 0 | this.versionNumber = builder.getVersionNumber(); |
124 | 0 | } |
125 | |
|
126 | |
@Override |
127 | |
public String getId() { |
128 | 0 | return this.id; |
129 | |
} |
130 | |
|
131 | |
@Override |
132 | |
public String getName() { |
133 | 0 | return this.name; |
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
public String getTypeId() { |
138 | 0 | return this.typeId; |
139 | |
} |
140 | |
|
141 | |
@Override |
142 | |
public String getContextId(){ |
143 | 0 | return this.contextId; |
144 | |
} |
145 | |
|
146 | |
@Override |
147 | |
public boolean isActive() { |
148 | 0 | return this.active; |
149 | |
} |
150 | |
|
151 | |
@Override |
152 | |
public String getFirstItemId(){ |
153 | 0 | return this.firstItemId; |
154 | |
} |
155 | |
|
156 | |
@Override |
157 | |
public Map<String, String> getAttributes() { |
158 | 0 | return this.attributes; |
159 | |
} |
160 | |
|
161 | |
@Override |
162 | |
public Long getVersionNumber() { |
163 | 0 | return versionNumber; |
164 | |
} |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | 0 | 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 | 0 | private Builder(String id, String name, String typeId, String contextId) { |
186 | 0 | setId(id); |
187 | 0 | setName(name); |
188 | 0 | setTypeId(typeId); |
189 | 0 | setContextId(contextId); |
190 | 0 | setActive(true); |
191 | 0 | setAttributes(new HashMap<String, String>()); |
192 | 0 | } |
193 | |
|
194 | |
public static Builder create(String id, String name, String typeId, String contextId){ |
195 | 0 | return new Builder(id, name, typeId, contextId); |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
public static Builder create(AgendaDefinitionContract contract) { |
204 | 0 | if (contract == null) { |
205 | 0 | throw new IllegalArgumentException("contract is null"); |
206 | |
} |
207 | 0 | Builder builder = new Builder(contract.getId(), contract.getName(), contract.getTypeId(), contract.getContextId()); |
208 | 0 | builder.setActive(contract.isActive()); |
209 | 0 | builder.setFirstItemId( contract.getFirstItemId() ); |
210 | 0 | if (contract.getAttributes() != null) { |
211 | 0 | builder.setAttributes(new HashMap<String, String>(contract.getAttributes())); |
212 | |
} |
213 | 0 | builder.setVersionNumber(contract.getVersionNumber()); |
214 | 0 | return builder; |
215 | |
} |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
public void setId(String agendaId) { |
225 | 0 | if (agendaId != null && StringUtils.isBlank(agendaId)) { |
226 | 0 | throw new IllegalArgumentException("agenda ID must be null or non-blank"); |
227 | |
} |
228 | 0 | this.id = agendaId; |
229 | 0 | } |
230 | |
|
231 | |
public void setName(String name) { |
232 | 0 | if (StringUtils.isBlank(name)) { |
233 | 0 | throw new IllegalArgumentException("name is blank"); |
234 | |
} |
235 | 0 | this.name = name; |
236 | 0 | } |
237 | |
|
238 | |
public void setTypeId(String typeId) { |
239 | 0 | this.typeId = typeId; |
240 | 0 | } |
241 | |
|
242 | |
public void setContextId(String contextId) { |
243 | 0 | if (StringUtils.isBlank(contextId)) { |
244 | 0 | throw new IllegalArgumentException("context id is blank"); |
245 | |
} |
246 | 0 | this.contextId = contextId; |
247 | 0 | } |
248 | |
|
249 | |
public void setActive(boolean active) { |
250 | 0 | this.active = active; |
251 | 0 | } |
252 | |
|
253 | |
public void setFirstItemId(String firstItemId) { |
254 | 0 | this.firstItemId = firstItemId; |
255 | 0 | } |
256 | |
|
257 | |
public void setAttributes(Map<String, String> attributes){ |
258 | 0 | if (attributes == null){ |
259 | 0 | this.attributes = Collections.emptyMap(); |
260 | |
} |
261 | 0 | this.attributes = Collections.unmodifiableMap(attributes); |
262 | 0 | } |
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
public void setVersionNumber(Long versionNumber){ |
275 | 0 | this.versionNumber = versionNumber; |
276 | 0 | } |
277 | |
|
278 | |
@Override |
279 | |
public String getId() { |
280 | 0 | return id; |
281 | |
} |
282 | |
|
283 | |
@Override |
284 | |
public String getName() { |
285 | 0 | return name; |
286 | |
} |
287 | |
|
288 | |
@Override |
289 | |
public String getTypeId() { |
290 | 0 | return typeId; |
291 | |
} |
292 | |
|
293 | |
@Override |
294 | |
public String getContextId() { |
295 | 0 | return contextId; |
296 | |
} |
297 | |
|
298 | |
@Override |
299 | |
public boolean isActive() { |
300 | 0 | return active; |
301 | |
} |
302 | |
|
303 | |
@Override |
304 | |
public String getFirstItemId() { |
305 | 0 | return firstItemId; |
306 | |
} |
307 | |
|
308 | |
@Override |
309 | |
public Map<String, String> getAttributes() { |
310 | 0 | return attributes; |
311 | |
} |
312 | |
|
313 | |
@Override |
314 | |
public Long getVersionNumber() { |
315 | 0 | return versionNumber; |
316 | |
} |
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
@Override |
324 | |
public AgendaDefinition build() { |
325 | 0 | return new AgendaDefinition(this); |
326 | |
} |
327 | |
|
328 | |
} |
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | 0 | public static class Constants { |
334 | |
final static String ROOT_ELEMENT_NAME = "agenda"; |
335 | |
final static String TYPE_NAME = "AgendaType"; |
336 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { "_furutreElements" }; |
337 | |
public final static String EVENT = "Event"; |
338 | |
} |
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | 0 | 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 | |
} |