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 com.google.common.collect.Maps; |
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.CoreConstants; |
21 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
22 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
23 | |
import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter; |
24 | |
import org.kuali.rice.kim.api.common.template.Template; |
25 | |
import org.w3c.dom.Element; |
26 | |
|
27 | |
import javax.xml.bind.annotation.XmlAccessType; |
28 | |
import javax.xml.bind.annotation.XmlAccessorType; |
29 | |
import javax.xml.bind.annotation.XmlAnyElement; |
30 | |
import javax.xml.bind.annotation.XmlElement; |
31 | |
import javax.xml.bind.annotation.XmlRootElement; |
32 | |
import javax.xml.bind.annotation.XmlType; |
33 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
34 | |
import java.io.Serializable; |
35 | |
import java.util.Collection; |
36 | |
import java.util.Collections; |
37 | |
import java.util.Map; |
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 | 4 | public final class Responsibility extends AbstractDataTransferObject implements ResponsibilityContract { |
61 | |
|
62 | |
private static final long serialVersionUID = 1L; |
63 | |
|
64 | |
@XmlElement(name = Responsibility.Elements.ID, required = false) |
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 = Responsibility.Elements.ATTRIBUTES, required = false) |
80 | |
@XmlJavaTypeAdapter(value = MapStringStringAdapter.class) |
81 | |
private final Map<String, String> attributes; |
82 | |
|
83 | |
@XmlElement(name = Responsibility.Elements.ACTIVE, required = false) |
84 | |
private boolean active; |
85 | |
|
86 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
87 | |
private final Long versionNumber; |
88 | |
|
89 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
90 | |
private final String objectId; |
91 | |
|
92 | 6 | @SuppressWarnings("unused") |
93 | |
@XmlAnyElement |
94 | |
private final Collection<Element> _futureElements = null; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 2 | private Responsibility() { |
101 | 2 | this.id = null; |
102 | 2 | this.namespaceCode = null; |
103 | 2 | this.name = null; |
104 | 2 | this.description = null; |
105 | 2 | this.template = null; |
106 | 2 | this.attributes = null; |
107 | 2 | this.active = false; |
108 | 2 | this.versionNumber = Long.valueOf(1L); |
109 | 2 | this.objectId = null; |
110 | 2 | } |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | 4 | private Responsibility(Builder builder) { |
118 | 4 | this.id = builder.getId(); |
119 | 4 | this.namespaceCode = builder.getNamespaceCode(); |
120 | 4 | this.name = builder.getName(); |
121 | 4 | this.description = builder.getDescription(); |
122 | 4 | this.template = builder.getTemplate().build(); |
123 | 4 | this.attributes = builder.getAttributes() != null ? builder.getAttributes() : Collections.<String, String>emptyMap(); |
124 | 4 | this.active = builder.isActive(); |
125 | 4 | this.versionNumber = builder.getVersionNumber(); |
126 | 4 | this.objectId = builder.getObjectId(); |
127 | 4 | } |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
@Override |
133 | |
public String getId() { |
134 | 1 | return id; |
135 | |
} |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
@Override |
141 | |
public String getNamespaceCode() { |
142 | 1 | return namespaceCode; |
143 | |
} |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
@Override |
149 | |
public String getName() { |
150 | 1 | return name; |
151 | |
} |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
@Override |
157 | |
public String getDescription() { |
158 | 1 | return description; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
@Override |
165 | |
public Template getTemplate() { |
166 | 1 | return template; |
167 | |
} |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
@Override |
173 | |
public boolean isActive() { |
174 | 1 | return active; |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
@Override |
182 | |
public Map<String, String> getAttributes() { |
183 | 2 | 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 | |
|
203 | |
|
204 | |
|
205 | 4 | public static final class Builder implements ResponsibilityContract, ModelBuilder, Serializable { |
206 | |
private String id; |
207 | |
private String namespaceCode; |
208 | |
private String name; |
209 | |
private String description; |
210 | |
private Template.Builder template; |
211 | |
private Map<String, String> attributes; |
212 | 6 | private Long versionNumber = 1L; |
213 | |
private String objectId; |
214 | |
private boolean active; |
215 | |
|
216 | 6 | private Builder(String namespaceCode, String name, Template.Builder template) { |
217 | 6 | setNamespaceCode(namespaceCode); |
218 | 6 | setName(name); |
219 | 6 | setTemplate(template); |
220 | 6 | } |
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public static Builder create(String namespaceCode, String name, Template.Builder template) { |
226 | 4 | return new Builder(namespaceCode, name, template); |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public static Builder create(ResponsibilityContract contract) { |
233 | 2 | Builder builder = new Builder(contract.getNamespaceCode(), contract.getName(), Template.Builder.create(contract.getTemplate())); |
234 | 2 | builder.setId(contract.getId()); |
235 | 2 | builder.setDescription(contract.getDescription()); |
236 | 2 | if (contract.getAttributes() != null) { |
237 | 2 | builder.setAttributes(contract.getAttributes()); |
238 | |
} |
239 | 2 | builder.setActive(contract.isActive()); |
240 | 2 | builder.setVersionNumber(contract.getVersionNumber()); |
241 | 2 | builder.setObjectId(contract.getObjectId()); |
242 | |
|
243 | 2 | return builder; |
244 | |
} |
245 | |
|
246 | |
@Override |
247 | |
public String getId() { |
248 | 4 | return id; |
249 | |
} |
250 | |
|
251 | |
public void setId(final String id) { |
252 | 2 | this.id = id; |
253 | 2 | } |
254 | |
|
255 | |
@Override |
256 | |
public String getNamespaceCode() { |
257 | 4 | return namespaceCode; |
258 | |
} |
259 | |
|
260 | |
public void setNamespaceCode(final String namespaceCode) { |
261 | 6 | if (StringUtils.isBlank(namespaceCode)) { |
262 | 0 | throw new IllegalArgumentException("namespaceCode is blank"); |
263 | |
} |
264 | 6 | this.namespaceCode = namespaceCode; |
265 | 6 | } |
266 | |
|
267 | |
@Override |
268 | |
public String getName() { |
269 | 4 | return name; |
270 | |
} |
271 | |
|
272 | |
public void setName(final String name) { |
273 | 6 | if (StringUtils.isBlank(name)) { |
274 | 0 | throw new IllegalArgumentException("name is blank"); |
275 | |
} |
276 | 6 | this.name = name; |
277 | 6 | } |
278 | |
|
279 | |
@Override |
280 | |
public String getDescription() { |
281 | 4 | return description; |
282 | |
} |
283 | |
|
284 | |
public void setDescription(final String description) { |
285 | 3 | this.description = description; |
286 | 3 | } |
287 | |
|
288 | |
@Override |
289 | |
public Template.Builder getTemplate() { |
290 | 4 | return template; |
291 | |
} |
292 | |
|
293 | |
public void setTemplate(final Template.Builder template) { |
294 | 6 | if (template == null) { |
295 | 0 | throw new IllegalArgumentException("template is null"); |
296 | |
} |
297 | 6 | this.template = template; |
298 | 6 | } |
299 | |
|
300 | |
@Override |
301 | |
public boolean isActive() { |
302 | 4 | return active; |
303 | |
} |
304 | |
|
305 | |
public void setActive(final boolean active) { |
306 | 2 | this.active = active; |
307 | 2 | } |
308 | |
|
309 | |
@Override |
310 | |
public Long getVersionNumber() { |
311 | 4 | return versionNumber; |
312 | |
} |
313 | |
|
314 | |
public void setVersionNumber(final Long versionNumber) { |
315 | 4 | if (versionNumber == null || versionNumber <= 0) { |
316 | 2 | throw new IllegalArgumentException("versionNumber is invalid"); |
317 | |
} |
318 | 2 | this.versionNumber = versionNumber; |
319 | 2 | } |
320 | |
|
321 | |
@Override |
322 | |
public String getObjectId() { |
323 | 4 | return objectId; |
324 | |
} |
325 | |
|
326 | |
public void setObjectId(final String objectId) { |
327 | 2 | this.objectId = objectId; |
328 | 2 | } |
329 | |
|
330 | |
@Override |
331 | |
public Map<String, String> getAttributes() { |
332 | 6 | return attributes; |
333 | |
} |
334 | |
|
335 | |
public void setAttributes(Map<String, String> attributes) { |
336 | 2 | this.attributes = Collections.unmodifiableMap(Maps.newHashMap(attributes)); |
337 | 2 | } |
338 | |
|
339 | |
@Override |
340 | |
public Responsibility build() { |
341 | 4 | return new Responsibility(this); |
342 | |
} |
343 | |
} |
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | 0 | static class Constants { |
349 | |
static final String ROOT_ELEMENT_NAME = "responsibility"; |
350 | |
static final String TYPE_NAME = "ResponsibilityType"; |
351 | |
} |
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | 0 | static class Elements { |
358 | |
static final String ID = "id"; |
359 | |
static final String NAMESPACE_CODE = "namespaceCode"; |
360 | |
static final String NAME = "name"; |
361 | |
static final String DESCRIPTION = "description"; |
362 | |
static final String TEMPLATE = "template"; |
363 | |
static final String ATTRIBUTES = "attributes"; |
364 | |
static final String ACTIVE = "active"; |
365 | |
} |
366 | |
} |