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