View Javadoc

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