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