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 }
237
238
239
240
241
242
243
244
245 public static Builder create(String id, String agendaId){
246 return new Builder(id, agendaId);
247 }
248
249
250
251
252
253
254
255
256 public static Builder create(AgendaItemDefinitionContract contract) {
257 if (contract == null) {
258 throw new IllegalArgumentException("contract is null");
259 }
260 Builder builder = new Builder(contract.getId(), contract.getAgendaId());
261 builder.setRuleId(contract.getRuleId());
262 builder.setSubAgendaId(contract.getSubAgendaId());
263 builder.setWhenTrueId(contract.getWhenTrueId());
264 builder.setWhenFalseId(contract.getWhenFalseId());
265 builder.setAlwaysId(contract.getAlwaysId());
266
267 if (contract.getRule() != null){
268 builder.setRule(RuleDefinition.Builder.create( contract.getRule() ));
269 }
270 if (contract.getSubAgenda() != null){
271 builder.setSubAgenda( AgendaDefinition.Builder.create( contract.getSubAgenda()));
272 }
273 if (contract.getWhenTrue() != null){
274 builder.setWhenTrue( AgendaItemDefinition.Builder.create( contract.getWhenTrue()));
275 }
276 if (contract.getWhenFalse() != null){
277 builder.setWhenFalse( AgendaItemDefinition.Builder.create( contract.getWhenFalse()));
278 }
279 if (contract.getAlways() != null){
280 builder.setAlways( AgendaItemDefinition.Builder.create( contract.getAlways()));
281 }
282 builder.setVersionNumber(contract.getVersionNumber());
283 return builder;
284 }
285
286
287
288
289
290
291
292
293
294 public void setId(String agendaItemId) {
295 if (agendaItemId != null && StringUtils.isBlank(agendaItemId)) {
296 throw new IllegalArgumentException("agendaItemId must be null or non-blank");
297 }
298 this.id = agendaItemId;
299 }
300
301
302
303
304
305
306
307 public void setAgendaId(String agendaId) {
308 if (StringUtils.isBlank(agendaId)) {
309 throw new IllegalArgumentException("agendaId is blank");
310 }
311 this.agendaId = agendaId;
312 }
313
314
315
316
317
318 public void setRuleId(String ruleId) {
319 this.ruleId = ruleId;
320 }
321
322
323
324
325
326 public void setSubAgendaId(String subAgendaId) {
327 this.subAgendaId = subAgendaId;
328 }
329
330
331
332
333
334 public void setWhenTrueId(String whenTrueId) {
335 this.whenTrueId = whenTrueId;
336 }
337
338
339
340
341
342 public void setWhenFalseId(String whenFalseId) {
343 this.whenFalseId = whenFalseId;
344 }
345
346
347
348
349
350 public void setAlwaysId(String alwaysId) {
351 this.alwaysId = alwaysId;
352 }
353
354
355
356
357
358 public void setRule(RuleDefinition.Builder rule) {
359 this.rule = rule;
360 }
361
362
363
364
365
366 public void setSubAgenda(AgendaDefinition.Builder subAgenda) {
367 this.subAgenda = subAgenda;
368 }
369
370
371
372
373
374
375 public void setWhenTrue(AgendaItemDefinition.Builder whenTrue) {
376 this.whenTrue = whenTrue;
377 this.whenTrueId = (whenTrue != null) ? whenTrue.getId() : null;
378 }
379
380
381
382
383
384
385 public void setWhenFalse(AgendaItemDefinition.Builder whenFalse) {
386 this.whenFalse = whenFalse;
387 this.whenFalseId = (whenFalse != null) ? whenFalse.getId() : null;
388 }
389
390
391
392
393
394
395 public void setAlways(AgendaItemDefinition.Builder always) {
396 this.always = always;
397 this.alwaysId = (always != null) ? always.getId() : null;
398 }
399
400
401
402
403
404 public void setVersionNumber(Long versionNumber){
405 this.versionNumber = versionNumber;
406 }
407
408 @Override
409 public String getId() {
410 return id;
411 }
412
413 @Override
414 public String getAgendaId() {
415 return agendaId;
416 }
417
418 @Override
419 public String getRuleId() {
420 return ruleId;
421 }
422
423 @Override
424 public String getSubAgendaId() {
425 return subAgendaId;
426 }
427
428 @Override
429 public String getWhenTrueId() {
430 return whenTrueId;
431 }
432
433 @Override
434 public String getWhenFalseId() {
435 return whenFalseId;
436 }
437
438 @Override
439 public String getAlwaysId() {
440 return alwaysId;
441 }
442
443 @Override
444 public RuleDefinition.Builder getRule() {
445 return rule;
446 }
447
448 @Override
449 public AgendaDefinition.Builder getSubAgenda() {
450 return subAgenda;
451 }
452
453 @Override
454 public AgendaItemDefinition.Builder getWhenTrue() {
455 return whenTrue;
456 }
457
458 @Override
459 public AgendaItemDefinition.Builder getWhenFalse() {
460 return whenFalse;
461 }
462
463 @Override
464 public AgendaItemDefinition.Builder getAlways() {
465 return always;
466 }
467
468 @Override
469 public Long getVersionNumber() {
470 return versionNumber;
471 }
472
473
474
475
476
477
478 @Override
479 public AgendaItemDefinition build() {
480 return new AgendaItemDefinition(this);
481 }
482
483 }
484
485
486
487
488 static class Constants {
489 final static String ROOT_ELEMENT_NAME = "AgendaItemDefinition";
490 final static String TYPE_NAME = "AgendaItemType";
491 }
492
493
494
495
496
497 public static class Elements {
498 final static String ID = "id";
499 final static String AGENDA_ID = "agendaId";
500 final static String RULE_ID = "ruleId";
501 final static String SUB_AGENDA_ID = "subAgendaId";
502 final static String WHEN_TRUE_ID = "whenTrueId";
503 final static String WHEN_FALSE_ID = "whenFalseId";
504 final static String ALWAYS_ID = "alwaysId";
505
506 final static String RULE = "rule";
507 final static String SUB_AGENDA = "subAgenda";
508 final static String WHEN_TRUE = "whenTrue";
509 final static String WHEN_FALSE = "whenFalse";
510 final static String ALWAYS = "always";
511 }
512
513 public static class Cache {
514 public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + AgendaItemDefinition.Constants.TYPE_NAME;
515 }
516 }