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 java.util.ArrayList;
19  import java.util.Collection;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
23  import org.kuali.rice.ken.bo.NotificationChannelBo;
24  import org.kuali.rice.ken.api.service.KENAPIService;
25  import org.kuali.rice.ken.service.NotificationChannelService;
26  import org.kuali.rice.ken.service.UserPreferenceService;
27  import org.springframework.beans.factory.annotation.Required;
28  
29  /**
30   * KEN API service implementation 
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class KENAPIServiceImpl implements KENAPIService {
35      private NotificationChannelService channelService;
36      private UserPreferenceService prefsService;
37  
38      /**
39       * Sets the NotificationChannelService
40       * @param ncs the NotificationChannelService
41       */
42      @Required
43      public void setNotificationChannelService(NotificationChannelService ncs) {
44          this.channelService = ncs;
45      }
46  
47      /**
48       * Sets the UserPreferenceService
49       * @param ups the UserPreferenceService
50       */
51      @Required
52      public void setUserPreferenceService(UserPreferenceService ups) {
53          this.prefsService = ups;
54      }
55  
56      /**
57       * @see org.kuali.rice.ken.service.KENAPIService#getAllChannels()
58       */
59      @Override
60      public Collection<String> getAllChannelNames() {
61          Collection<NotificationChannelBo> chans = channelService.getAllNotificationChannels();
62          Collection<String> chanNames = new ArrayList<String>(chans.size());
63          for (NotificationChannelBo c: chans) {
64              chanNames.add(c.getName());
65          }
66          return chanNames;
67      }
68  
69      /**
70       * @see org.kuali.rice.ken.service.KENAPIService#getDeliverersForRecipientAndChannel(java.lang.String, java.lang.String)
71       */
72      @Override
73      public Collection<String> getDeliverersForRecipientAndChannel(String recipient, String channel) {
74          if (StringUtils.isBlank(recipient)) {
75              throw new RiceIllegalArgumentException("recipient is null or blank");
76          }
77  
78          if (StringUtils.isBlank(channel)) {
79              throw new RiceIllegalArgumentException("channel is null or blank");
80          }
81  
82          /*NotificationChannel nc = channelService.getNotificationChannelByName(channel);
83          if (nc == null) {
84              throw new RiceIllegalArgumentException("Invalid channel: '" + channel + "'");
85          }
86          Collection<UserDelivererConfig> configs = prefsService.getMessageDelivererConfigurationsForUserAndChannel(recipient, nc);
87          Collection<String> deliverers = new ArrayList<String>(configs.size());
88          for (UserDelivererConfig cfg: configs) {
89              deliverers.add(cfg.getDelivererName());
90          }
91          return deliverers;*/
92          return null;
93      }
94  
95      /**
96       * @see org.kuali.rice.ken.service.KENAPIService#getRecipientPreference(java.lang.String, java.lang.String)
97       */
98      @Override
99      public String getRecipientPreference(String recipient, String prefKey) {
100         if (StringUtils.isBlank(recipient)) {
101             throw new RiceIllegalArgumentException("recipient is null or blank");
102         }
103 
104         if (StringUtils.isBlank(prefKey)) {
105             throw new RiceIllegalArgumentException("prefKey is null or blank");
106         }
107 
108         /*RecipientPreference rp = prefsService.getUserRecipientPreferences(recipient, prefKey);
109         if (rp == null) return null;
110         return rp.getValue();
111         */
112         return null;
113     }
114 }