1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.bo;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.hibernate.annotations.GenericGenerator;
20 import org.hibernate.annotations.Parameter;
21 import org.kuali.rice.ken.api.notification.NotificationChannel;
22 import org.kuali.rice.ken.api.notification.NotificationChannelContract;
23 import org.kuali.rice.ken.api.notification.NotificationChannelReviewer;
24 import org.kuali.rice.ken.api.notification.NotificationChannelReviewerContract;
25 import org.kuali.rice.ken.api.notification.NotificationContentType;
26 import org.kuali.rice.ken.api.notification.NotificationListRecipient;
27 import org.kuali.rice.ken.api.notification.NotificationListRecipientContract;
28 import org.kuali.rice.ken.api.notification.NotificationProducer;
29 import org.kuali.rice.ken.api.notification.NotificationProducerContract;
30 import org.kuali.rice.ken.api.notification.UserChannelSubscription;
31 import org.kuali.rice.ken.api.notification.UserChannelSubscriptionContract;
32 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
33
34 import javax.persistence.*;
35 import java.util.ArrayList;
36 import java.util.List;
37
38
39
40
41
42
43
44
45 @Entity
46 @Table(name = "KREN_CHNL_T")
47 public class NotificationChannelBo extends PersistableBusinessObjectBase implements NotificationChannelContract {
48 @Id
49 @GeneratedValue(generator="KREN_CHNL_S")
50 @GenericGenerator(name="KREN_CHNL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
51 @Parameter(name="sequence_name",value="KREN_CHNL_S"),
52 @Parameter(name="value_column",value="id")
53 })
54 @Column(name = "CHNL_ID")
55 private Long id;
56 @Column(name = "NM", nullable = false)
57 private String name;
58 @Column(name = "DESC_TXT", nullable = false)
59 private String description;
60 @Column(name = "SUBSCRB_IND", nullable = false)
61 private boolean subscribable;
62
63
64 @OneToMany(cascade={CascadeType.REFRESH, CascadeType.DETACH, CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST},
65 targetEntity=NotificationRecipientListBo.class, mappedBy="channel")
66 @OrderBy ("id ASC")
67 private List<NotificationRecipientListBo> recipientLists;
68
69 @ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST})@JoinTable(name="KREN_CHNL_PRODCR_T",
70 joinColumns=@JoinColumn(name="CHNL_ID"),
71 inverseJoinColumns=@JoinColumn(name="PRODCR_ID"))
72 @OrderBy ("id ASC")
73 private List<NotificationProducerBo> producers;
74
75 @OneToMany(cascade={CascadeType.REFRESH, CascadeType.DETACH, CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST},
76 targetEntity=NotificationChannelReviewerBo.class, mappedBy="channel")
77 @OrderBy ("id ASC")
78 private List<NotificationChannelReviewerBo> reviewers = new ArrayList<NotificationChannelReviewerBo>();
79
80 @OneToMany(cascade={CascadeType.REFRESH, CascadeType.DETACH, CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST},
81 targetEntity=UserChannelSubscriptionBo.class, mappedBy="channel")
82 @OrderBy ("id ASC")
83 private List<UserChannelSubscriptionBo> subscriptions = new ArrayList<UserChannelSubscriptionBo>();
84
85
86
87
88
89 public NotificationChannelBo() {
90 super();
91 recipientLists = new ArrayList<NotificationRecipientListBo>();
92 producers = new ArrayList<NotificationProducerBo>();
93 }
94
95
96
97
98
99
100 public List<NotificationRecipientListBo> getRecipientLists() {
101 return recipientLists;
102 }
103
104
105
106
107
108
109
110 public void setRecipientLists(List<NotificationRecipientListBo> recipientLists) {
111 this.recipientLists = recipientLists;
112 }
113
114
115
116
117
118
119 public void addRecipientList(NotificationRecipientListBo recipientList) {
120 this.recipientLists.add(recipientList);
121 }
122
123
124
125
126
127
128 public void removeRecipientList(NotificationRecipientListBo recipientList) {
129 this.recipientLists.remove(recipientList);
130 }
131
132
133
134
135
136
137 public String getDescription() {
138 return description;
139 }
140
141
142
143
144
145
146
147 public void setDescription(String description) {
148 this.description = description;
149 }
150
151
152
153
154
155
156 public Long getId() {
157 return id;
158 }
159
160
161
162
163
164
165
166 public void setId(Long id) {
167 this.id = id;
168 }
169
170
171
172
173
174
175 public String getName() {
176 return name;
177 }
178
179
180
181
182
183
184
185 public void setName(String name) {
186 this.name = name;
187 }
188
189
190
191
192
193
194 public boolean isSubscribable() {
195 return subscribable;
196 }
197
198
199
200
201
202
203
204 public void setSubscribable(boolean subscribable) {
205 this.subscribable = subscribable;
206 }
207
208
209
210
211
212
213 public List<NotificationProducerBo> getProducers() {
214 return producers;
215 }
216
217
218
219
220
221
222
223 public void setProducers(List<NotificationProducerBo> producers) {
224 this.producers = producers;
225 }
226
227
228
229
230
231
232 public List<NotificationChannelReviewerBo> getReviewers() {
233 return reviewers;
234 }
235
236
237
238
239
240
241
242 public void setReviewers(List<NotificationChannelReviewerBo> reviewers) {
243 this.reviewers = reviewers;
244 }
245
246
247
248
249
250
251 public List<UserChannelSubscriptionBo> getSubscriptions() {
252 return subscriptions;
253 }
254
255
256
257
258
259
260
261 public void setSubscriptions(List<UserChannelSubscriptionBo> subscriptions) {
262 this.subscriptions = subscriptions;
263 }
264
265
266
267
268
269
270 @Override
271 public boolean equals(Object obj) {
272 NotificationChannelBo channelToCompare = (NotificationChannelBo) obj;
273 return this.getId().equals(channelToCompare.getId());
274 }
275
276
277
278
279
280
281 public static NotificationChannel to(NotificationChannelBo bo) {
282 if (bo == null) {
283 return null;
284 }
285
286 return NotificationChannel.Builder.create(bo).build();
287 }
288
289
290
291
292
293
294 public static NotificationChannelBo from(NotificationChannel im) {
295 if (im == null) {
296 return null;
297 }
298
299 NotificationChannelBo bo = new NotificationChannelBo();
300 bo.setId(im.getId());
301 bo.setVersionNumber(im.getVersionNumber());
302 bo.setObjectId(im.getObjectId());
303 bo.setName(im.getName());
304 bo.setDescription(im.getDescription());
305
306 bo.setSubscribable(im.isSubscribable());
307
308 List<NotificationRecipientListBo> tempRecipientLists = new ArrayList<NotificationRecipientListBo>();
309 if (CollectionUtils.isNotEmpty(im.getRecipientLists())) {
310 for (NotificationListRecipient listRecipient : im.getRecipientLists()) {
311 tempRecipientLists.add(NotificationRecipientListBo.from(listRecipient));
312 }
313 bo.setRecipientLists(tempRecipientLists);
314 }
315
316 List<NotificationProducerBo> tempProducers = new ArrayList<NotificationProducerBo>();
317 if (CollectionUtils.isNotEmpty(im.getProducers())) {
318 for (NotificationProducer producer : im.getProducers()) {
319 tempProducers.add(NotificationProducerBo.from(producer));
320 }
321 bo.setProducers(tempProducers);
322 }
323
324 List<NotificationChannelReviewerBo> tempReviewers = new ArrayList<NotificationChannelReviewerBo>();
325 if (CollectionUtils.isNotEmpty(im.getReviewers())) {
326 for (NotificationChannelReviewer reviewer : im.getReviewers()) {
327 tempReviewers.add(NotificationChannelReviewerBo.from(reviewer));
328 }
329 bo.setReviewers(tempReviewers);
330 }
331
332 List<UserChannelSubscriptionBo> tempSubscriptions = new ArrayList<UserChannelSubscriptionBo>();
333 if (CollectionUtils.isNotEmpty(im.getSubscriptions())) {
334 for (UserChannelSubscription subscription : im.getSubscriptions()) {
335 tempSubscriptions.add(UserChannelSubscriptionBo.from(subscription));
336 }
337 bo.setSubscriptions(tempSubscriptions);
338 }
339
340 return bo;
341 }
342 }