001/** 002 * Copyright 2005-2014 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 */ 016package org.kuali.rice.ken.api.notification; 017 018import java.io.Serializable; 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.List; 022import javax.xml.bind.annotation.XmlAccessType; 023import javax.xml.bind.annotation.XmlAccessorType; 024import javax.xml.bind.annotation.XmlAnyElement; 025import javax.xml.bind.annotation.XmlElement; 026import javax.xml.bind.annotation.XmlElementWrapper; 027import javax.xml.bind.annotation.XmlRootElement; 028import javax.xml.bind.annotation.XmlType; 029import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 030 031import org.apache.commons.collections.CollectionUtils; 032import org.joda.time.DateTime; 033import org.kuali.rice.core.api.CoreConstants; 034import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 035import org.kuali.rice.core.api.mo.ModelBuilder; 036import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter; 037import 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 Notification.Elements.DOC_TYPE_NAME, 061 CoreConstants.CommonElements.FUTURE_ELEMENTS 062}) 063public final class Notification 064 extends AbstractDataTransferObject 065 implements NotificationContract 066{ 067 068 @XmlElement(name = Elements.PRIORITY, required = false) 069 private final NotificationPriority priority; 070 @XmlElement(name = Elements.CONTENT, required = false) 071 private final String content; 072 @XmlElement(name = Elements.CHANNEL, required = false) 073 private final NotificationChannel channel; 074 @XmlElement(name = Elements.CONTENT_TYPE, required = false) 075 private final NotificationContentType contentType; 076 @XmlElement(name = Elements.CREATION_DATE_TIME, required = false) 077 @XmlJavaTypeAdapter(DateTimeAdapter.class) 078 private final DateTime creationDateTime; 079 @XmlElementWrapper(name = Elements.RECIPIENTS, required = false) 080 @XmlElement(name = Elements.RECIPIENT, required = false) 081 private final List<NotificationRecipient> recipients; 082 @XmlElementWrapper(name = Elements.SENDERS, required = false) 083 @XmlElement(name = Elements.SENDER, required = false) 084 private final List<NotificationSender> senders; 085 @XmlElement(name = Elements.AUTO_REMOVE_DATE_TIME, required = false) 086 @XmlJavaTypeAdapter(DateTimeAdapter.class) 087 private final DateTime autoRemoveDateTime; 088 @XmlElement(name = Elements.DELIVERY_TYPE, required = false) 089 private final String deliveryType; 090 @XmlElement(name = Elements.PRODUCER, required = false) 091 private final NotificationProducer producer; 092 @XmlElement(name = Elements.SEND_DATE_TIME, required = false) 093 @XmlJavaTypeAdapter(DateTimeAdapter.class) 094 private final DateTime sendDateTime; 095 @XmlElement(name = Elements.PROCESSING_FLAG, required = false) 096 private final String processingFlag; 097 @XmlElement(name = Elements.LOCKED_DATE, required = false) 098 @XmlJavaTypeAdapter(DateTimeAdapter.class) 099 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 * @since 2.3.1 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 * Private constructor used only by JAXB. 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 * A builder which can be used to construct {@link Notification} instances. Enforces the constraints of the {@link NotificationContract}. 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 // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods 305 } 306 307 public static Builder create() { 308 // TODO modify as needed to pass any required values and add them to the signature of the 'create' method 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 // TODO if create() is modified to accept required parameters, this will need to be modified 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 * Sets the custom document type name. 525 * 526 * <p> 527 * If null, the system will use the default {@code KualiNotification} document type when routing the notification. 528 * If the document type does not match any document type name in the system, the system behavior is undefined. 529 * </p> 530 * 531 * @param docTypeName document type name of this notification 532 * @since 2.3.1 533 */ 534 public void setDocTypeName(String docTypeName) { 535 this.docTypeName = docTypeName; 536 } 537 } 538 539 540 /** 541 * Defines some internal constants used on this class. 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 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 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}