1 /**
2 * Copyright 2005-2011 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.NotificationChannel;
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 public Collection<String> getAllChannelNames() {
60 Collection<NotificationChannel> chans = channelService.getAllNotificationChannels();
61 Collection<String> chanNames = new ArrayList<String>(chans.size());
62 for (NotificationChannel c: chans) {
63 chanNames.add(c.getName());
64 }
65 return chanNames;
66 }
67
68 /**
69 * @see org.kuali.rice.ken.service.KENAPIService#getDeliverersForRecipientAndChannel(java.lang.String, java.lang.String)
70 */
71 public Collection<String> getDeliverersForRecipientAndChannel(String recipient, String channel) {
72 if (StringUtils.isBlank(recipient)) {
73 throw new RiceIllegalArgumentException("recipient is null or blank");
74 }
75
76 if (StringUtils.isBlank(channel)) {
77 throw new RiceIllegalArgumentException("channel is null or blank");
78 }
79
80 /*NotificationChannel nc = channelService.getNotificationChannelByName(channel);
81 if (nc == null) {
82 throw new RiceIllegalArgumentException("Invalid channel: '" + channel + "'");
83 }
84 Collection<UserDelivererConfig> configs = prefsService.getMessageDelivererConfigurationsForUserAndChannel(recipient, nc);
85 Collection<String> deliverers = new ArrayList<String>(configs.size());
86 for (UserDelivererConfig cfg: configs) {
87 deliverers.add(cfg.getDelivererName());
88 }
89 return deliverers;*/
90 return null;
91 }
92
93 /**
94 * @see org.kuali.rice.ken.service.KENAPIService#getRecipientPreference(java.lang.String, java.lang.String)
95 */
96 public String getRecipientPreference(String recipient, String prefKey) {
97 if (StringUtils.isBlank(recipient)) {
98 throw new RiceIllegalArgumentException("recipient is null or blank");
99 }
100
101 if (StringUtils.isBlank(prefKey)) {
102 throw new RiceIllegalArgumentException("prefKey is null or blank");
103 }
104
105 /*RecipientPreference rp = prefsService.getUserRecipientPreferences(recipient, prefKey);
106 if (rp == null) return null;
107 return rp.getValue();
108 */
109 return null;
110 }
111 }