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.core.api.resourceloader.GlobalResourceLoader;
20 import org.kuali.rice.ken.api.notification.NotificationProducer;
21 import org.kuali.rice.ken.api.notification.NotificationProducerContract;
22 import org.kuali.rice.ken.service.NotificationChannelService;
23 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
24 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
25
26 import javax.persistence.CascadeType;
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.FetchType;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.Id;
32 import javax.persistence.JoinColumn;
33 import javax.persistence.JoinTable;
34 import javax.persistence.ManyToMany;
35 import javax.persistence.OrderBy;
36 import javax.persistence.Table;
37 import java.util.ArrayList;
38 import java.util.List;
39
40
41
42
43
44
45 @Entity
46 @Table(name="KREN_PRODCR_T")
47 public class NotificationProducerBo extends PersistableBusinessObjectBase implements NotificationProducerContract {
48 @Id
49 @GeneratedValue(generator="KREN_PRODCR_S")
50 @PortableSequenceGenerator(name="KREN_PRODCR_S")
51 @Column(name="PRODCR_ID")
52 private Long id;
53 @Column(name="NM", nullable=false)
54 private String name;
55 @Column(name="DESC_TXT", nullable=false)
56 private String description;
57 @Column(name="CNTCT_INFO", nullable=false)
58 private String contactInfo;
59
60
61 @ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})@JoinTable(name="KREN_CHNL_PRODCR_T",
62 joinColumns=@JoinColumn(name="PRODCR_ID"),
63 inverseJoinColumns=@JoinColumn(name="CHNL_ID"))
64 @OrderBy("id ASC")
65 private List<NotificationChannelBo> channels;
66
67
68
69
70 public NotificationProducerBo() {
71 channels = new ArrayList<NotificationChannelBo>();
72 }
73
74
75
76
77
78 public String getContactInfo() {
79 return contactInfo;
80 }
81
82 @Override
83 public List<Long> getChannelIds() {
84 List<Long> ids = new ArrayList<Long>();
85 for (NotificationChannelBo bo : this.getChannels()) {
86 ids.add(bo.getId());
87 }
88 return ids;
89 }
90
91
92
93
94
95 public void setContactInfo(String contactInfo) {
96 this.contactInfo = contactInfo;
97 }
98
99
100
101
102
103 public String getDescription() {
104 return description;
105 }
106
107
108
109
110
111 public void setDescription(String description) {
112 this.description = description;
113 }
114
115
116
117
118
119 public Long getId() {
120 return id;
121 }
122
123
124
125
126
127 public void setId(Long id) {
128 this.id = id;
129 }
130
131
132
133
134
135 public String getName() {
136 return name;
137 }
138
139
140
141
142
143 public void setName(String name) {
144 this.name = name;
145 }
146
147
148
149
150
151 public List<NotificationChannelBo> getChannels() {
152 return channels;
153 }
154
155
156
157
158
159 public void setChannels(List<NotificationChannelBo> channels) {
160 this.channels = channels;
161 }
162
163
164
165
166
167
168 public static NotificationProducer to(NotificationProducerBo bo) {
169 if (bo == null) {
170 return null;
171 }
172
173 return NotificationProducer.Builder.create(bo).build();
174 }
175
176
177
178
179
180
181
182 public static NotificationProducerBo from(NotificationProducer im) {
183 if (im == null) {
184 return null;
185 }
186
187 NotificationProducerBo bo = new NotificationProducerBo();
188 bo.setId(im.getId());
189 bo.setVersionNumber(im.getVersionNumber());
190 bo.setObjectId(im.getObjectId());
191
192 bo.setName(im.getName());
193 bo.setDescription(im.getDescription());
194 bo.setContactInfo(im.getContactInfo());
195
196 List<NotificationChannelBo> tempChannels = new ArrayList<NotificationChannelBo>();
197 if (CollectionUtils.isNotEmpty(im.getChannelIds())) {
198 NotificationChannelService ncs = GlobalResourceLoader.getService("notificationChannelService");
199 for (Long channelId : im.getChannelIds()) {
200 tempChannels.add(ncs.getNotificationChannel(channelId.toString()));
201 }
202 bo.setChannels(tempChannels);
203 }
204 return bo;
205 }
206 }