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