001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ken.api.notification;
017
018 import java.io.Serializable;
019 import java.util.ArrayList;
020 import java.util.Collection;
021 import java.util.List;
022 import javax.xml.bind.annotation.XmlAccessType;
023 import javax.xml.bind.annotation.XmlAccessorType;
024 import javax.xml.bind.annotation.XmlAnyElement;
025 import javax.xml.bind.annotation.XmlElement;
026 import javax.xml.bind.annotation.XmlElementWrapper;
027 import javax.xml.bind.annotation.XmlRootElement;
028 import javax.xml.bind.annotation.XmlType;
029 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
030
031 import org.apache.commons.collections.CollectionUtils;
032 import org.joda.time.DateTime;
033 import org.kuali.rice.core.api.CoreConstants;
034 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
035 import org.kuali.rice.core.api.mo.ModelBuilder;
036 import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
037 import org.w3c.dom.Element;
038
039 @XmlRootElement(name = Notification.Constants.ROOT_ELEMENT_NAME)
040 @XmlAccessorType(XmlAccessType.NONE)
041 @XmlType(name = Notification.Constants.TYPE_NAME, propOrder = {
042 Notification.Elements.PRIORITY,
043 Notification.Elements.CONTENT,
044 Notification.Elements.CHANNEL,
045 Notification.Elements.CONTENT_TYPE,
046 Notification.Elements.CREATION_DATE_TIME,
047 Notification.Elements.RECIPIENTS,
048 Notification.Elements.SENDERS,
049 Notification.Elements.AUTO_REMOVE_DATE_TIME,
050 Notification.Elements.DELIVERY_TYPE,
051 Notification.Elements.PRODUCER,
052 Notification.Elements.SEND_DATE_TIME,
053 Notification.Elements.PROCESSING_FLAG,
054 Notification.Elements.LOCKED_DATE,
055 Notification.Elements.TITLE,
056 Notification.Elements.CONTENT_MESSAGE,
057 Notification.Elements.ID,
058 CoreConstants.CommonElements.VERSION_NUMBER,
059 CoreConstants.CommonElements.OBJECT_ID,
060 CoreConstants.CommonElements.FUTURE_ELEMENTS
061 })
062 public final class Notification
063 extends AbstractDataTransferObject
064 implements NotificationContract
065 {
066
067 @XmlElement(name = Elements.PRIORITY, required = false)
068 private final NotificationPriority priority;
069 @XmlElement(name = Elements.CONTENT, required = false)
070 private final String content;
071 @XmlElement(name = Elements.CHANNEL, required = false)
072 private final NotificationChannel channel;
073 @XmlElement(name = Elements.CONTENT_TYPE, required = false)
074 private final NotificationContentType contentType;
075 @XmlElement(name = Elements.CREATION_DATE_TIME, required = false)
076 @XmlJavaTypeAdapter(DateTimeAdapter.class)
077 private final DateTime creationDateTime;
078 @XmlElementWrapper(name = Elements.RECIPIENTS, required = false)
079 @XmlElement(name = Elements.RECIPIENT, required = false)
080 private final List<NotificationRecipient> recipients;
081 @XmlElementWrapper(name = Elements.SENDERS, required = false)
082 @XmlElement(name = Elements.SENDER, required = false)
083 private final List<NotificationSender> senders;
084 @XmlElement(name = Elements.AUTO_REMOVE_DATE_TIME, required = false)
085 @XmlJavaTypeAdapter(DateTimeAdapter.class)
086 private final DateTime autoRemoveDateTime;
087 @XmlElement(name = Elements.DELIVERY_TYPE, required = false)
088 private final String deliveryType;
089 @XmlElement(name = Elements.PRODUCER, required = false)
090 private final NotificationProducer producer;
091 @XmlElement(name = Elements.SEND_DATE_TIME, required = false)
092 @XmlJavaTypeAdapter(DateTimeAdapter.class)
093 private final DateTime sendDateTime;
094 @XmlElement(name = Elements.PROCESSING_FLAG, required = false)
095 private final String processingFlag;
096 @XmlElement(name = Elements.LOCKED_DATE, required = false)
097 @XmlJavaTypeAdapter(DateTimeAdapter.class)
098 private final DateTime lockedDate;
099 @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 }