View Javadoc
1   /**
2    * Copyright 2005-2016 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 org.hibernate.annotations.GenericGenerator;
19  import org.hibernate.annotations.Parameter;
20  import org.kuali.rice.ken.api.notification.NotificationRecipient;
21  import org.kuali.rice.ken.api.notification.NotificationSender;
22  import org.kuali.rice.ken.api.notification.NotificationSenderContract;
23  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
24  
25  import javax.persistence.*;
26  
27  /**
28   * This class represents the data structure that will house information about the non-system 
29   * sender that a notification message is sent on behalf of.
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  @Entity
33  @Table(name="KREN_SNDR_T")
34  public class NotificationSenderBo extends PersistableBusinessObjectBase implements NotificationSenderContract {
35      @Id
36      @GeneratedValue(generator="KREN_SNDR_S")
37  	@GenericGenerator(name="KREN_SNDR_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
38  			@Parameter(name="sequence_name",value="KREN_SNDR_S"),
39  			@Parameter(name="value_column",value="id")
40  	})
41  	@Column(name="SNDR_ID")
42  	private Long id;
43      @Column(name="NTFCTN_ID", nullable=false)
44  	private Long notificationId;
45      @Column(name="NM", nullable=false)
46  	private String senderName;
47  
48      // Added for JPA uni-directional one-to-many (not yet supported by JPA)
49      @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE})
50      @JoinColumn(name="NTFCTN_ID", insertable=false, updatable=false)
51      private NotificationBo notification;
52  
53      /**
54       * Constructs a NotificationSender.java instance.
55       */
56      public NotificationSenderBo() {
57      }
58  
59      /**
60       * Gets the id attribute. 
61       * @return Returns the id.
62       */
63      public Long getId() {
64          return id;
65      }
66  
67      /**
68       * Sets the id attribute value.
69       * @param id The id to set.
70       */
71      public void setId(Long id) {
72          this.id = id;
73      }
74  
75      /**
76       * Gets the notificationId attribute. 
77       * @return Returns the notificationId.
78       */
79      public Long getNotificationId() {
80          return notificationId;
81      }
82  
83      /**
84       * Sets the notificationId attribute value.
85       * @param notificationId The notificationId to set.
86       */
87      public void setNotificationId(Long notificationId) {
88          this.notificationId = notificationId;
89      }
90  
91      /**
92       * Gets the senderName attribute. 
93       * @return Returns the senderName.
94       */
95      public String getSenderName() {
96          return senderName;
97      }
98  
99      /**
100      * Sets the senderName attribute value.
101      * @param userId The senderName to set.
102      */
103     public void setSenderName(String userId) {
104         this.senderName = userId;
105     }
106 
107     /**
108      * Converts a mutable bo to its immutable counterpart
109      * @param bo the mutable business object
110      * @return the immutable object
111      */
112     public static NotificationSender to(NotificationSenderBo bo) {
113         if (bo == null) {
114             return null;
115         }
116 
117         return NotificationSender.Builder.create(bo).build();
118     }
119 
120     /**
121      * Converts a immutable object to its mutable counterpart
122      * @param im immutable object
123      * @return the mutable bo
124      */
125     public static NotificationSenderBo from(NotificationSender im) {
126         if (im == null) {
127             return null;
128         }
129 
130         NotificationSenderBo bo = new NotificationSenderBo();
131         bo.setId(im.getId());
132         bo.setVersionNumber(im.getVersionNumber());
133         bo.setObjectId(im.getObjectId());
134         bo.setSenderName(im.getSenderName());
135         bo.setNotificationId(im.getNotificationId());
136         return bo;
137     }
138 }