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