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