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