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