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.hibernate.annotations.GenericGenerator;
19  import org.hibernate.annotations.Parameter;
20  import org.kuali.rice.ken.api.notification.NotificationContentType;
21  import org.kuali.rice.ken.api.notification.UserChannelSubscription;
22  import org.kuali.rice.ken.api.notification.UserChannelSubscriptionContract;
23  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
24  
25  import javax.persistence.*;
26  
27  /**
28   * This class represents an instance of a user's subscription to a specific 
29   * notification channel.
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  @Entity
33  @Table(name="KREN_CHNL_SUBSCRP_T")
34  public class UserChannelSubscriptionBo extends PersistableBusinessObjectBase implements UserChannelSubscriptionContract {
35      @Id
36      @GeneratedValue(generator="KREN_CHNL_SUBSCRP_S")
37  	@GenericGenerator(name="KREN_CHNL_SUBSCRP_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
38  			@Parameter(name="sequence_name",value="KREN_CHNL_SUBSCRP_S"),
39  			@Parameter(name="value_column",value="id")
40  	})
41  	@Column(name="CHNL_SUBSCRP_ID")
42  	private Long id;
43      @Column(name="PRNCPL_ID", nullable=false)
44  	private String userId;
45      
46      @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.MERGE})
47  	@JoinColumn(name="CHNL_ID")
48  	private NotificationChannelBo channel;
49      
50      /**
51       * Constructs a UserChannelSubscription instance.
52       */
53      public UserChannelSubscriptionBo() {
54      }
55  
56      /**
57       * Gets the channel attribute. 
58       * @return Returns the channel.
59       */
60      public NotificationChannelBo getChannel() {
61  	    return channel;
62      }
63  
64      /**
65       * Sets the channel attribute value.
66       * @param channel The channel to set.
67       */
68      public void setChannel(NotificationChannelBo channel) {
69  	    this.channel = channel;
70      }
71  
72      /**
73       * Gets the id attribute. 
74       * @return Returns the id.
75       */
76      public Long getId() {
77  	    return id;
78      }
79  
80      /**
81       * Sets the id attribute value.
82       * @param id The id to set.
83       */
84      public void setId(Long id) {
85  	    this.id = id;
86      }
87  
88      /**
89       * Gets the userId attribute. 
90       * @return Returns the userId.
91       */
92      public String getUserId() {
93  	    return userId;
94      }
95  
96      /**
97       * Sets the userId attribute value.
98       * @param userId The userId to set.
99       */
100     public void setUserId(String userId) {
101 	    this.userId = userId;
102     }
103 
104     /**
105      * Converts a mutable bo to its immutable counterpart
106      * @param bo the mutable business object
107      * @return the immutable object
108      */
109     public static UserChannelSubscription to(UserChannelSubscriptionBo bo) {
110         if (bo == null) {
111             return null;
112         }
113 
114         return UserChannelSubscription.Builder.create(bo).build();
115     }
116 
117     /**
118      * Converts a immutable object to its mutable counterpart
119      * @param im immutable object
120      * @return the mutable bo
121      */
122     public static UserChannelSubscriptionBo from(UserChannelSubscription im) {
123         if (im == null) {
124             return null;
125         }
126 
127         UserChannelSubscriptionBo bo = new UserChannelSubscriptionBo();
128         bo.setId(im.getId());
129         bo.setVersionNumber(im.getVersionNumber());
130         bo.setObjectId(im.getObjectId());
131 
132         bo.setUserId(im.getUserId());
133         bo.setChannel(im.getChannel() == null ? null : NotificationChannelBo.from(im.getChannel()));
134         
135         return bo;
136     }
137 }
138