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