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