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.UserChannelSubscription;
19  import org.kuali.rice.ken.api.notification.UserChannelSubscriptionContract;
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.OneToOne;
31  import javax.persistence.Table;
32  
33  /**
34   * This class represents an instance of a user's subscription to a specific 
35   * notification channel.
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @Entity
39  @Table(name="KREN_CHNL_SUBSCRP_T")
40  public class UserChannelSubscriptionBo extends PersistableBusinessObjectBase implements UserChannelSubscriptionContract {
41      @Id
42      @GeneratedValue(generator="KREN_CHNL_SUBSCRP_S")
43      @PortableSequenceGenerator(name="KREN_CHNL_SUBSCRP_S")
44  	@Column(name="CHNL_SUBSCRP_ID")
45  	private Long id;
46      @Column(name="PRNCPL_ID", nullable=false)
47  	private String userId;
48      
49      @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.MERGE})
50  	@JoinColumn(name="CHNL_ID")
51  	private NotificationChannelBo channel;
52      
53      /**
54       * Constructs a UserChannelSubscription instance.
55       */
56      public UserChannelSubscriptionBo() {
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       * Sets the channel attribute value.
69       * @param channel The channel to set.
70       */
71      public void setChannel(NotificationChannelBo channel) {
72  	    this.channel = channel;
73      }
74  
75      /**
76       * Gets the id attribute. 
77       * @return Returns the id.
78       */
79      public Long getId() {
80  	    return id;
81      }
82  
83      /**
84       * Sets the id attribute value.
85       * @param id The id to set.
86       */
87      public void setId(Long id) {
88  	    this.id = id;
89      }
90  
91      /**
92       * Gets the userId attribute. 
93       * @return Returns the userId.
94       */
95      public String getUserId() {
96  	    return userId;
97      }
98  
99      /**
100      * Sets the userId attribute value.
101      * @param userId The userId to set.
102      */
103     public void setUserId(String userId) {
104 	    this.userId = 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 UserChannelSubscription to(UserChannelSubscriptionBo bo) {
113         if (bo == null) {
114             return null;
115         }
116 
117         return UserChannelSubscription.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 UserChannelSubscriptionBo from(UserChannelSubscription im) {
126         if (im == null) {
127             return null;
128         }
129 
130         UserChannelSubscriptionBo bo = new UserChannelSubscriptionBo();
131         bo.setId(im.getId());
132         bo.setVersionNumber(im.getVersionNumber());
133         bo.setObjectId(im.getObjectId());
134 
135         bo.setUserId(im.getUserId());
136         bo.setChannel(im.getChannel() == null ? null : NotificationChannelBo.from(im.getChannel()));
137         
138         return bo;
139     }
140 }
141