1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.api.repository.language;
17
18 import org.kuali.rice.core.api.CoreConstants;
19 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
20 import org.kuali.rice.core.api.mo.ModelBuilder;
21 import org.w3c.dom.Element;
22 import javax.xml.bind.annotation.XmlAccessType;
23 import javax.xml.bind.annotation.XmlAccessorType;
24 import javax.xml.bind.annotation.XmlAnyElement;
25 import javax.xml.bind.annotation.XmlElement;
26 import javax.xml.bind.annotation.XmlRootElement;
27 import javax.xml.bind.annotation.XmlType;
28 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
29 import java.io.Serializable;
30 import java.util.Collection;
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.Map;
34
35
36
37
38
39
40
41
42
43
44
45 @XmlRootElement(name = NaturalLanguageTemplate.Constants.ROOT_ELEMENT_NAME)
46 @XmlAccessorType(XmlAccessType.NONE)
47 @XmlType(name = NaturalLanguageTemplate.Constants.TYPE_NAME, propOrder = {
48 NaturalLanguageTemplate.Elements.ATTRIBUTES,
49 NaturalLanguageTemplate.Elements.LANGUAGE_CODE,
50 NaturalLanguageTemplate.Elements.NATURAL_LANGUAGE_USAGE_ID,
51 NaturalLanguageTemplate.Elements.TYPE_ID,
52 NaturalLanguageTemplate.Elements.TEMPLATE,
53 NaturalLanguageTemplate.Elements.ID,
54 NaturalLanguageTemplate.Elements.ACTIVE,
55 CoreConstants.CommonElements.VERSION_NUMBER,
56 CoreConstants.CommonElements.FUTURE_ELEMENTS
57 })
58 public final class NaturalLanguageTemplate
59 extends AbstractDataTransferObject
60 implements NaturalLanguageTemplateContract
61 {
62
63 @XmlJavaTypeAdapter(org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter.class)
64 @XmlElement(name = Elements.ATTRIBUTES, required = false)
65 private final Map<String, String> attributes;
66 @XmlElement(name = Elements.LANGUAGE_CODE, required = false)
67 private final String languageCode;
68 @XmlElement(name = Elements.NATURAL_LANGUAGE_USAGE_ID, required = false)
69 private final String naturalLanguageUsageId;
70 @XmlElement(name = Elements.TYPE_ID, required = false)
71 private final String typeId;
72 @XmlElement(name = Elements.TEMPLATE, required = false)
73 private final String template;
74 @XmlElement(name = Elements.ID, required = false)
75 private final String id;
76 @XmlElement(name = Elements.ACTIVE, required = false)
77 private final boolean active;
78 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
79 private final Long versionNumber;
80 @SuppressWarnings("unused")
81 @XmlAnyElement
82 private final Collection<Element> _futureElements = null;
83
84
85
86
87
88
89 private NaturalLanguageTemplate() {
90 this.attributes = null;
91 this.languageCode = null;
92 this.naturalLanguageUsageId = null;
93 this.typeId = null;
94 this.template = null;
95 this.id = null;
96 this.active = true;
97 this.versionNumber = null;
98 }
99
100
101
102
103
104
105
106 private NaturalLanguageTemplate(Builder builder) {
107 this.attributes = builder.getAttributes();
108 this.languageCode = builder.getLanguageCode();
109 this.naturalLanguageUsageId = builder.getNaturalLanguageUsageId();
110 this.typeId = builder.getTypeId();
111 this.template = builder.getTemplate();
112 this.id = builder.getId();
113 this.active = builder.isActive();
114 this.versionNumber = builder.getVersionNumber();
115 }
116
117 @Override
118 public Map<String, String> getAttributes() {
119 return this.attributes;
120 }
121
122 @Override
123 public String getLanguageCode() {
124 return this.languageCode;
125 }
126
127 @Override
128 public String getNaturalLanguageUsageId() {
129 return this.naturalLanguageUsageId;
130 }
131
132 @Override
133 public String getTypeId() {
134 return this.typeId;
135 }
136
137 @Override
138 public String getTemplate() {
139 return this.template;
140 }
141
142 @Override
143 public String getId() {
144 return this.id;
145 }
146
147 @Override
148 public boolean isActive() {
149 return this.active;
150 }
151
152 @Override
153 public Long getVersionNumber() {
154 return this.versionNumber;
155 }
156
157
158
159
160
161
162 public final static class Builder
163 implements Serializable, ModelBuilder, NaturalLanguageTemplateContract
164 {
165
166 private Map<String, String> attributes;
167 private String languageCode;
168 private String naturalLanguageUsageId;
169 private String typeId;
170 private String template;
171 private String id;
172 private boolean active;
173 private Long versionNumber;
174
175 private Builder(String languageCode, String naturalLanguageUsageId, String template, String typeId) {
176
177 setAttributes(null);
178 setLanguageCode(languageCode);
179 setNaturalLanguageUsageId(naturalLanguageUsageId);
180 setTemplate(template);
181 setTypeId(typeId);
182 }
183
184 public static Builder create(String languageCode, String naturalLanguageUsageId, String template, String typeId) {
185
186 return new Builder(languageCode, naturalLanguageUsageId, template, typeId);
187 }
188
189 public static Builder create(NaturalLanguageTemplateContract contract) {
190 if (contract == null) {
191 throw new IllegalArgumentException("contract was null");
192 }
193
194 Builder builder = create(contract.getLanguageCode(), contract.getNaturalLanguageUsageId(), contract.getTemplate(), contract.getTypeId());
195 builder.setId(contract.getId());
196 builder.setActive(contract.isActive());
197 builder.setAttributes(contract.getAttributes());
198 builder.setVersionNumber(contract.getVersionNumber());
199 return builder;
200 }
201
202
203
204
205
206
207
208 public NaturalLanguageTemplate build() {
209 return new NaturalLanguageTemplate(this);
210 }
211
212 @Override
213 public boolean isActive() {
214 return this.active;
215 }
216
217 @Override
218 public Map<String, String> getAttributes() {
219 return this.attributes;
220 }
221
222 @Override
223 public String getId() {
224 return this.id;
225 }
226
227 @Override
228 public String getLanguageCode() {
229 return this.languageCode;
230 }
231
232 @Override
233 public String getNaturalLanguageUsageId() {
234 return this.naturalLanguageUsageId;
235 }
236
237 @Override
238 public String getTemplate() {
239 return this.template;
240 }
241
242 @Override
243 public String getTypeId() {
244 return this.typeId;
245 }
246
247 @Override
248 public Long getVersionNumber() {
249 return this.versionNumber;
250 }
251
252
253
254
255
256
257
258 public void setActive(boolean active) {
259 this.active = active;
260 }
261
262
263
264
265
266
267
268 public void setAttributes(Map<String, String> attributes) {
269 if (attributes == null){
270 this.attributes = Collections.emptyMap();
271 } else {
272 this.attributes = Collections.unmodifiableMap(attributes);
273 }
274 }
275
276
277
278
279
280
281
282
283 public void setId(String id) {
284 if (id != null && org.apache.commons.lang.StringUtils.isBlank(id)) {
285 throw new IllegalArgumentException("id is blank");
286 }
287 this.id = id;
288 }
289
290
291
292
293
294
295
296
297 public void setLanguageCode(String languageCode) {
298 if (org.apache.commons.lang.StringUtils.isBlank(languageCode)) {
299 throw new IllegalArgumentException("languageCode is null or blank");
300 }
301 this.languageCode = languageCode;
302 }
303
304
305
306
307
308
309
310
311 public void setNaturalLanguageUsageId(String naturalLanguageUsageId) {
312 if (org.apache.commons.lang.StringUtils.isBlank(naturalLanguageUsageId)) {
313 throw new IllegalArgumentException("naturalLanguageUsageId is null or blank");
314 }
315 this.naturalLanguageUsageId = naturalLanguageUsageId;
316 }
317
318
319
320
321
322
323
324
325 public void setTemplate(String template) {
326 if (org.apache.commons.lang.StringUtils.isBlank(template)) {
327 throw new IllegalArgumentException("template is null or blank");
328 }
329 this.template = template;
330 }
331
332
333
334
335
336
337
338
339 public void setTypeId(String typeId) {
340 if (org.apache.commons.lang.StringUtils.isBlank(typeId)) {
341 throw new IllegalArgumentException("typeId is null or blank");
342 }
343 this.typeId = typeId;
344 }
345
346
347
348
349
350
351
352 public void setVersionNumber(Long versionNumber) {
353 this.versionNumber = versionNumber;
354 }
355
356 }
357
358
359
360
361
362
363 static class Constants {
364
365 final static String ROOT_ELEMENT_NAME = "naturalLanguageTemplate";
366 final static String TYPE_NAME = "NaturalLanguageTemplateType";
367
368 }
369
370
371
372
373
374
375 static class Elements {
376
377 final static String ATTRIBUTES = "attributes";
378 final static String LANGUAGE_CODE = "languageCode";
379 final static String NATURAL_LANGUAGE_USAGE_ID = "naturalLanguageUsageId";
380 final static String TYPE_ID = "typeId";
381 final static String TEMPLATE = "template";
382 final static String ID = "id";
383 final static String ACTIVE = "active";
384
385 }
386
387 }