001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ken.service.impl;
017
018 import java.util.ArrayList;
019 import java.util.Collection;
020
021 import org.apache.commons.lang.StringUtils;
022 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
023 import org.kuali.rice.ken.bo.NotificationChannelBo;
024 import org.kuali.rice.ken.api.service.KENAPIService;
025 import org.kuali.rice.ken.service.NotificationChannelService;
026 import org.kuali.rice.ken.service.UserPreferenceService;
027 import org.springframework.beans.factory.annotation.Required;
028
029 /**
030 * KEN API service implementation
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034 public class KENAPIServiceImpl implements KENAPIService {
035 private NotificationChannelService channelService;
036 private UserPreferenceService prefsService;
037
038 /**
039 * Sets the NotificationChannelService
040 * @param ncs the NotificationChannelService
041 */
042 @Required
043 public void setNotificationChannelService(NotificationChannelService ncs) {
044 this.channelService = ncs;
045 }
046
047 /**
048 * Sets the UserPreferenceService
049 * @param ups the UserPreferenceService
050 */
051 @Required
052 public void setUserPreferenceService(UserPreferenceService ups) {
053 this.prefsService = ups;
054 }
055
056 /**
057 * @see org.kuali.rice.ken.service.KENAPIService#getAllChannels()
058 */
059 @Override
060 public Collection<String> getAllChannelNames() {
061 Collection<NotificationChannelBo> chans = channelService.getAllNotificationChannels();
062 Collection<String> chanNames = new ArrayList<String>(chans.size());
063 for (NotificationChannelBo c: chans) {
064 chanNames.add(c.getName());
065 }
066 return chanNames;
067 }
068
069 /**
070 * @see org.kuali.rice.ken.service.KENAPIService#getDeliverersForRecipientAndChannel(java.lang.String, java.lang.String)
071 */
072 @Override
073 public Collection<String> getDeliverersForRecipientAndChannel(String recipient, String channel) {
074 if (StringUtils.isBlank(recipient)) {
075 throw new RiceIllegalArgumentException("recipient is null or blank");
076 }
077
078 if (StringUtils.isBlank(channel)) {
079 throw new RiceIllegalArgumentException("channel is null or blank");
080 }
081
082 /*NotificationChannel nc = channelService.getNotificationChannelByName(channel);
083 if (nc == null) {
084 throw new RiceIllegalArgumentException("Invalid channel: '" + channel + "'");
085 }
086 Collection<UserDelivererConfig> configs = prefsService.getMessageDelivererConfigurationsForUserAndChannel(recipient, nc);
087 Collection<String> deliverers = new ArrayList<String>(configs.size());
088 for (UserDelivererConfig cfg: configs) {
089 deliverers.add(cfg.getDelivererName());
090 }
091 return deliverers;*/
092 return null;
093 }
094
095 /**
096 * @see org.kuali.rice.ken.service.KENAPIService#getRecipientPreference(java.lang.String, java.lang.String)
097 */
098 @Override
099 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 }