View Javadoc

1   /**
2    * Copyright 2005-2014 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.NotificationListRecipient;
21  import org.kuali.rice.ken.api.notification.NotificationRecipient;
22  import org.kuali.rice.ken.api.notification.NotificationRecipientContract;
23  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
24  
25  import javax.persistence.*;
26  
27  /**
28   * This class houses information pertaining to each recipient for a Notification message.  This 
29   * recipient can be either a user or a group - which is specified by the recipient type.
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  @Entity
33  @Table(name="KREN_RECIP_T")
34  public class NotificationRecipientBo extends PersistableBusinessObjectBase implements NotificationRecipientContract {
35      @Id
36      @GeneratedValue(generator="KREN_RECIP_S")
37  	@GenericGenerator(name="KREN_RECIP_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
38  			@Parameter(name="sequence_name",value="KREN_RECIP_S"),
39  			@Parameter(name="value_column",value="id")
40  	})
41  	@Column(name="RECIP_ID")
42  	private Long id;
43      @Column(name="NTFCTN_ID", nullable=false)
44  	private Long notificationId;
45      @Column(name="RECIP_TYP_CD", nullable=false)
46  	private String recipientType;
47      @Column(name="PRNCPL_ID", nullable=false)
48  	private String recipientId;
49      
50      // Added for JPA uni-directional one-to-many (not yet supported by JPA)
51      @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE})
52      @JoinColumn(name="NTFCTN_ID", insertable=false, updatable=false)
53      private NotificationBo notification;
54      
55      /**
56       * Constructs a NotificationRecipient instance.
57       */
58      public NotificationRecipientBo() {
59      }
60  
61      /**
62       * Gets the id attribute. 
63       * @return Returns the id.
64       */
65      public Long getId() {
66  	    return id;
67      }
68  
69      /**
70       * Sets the id attribute value.
71       * @param id The id to set.
72       */
73      public void setId(Long id) {
74  	    this.id = id;
75      }
76  
77      /**
78       * Gets the notificationId attribute. 
79       * @return Returns the notificationId.
80       */
81      public Long getNotificationId() {
82  	    return notificationId;
83      }
84  
85      /**
86       * Sets the notificationId attribute value.
87       * @param notificationId The notificationId to set.
88       */
89      public void setNotificationId(Long notificationId) {
90  	    this.notificationId = notificationId;
91      }
92  
93      /**
94       * Gets the recipientId attribute. 
95       * @return Returns the recipientId.
96       */
97      public String getRecipientId() {
98  	    return recipientId;
99      }
100 
101     /**
102      * Sets the recipientId attribute value.
103      * @param recipientId The recipientId to set.
104      */
105     public void setRecipientId(String recipientId) {
106 	    this.recipientId = recipientId;
107     }
108 
109     /**
110      * Gets the recipientType attribute. 
111      * @return Returns the recipientType.
112      */
113     public String getRecipientType() {
114 	    return recipientType;
115     }
116 
117     /**
118      * Sets the recipientType attribute value.
119      * @param recipientType The recipientType to set.
120      */
121     public void setRecipientType(String recipientType) {
122 	    this.recipientType = recipientType;
123     }
124 
125     /**
126      * Converts a mutable bo to its immutable counterpart
127      * @param bo the mutable business object
128      * @return the immutable object
129      */
130     public static NotificationRecipient to(NotificationRecipientBo bo) {
131         if (bo == null) {
132             return null;
133         }
134 
135         return NotificationRecipient.Builder.create(bo).build();
136     }
137 
138     /**
139      * Converts a immutable object to its mutable counterpart
140      * @param im immutable object
141      * @return the mutable bo
142      */
143     public static NotificationRecipientBo from(NotificationRecipient im) {
144         if (im == null) {
145             return null;
146         }
147 
148         NotificationRecipientBo bo = new NotificationRecipientBo();
149         bo.setId(im.getId());
150         bo.setVersionNumber(im.getVersionNumber());
151         bo.setObjectId(im.getObjectId());
152 
153         bo.setRecipientType(im.getRecipientType());
154         bo.setRecipientId(im.getRecipientId());
155         bo.setNotificationId(im.getNotificationId());
156         return bo;
157     }
158 }
159