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