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 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.krms.api.KrmsConstants;
23 import org.kuali.rice.krms.api.repository.LogicalOperator;
24 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
25
26 import javax.xml.bind.annotation.XmlAccessType;
27 import javax.xml.bind.annotation.XmlAccessorType;
28 import javax.xml.bind.annotation.XmlAnyElement;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.XmlElementWrapper;
31 import javax.xml.bind.annotation.XmlRootElement;
32 import javax.xml.bind.annotation.XmlType;
33 import java.io.Serializable;
34 import java.util.ArrayList;
35 import java.util.Collection;
36 import java.util.Collections;
37 import java.util.List;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 @XmlRootElement(name = PropositionDefinition.Constants.ROOT_ELEMENT_NAME)
60 @XmlAccessorType(XmlAccessType.NONE)
61 @XmlType(name = PropositionDefinition.Constants.TYPE_NAME, propOrder = {
62 PropositionDefinition.Elements.ID,
63 PropositionDefinition.Elements.DESC,
64 PropositionDefinition.Elements.RULE_ID,
65 PropositionDefinition.Elements.TYPE_ID,
66 PropositionDefinition.Elements.PROP_TYPE_CODE,
67 PropositionDefinition.Elements.PARAMETERS,
68 PropositionDefinition.Elements.CMPND_OP_CODE,
69 PropositionDefinition.Elements.CMPND_COMPONENTS,
70 CoreConstants.CommonElements.VERSION_NUMBER,
71 CoreConstants.CommonElements.FUTURE_ELEMENTS
72 })
73 public final class PropositionDefinition extends AbstractDataTransferObject implements PropositionDefinitionContract {
74 private static final long serialVersionUID = 2783959459503209577L;
75
76
77 @XmlElement(name = Elements.ID, required=true)
78 private String id;
79
80 @XmlElement(name = Elements.DESC, required=true)
81 private String description;
82
83 @XmlElement(name = Elements.TYPE_ID, required=true)
84 private String typeId;
85
86 @XmlElement(name = Elements.RULE_ID, required=true)
87 private String ruleId;
88
89 @XmlElement(name = Elements.PROP_TYPE_CODE, required=true)
90 private String propositionTypeCode;
91
92 @XmlElementWrapper(name = Elements.PARAMETERS)
93 @XmlElement(name = Elements.PARAMETER, required=false)
94 private List<PropositionParameter> parameters;
95
96 @XmlElement(name = Elements.CMPND_OP_CODE, required=false)
97 private String compoundOpCode;
98
99 @XmlElementWrapper(name = Elements.CMPND_COMPONENTS, required=false)
100 @XmlElement(name = Elements.CMPND_COMPONENT, required=false)
101 private List<PropositionDefinition> compoundComponents;
102
103 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
104 private final Long versionNumber;
105
106 @SuppressWarnings("unused")
107 @XmlAnyElement
108 private final Collection<org.w3c.dom.Element> _futureElements = null;
109
110
111
112
113
114 private PropositionDefinition() {
115 this.id = null;
116 this.description = null;
117 this.typeId = null;
118 this.propositionTypeCode = null;
119 this.parameters = null;
120 this.compoundOpCode = null;
121 this.compoundComponents = null;
122 this.versionNumber = null;
123 }
124
125
126
127
128
129
130
131 private PropositionDefinition(Builder builder) {
132 this.id = builder.getId();
133 this.description = builder.getDescription();
134 this.ruleId = builder.getRuleId();
135 this.typeId = builder.getTypeId();
136 this.propositionTypeCode = builder.getPropositionTypeCode();
137
138
139 List<PropositionParameter> paramList = new ArrayList<PropositionParameter>();
140 for (PropositionParameter.Builder b : builder.parameters){
141 b.setProposition(builder);
142 paramList.add(b.build());
143 }
144 this.parameters = Collections.unmodifiableList(paramList);
145
146
147 this.compoundOpCode = builder.getCompoundOpCode();
148 List <PropositionDefinition> componentList = new ArrayList<PropositionDefinition>();
149 if (builder.compoundComponents != null){
150 for (Builder b : builder.compoundComponents){
151 componentList.add(b.build());
152 }
153 this.compoundComponents = Collections.unmodifiableList(componentList);
154 }
155 this.versionNumber = builder.getVersionNumber();
156 }
157
158 @Override
159 public String getId() {
160 return this.id;
161 }
162
163 @Override
164 public String getDescription() {
165 return this.description;
166 }
167
168
169
170
171 @Override
172 public String getRuleId() {
173 return this.ruleId;
174 }
175
176 @Override
177 public String getTypeId() {
178 return this.typeId;
179 }
180
181 @Override
182 public String getPropositionTypeCode() {
183 return this.propositionTypeCode;
184 }
185
186 @Override
187 public List<PropositionParameter> getParameters() {
188 return this.parameters;
189 }
190
191 @Override
192 public String getCompoundOpCode() {
193 return this.compoundOpCode;
194 }
195
196 @Override
197 public List<PropositionDefinition> getCompoundComponents() {
198 return this.compoundComponents;
199 }
200
201 @Override
202 public Long getVersionNumber() {
203 return versionNumber;
204 }
205
206
207
208
209 public static class Builder implements PropositionDefinitionContract, ModelBuilder, Serializable {
210 private static final long serialVersionUID = -6889320709850568900L;
211
212 private String id;
213 private String description;
214 private String ruleId;
215 private String typeId;
216 private String propositionTypeCode;
217 private List<PropositionParameter.Builder> parameters;
218 private String compoundOpCode;
219 private List<Builder> compoundComponents;
220 private RuleDefinition.Builder rule;
221 private Long versionNumber;
222
223
224
225
226
227
228
229
230
231 private Builder(String propId, String propTypeCode, String ruleId, String typeId, List<PropositionParameter.Builder> parameters) {
232 setId(propId);
233 setPropositionTypeCode(propTypeCode);
234 setRuleId(ruleId);
235 setTypeId(typeId);
236 setParameters(parameters);
237 }
238
239
240
241
242
243
244 public Builder compoundOpCode(String opCode){
245 setCompoundOpCode(opCode);
246 return this;
247 }
248
249
250
251
252
253
254 public Builder compoundComponents (List<Builder> components){
255 setCompoundComponents(components);
256 return this;
257 }
258
259
260
261
262
263
264
265
266
267
268 public static Builder create(String propId, String propTypeCode, String ruleId, String typeId, List<PropositionParameter.Builder> parameters){
269 return new Builder(propId, propTypeCode, ruleId, typeId, parameters);
270 }
271
272
273
274
275
276
277
278 public static Builder create(PropositionDefinitionContract contract) {
279 if (contract == null) {
280 throw new IllegalArgumentException("contract is null");
281 }
282 List <PropositionParameter.Builder> paramBuilderList = new ArrayList<PropositionParameter.Builder>();
283 if (contract.getParameters() != null){
284 for (PropositionParameterContract paramContract : contract.getParameters()){
285 PropositionParameter.Builder myBuilder = PropositionParameter.Builder.create(paramContract);
286 paramBuilderList.add(myBuilder);
287 }
288 }
289 Builder builder = new Builder(contract.getId(), contract.getPropositionTypeCode(), contract.getRuleId(), contract.getTypeId(), paramBuilderList);
290
291 List <Builder> componentBuilderList = new ArrayList<Builder>();
292 if (contract.getCompoundComponents() != null) {
293 for (PropositionDefinitionContract cContract : contract.getCompoundComponents()){
294 Builder pBuilder = Builder.create(cContract);
295 componentBuilderList.add(pBuilder);
296 }
297 builder.setCompoundComponents(componentBuilderList);
298 }
299 builder.setCompoundOpCode(contract.getCompoundOpCode());
300 builder.setDescription(contract.getDescription());
301 builder.setVersionNumber(contract.getVersionNumber());
302 return builder;
303 }
304
305
306
307
308
309
310
311 public void setId(String propId) {
312 if (propId != null && StringUtils.isBlank(propId)) {
313 throw new IllegalArgumentException("proposition id must not be blank");
314 }
315 this.id = propId;
316 }
317
318
319
320
321
322
323 public void setDescription(String description) {
324 this.description = description;
325 }
326
327
328
329
330
331
332 public void setTypeId(String typeId) {
333 this.typeId = typeId;
334 }
335
336
337
338
339
340
341 public void setRuleId(String ruleId) {
342 this.ruleId = ruleId;
343 }
344
345
346
347
348
349
350 public void setRule(RuleDefinition.Builder rule) {
351 if (rule != null && !StringUtils.isBlank(rule.getId())) {
352 setRuleId(rule.getId());
353 }
354 this.rule = rule;
355 }
356
357
358
359
360
361
362
363 public void setPropositionTypeCode(String propTypeCode) {
364 if (StringUtils.isBlank(propTypeCode)) {
365 throw new IllegalArgumentException("proposition type code is blank");
366 }
367 if (!PropositionType.VALID_TYPE_CODES.contains(propTypeCode)) {
368 throw new IllegalArgumentException("invalid proposition type code");
369 }
370 this.propositionTypeCode = propTypeCode;
371 }
372
373
374
375
376
377
378 public void setParameters(List<PropositionParameter.Builder> parameters) {
379
380
381 if (parameters == null || parameters.isEmpty()){
382 this.parameters = Collections.unmodifiableList(new ArrayList<PropositionParameter.Builder>());
383 } else {
384 this.parameters = Collections.unmodifiableList(parameters);
385 }
386 }
387
388
389
390
391
392
393
394 public void setCompoundOpCode(String opCode){
395 if (StringUtils.isBlank(opCode)){ return; }
396 if (!LogicalOperator.OP_CODES.contains(opCode)){
397 throw new IllegalArgumentException("invalid opCode value");
398 }
399 this.compoundOpCode = opCode;
400 }
401
402
403
404
405
406
407 public void setCompoundComponents(List<Builder> components){
408 if (components == null || components.isEmpty()){
409 this.compoundComponents = new ArrayList<Builder>();
410 return;
411 }
412 this.compoundComponents = new ArrayList<Builder>(components);
413 }
414
415
416
417
418
419
420 public void setVersionNumber(Long versionNumber){
421 this.versionNumber = versionNumber;
422 }
423
424 @Override
425 public String getId() {
426 return id;
427 }
428
429 @Override
430 public String getDescription() {
431 return description;
432 }
433
434 @Override
435 public String getRuleId() {
436 return ruleId;
437 }
438
439 @Override
440 public String getTypeId() {
441 return typeId;
442 }
443
444 @Override
445 public String getPropositionTypeCode() {
446 return propositionTypeCode;
447 }
448
449 @Override
450 public List<PropositionParameter.Builder> getParameters() {
451 return parameters;
452 }
453
454 @Override
455 public String getCompoundOpCode() {
456 return compoundOpCode;
457 }
458
459 @Override
460 public List<Builder> getCompoundComponents() {
461 return compoundComponents;
462 }
463
464 @Override
465 public Long getVersionNumber() {
466 return versionNumber;
467 }
468
469
470
471
472
473
474 @Override
475 public PropositionDefinition build() {
476 return new PropositionDefinition(this);
477 }
478
479 }
480
481
482
483
484 static class Constants {
485 final static String ROOT_ELEMENT_NAME = "proposition";
486 final static String TYPE_NAME = "PropositionType";
487 }
488
489
490
491
492
493 public static class Elements {
494 final static String ID = "id";
495 final static String DESC = "description";
496 final static String RULE_ID = "ruleId";
497 final static String TYPE_ID = "typeId";
498 final static String PROP_TYPE_CODE = "propositionTypeCode";
499 final static String PARAMETER = "parameter";
500 final static String PARAMETERS = "parameters";
501 final static String CMPND_OP_CODE = "compoundOpCode";
502 final static String CMPND_COMPONENTS = "compoundComponents";
503 final static String CMPND_COMPONENT = "proposition";
504 }
505
506 public static class Cache {
507 public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + Constants.TYPE_NAME;
508 }
509
510 }