View Javadoc
1   /**
2    * Copyright 2005-2015 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  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
22  
23  import javax.persistence.CascadeType;
24  import javax.persistence.Column;
25  import javax.persistence.Entity;
26  import javax.persistence.FetchType;
27  import javax.persistence.GeneratedValue;
28  import javax.persistence.Id;
29  import javax.persistence.JoinColumn;
30  import javax.persistence.ManyToOne;
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      @PortableSequenceGenerator(name="KREN_RECIP_LIST_S")
43  	@Column(name="RECIP_LIST_ID")
44  	private Long id;
45      @Column(name="RECIP_TYP_CD", nullable=false)
46  	private String recipientType;
47      @Column(name="RECIP_ID", nullable=false)
48  	private String recipientId;
49      
50      @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.MERGE})
51  	@JoinColumn(name="CHNL_ID", insertable=false, updatable=false)
52  	private NotificationChannelBo channel;
53      
54      /**
55       * Constructs a NotificationRecipientList.java instance.
56       */
57      public NotificationRecipientListBo() {
58      }
59  
60      /**
61       * Gets the channel attribute. 
62       * @return Returns the channel.
63       */
64      public NotificationChannelBo getChannel() {
65          return channel;
66      }
67  
68  
69      /**
70       * Sets the channel attribute value.
71       * @param channel The channel to set.
72       */
73      public void setChannel(NotificationChannelBo channel) {
74          this.channel = channel;
75      }
76  
77      /**
78       * Gets the id attribute. 
79       * @return Returns the id.
80       */
81      public Long getId() {
82          return id;
83      }
84  
85      /**
86       * Sets the id attribute value.
87       * @param id The id to set.
88       */
89      public void setId(Long id) {
90          this.id = id;
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 NotificationListRecipient to(NotificationRecipientListBo bo) {
131         if (bo == null) {
132             return null;
133         }
134 
135         return NotificationListRecipient.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 NotificationRecipientListBo from(NotificationListRecipient im) {
144         if (im == null) {
145             return null;
146         }
147 
148         NotificationRecipientListBo bo = new NotificationRecipientListBo();
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 
156         bo.setChannel(im.getChannel() == null ? null : NotificationChannelBo.from(im.getChannel()));
157         return bo;
158     }
159 }
160