View Javadoc

1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ken.api.notification;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.List;
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  import javax.xml.bind.annotation.XmlAnyElement;
25  import javax.xml.bind.annotation.XmlElement;
26  import javax.xml.bind.annotation.XmlElementWrapper;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  
30  import org.apache.commons.collections.CollectionUtils;
31  import org.kuali.rice.core.api.CoreConstants;
32  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
33  import org.kuali.rice.core.api.mo.ModelBuilder;
34  import org.w3c.dom.Element;
35  
36  @XmlRootElement(name = NotificationChannel.Constants.ROOT_ELEMENT_NAME)
37  @XmlAccessorType(XmlAccessType.NONE)
38  @XmlType(name = NotificationChannel.Constants.TYPE_NAME, propOrder = {
39          NotificationChannel.Elements.NAME,
40          NotificationChannel.Elements.DESCRIPTION,
41          NotificationChannel.Elements.SUBSCRIBABLE,
42          NotificationChannel.Elements.RECIPIENT_LISTS,
43          NotificationChannel.Elements.PRODUCERS,
44          NotificationChannel.Elements.REVIEWERS,
45          NotificationChannel.Elements.SUBSCRIPTIONS,
46          NotificationChannel.Elements.ID,
47          CoreConstants.CommonElements.VERSION_NUMBER,
48          CoreConstants.CommonElements.OBJECT_ID,
49          CoreConstants.CommonElements.FUTURE_ELEMENTS
50  })
51  public final class NotificationChannel
52          extends AbstractDataTransferObject
53          implements NotificationChannelContract
54  {
55  
56      @XmlElement(name = Elements.NAME, required = false)
57      private final String name;
58      @XmlElement(name = Elements.DESCRIPTION, required = false)
59      private final String description;
60      @XmlElement(name = Elements.SUBSCRIBABLE, required = false)
61      private final boolean subscribable;
62      @XmlElementWrapper(name = Elements.RECIPIENT_LISTS, required = false)
63      @XmlElement(name = Elements.RECIPIENT_LIST, required = false)
64      private final List<NotificationListRecipient> recipientLists;
65      @XmlElementWrapper(name = Elements.PRODUCERS, required = false)
66      @XmlElement(name = Elements.PRODUCER, required = false)
67      private final List<NotificationProducer> producers;
68      @XmlElementWrapper(name = Elements.REVIEWERS, required = false)
69      @XmlElement(name = Elements.REVIEWER, required = false)
70      private final List<NotificationChannelReviewer> reviewers;
71      @XmlElementWrapper(name = Elements.SUBSCRIPTIONS, required = false)
72      @XmlElement(name = Elements.SUBSCRIPTION, required = false)
73      private final List<UserChannelSubscription> subscriptions;
74      @XmlElement(name = Elements.ID, required = false)
75      private final Long id;
76      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
77      private final Long versionNumber;
78      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
79      private final String objectId;
80      @SuppressWarnings("unused")
81      @XmlAnyElement
82      private final Collection<Element> _futureElements = null;
83  
84      /**
85       * Private constructor used only by JAXB.
86       *
87       */
88      private NotificationChannel() {
89          this.name = null;
90          this.description = null;
91          this.subscribable = false;
92          this.recipientLists = null;
93          this.producers = null;
94          this.reviewers = null;
95          this.subscriptions = null;
96          this.id = null;
97          this.versionNumber = null;
98          this.objectId = null;
99      }
100 
101     private NotificationChannel(Builder builder) {
102         this.name = builder.getName();
103         this.description = builder.getDescription();
104         this.subscribable = builder.isSubscribable();
105 
106         this.recipientLists = new ArrayList<NotificationListRecipient>();
107         if (CollectionUtils.isNotEmpty(builder.getRecipientLists())) {
108             for (NotificationListRecipient.Builder listRecipient : builder.getRecipientLists()) {
109                 this.recipientLists.add(listRecipient.build());
110             }
111         }
112 
113         this.producers = new ArrayList<NotificationProducer>();
114         if (CollectionUtils.isNotEmpty(builder.getProducers())) {
115             for (NotificationProducer.Builder producer : builder.getProducers()) {
116                 this.producers.add(producer.build());
117             }
118         }
119 
120         this.reviewers = new ArrayList<NotificationChannelReviewer>();
121         if (CollectionUtils.isNotEmpty(builder.getReviewers())) {
122             for (NotificationChannelReviewer.Builder reviewer : builder.getReviewers()) {
123                 this.reviewers.add(reviewer.build());
124             }
125         }
126 
127         this.subscriptions = new ArrayList<UserChannelSubscription>();
128         if (CollectionUtils.isNotEmpty(builder.getSubscriptions())) {
129             for (UserChannelSubscription.Builder subscription : builder.getSubscriptions()) {
130                 this.subscriptions.add(subscription.build());
131             }
132         }
133 
134         this.id = builder.getId();
135         this.versionNumber = builder.getVersionNumber();
136         this.objectId = builder.getObjectId();
137     }
138 
139     @Override
140     public String getName() {
141         return this.name;
142     }
143 
144     @Override
145     public String getDescription() {
146         return this.description;
147     }
148 
149     @Override
150     public boolean isSubscribable() {
151         return this.subscribable;
152     }
153 
154     @Override
155     public List<NotificationListRecipient> getRecipientLists() {
156         return this.recipientLists;
157     }
158 
159     @Override
160     public List<NotificationProducer> getProducers() {
161         return this.producers;
162     }
163 
164     @Override
165     public List<NotificationChannelReviewer> getReviewers() {
166         return this.reviewers;
167     }
168 
169     @Override
170     public List<UserChannelSubscription> getSubscriptions() {
171         return this.subscriptions;
172     }
173 
174     @Override
175     public Long getId() {
176         return this.id;
177     }
178 
179     @Override
180     public Long getVersionNumber() {
181         return this.versionNumber;
182     }
183 
184     @Override
185     public String getObjectId() {
186         return this.objectId;
187     }
188 
189 
190     /**
191      * A builder which can be used to construct {@link NotificationChannel} instances.  Enforces the constraints of the {@link NotificationChannelContract}.
192      *
193      */
194     public final static class Builder
195             implements Serializable, ModelBuilder, NotificationChannelContract
196     {
197 
198         private String name;
199         private String description;
200         private boolean subscribable;
201         private List<NotificationListRecipient.Builder> recipientLists;
202         private List<NotificationProducer.Builder> producers;
203         private List<NotificationChannelReviewer.Builder> reviewers;
204         private List<UserChannelSubscription.Builder> subscriptions;
205         private Long id;
206         private Long versionNumber;
207         private String objectId;
208 
209         private Builder() {
210         }
211 
212         public static Builder create() {
213             return new Builder();
214         }
215 
216         public static Builder create(NotificationChannelContract contract) {
217             if (contract == null) {
218                 throw new IllegalArgumentException("contract was null");
219             }
220             Builder builder = create();
221             builder.setName(contract.getName());
222             builder.setDescription(contract.getDescription());
223             builder.setSubscribable(contract.isSubscribable());
224             if (contract.getRecipientLists() != null) {
225                 List<NotificationListRecipient.Builder> tempListRecipient = new ArrayList<NotificationListRecipient.Builder>();
226                 for (NotificationListRecipientContract listRecipient : contract.getRecipientLists()) {
227                     tempListRecipient.add(NotificationListRecipient.Builder.create(listRecipient));
228                 }
229                 builder.setRecipientLists(tempListRecipient);
230             }
231             if (contract.getProducers() != null) {
232                 List<NotificationProducer.Builder> tempProducers = new ArrayList<NotificationProducer.Builder>();
233                 for (NotificationProducerContract producer : contract.getProducers()) {
234                     tempProducers.add(NotificationProducer.Builder.create(producer));
235                 }
236                 builder.setProducers(tempProducers);
237             }
238             if (contract.getReviewers() != null) {
239                 List<NotificationChannelReviewer.Builder> tempReviewers = new ArrayList<NotificationChannelReviewer.Builder>();
240                 for (NotificationChannelReviewerContract reviewer : contract.getReviewers()) {
241                     tempReviewers.add(NotificationChannelReviewer.Builder.create(reviewer));
242                 }
243                 builder.setReviewers(tempReviewers);
244             }
245             if (contract.getSubscriptions() != null) {
246                 List<UserChannelSubscription.Builder> tempSubscriptions = new ArrayList<UserChannelSubscription.Builder>();
247                 for (UserChannelSubscriptionContract subscription : contract.getSubscriptions()) {
248                     tempSubscriptions.add(UserChannelSubscription.Builder.create(subscription));
249                 }
250                 builder.setSubscriptions(tempSubscriptions);
251             }
252             builder.setId(contract.getId());
253             builder.setVersionNumber(contract.getVersionNumber());
254             builder.setObjectId(contract.getObjectId());
255             return builder;
256         }
257 
258         public NotificationChannel build() {
259             return new NotificationChannel(this);
260         }
261 
262         @Override
263         public String getName() {
264             return this.name;
265         }
266 
267         @Override
268         public String getDescription() {
269             return this.description;
270         }
271 
272         @Override
273         public boolean isSubscribable() {
274             return this.subscribable;
275         }
276 
277         @Override
278         public List<NotificationListRecipient.Builder> getRecipientLists() {
279             return this.recipientLists;
280         }
281 
282         @Override
283         public List<NotificationProducer.Builder> getProducers() {
284             return this.producers;
285         }
286 
287         @Override
288         public List<NotificationChannelReviewer.Builder> getReviewers() {
289             return this.reviewers;
290         }
291 
292         @Override
293         public List<UserChannelSubscription.Builder> getSubscriptions() {
294             return this.subscriptions;
295         }
296 
297         @Override
298         public Long getId() {
299             return this.id;
300         }
301 
302         @Override
303         public Long getVersionNumber() {
304             return this.versionNumber;
305         }
306 
307         @Override
308         public String getObjectId() {
309             return this.objectId;
310         }
311 
312         public void setName(String name) {
313             this.name = name;
314         }
315 
316         public void setDescription(String description) {
317             this.description = description;
318         }
319 
320         public void setSubscribable(boolean subscribable) {
321             this.subscribable = subscribable;
322         }
323 
324         public void setRecipientLists(List<NotificationListRecipient.Builder> recipientLists) {
325             this.recipientLists = recipientLists;
326         }
327 
328         public void setProducers(List<NotificationProducer.Builder> producers) {
329             this.producers = producers;
330         }
331 
332         public void setReviewers(List<NotificationChannelReviewer.Builder> reviewers) {
333             this.reviewers = reviewers;
334         }
335 
336         public void setSubscriptions(List<UserChannelSubscription.Builder> subscriptions) {
337             this.subscriptions = subscriptions;
338         }
339 
340         public void setId(Long id) {
341             this.id = id;
342         }
343 
344         public void setVersionNumber(Long versionNumber) {
345             this.versionNumber = versionNumber;
346         }
347 
348         public void setObjectId(String objectId) {
349             this.objectId = objectId;
350         }
351 
352     }
353 
354 
355     /**
356      * Defines some internal constants used on this class.
357      *
358      */
359     static class Constants {
360 
361         final static String ROOT_ELEMENT_NAME = "notificationChannel";
362         final static String TYPE_NAME = "NotificationChannelType";
363 
364     }
365 
366 
367     /**
368      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
369      *
370      */
371     static class Elements {
372 
373         final static String NAME = "name";
374         final static String DESCRIPTION = "description";
375         final static String SUBSCRIBABLE = "subscribable";
376         final static String RECIPIENT_LISTS = "recipientLists";
377         final static String RECIPIENT_LIST = "recipientList";
378         final static String PRODUCERS = "producers";
379         final static String PRODUCER = "producer";
380         final static String REVIEWERS = "reviewers";
381         final static String REVIEWER = "reviewer";
382         final static String SUBSCRIPTIONS = "subscriptions";
383         final static String SUBSCRIPTION = "subscription";
384         final static String ID = "id";
385 
386     }
387 
388 }