1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.api.repository.proposition;
17
18 import java.io.Serializable;
19 import java.util.Collection;
20
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlAnyElement;
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlType;
27
28 import org.apache.commons.lang.StringUtils;
29 import org.kuali.rice.core.api.CoreConstants;
30 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
31 import org.kuali.rice.core.api.mo.ModelBuilder;
32
33
34
35
36
37
38
39
40 @XmlRootElement(name = PropositionParameter.Constants.ROOT_ELEMENT_NAME)
41 @XmlAccessorType(XmlAccessType.NONE)
42 @XmlType(name = PropositionParameter.Constants.TYPE_NAME, propOrder = {
43 PropositionParameter.Elements.ID,
44 PropositionParameter.Elements.PROP_ID,
45 PropositionParameter.Elements.VALUE,
46 PropositionParameter.Elements.PARM_TYPE,
47 PropositionParameter.Elements.SEQUENCE,
48 CoreConstants.CommonElements.VERSION_NUMBER,
49 CoreConstants.CommonElements.FUTURE_ELEMENTS
50 })
51 public final class PropositionParameter extends AbstractDataTransferObject implements PropositionParameterContract {
52 private static final long serialVersionUID = 2783959459503209577L;
53
54 @XmlElement(name = Elements.ID, required=true)
55 private String id;
56 @XmlElement(name = Elements.PROP_ID, required=true)
57 private String propId;
58 @XmlElement(name = Elements.VALUE, required=true)
59 private String value;
60 @XmlElement(name = Elements.PARM_TYPE, required=true)
61 private String parameterType;
62 @XmlElement(name = Elements.SEQUENCE, required=true)
63 private Integer sequenceNumber;
64 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
65 private final Long versionNumber;
66
67 @SuppressWarnings("unused")
68 @XmlAnyElement
69 private final Collection<org.w3c.dom.Element> _futureElements = null;
70
71
72
73
74
75 private PropositionParameter() {
76 this.id = null;
77 this.propId = null;
78 this.value = null;
79 this.parameterType = null;
80 this.sequenceNumber = null;
81 this.versionNumber = null;
82 }
83
84
85
86
87
88
89
90 private PropositionParameter(Builder builder) {
91 this.id = builder.getId();
92 this.propId = builder.getPropId();
93 this.value = builder.getValue();
94 this.parameterType = builder.getParameterType();
95 this.sequenceNumber = builder.getSequenceNumber();
96 this.versionNumber = builder.getVersionNumber();
97 }
98
99 @Override
100 public String getId() {
101 return this.id;
102 }
103
104 @Override
105 public String getPropId() {
106 return this.propId;
107 }
108
109 @Override
110 public String getValue() {
111 return this.value;
112 }
113
114 @Override
115 public String getParameterType() {
116 return this.parameterType;
117 }
118 @Override
119 public Integer getSequenceNumber() {
120 return this.sequenceNumber;
121 }
122
123 @Override
124 public Long getVersionNumber() {
125 return versionNumber;
126 }
127
128
129
130
131
132 public static class Builder implements PropositionParameterContract, ModelBuilder, Serializable {
133 private static final long serialVersionUID = -6889320709850568900L;
134
135 private String id;
136 private String propId;
137 private String value;
138 private String parameterType;
139 private Integer sequenceNumber;
140 private Long versionNumber;
141 private PropositionDefinition.Builder proposition;
142
143
144
145
146
147
148
149
150
151 private Builder(String id, String propId, String value, String parameterType, Integer sequenceNumber) {
152 setId(id);
153 setPropId(propId);
154 setValue(value);
155 setParameterType(parameterType);
156 setSequenceNumber(sequenceNumber);
157 }
158
159
160
161
162
163
164
165
166
167
168 public static Builder create(String id, String propId, String value, String parameterType, Integer sequenceNumber) {
169 return new Builder(id, propId, value, parameterType, sequenceNumber);
170 }
171
172
173
174
175
176
177
178 public static Builder create(PropositionParameterContract contract) {
179 if (contract == null) {
180 throw new IllegalArgumentException("contract is null");
181 }
182 Builder builder = new Builder(contract.getId(), contract.getPropId(), contract.getValue(), contract.getParameterType(), contract.getSequenceNumber());
183 builder.setVersionNumber(contract.getVersionNumber());
184 return builder;
185 }
186
187
188
189
190
191
192
193 public void setId(String id) {
194 if (id != null && StringUtils.isBlank(id)) {
195 throw new IllegalArgumentException("id must not be null or blank");
196 }
197 this.id = id;
198 }
199
200
201
202
203
204
205
206 public void setPropId(String propId) {
207
208 if (null != propId && StringUtils.isBlank(propId)) {
209 throw new IllegalArgumentException("propId must be not be null or blank");
210 }
211 this.propId = propId;
212 }
213
214
215
216
217
218
219
220 public void setValue(String value) {
221 if (value != null && "".equals(value.trim())) {
222 throw new IllegalArgumentException("value must contain non-whitespace characters");
223 }
224 this.value = value;
225 }
226
227
228
229
230
231
232
233 public void setParameterType(String parameterType) {
234 if (StringUtils.isBlank(parameterType)){
235 throw new IllegalArgumentException("parameter type is null or blank");
236 }
237 if (!PropositionParameterType.VALID_TYPE_CODES.contains(parameterType)){
238 throw new IllegalArgumentException("parameter type is invalid");
239 }
240
241 this.parameterType = parameterType;
242 }
243
244
245
246
247
248
249
250 public void setSequenceNumber(Integer sequenceNumber) {
251 if (sequenceNumber == null) {
252 throw new IllegalArgumentException("sequenceNumber type is blank");
253 }
254 this.sequenceNumber = sequenceNumber;
255 }
256
257
258
259
260
261
262 public void setProposition(PropositionDefinition.Builder proposition) {
263 if (proposition != null && !StringUtils.isBlank(proposition.getId())) {
264 setPropId(proposition.getId());
265 }
266 this.proposition = proposition;
267 }
268
269
270
271
272
273
274 public void setVersionNumber(Long versionNumber){
275 this.versionNumber = versionNumber;
276 }
277
278 @Override
279 public String getId() {
280 return id;
281 }
282
283 @Override
284 public String getPropId() {
285 return propId;
286 }
287
288 @Override
289 public String getValue() {
290 return value;
291 }
292
293 @Override
294 public String getParameterType() {
295 return parameterType;
296 }
297
298 @Override
299 public Integer getSequenceNumber() {
300 return sequenceNumber;
301 }
302
303 @Override
304 public Long getVersionNumber() {
305 return versionNumber;
306 }
307
308
309
310
311
312
313 @Override
314 public PropositionParameter build() {
315 if (proposition == null && StringUtils.isBlank(propId)) {
316 throw new IllegalStateException("either proposition must be non-null or propId must be non-blank");
317 }
318 return new PropositionParameter(this);
319 }
320
321 }
322
323
324
325
326 static class Constants {
327 final static String ROOT_ELEMENT_NAME = "PropositionParameter";
328 final static String TYPE_NAME = "PropositionParameterType";
329 }
330
331
332
333
334
335 public static class Elements {
336 final static String ID = "id";
337 final static String PROP_ID = "propId";
338 final static String VALUE = "value";
339 final static String PARM_TYPE = "parameterType";
340 final static String SEQUENCE = "sequenceNumber";
341 }
342
343 }