View Javadoc

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