1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.api.repository.agenda;
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 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
33
34
35
36
37
38
39
40
41 @XmlRootElement(name = AgendaItemDefinition.Constants.ROOT_ELEMENT_NAME)
42 @XmlAccessorType(XmlAccessType.NONE)
43 @XmlType(name = AgendaItemDefinition.Constants.TYPE_NAME, propOrder = {
44 AgendaItemDefinition.Elements.ID,
45 AgendaItemDefinition.Elements.AGENDA_ID,
46 AgendaItemDefinition.Elements.RULE_ID,
47 AgendaItemDefinition.Elements.SUB_AGENDA_ID,
48 AgendaItemDefinition.Elements.WHEN_TRUE_ID,
49 AgendaItemDefinition.Elements.WHEN_FALSE_ID,
50 AgendaItemDefinition.Elements.ALWAYS_ID,
51 AgendaItemDefinition.Elements.RULE,
52 AgendaItemDefinition.Elements.SUB_AGENDA,
53 AgendaItemDefinition.Elements.WHEN_TRUE,
54 AgendaItemDefinition.Elements.WHEN_FALSE,
55 AgendaItemDefinition.Elements.ALWAYS,
56 CoreConstants.CommonElements.VERSION_NUMBER,
57 CoreConstants.CommonElements.FUTURE_ELEMENTS
58 })
59 public final class AgendaItemDefinition extends AbstractDataTransferObject implements AgendaItemDefinitionContract {
60 private static final long serialVersionUID = 2783959459503209577L;
61
62 @XmlElement(name = Elements.ID, required=true)
63 private String id;
64 @XmlElement(name = Elements.AGENDA_ID, required=true)
65 private String agendaId;
66 @XmlElement(name = Elements.RULE_ID, required=false)
67 private String ruleId;
68 @XmlElement(name = Elements.SUB_AGENDA_ID, required=false)
69 private String subAgendaId;
70 @XmlElement(name = Elements.WHEN_TRUE_ID, required=false)
71 private String whenTrueId;
72 @XmlElement(name = Elements.WHEN_FALSE_ID, required=false)
73 private String whenFalseId;
74 @XmlElement(name = Elements.ALWAYS_ID, required=false)
75 private String alwaysId;
76
77 @XmlElement(name = Elements.RULE, required=false)
78 private RuleDefinition rule;;
79 @XmlElement(name = Elements.SUB_AGENDA, required=false)
80 private AgendaDefinition subAgenda;
81 @XmlElement(name = Elements.WHEN_TRUE, required=false)
82 private AgendaItemDefinition whenTrue;
83 @XmlElement(name = Elements.WHEN_FALSE, required=false)
84 private AgendaItemDefinition whenFalse;
85 @XmlElement(name = Elements.ALWAYS, required=false)
86 private AgendaItemDefinition always;
87
88 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
89 private final Long versionNumber;
90
91 @SuppressWarnings("unused")
92 @XmlAnyElement
93 private final Collection<org.w3c.dom.Element> _futureElements = null;
94
95
96
97
98
99
100 private AgendaItemDefinition() {
101 this.id = null;
102 this.agendaId = null;
103 this.ruleId = null;
104 this.subAgendaId = null;
105 this.whenTrueId = null;
106 this.whenFalseId = null;
107 this.alwaysId = null;
108
109 this.rule = null;
110 this.subAgenda = null;
111
112 this.whenTrue = null;
113 this.whenFalse = null;
114 this.always = null;
115
116 this.versionNumber = null;
117 }
118
119
120
121
122
123
124
125 private AgendaItemDefinition(Builder builder) {
126 this.id = builder.getId();
127 this.agendaId = builder.getAgendaId();
128 this.ruleId = builder.getRuleId();
129 this.subAgendaId = builder.getSubAgendaId();
130 this.whenTrueId = builder.getWhenTrueId();
131 this.whenFalseId = builder.getWhenFalseId();
132 this.alwaysId = builder.getAlwaysId();
133 this.versionNumber = builder.getVersionNumber();
134
135 if (builder.getRule() != null) { this.rule = builder.getRule().build(); }
136 if (builder.getSubAgenda() != null) { this.subAgenda = builder.getSubAgenda().build(); }
137 if (builder.getWhenTrue() != null) { this.whenTrue = builder.getWhenTrue().build(); }
138 if (builder.getWhenFalse() != null) { this.whenFalse = builder.getWhenFalse().build(); }
139 if (builder.getAlways() != null) { this.always = builder.getAlways().build(); }
140 }
141
142 @Override
143 public String getId() {
144 return this.id;
145 }
146
147 @Override
148 public String getAgendaId() {
149 return this.agendaId;
150 }
151
152 @Override
153 public String getRuleId() {
154 return this.ruleId;
155 }
156
157 @Override
158 public String getSubAgendaId() {
159 return this.subAgendaId;
160 }
161
162 @Override
163 public String getWhenTrueId() {
164 return this.whenTrueId;
165 }
166
167 @Override
168 public String getWhenFalseId() {
169 return this.whenFalseId;
170 }
171
172 @Override
173 public String getAlwaysId() {
174 return this.alwaysId;
175 }
176
177 @Override
178 public RuleDefinition getRule() {
179 return this.rule;
180 }
181
182 @Override
183 public AgendaDefinition getSubAgenda() {
184 return this.subAgenda;
185 }
186
187 @Override
188 public AgendaItemDefinition getWhenTrue() {
189 return this.whenTrue;
190 }
191
192 @Override
193 public AgendaItemDefinition getWhenFalse() {
194 return this.whenFalse;
195 }
196
197 @Override
198 public AgendaItemDefinition getAlways() {
199 return this.always;
200 }
201
202 @Override
203 public Long getVersionNumber() {
204 return versionNumber;
205 }
206
207
208
209
210 public static class Builder implements AgendaItemDefinitionContract, ModelBuilder, Serializable {
211
212 private String id;
213 private String agendaId;
214 private String ruleId;
215 private String subAgendaId;
216 private String whenTrueId;
217 private String whenFalseId;
218 private String alwaysId;
219 private Long versionNumber;
220
221 private RuleDefinition.Builder rule;
222 private AgendaDefinition.Builder subAgenda;
223
224 private AgendaItemDefinition.Builder whenTrue;
225 private AgendaItemDefinition.Builder whenFalse;
226 private AgendaItemDefinition.Builder always;
227
228
229
230
231
232 private Builder(String id, String agendaId) {
233 setId(id);
234 setAgendaId(agendaId);
235 }
236
237
238
239
240
241
242
243
244 public static Builder create(String id, String agendaId){
245 return new Builder(id, agendaId);
246 }
247
248
249
250
251
252
253
254
255 public static Builder create(AgendaItemDefinitionContract contract) {
256 if (contract == null) {
257 throw new IllegalArgumentException("contract is null");
258 }
259 Builder builder = new Builder(contract.getId(), contract.getAgendaId());
260 builder.setRuleId(contract.getRuleId());
261 builder.setSubAgendaId(contract.getSubAgendaId());
262 builder.setWhenTrueId(contract.getWhenTrueId());
263 builder.setWhenFalseId(contract.getWhenFalseId());
264 builder.setAlwaysId(contract.getAlwaysId());
265
266 if (contract.getRule() != null){
267 builder.setRule(RuleDefinition.Builder.create( contract.getRule() ));
268 }
269 if (contract.getSubAgenda() != null){
270 builder.setSubAgenda( AgendaDefinition.Builder.create( contract.getSubAgenda()));
271 }
272 if (contract.getWhenTrue() != null){
273 builder.setWhenTrue( AgendaItemDefinition.Builder.create( contract.getWhenTrue()));
274 }
275 if (contract.getWhenFalse() != null){
276 builder.setWhenFalse( AgendaItemDefinition.Builder.create( contract.getWhenFalse()));
277 }
278 if (contract.getAlways() != null){
279 builder.setAlways( AgendaItemDefinition.Builder.create( contract.getAlways()));
280 }
281 builder.setVersionNumber(contract.getVersionNumber());
282 return builder;
283 }
284
285
286
287
288
289
290
291
292
293 public void setId(String agendaItemId) {
294 if (id != null && StringUtils.isBlank(agendaItemId)) {
295 throw new IllegalArgumentException("agendaItemId must be null or non-blank");
296 }
297 this.id = agendaItemId;
298 }
299
300
301
302
303
304
305
306 public void setAgendaId(String agendaId) {
307 if (StringUtils.isBlank(agendaId)) {
308 throw new IllegalArgumentException("agendaId is blank");
309 }
310 this.agendaId = agendaId;
311 }
312
313
314
315
316
317 public void setRuleId(String ruleId) {
318 this.ruleId = ruleId;
319 }
320
321
322
323
324
325 public void setSubAgendaId(String subAgendaId) {
326 this.subAgendaId = subAgendaId;
327 }
328
329
330
331
332
333 public void setWhenTrueId(String whenTrueId) {
334 this.whenTrueId = whenTrueId;
335 }
336
337
338
339
340
341 public void setWhenFalseId(String whenFalseId) {
342 this.whenFalseId = whenFalseId;
343 }
344
345
346
347
348
349 public void setAlwaysId(String alwaysId) {
350 this.alwaysId = alwaysId;
351 }
352
353
354
355
356
357 public void setRule(RuleDefinition.Builder rule) {
358 this.rule = rule;
359 }
360
361
362
363
364
365 public void setSubAgenda(AgendaDefinition.Builder subAgenda) {
366 this.subAgenda = subAgenda;
367 }
368
369
370
371
372
373 public void setWhenTrue(AgendaItemDefinition.Builder whenTrue) {
374 this.whenTrue = whenTrue;
375 }
376
377
378
379
380
381 public void setWhenFalse(AgendaItemDefinition.Builder whenFalse) {
382 this.whenTrue = whenFalse;
383 }
384
385
386
387
388
389 public void setAlways(AgendaItemDefinition.Builder always) {
390 this.always = always;
391 }
392
393
394
395
396
397 public void setVersionNumber(Long versionNumber){
398 this.versionNumber = versionNumber;
399 }
400
401 @Override
402 public String getId() {
403 return id;
404 }
405
406 @Override
407 public String getAgendaId() {
408 return agendaId;
409 }
410
411 @Override
412 public String getRuleId() {
413 return ruleId;
414 }
415
416 @Override
417 public String getSubAgendaId() {
418 return subAgendaId;
419 }
420
421 @Override
422 public String getWhenTrueId() {
423 return whenTrueId;
424 }
425
426 @Override
427 public String getWhenFalseId() {
428 return whenFalseId;
429 }
430
431 @Override
432 public String getAlwaysId() {
433 return alwaysId;
434 }
435
436 @Override
437 public RuleDefinition.Builder getRule() {
438 return rule;
439 }
440
441 @Override
442 public AgendaDefinition.Builder getSubAgenda() {
443 return subAgenda;
444 }
445
446 @Override
447 public AgendaItemDefinition.Builder getWhenTrue() {
448 return whenTrue;
449 }
450
451 @Override
452 public AgendaItemDefinition.Builder getWhenFalse() {
453 return whenFalse;
454 }
455
456 @Override
457 public AgendaItemDefinition.Builder getAlways() {
458 return always;
459 }
460
461 @Override
462 public Long getVersionNumber() {
463 return versionNumber;
464 }
465
466
467
468
469
470
471 @Override
472 public AgendaItemDefinition build() {
473 return new AgendaItemDefinition(this);
474 }
475
476 }
477
478
479
480
481 static class Constants {
482 final static String ROOT_ELEMENT_NAME = "AgendaItemDefinition";
483 final static String TYPE_NAME = "AgendaItemType";
484 }
485
486
487
488
489
490 public static class Elements {
491 final static String ID = "id";
492 final static String AGENDA_ID = "agendaId";
493 final static String RULE_ID = "ruleId";
494 final static String SUB_AGENDA_ID = "subAgendaId";
495 final static String WHEN_TRUE_ID = "whenTrueId";
496 final static String WHEN_FALSE_ID = "whenFalseId";
497 final static String ALWAYS_ID = "alwaysId";
498
499 final static String RULE = "rule";
500 final static String SUB_AGENDA = "subAgenda";
501 final static String WHEN_TRUE = "whenTrue";
502 final static String WHEN_FALSE = "whenFalse";
503 final static String ALWAYS = "always";
504 }
505
506 }