View Javadoc
1   /**
2    * Copyright 2005-2014 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.service.impl;
17  
18  import org.kuali.rice.core.api.criteria.QueryByCriteria;
19  import org.kuali.rice.ken.bo.NotificationChannelBo;
20  import org.kuali.rice.ken.service.NotificationChannelService;
21  import org.kuali.rice.krad.data.DataObjectService;
22  
23  import java.util.Collection;
24  import java.util.List;
25  
26  import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
27  import static org.kuali.rice.core.api.criteria.PredicateFactory.isNotNull;
28  
29  /**
30   * NotificationChannelService implementation - uses the businessObjectDao to get at data in the underlying database.
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class NotificationChannelServiceImpl implements NotificationChannelService {
34      private DataObjectService dataObjectService;
35  
36      /**
37       * Constructs a NotificationChannelServiceImpl.java.
38       * @param dataObjectService service persists data to datasource.
39       */
40      public NotificationChannelServiceImpl(DataObjectService dataObjectService) {
41          this.dataObjectService = dataObjectService;
42      }
43  
44      /**
45       * @see org.kuali.rice.ken.service.NotificationChannelService#getNotificationChannel(java.lang.String)
46       */
47      @Override
48      public NotificationChannelBo getNotificationChannel(String id) {
49  
50          return dataObjectService.find(NotificationChannelBo.class, Long.valueOf(id));
51      }
52  
53      /**
54       * @see org.kuali.rice.ken.service.NotificationChannelService#getNotificationChannelByName(java.lang.String)
55       */
56      @Override
57      public NotificationChannelBo getNotificationChannelByName(String name) {
58          QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
59  
60          criteria.setPredicates(equal("name", name));
61          List<NotificationChannelBo> found = dataObjectService.findMatching(NotificationChannelBo.class, criteria.build()).getResults();
62          assert(found.size() <= 1);
63  
64          return ((found.isEmpty() ? null : found.get(0)));
65      }
66  
67      /**
68       * @see org.kuali.rice.ken.service.NotificationChannelService#getSubscribableChannels()
69       */
70      @Override
71      public Collection getSubscribableChannels() {
72          QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
73          criteria.setPredicates(equal("subscribable", Boolean.TRUE));
74          criteria.setOrderByAscending("name");
75  
76          return dataObjectService.findMatching(NotificationChannelBo.class, criteria.build()).getResults();
77      }
78  
79      /**
80       * @see org.kuali.rice.ken.service.NotificationChannelService#getAllNotificationChannels()
81       */
82      @Override
83      public Collection getAllNotificationChannels() {
84          QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
85          criteria.setOrderByAscending("name");
86  
87          return dataObjectService.findMatching(NotificationChannelBo.class, criteria.build()).getResults();
88      }
89  }