View Javadoc

1   /**
2    * Copyright 2005-2013 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.NotificationListRecipient;
19  import org.kuali.rice.ken.api.notification.NotificationListRecipientContract;
20  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
21  
22  import javax.persistence.CascadeType;
23  import javax.persistence.Column;
24  import javax.persistence.Entity;
25  import javax.persistence.FetchType;
26  import javax.persistence.GeneratedValue;
27  import javax.persistence.Id;
28  import javax.persistence.JoinColumn;
29  import javax.persistence.ManyToOne;
30  import javax.persistence.Parameter;
31  import javax.persistence.Table;
32  
33  /**
34   * This class represents the data structure that will house a default recipient list for a notification channel.
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  @Entity
38  @Table(name="KREN_RECIP_LIST_T")
39  public class NotificationRecipientListBo extends PersistableBusinessObjectBase implements NotificationListRecipientContract {
40      @Id
41      @GeneratedValue(generator="KREN_RECIP_LIST_S")
42  	@Column(name="RECIP_LIST_ID")
43  	private Long id;
44      @Column(name="RECIP_TYP_CD", nullable=false)
45  	private String recipientType;
46      @Column(name="RECIP_ID", nullable=false)
47  	private String recipientId;
48      
49      @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.MERGE})
50  	@JoinColumn(name="CHNL_ID", insertable=false, updatable=false)
51  	private NotificationChannelBo channel;
52      
53      /**
54       * Constructs a NotificationRecipientList.java instance.
55       */
56      public NotificationRecipientListBo() {
57      }
58  
59      /**
60       * Gets the channel attribute. 
61       * @return Returns the channel.
62       */
63      public NotificationChannelBo getChannel() {
64          return channel;
65      }
66  
67  
68      /**
69       * Sets the channel attribute value.
70       * @param channel The channel to set.
71       */
72      public void setChannel(NotificationChannelBo channel) {
73          this.channel = channel;
74      }
75  
76      /**
77       * Gets the id attribute. 
78       * @return Returns the id.
79       */
80      public Long getId() {
81          return id;
82      }
83  
84      /**
85       * Sets the id attribute value.
86       * @param id The id to set.
87       */
88      public void setId(Long id) {
89          this.id = id;
90      }
91  
92      /**
93       * Gets the recipientId attribute. 
94       * @return Returns the recipientId.
95       */
96      public String getRecipientId() {
97          return recipientId;
98      }
99  
100     /**
101      * Sets the recipientId attribute value.
102      * @param recipientId The recipientId to set.
103      */
104     public void setRecipientId(String recipientId) {
105         this.recipientId = recipientId;
106     }
107 
108     /**
109      * Gets the recipientType attribute. 
110      * @return Returns the recipientType.
111      */
112     public String getRecipientType() {
113         return recipientType;
114     }
115 
116     /**
117      * Sets the recipientType attribute value.
118      * @param recipientType The recipientType to set.
119      */
120     public void setRecipientType(String recipientType) {
121         this.recipientType = recipientType;
122     }
123 
124     /**
125      * Converts a mutable bo to its immutable counterpart
126      * @param bo the mutable business object
127      * @return the immutable object
128      */
129     public static NotificationListRecipient to(NotificationRecipientListBo bo) {
130         if (bo == null) {
131             return null;
132         }
133 
134         return NotificationListRecipient.Builder.create(bo).build();
135     }
136 
137     /**
138      * Converts a immutable object to its mutable counterpart
139      * @param im immutable object
140      * @return the mutable bo
141      */
142     public static NotificationRecipientListBo from(NotificationListRecipient im) {
143         if (im == null) {
144             return null;
145         }
146 
147         NotificationRecipientListBo bo = new NotificationRecipientListBo();
148         bo.setId(im.getId());
149         bo.setVersionNumber(im.getVersionNumber());
150         bo.setObjectId(im.getObjectId());
151 
152         bo.setRecipientType(im.getRecipientType());
153         bo.setRecipientId(im.getRecipientId());
154 
155         bo.setChannel(im.getChannel() == null ? null : NotificationChannelBo.from(im.getChannel()));
156         return bo;
157     }
158 }
159