Coverage Report - org.kuali.rice.ken.bo.Notification
 
Classes in this File Line Coverage Branch Coverage Complexity
Notification
0%
0/61
0%
0/4
1.051
 
 1  
 /*
 2  
  * Copyright 2007 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.bo;
 17  
 
 18  
 import java.sql.Timestamp;
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.persistence.Basic;
 23  
 import javax.persistence.CascadeType;
 24  
 import javax.persistence.Column;
 25  
 import javax.persistence.Entity;
 26  
 import javax.persistence.FetchType;
 27  
 import javax.persistence.Id;
 28  
 import javax.persistence.JoinColumn;
 29  
 import javax.persistence.Lob;
 30  
 import javax.persistence.OneToMany;
 31  
 import javax.persistence.OneToOne;
 32  
 import javax.persistence.Table;
 33  
 import javax.persistence.Version;
 34  
 
 35  
 import org.apache.commons.lang.StringUtils;
 36  
 import org.apache.commons.lang.builder.ToStringBuilder;
 37  
 import org.kuali.rice.ken.util.NotificationConstants;
 38  
 
 39  
 /**
 40  
  * This class represents an instace of a notification message that is received by the overall 
 41  
  * system.
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  */
 44  
 @Entity
 45  
 @Table(name="KREN_NTFCTN_T")
 46  
 public class Notification implements Lockable {
 47  
     @Id
 48  
         @Column(name="NTFCTN_ID")
 49  
         private Long id;
 50  
     @Column(name="DELIV_TYP", nullable=false)
 51  
         private String deliveryType;
 52  
         @Column(name="CRTE_DTTM", nullable=false)
 53  
         private Timestamp creationDateTime;
 54  
         @Column(name="SND_DTTM", nullable=true)
 55  
         private Timestamp sendDateTime;
 56  
         @Column(name="AUTO_RMV_DTTM", nullable=true)
 57  
         private Timestamp autoRemoveDateTime;
 58  
     @Column(name="TTL", nullable=true)
 59  
         private String title;
 60  
     @Lob
 61  
         @Basic(fetch=FetchType.LAZY)
 62  
         @Column(name="CNTNT", nullable=false)
 63  
         private String content;
 64  
     @Column(name="PROCESSING_FLAG", nullable=false)
 65  
         private String processingFlag;
 66  
         @Column(name="LOCKD_DTTM", nullable=true)
 67  
         private Timestamp lockedDate;
 68  
     /**
 69  
      * Lock column for OJB optimistic locking
 70  
      */
 71  
     @Version
 72  
         @Column(name="VER_NBR")
 73  
         private Integer lockVerNbr;
 74  
     
 75  
     // object references
 76  
     @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
 77  
         @JoinColumn(name="PRIO_ID")
 78  
         private NotificationPriority priority;
 79  
     @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
 80  
         @JoinColumn(name="CNTNT_TYP_ID")
 81  
         private NotificationContentType contentType;
 82  
     @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
 83  
         @JoinColumn(name="CHNL_ID")
 84  
         private NotificationChannel channel;
 85  
     @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
 86  
         @JoinColumn(name="PRODCR_ID")
 87  
         private NotificationProducer producer;
 88  
     
 89  
     // lists
 90  
     @OneToMany(cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE},
 91  
            targetEntity=org.kuali.rice.ken.bo.NotificationRecipient.class, mappedBy="notification")
 92  
         private List<NotificationRecipient> recipients;
 93  
     @OneToMany(cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE},
 94  
            targetEntity=org.kuali.rice.ken.bo.NotificationSender.class, mappedBy="notification")
 95  
         private List<NotificationSender> senders;
 96  
     
 97  
     /**
 98  
      * Constructs a Notification instance.
 99  
      */
 100  0
     public Notification() {
 101  0
         recipients = new ArrayList<NotificationRecipient>();
 102  0
         senders = new ArrayList<NotificationSender>();
 103  0
         processingFlag = NotificationConstants.PROCESSING_FLAGS.UNRESOLVED;
 104  0
     }
 105  
 
 106  
     /**
 107  
      * Returns when this Notification entry was created 
 108  
      * @return when this Notification entry was created
 109  
      */
 110  
     public Timestamp getCreationDateTime() {
 111  0
         return creationDateTime;
 112  
     }
 113  
 
 114  
     /**
 115  
      * Sets the creation date of this Notification entry
 116  
      * @param created the creation date of this Notification entry
 117  
      */
 118  
     public void setCreationDateTime(Timestamp created) {
 119  0
         this.creationDateTime = created;
 120  0
     }
 121  
 
 122  
     /**
 123  
      * Return value of lock column for OJB optimistic locking
 124  
      * @return value of lock column for OJB optimistic locking
 125  
      */
 126  
     public Integer getLockVerNbr() {
 127  0
         return lockVerNbr;
 128  
     }
 129  
 
 130  
     /**
 131  
      * Set value of lock column for OJB optimistic locking
 132  
      * @param lockVerNbr value of lock column for OJB optimistic locking
 133  
      */
 134  
     public void setLockVerNbr(Integer lockVerNbr) {
 135  0
         this.lockVerNbr = lockVerNbr;
 136  0
     }
 137  
 
 138  
     /**
 139  
      * Gets the recipients attribute. 
 140  
      * @return Returns the recipients.
 141  
      */
 142  
     public List<NotificationRecipient> getRecipients() {
 143  0
         return recipients;
 144  
     }
 145  
 
 146  
     /**
 147  
      * Sets the recipients attribute value.
 148  
      * @param recipients The recipients to set.
 149  
      */
 150  
     public void setRecipients(List<NotificationRecipient> recipients) {
 151  0
         this.recipients = recipients;
 152  0
     }
 153  
 
 154  
     /**
 155  
      * Retrieves a recipient at the specified index
 156  
      * @param index the index in the recipients collection
 157  
      * @return the recipient if found or null
 158  
      */
 159  
     public NotificationRecipient getRecipient(int index) {
 160  0
         return (NotificationRecipient) recipients.get(index);
 161  
     }
 162  
     
 163  
     /**
 164  
      * Adds a recipient
 165  
      * @param recipient The recipient to add
 166  
      */
 167  
     public void addRecipient(NotificationRecipient recipient) {
 168  0
         recipients.add(recipient);
 169  0
     }
 170  
 
 171  
     /**
 172  
      * Gets the senders attribute. 
 173  
      * @return Returns the senders.
 174  
      */
 175  
     public List<NotificationSender> getSenders() {
 176  0
         return senders;
 177  
     }
 178  
 
 179  
     /**
 180  
      * Sets the senders attribute value.
 181  
      * @param senders The senders to set.
 182  
      */
 183  
     public void setSenders(List<NotificationSender> senders) {
 184  0
         this.senders = senders;
 185  0
     }
 186  
 
 187  
     /**
 188  
      * Retrieves a sender at the specified index
 189  
      * @param index the index in the senders collection
 190  
      * @return the sender if found or null
 191  
      */
 192  
     public NotificationSender getSender(int index) {
 193  0
         return (NotificationSender) senders.get(index);
 194  
     }
 195  
     /**
 196  
      * Adds a sender
 197  
      * @param sender The sender to add
 198  
      */
 199  
     public void addSender(NotificationSender sender) {
 200  0
         senders.add(sender);
 201  0
     }
 202  
 
 203  
     /**
 204  
      * Gets the autoRemoveDateTime attribute. 
 205  
      * @return Returns the autoRemoveDateTime.
 206  
      */
 207  
     public Timestamp getAutoRemoveDateTime() {
 208  0
         return autoRemoveDateTime;
 209  
     }
 210  
 
 211  
     /**
 212  
      * Sets the autoRemoveDateTime attribute value.
 213  
      * @param autoRemoveDateTime The autoRemoveDateTime to set.
 214  
      */
 215  
     public void setAutoRemoveDateTime(Timestamp autoRemoveDateTime) {
 216  0
         this.autoRemoveDateTime = autoRemoveDateTime;
 217  0
     }
 218  
 
 219  
     /**
 220  
      * Gets the channel attribute. 
 221  
      * @return Returns the channel.
 222  
      */
 223  
     public NotificationChannel getChannel() {
 224  0
         return channel;
 225  
     }
 226  
 
 227  
     /**
 228  
      * Sets the channel attribute value.
 229  
      * @param channel The channel to set.
 230  
      */
 231  
     public void setChannel(NotificationChannel channel) {
 232  0
         this.channel = channel;
 233  0
     }
 234  
 
 235  
     /**
 236  
      * Gets the content attribute. 
 237  
      * @return Returns the content.
 238  
      */
 239  
     public String getContent() {
 240  0
         return content;
 241  
     }
 242  
 
 243  
     /**
 244  
      * Sets the content attribute value.
 245  
      * @param content The content to set.
 246  
      */
 247  
     public void setContent(String content) {
 248  0
         this.content = content;
 249  0
     }
 250  
 
 251  
     /**
 252  
      * Gets the contentType attribute. 
 253  
      * @return Returns the contentType.
 254  
      */
 255  
     public NotificationContentType getContentType() {
 256  0
         return contentType;
 257  
     }
 258  
 
 259  
     /**
 260  
      * Sets the contentType attribute value.
 261  
      * @param contentType The contentType to set.
 262  
      */
 263  
     public void setContentType(NotificationContentType contentType) {
 264  0
         this.contentType = contentType;
 265  0
     }
 266  
 
 267  
     /**
 268  
      * Gets the deliveryType attribute. 
 269  
      * @return Returns the deliveryType.
 270  
      */
 271  
     public String getDeliveryType() {
 272  0
         return deliveryType;
 273  
     }
 274  
 
 275  
     /**
 276  
      * Sets the deliveryType attribute value.
 277  
      * @param deliveryType The deliveryType to set.
 278  
      */
 279  
     public void setDeliveryType(String deliveryType) {
 280  0
         this.deliveryType = deliveryType.toUpperCase();
 281  0
     }
 282  
 
 283  
     /**
 284  
      * Gets the id attribute. 
 285  
      * @return Returns the id.
 286  
      */
 287  
     public Long getId() {
 288  0
         return id;
 289  
     }
 290  
 
 291  
     /**
 292  
      * Sets the id attribute value.
 293  
      * @param id The id to set.
 294  
      */
 295  
     public void setId(Long id) {
 296  0
         this.id = id;
 297  0
     }
 298  
 
 299  
     /**
 300  
      * Gets the priority attribute. 
 301  
      * @return Returns the priority.
 302  
      */
 303  
     public NotificationPriority getPriority() {
 304  0
         return priority;
 305  
     }
 306  
 
 307  
     /**
 308  
      * Sets the priority attribute value.
 309  
      * @param priority The priority to set.
 310  
      */
 311  
     public void setPriority(NotificationPriority priority) {
 312  0
         this.priority = priority;
 313  0
     }
 314  
 
 315  
     /**
 316  
      * Gets the producer attribute. 
 317  
      * @return Returns the producer.
 318  
      */
 319  
     public NotificationProducer getProducer() {
 320  0
         return producer;
 321  
     }
 322  
 
 323  
     /**
 324  
      * Sets the producer attribute value.
 325  
      * @param producer The producer to set.
 326  
      */
 327  
     public void setProducer(NotificationProducer producer) {
 328  0
         this.producer = producer;
 329  0
     }
 330  
 
 331  
     /**
 332  
      * Gets the sendDateTime attribute. 
 333  
      * @return Returns the sendDateTime.
 334  
      */
 335  
     public Timestamp getSendDateTime() {
 336  0
         return sendDateTime;
 337  
     }
 338  
 
 339  
     /**
 340  
      * Sets the sendDateTime attribute value.
 341  
      * @param sendDateTime The sendDateTime to set.
 342  
      */
 343  
     public void setSendDateTime(Timestamp sendDateTime) {
 344  0
         this.sendDateTime = sendDateTime;
 345  0
     }
 346  
 
 347  
     /**
 348  
      * Gets the processingFlag attribute. 
 349  
      * @return Returns the processingFlag.
 350  
      */
 351  
     public String getProcessingFlag() {
 352  0
         return processingFlag;
 353  
     }
 354  
 
 355  
     /**
 356  
      * Sets the processingFlag attribute value.
 357  
      * @param processingFlag The processingFlag to set.
 358  
      */
 359  
     public void setProcessingFlag(String processingFlag) {
 360  0
         this.processingFlag = processingFlag;
 361  0
     }
 362  
     
 363  
     /**
 364  
      * Gets the lockedDate attribute. 
 365  
      * @return Returns the lockedDate.
 366  
      */
 367  
     public Timestamp getLockedDate() {
 368  0
         return lockedDate;
 369  
     }
 370  
     
 371  
     /**
 372  
      * Sets the lockedDate attribute value.
 373  
      * @param lockedDate The lockedDate to set.
 374  
      */
 375  
     public void setLockedDate(Timestamp lockedDate) {
 376  0
         this.lockedDate = lockedDate;
 377  0
     }
 378  
 
 379  
     /**
 380  
      * Gets the title
 381  
      * @return the title of this notification
 382  
      */
 383  
     public String getTitle() {
 384  0
         return title;
 385  
     }
 386  
 
 387  
     /**
 388  
      * Sets the title
 389  
      * @param title the title of this notification
 390  
      */
 391  
     public void setTitle(String title) {
 392  0
         this.title = title;
 393  0
     }
 394  
 
 395  
     /**
 396  
      * This method just uses StringUtils to get at the content of the <message> tag 
 397  
      * that exists in the notification content.
 398  
      * @return String
 399  
      */
 400  
     public String getContentMessage() {
 401  0
         return StringUtils.substringBetween(content, NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_OPEN, NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_CLOSE);        
 402  
     }
 403  
     
 404  
     /**
 405  
      * @see java.lang.Object#toString()
 406  
      */
 407  
     public String toString() {
 408  0
         return new ToStringBuilder(this)
 409  
                        .append("id", id)
 410  
                        .append("deliveryType", deliveryType)
 411  
                        .append("sendDateTime", sendDateTime)
 412  
                        .append("autoRemoveDateTime", autoRemoveDateTime)
 413  
                        .append("content", StringUtils.abbreviate(content, 100))
 414  
                        .append("processingFlag", processingFlag)
 415  
                        .append("lockedDate", lockedDate)
 416  
                        .append("lockVerNbr", lockVerNbr)
 417  
                        .append("priority", priority)
 418  
                        .append("contentType", contentType)
 419  
                        .append("channel", channel)
 420  
                        .append("producer", producer)
 421  
                        .append("recipients", recipients == null ? null : "" + recipients.size())
 422  
                        .append("senders", senders == null ? null : "" + senders.size()).toString();
 423  
     }
 424  
 }