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