001    /*
002     * Copyright 2007-2008 The Kuali Foundation
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.ken.bo;
017    
018    import org.hibernate.annotations.GenericGenerator;
019    import org.hibernate.annotations.Parameter;
020    import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
021    
022    import javax.persistence.*;
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    /**
027     * This class represents and instance of a Notification Channel. A Notification Channel is correlated to a specific class of
028     * notification, or in other words a specific business purpose. For instance, all overdue books from a specific library could
029     * be a channel or a channel for concerts coming to campus could be another channel.
030     * 
031     * @author Kuali Rice Team (rice.collab@kuali.org)
032     */
033    @Entity
034    @Table(name = "KREN_CHNL_T")
035    public class NotificationChannel extends PersistableBusinessObjectBase {
036            @Id
037            @GeneratedValue(generator="KREN_CHNL_S")
038            @GenericGenerator(name="KREN_CHNL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
039                            @Parameter(name="sequence_name",value="KREN_CHNL_S"),
040                            @Parameter(name="value_column",value="id")
041            })
042            @Column(name = "CHNL_ID")
043            private Long id;
044            @Column(name = "NM", nullable = false)
045            private String name;
046            @Column(name = "DESC_TXT", nullable = false)
047            private String description;
048            @Column(name = "SUBSCRB_IND", nullable = false)
049            private boolean subscribable;
050    
051            // List references
052            @OneToMany(cascade={CascadeType.REFRESH, CascadeType.DETACH, CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST}, 
053                            targetEntity=org.kuali.rice.ken.bo.NotificationRecipientList.class, mappedBy="channel")
054            @OrderBy ("id ASC")
055            private List<NotificationRecipientList> recipientLists;
056            
057            @ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST})@JoinTable(name="KREN_CHNL_PRODCR_T", 
058                            joinColumns=@JoinColumn(name="CHNL_ID"), 
059                            inverseJoinColumns=@JoinColumn(name="PRODCR_ID"))
060            @OrderBy ("id ASC")
061            private List<NotificationProducer> producers;
062            
063            @OneToMany(cascade={CascadeType.REFRESH, CascadeType.DETACH, CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST}, 
064                            targetEntity=org.kuali.rice.ken.bo.NotificationChannelReviewer.class, mappedBy="channel")
065            @OrderBy ("id ASC")
066            private List<NotificationChannelReviewer> reviewers = new ArrayList<NotificationChannelReviewer>();
067            
068            @OneToMany(cascade={CascadeType.REFRESH, CascadeType.DETACH, CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST}, 
069                            targetEntity=org.kuali.rice.ken.bo.UserChannelSubscription.class, mappedBy="channel")
070            @OrderBy ("id ASC")
071            private List<UserChannelSubscription> subscriptions = new ArrayList<UserChannelSubscription>();
072    
073    
074            /**
075             * Constructs a NotificationChannel instance.
076             */
077            public NotificationChannel() {
078                    super();
079                    recipientLists = new ArrayList<NotificationRecipientList>();
080                    producers = new ArrayList<NotificationProducer>();
081            }
082    
083            /**
084             * Gets the recipientLists attribute.
085             * 
086             * @return Returns the recipientLists.
087             */
088            public List<NotificationRecipientList> getRecipientLists() {
089                    return recipientLists;
090            }
091    
092            /**
093             * Sets the recipientLists attribute value.
094             * 
095             * @param recipientLists
096             *            The recipientLists to set.
097             */
098            public void setRecipientLists(List<NotificationRecipientList> recipientLists) {
099                    this.recipientLists = recipientLists;
100            }
101    
102            /**
103             * This method adds a recipient list to the overall set of recipient lists that are associated with this channnel.
104             * 
105             * @param recipientList
106             */
107            public void addRecipientList(NotificationRecipientList recipientList) {
108                    this.recipientLists.add(recipientList);
109            }
110    
111            /**
112             * This method removes a recipient list object from the overall list.
113             * 
114             * @param recipientList
115             */
116            public void removeRecipientList(NotificationRecipientList recipientList) {
117                    this.recipientLists.remove(recipientList);
118            }
119    
120            /**
121             * Gets the description attribute.
122             * 
123             * @return Returns the description.
124             */
125            public String getDescription() {
126                    return description;
127            }
128    
129            /**
130             * Sets the description attribute value.
131             * 
132             * @param description
133             *            The description to set.
134             */
135            public void setDescription(String description) {
136                    this.description = description;
137            }
138    
139            /**
140             * Gets the id attribute.
141             * 
142             * @return Returns the id.
143             */
144            public Long getId() {
145                    return id;
146            }
147    
148            /**
149             * Sets the id attribute value.
150             * 
151             * @param id
152             *            The id to set.
153             */
154            public void setId(Long id) {
155                    this.id = id;
156            }
157    
158            /**
159             * Gets the name attribute.
160             * 
161             * @return Returns the name.
162             */
163            public String getName() {
164                    return name;
165            }
166    
167            /**
168             * Sets the name attribute value.
169             * 
170             * @param name
171             *            The name to set.
172             */
173            public void setName(String name) {
174                    this.name = name;
175            }
176    
177            /**
178             * Gets the subscribable attribute.
179             * 
180             * @return Returns the subscribable.
181             */
182            public boolean isSubscribable() {
183                    return subscribable;
184            }
185    
186            /**
187             * Sets the subscribable attribute value.
188             * 
189             * @param subscribable
190             *            The subscribable to set.
191             */
192            public void setSubscribable(boolean subscribable) {
193                    this.subscribable = subscribable;
194            }
195    
196            /**
197             * Gets the producers attribute.
198             * 
199             * @return Returns the producers.
200             */
201            public List<NotificationProducer> getProducers() {
202                    return producers;
203            }
204    
205            /**
206             * Sets the producers attribute value.
207             * 
208             * @param producers
209             *            The producers to set.
210             */
211            public void setProducers(List<NotificationProducer> producers) {
212                    this.producers = producers;
213            }
214    
215            /**
216             * Gets the list of reviewers for notification publications to this channel
217             * 
218             * @return the list of reviewers for notification publications to this channel
219             */
220            public List<NotificationChannelReviewer> getReviewers() {
221                    return reviewers;
222            }
223    
224            /**
225             * Sets the list of reviewers for notification publications to this channel
226             * 
227             * @param reviewers
228             *            the list of reviewers for notification publications to this channel
229             */
230            public void setReviewers(List<NotificationChannelReviewer> reviewers) {
231                    this.reviewers = reviewers;
232            }
233    
234            /**
235             * Gets the list of subscriptions to this channel
236             * 
237             * @return the list of subscriptions to this channel
238             */
239            public List<UserChannelSubscription> getSubscriptions() {
240                    return subscriptions;
241            }
242    
243            /**
244             * Sets the list of subscriptions to this channel
245             * 
246             * @param subscriptions
247             *            the list of subscriptions to this channel
248             */
249            public void setSubscriptions(List<UserChannelSubscription> subscriptions) {
250                    this.subscriptions = subscriptions;
251            }
252    
253            /**
254             * Compares the id values of each NotificationChannel object.
255             * 
256             * @see java.lang.Object#equals(java.lang.Object)
257             */
258            @Override
259            public boolean equals(Object obj) {
260                    NotificationChannel channelToCompare = (NotificationChannel) obj;
261                    return this.getId().equals(channelToCompare.getId());
262            }
263    }