1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.api.notification;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22 import javax.xml.bind.annotation.XmlAccessType;
23 import javax.xml.bind.annotation.XmlAccessorType;
24 import javax.xml.bind.annotation.XmlAnyElement;
25 import javax.xml.bind.annotation.XmlElement;
26 import javax.xml.bind.annotation.XmlElementWrapper;
27 import javax.xml.bind.annotation.XmlRootElement;
28 import javax.xml.bind.annotation.XmlType;
29 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
30
31 import org.apache.commons.collections.CollectionUtils;
32 import org.joda.time.DateTime;
33 import org.kuali.rice.core.api.CoreConstants;
34 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
35 import org.kuali.rice.core.api.mo.ModelBuilder;
36 import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
37 import org.w3c.dom.Element;
38
39 @XmlRootElement(name = Notification.Constants.ROOT_ELEMENT_NAME)
40 @XmlAccessorType(XmlAccessType.NONE)
41 @XmlType(name = Notification.Constants.TYPE_NAME, propOrder = {
42 Notification.Elements.PRIORITY,
43 Notification.Elements.CONTENT,
44 Notification.Elements.CHANNEL,
45 Notification.Elements.CONTENT_TYPE,
46 Notification.Elements.CREATION_DATE_TIME,
47 Notification.Elements.RECIPIENTS,
48 Notification.Elements.SENDERS,
49 Notification.Elements.AUTO_REMOVE_DATE_TIME,
50 Notification.Elements.DELIVERY_TYPE,
51 Notification.Elements.PRODUCER,
52 Notification.Elements.SEND_DATE_TIME,
53 Notification.Elements.PROCESSING_FLAG,
54 Notification.Elements.LOCKED_DATE,
55 Notification.Elements.TITLE,
56 Notification.Elements.CONTENT_MESSAGE,
57 Notification.Elements.ID,
58 CoreConstants.CommonElements.VERSION_NUMBER,
59 CoreConstants.CommonElements.OBJECT_ID,
60 Notification.Elements.DOC_TYPE_NAME,
61 CoreConstants.CommonElements.FUTURE_ELEMENTS
62 })
63 public final class Notification
64 extends AbstractDataTransferObject
65 implements NotificationContract
66 {
67
68 @XmlElement(name = Elements.PRIORITY, required = false)
69 private final NotificationPriority priority;
70 @XmlElement(name = Elements.CONTENT, required = false)
71 private final String content;
72 @XmlElement(name = Elements.CHANNEL, required = false)
73 private final NotificationChannel channel;
74 @XmlElement(name = Elements.CONTENT_TYPE, required = false)
75 private final NotificationContentType contentType;
76 @XmlElement(name = Elements.CREATION_DATE_TIME, required = false)
77 @XmlJavaTypeAdapter(DateTimeAdapter.class)
78 private final DateTime creationDateTime;
79 @XmlElementWrapper(name = Elements.RECIPIENTS, required = false)
80 @XmlElement(name = Elements.RECIPIENT, required = false)
81 private final List<NotificationRecipient> recipients;
82 @XmlElementWrapper(name = Elements.SENDERS, required = false)
83 @XmlElement(name = Elements.SENDER, required = false)
84 private final List<NotificationSender> senders;
85 @XmlElement(name = Elements.AUTO_REMOVE_DATE_TIME, required = false)
86 @XmlJavaTypeAdapter(DateTimeAdapter.class)
87 private final DateTime autoRemoveDateTime;
88 @XmlElement(name = Elements.DELIVERY_TYPE, required = false)
89 private final String deliveryType;
90 @XmlElement(name = Elements.PRODUCER, required = false)
91 private final NotificationProducer producer;
92 @XmlElement(name = Elements.SEND_DATE_TIME, required = false)
93 @XmlJavaTypeAdapter(DateTimeAdapter.class)
94 private final DateTime sendDateTime;
95 @XmlElement(name = Elements.PROCESSING_FLAG, required = false)
96 private final String processingFlag;
97 @XmlElement(name = Elements.LOCKED_DATE, required = false)
98 @XmlJavaTypeAdapter(DateTimeAdapter.class)
99 private final DateTime lockedDate;
100 @XmlElement(name = Elements.TITLE, required = false)
101 private final String title;
102 @XmlElement(name = Elements.CONTENT_MESSAGE, required = false)
103 private final String contentMessage;
104 @XmlElement(name = Elements.ID, required = false)
105 private final Long id;
106 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
107 private final Long versionNumber;
108 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
109 private final String objectId;
110
111
112
113
114 @XmlElement(name = Elements.DOC_TYPE_NAME, required = false)
115 private final String docTypeName;
116
117 @SuppressWarnings("unused")
118 @XmlAnyElement
119 private final Collection<Element> _futureElements = null;
120
121
122
123
124
125 private Notification() {
126 this.priority = null;
127 this.content = null;
128 this.channel = null;
129 this.contentType = null;
130 this.creationDateTime = null;
131 this.recipients = null;
132 this.senders = null;
133 this.autoRemoveDateTime = null;
134 this.deliveryType = null;
135 this.producer = null;
136 this.sendDateTime = null;
137 this.processingFlag = null;
138 this.lockedDate = null;
139 this.title = null;
140 this.contentMessage = null;
141 this.id = null;
142 this.versionNumber = null;
143 this.objectId = null;
144 this.docTypeName = null;
145 }
146
147 private Notification(Builder builder) {
148 this.priority = builder.getPriority() == null ? null : builder.getPriority().build();
149 this.content = builder.getContent();
150 this.channel = builder.getChannel() == null ? null : builder.getChannel().build();
151 this.contentType = builder.getContentType() == null ? null : builder.getContentType().build();
152 this.creationDateTime = builder.getCreationDateTime();
153 this.recipients = new ArrayList<NotificationRecipient>();
154 if (CollectionUtils.isNotEmpty(builder.getRecipients())) {
155 for (NotificationRecipient.Builder recipient : builder.getRecipients()) {
156 this.recipients.add(recipient.build());
157 }
158 }
159 this.senders = new ArrayList<NotificationSender>();
160 if (CollectionUtils.isNotEmpty(builder.getSenders())) {
161 for (NotificationSender.Builder sender : builder.getSenders()) {
162 this.senders.add(sender.build());
163 }
164 }
165 this.autoRemoveDateTime = builder.getAutoRemoveDateTime();
166 this.deliveryType = builder.getDeliveryType();
167 this.producer = builder.getProducer() == null ? null : builder.getProducer().build();
168 this.sendDateTime = builder.getSendDateTime();
169 this.processingFlag = builder.getProcessingFlag();
170 this.lockedDate = builder.getLockedDate();
171 this.title = builder.getTitle();
172 this.contentMessage = builder.getContentMessage();
173 this.id = builder.getId();
174 this.versionNumber = builder.getVersionNumber();
175 this.objectId = builder.getObjectId();
176 this.docTypeName = builder.getDocTypeName();
177 }
178
179 @Override
180 public NotificationPriority getPriority() {
181 return this.priority;
182 }
183
184 @Override
185 public String getContent() {
186 return this.content;
187 }
188
189 @Override
190 public NotificationChannel getChannel() {
191 return this.channel;
192 }
193
194 @Override
195 public NotificationContentType getContentType() {
196 return this.contentType;
197 }
198
199 @Override
200 public DateTime getCreationDateTime() {
201 return this.creationDateTime;
202 }
203
204 @Override
205 public List<NotificationRecipient> getRecipients() {
206 return this.recipients;
207 }
208
209 @Override
210 public List<NotificationSender> getSenders() {
211 return this.senders;
212 }
213
214 @Override
215 public DateTime getAutoRemoveDateTime() {
216 return this.autoRemoveDateTime;
217 }
218
219 @Override
220 public String getDeliveryType() {
221 return this.deliveryType;
222 }
223
224 @Override
225 public NotificationProducer getProducer() {
226 return this.producer;
227 }
228
229 @Override
230 public DateTime getSendDateTime() {
231 return this.sendDateTime;
232 }
233
234 @Override
235 public String getProcessingFlag() {
236 return this.processingFlag;
237 }
238
239 @Override
240 public DateTime getLockedDate() {
241 return this.lockedDate;
242 }
243
244 @Override
245 public String getTitle() {
246 return this.title;
247 }
248
249 @Override
250 public String getContentMessage() {
251 return this.contentMessage;
252 }
253
254 @Override
255 public Long getId() {
256 return this.id;
257 }
258
259 @Override
260 public Long getVersionNumber() {
261 return this.versionNumber;
262 }
263
264 @Override
265 public String getObjectId() {
266 return this.objectId;
267 }
268
269 @Override
270 public String getDocTypeName() {
271 return this.docTypeName;
272 }
273
274
275
276
277
278
279 public final static class Builder
280 implements Serializable, ModelBuilder, NotificationContract
281 {
282
283 private NotificationPriority.Builder priority;
284 private String content;
285 private NotificationChannel.Builder channel;
286 private NotificationContentType.Builder contentType;
287 private DateTime creationDateTime;
288 private List<NotificationRecipient.Builder> recipients;
289 private List<NotificationSender.Builder> senders;
290 private DateTime autoRemoveDateTime;
291 private String deliveryType;
292 private NotificationProducer.Builder producer;
293 private DateTime sendDateTime;
294 private String processingFlag;
295 private DateTime lockedDate;
296 private String title;
297 private String contentMessage;
298 private Long id;
299 private Long versionNumber;
300 private String objectId;
301 private String docTypeName;
302
303 private Builder() {
304
305 }
306
307 public static Builder create() {
308
309 return new Builder();
310 }
311
312 public static Builder create(NotificationContract contract) {
313 if (contract == null) {
314 throw new IllegalArgumentException("contract was null");
315 }
316
317 Builder builder = create();
318 builder.setPriority(contract.getPriority() == null ? null : NotificationPriority.Builder.create(contract.getPriority()));
319 builder.setContent(contract.getContent());
320 builder.setChannel(contract.getChannel() == null ? null : NotificationChannel.Builder.create(contract.getChannel()));
321 builder.setContentType(contract.getContentType() == null ? null : NotificationContentType.Builder.create(contract.getContentType()));
322 builder.setCreationDateTime(contract.getCreationDateTime());
323 if (contract.getRecipients() != null) {
324 List<NotificationRecipient.Builder> tempRecipients = new ArrayList<NotificationRecipient.Builder>();
325 for (NotificationRecipientContract recipient : contract.getRecipients()) {
326 tempRecipients.add(NotificationRecipient.Builder.create(recipient));
327 }
328 builder.setRecipients(tempRecipients);
329 }
330 if (contract.getSenders() != null) {
331 List<NotificationSender.Builder> tempSenders = new ArrayList<NotificationSender.Builder>();
332 for (NotificationSenderContract sender : contract.getSenders()) {
333 tempSenders.add(NotificationSender.Builder.create(sender));
334 }
335 builder.setSenders(tempSenders);
336 }
337 builder.setAutoRemoveDateTime(contract.getAutoRemoveDateTime());
338 builder.setDeliveryType(contract.getDeliveryType());
339 builder.setProducer(contract.getProducer() == null ? null : NotificationProducer.Builder.create(contract.getProducer()));
340 builder.setSendDateTime(contract.getSendDateTime());
341 builder.setProcessingFlag(contract.getProcessingFlag());
342 builder.setLockedDate(contract.getLockedDate());
343 builder.setTitle(contract.getTitle());
344 builder.setContentMessage(contract.getContentMessage());
345 builder.setId(contract.getId());
346 builder.setVersionNumber(contract.getVersionNumber());
347 builder.setObjectId(contract.getObjectId());
348 builder.setDocTypeName(contract.getDocTypeName());
349 return builder;
350 }
351
352 public Notification build() {
353 return new Notification(this);
354 }
355
356 @Override
357 public NotificationPriority.Builder getPriority() {
358 return this.priority;
359 }
360
361 @Override
362 public String getContent() {
363 return this.content;
364 }
365
366 @Override
367 public NotificationChannel.Builder getChannel() {
368 return this.channel;
369 }
370
371 @Override
372 public NotificationContentType.Builder getContentType() {
373 return this.contentType;
374 }
375
376 @Override
377 public DateTime getCreationDateTime() {
378 return this.creationDateTime;
379 }
380
381 @Override
382 public List<NotificationRecipient.Builder> getRecipients() {
383 return this.recipients;
384 }
385
386 @Override
387 public List<NotificationSender.Builder> getSenders() {
388 return this.senders;
389 }
390
391 @Override
392 public DateTime getAutoRemoveDateTime() {
393 return this.autoRemoveDateTime;
394 }
395
396 @Override
397 public String getDeliveryType() {
398 return this.deliveryType;
399 }
400
401 @Override
402 public NotificationProducer.Builder getProducer() {
403 return this.producer;
404 }
405
406 @Override
407 public DateTime getSendDateTime() {
408 return this.sendDateTime;
409 }
410
411 @Override
412 public String getProcessingFlag() {
413 return this.processingFlag;
414 }
415
416 @Override
417 public DateTime getLockedDate() {
418 return this.lockedDate;
419 }
420
421 @Override
422 public String getTitle() {
423 return this.title;
424 }
425
426 @Override
427 public String getContentMessage() {
428 return this.contentMessage;
429 }
430
431 @Override
432 public Long getId() {
433 return this.id;
434 }
435
436 @Override
437 public Long getVersionNumber() {
438 return this.versionNumber;
439 }
440
441 @Override
442 public String getObjectId() {
443 return this.objectId;
444 }
445
446 @Override
447 public String getDocTypeName() {
448 return this.docTypeName;
449 }
450
451 public void setPriority(NotificationPriority.Builder priority) {
452 this.priority = priority;
453 }
454
455 public void setContent(String content) {
456 this.content = content;
457 }
458
459 public void setChannel(NotificationChannel.Builder channel) {
460 this.channel = channel;
461 }
462
463 public void setContentType(NotificationContentType.Builder contentType) {
464 this.contentType = contentType;
465 }
466
467 public void setCreationDateTime(DateTime creationDateTime) {
468 this.creationDateTime = creationDateTime;
469 }
470
471 public void setRecipients(List<NotificationRecipient.Builder> recipients) {
472 this.recipients = recipients;
473 }
474
475 public void setSenders(List<NotificationSender.Builder> senders) {
476 this.senders = senders;
477 }
478
479 public void setAutoRemoveDateTime(DateTime autoRemoveDateTime) {
480 this.autoRemoveDateTime = autoRemoveDateTime;
481 }
482
483 public void setDeliveryType(String deliveryType) {
484 this.deliveryType = deliveryType;
485 }
486
487 public void setProducer(NotificationProducer.Builder producer) {
488 this.producer = producer;
489 }
490
491 public void setSendDateTime(DateTime sendDateTime) {
492 this.sendDateTime = sendDateTime;
493 }
494
495 public void setProcessingFlag(String processingFlag) {
496 this.processingFlag = processingFlag;
497 }
498
499 public void setLockedDate(DateTime lockedDate) {
500 this.lockedDate = lockedDate;
501 }
502
503 public void setTitle(String title) {
504 this.title = title;
505 }
506
507 public void setContentMessage(String contentMessage) {
508 this.contentMessage = contentMessage;
509 }
510
511 public void setId(Long id) {
512 this.id = id;
513 }
514
515 public void setVersionNumber(Long versionNumber) {
516 this.versionNumber = versionNumber;
517 }
518
519 public void setObjectId(String objectId) {
520 this.objectId = objectId;
521 }
522
523
524
525
526
527
528
529
530
531
532
533
534 public void setDocTypeName(String docTypeName) {
535 this.docTypeName = docTypeName;
536 }
537 }
538
539
540
541
542
543
544 static class Constants {
545
546 final static String ROOT_ELEMENT_NAME = "notification";
547 final static String TYPE_NAME = "NotificationType";
548
549 }
550
551
552
553
554
555
556 static class Elements {
557
558 final static String PRIORITY = "priority";
559 final static String CONTENT = "content";
560 final static String CHANNEL = "channel";
561 final static String CONTENT_TYPE = "contentType";
562 final static String CREATION_DATE_TIME = "creationDateTime";
563 final static String LOCK_VER_NBR = "lockVerNbr";
564 final static String RECIPIENTS = "recipients";
565 final static String RECIPIENT = "recipient";
566 final static String SENDERS = "senders";
567 final static String SENDER = "sender";
568 final static String AUTO_REMOVE_DATE_TIME = "autoRemoveDateTime";
569 final static String DELIVERY_TYPE = "deliveryType";
570 final static String PRODUCER = "producer";
571 final static String SEND_DATE_TIME = "sendDateTime";
572 final static String PROCESSING_FLAG = "processingFlag";
573 final static String LOCKED_DATE = "lockedDate";
574 final static String TITLE = "title";
575 final static String CONTENT_MESSAGE = "contentMessage";
576 final static String ID = "id";
577 final static String DOC_TYPE_NAME = "docTypeName";
578
579 }
580
581 }