1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.api.repository.term; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collection; |
21 | |
import java.util.Collections; |
22 | |
import java.util.List; |
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.XmlElementWrapper; |
29 | |
import javax.xml.bind.annotation.XmlRootElement; |
30 | |
import javax.xml.bind.annotation.XmlType; |
31 | |
|
32 | |
import org.apache.commons.lang.StringUtils; |
33 | |
import org.kuali.rice.core.api.CoreConstants; |
34 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
35 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
36 | |
import org.kuali.rice.krms.api.repository.BuilderUtils; |
37 | |
import org.kuali.rice.krms.api.repository.BuilderUtils.Transformer; |
38 | |
import org.kuali.rice.krms.api.repository.category.CategoryDefinition; |
39 | |
import org.kuali.rice.krms.api.repository.category.CategoryDefinitionContract; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
@XmlRootElement(name = TermSpecificationDefinition.Constants.ROOT_ELEMENT_NAME) |
48 | |
@XmlAccessorType(XmlAccessType.NONE) |
49 | |
@XmlType(name = TermSpecificationDefinition.Constants.TYPE_NAME, propOrder = { |
50 | |
TermSpecificationDefinition.Elements.ID, |
51 | |
TermSpecificationDefinition.Elements.NAME, |
52 | |
TermSpecificationDefinition.Elements.NAMESPACE, |
53 | |
TermSpecificationDefinition.Elements.TYPE, |
54 | |
TermSpecificationDefinition.Elements.DESCRIPTION, |
55 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
56 | |
TermSpecificationDefinition.Elements.CATEGORIES, |
57 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
58 | |
}) |
59 | 0 | public final class TermSpecificationDefinition extends AbstractDataTransferObject implements TermSpecificationDefinitionContract { |
60 | |
|
61 | |
private static final long serialVersionUID = 1L; |
62 | |
|
63 | |
@XmlElement(name = Elements.ID, required=false) |
64 | |
private final String id; |
65 | |
@XmlElement(name = Elements.NAME, required=true) |
66 | |
private final String name; |
67 | |
@XmlElement(name = Elements.NAMESPACE, required=true) |
68 | |
private final String namespace; |
69 | |
@XmlElement(name = Elements.TYPE, required=true) |
70 | |
private final String type; |
71 | |
@XmlElement(name = Elements.DESCRIPTION, required=false) |
72 | |
private final String description; |
73 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
74 | |
private final Long versionNumber; |
75 | |
|
76 | |
@XmlElementWrapper(name = Elements.CATEGORIES, required = false) |
77 | |
@XmlElement(name = Elements.CATEGORY, required = false) |
78 | |
private final List<CategoryDefinition> categories; |
79 | |
|
80 | |
|
81 | 0 | @SuppressWarnings("unused") |
82 | |
@XmlAnyElement |
83 | |
private final Collection<org.w3c.dom.Element> _futureElements = null; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | 0 | private TermSpecificationDefinition() { |
89 | 0 | id = null; |
90 | 0 | name = null; |
91 | 0 | namespace = null; |
92 | 0 | type = null; |
93 | 0 | description = null; |
94 | 0 | versionNumber = null; |
95 | 0 | this.categories = null; |
96 | 0 | } |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | 0 | private TermSpecificationDefinition(Builder b) { |
104 | 0 | id = b.getId(); |
105 | 0 | name = b.getName(); |
106 | 0 | namespace = b.getNamespace(); |
107 | 0 | type = b.getType(); |
108 | 0 | description = b.getDescription(); |
109 | 0 | versionNumber = b.getVersionNumber(); |
110 | 0 | this.categories = constructCategories(b.getCategories()); |
111 | 0 | } |
112 | |
|
113 | |
private static List<CategoryDefinition> constructCategories(List<CategoryDefinition.Builder> categoryBuilders) { |
114 | 0 | List<CategoryDefinition> categories = new ArrayList<CategoryDefinition>(); |
115 | 0 | if (categoryBuilders != null) { |
116 | 0 | for (CategoryDefinition.Builder categoryBuilder : categoryBuilders) { |
117 | 0 | categories.add(categoryBuilder.build()); |
118 | |
} |
119 | |
} |
120 | 0 | return categories; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | 0 | public static class Builder implements TermSpecificationDefinitionContract, ModelBuilder, Serializable { |
129 | |
|
130 | |
private static final long serialVersionUID = 1L; |
131 | |
|
132 | |
private String termSpecificationId; |
133 | |
private String name; |
134 | |
private String namespace; |
135 | |
private String type; |
136 | |
private String description; |
137 | |
private Long versionNumber; |
138 | |
private List<CategoryDefinition.Builder> categories; |
139 | |
|
140 | |
private static final String NON_NULL_NON_EMPTY_ERROR = " must be non-null and must contain non-whitespace chars"; |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
public static final Transformer<TermSpecificationDefinitionContract, TermSpecificationDefinition.Builder> |
146 | 0 | toBuilder = new BuilderUtils.Transformer<TermSpecificationDefinitionContract, TermSpecificationDefinition.Builder>() { |
147 | |
public TermSpecificationDefinition.Builder transform(TermSpecificationDefinitionContract input) { |
148 | 0 | return TermSpecificationDefinition.Builder.create(input); |
149 | |
} |
150 | |
}; |
151 | |
|
152 | 0 | private Builder(String termSpecificationId, String name, String namespace, String type) { |
153 | |
|
154 | 0 | setId(termSpecificationId); |
155 | 0 | setNamespace(namespace); |
156 | 0 | setName(name); |
157 | 0 | setType(type); |
158 | 0 | setCategories(new ArrayList<CategoryDefinition.Builder>()); |
159 | 0 | } |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
public static Builder create(String termSpecificationId, String name, String namespace, String type) { |
174 | 0 | return new Builder(termSpecificationId, name, namespace, type); |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
public static Builder create(TermSpecificationDefinitionContract termSpecification) { |
184 | 0 | if (termSpecification == null) throw new IllegalArgumentException("termSpecification must be non-null"); |
185 | 0 | Builder builder =new Builder(termSpecification.getId(), termSpecification.getName(), termSpecification.getNamespace(), |
186 | |
termSpecification.getType()); |
187 | 0 | builder.setDescription(termSpecification.getDescription()); |
188 | 0 | builder.setVersionNumber(termSpecification.getVersionNumber()); |
189 | 0 | for (CategoryDefinitionContract category : termSpecification.getCategories()) { |
190 | 0 | builder.getCategories().add(CategoryDefinition.Builder.create(category)); |
191 | |
} |
192 | |
|
193 | 0 | return builder; |
194 | |
} |
195 | |
|
196 | |
public void setDescription(String description) { |
197 | 0 | this.description = description; |
198 | 0 | } |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
public void setId(String termSpecificationId) { |
208 | 0 | if (termSpecificationId != null && StringUtils.isBlank(termSpecificationId)) |
209 | 0 | throw new IllegalArgumentException("termSpecificationId must contain non-whitespace chars"); |
210 | 0 | this.termSpecificationId = termSpecificationId; |
211 | 0 | } |
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
public void setNamespace(String namespace) { |
217 | 0 | if (StringUtils.isBlank(namespace)) { |
218 | 0 | throw new IllegalArgumentException("namespace" + NON_NULL_NON_EMPTY_ERROR); |
219 | |
} |
220 | 0 | this.namespace = namespace; |
221 | 0 | } |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
public void setName(String name) { |
227 | 0 | if (StringUtils.isBlank(name)) { |
228 | 0 | throw new IllegalArgumentException("name" + NON_NULL_NON_EMPTY_ERROR); |
229 | |
} |
230 | 0 | this.name = name; |
231 | 0 | } |
232 | |
|
233 | |
|
234 | |
|
235 | |
public void setType(String type) { |
236 | 0 | if (StringUtils.isBlank(type)) { |
237 | 0 | throw new IllegalArgumentException("type" + NON_NULL_NON_EMPTY_ERROR); |
238 | |
} |
239 | 0 | this.type = type; |
240 | 0 | } |
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
public void setVersionNumber(Long versionNumber){ |
246 | 0 | this.versionNumber = versionNumber; |
247 | 0 | } |
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
public void setCategories(List<CategoryDefinition.Builder> categories) { |
253 | 0 | if (categories == null) { |
254 | 0 | throw new IllegalArgumentException("categories was null"); |
255 | |
} |
256 | 0 | this.categories = categories; |
257 | 0 | } |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
@Override |
265 | |
public String getId() { |
266 | 0 | return this.termSpecificationId; |
267 | |
} |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
@Override |
273 | |
public String getNamespace() { |
274 | 0 | return this.namespace; |
275 | |
} |
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
@Override |
281 | |
public String getName() { |
282 | 0 | return this.name; |
283 | |
} |
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
@Override |
289 | |
public String getType() { |
290 | 0 | return this.type; |
291 | |
} |
292 | |
|
293 | |
@Override |
294 | |
public String getDescription() { |
295 | 0 | return this.description; |
296 | |
} |
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
@Override |
302 | |
public Long getVersionNumber() { |
303 | 0 | return this.versionNumber; |
304 | |
} |
305 | |
|
306 | |
|
307 | |
|
308 | |
|
309 | |
@Override |
310 | |
public List<CategoryDefinition.Builder> getCategories() { |
311 | 0 | return this.categories; |
312 | |
} |
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
@Override |
320 | |
public TermSpecificationDefinition build() { |
321 | 0 | return new TermSpecificationDefinition(this); |
322 | |
} |
323 | |
} |
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
@Override |
330 | |
public String getId() { |
331 | 0 | return id; |
332 | |
} |
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
@Override |
338 | |
public String getName() { |
339 | 0 | return name; |
340 | |
} |
341 | |
|
342 | |
@Override |
343 | |
public String getNamespace() { |
344 | 0 | return namespace; |
345 | |
} |
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
@Override |
351 | |
public String getType() { |
352 | 0 | return type; |
353 | |
} |
354 | |
|
355 | |
@Override |
356 | |
public String getDescription() { |
357 | 0 | return description; |
358 | |
} |
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
@Override |
364 | |
public Long getVersionNumber() { |
365 | 0 | return versionNumber; |
366 | |
} |
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
@Override |
372 | |
public List<CategoryDefinition> getCategories() { |
373 | 0 | return Collections.unmodifiableList(categories); |
374 | |
} |
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | 0 | static class Constants { |
380 | |
final static String ROOT_ELEMENT_NAME = "termSpecification"; |
381 | |
final static String TYPE_NAME = "TermSpecificationType"; |
382 | |
} |
383 | |
|
384 | 0 | static class Elements { |
385 | |
public static final String ID = "id"; |
386 | |
public static final String NAME = "name"; |
387 | |
public final static String NAMESPACE = "namespace"; |
388 | |
public static final String TYPE = "type"; |
389 | |
public static final String DESCRIPTION = "description"; |
390 | |
public final static String CATEGORIES = "categories"; |
391 | |
public final static String CATEGORY = "category"; |
392 | |
} |
393 | |
|
394 | |
|
395 | |
} |