Coverage Report - org.kuali.rice.ken.service.impl.UserPreferenceServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
UserPreferenceServiceImpl
0%
0/26
N/A
1.4
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.Collection;
 19  
 import java.util.HashMap;
 20  
 
 21  
 import org.apache.log4j.Logger;
 22  
 import org.kuali.rice.core.dao.GenericDao;
 23  
 import org.kuali.rice.ken.bo.UserChannelSubscription;
 24  
 import org.kuali.rice.ken.service.NotificationChannelService;
 25  
 import org.kuali.rice.ken.service.UserPreferenceService;
 26  
 import org.kuali.rice.ken.util.NotificationConstants;
 27  
 
 28  
 /**
 29  
  * UserPreferenceService implementation - uses the businessObjectDao to get at data in the underlying database.
 30  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 31  
  */
 32  
 public class UserPreferenceServiceImpl implements UserPreferenceService {
 33  
     private GenericDao businessObjectDao;
 34  
     private NotificationChannelService notificationChannelService;
 35  
 
 36  0
     private static final Logger LOG = Logger.getLogger(UserPreferenceServiceImpl.class);
 37  
 
 38  
     /**
 39  
      * Constructs a UserPreferenceServiceImpl 
 40  
      * @param businessObjectDao
 41  
      * @param notificationChannelService
 42  
      */
 43  0
     public UserPreferenceServiceImpl(GenericDao businessObjectDao, NotificationChannelService notificationChannelService) {
 44  0
         this.businessObjectDao = businessObjectDao;
 45  0
         this.notificationChannelService = notificationChannelService;
 46  0
     }
 47  
 
 48  
     /**
 49  
      * @see org.kuali.rice.ken.service.UserPreferenceService#getCurrentSubscriptions(java.lang.String)
 50  
      */
 51  
     public Collection<UserChannelSubscription> getCurrentSubscriptions(String userid) {
 52  0
         UserChannelSubscription userChannelSubscription = new UserChannelSubscription();
 53  0
         userChannelSubscription.setUserId(userid);
 54  
 
 55  0
         return businessObjectDao.findMatchingByExample(userChannelSubscription);
 56  
     }
 57  
 
 58  
     /**
 59  
      * @see org.kuali.rice.ken.service.UserPreferenceService#getSubscription(java.lang.String, java.lang.String)
 60  
      */
 61  
     public UserChannelSubscription getSubscription(String channelid, String userid) {
 62  0
         HashMap<String, String> uniqueKeys = new HashMap<String,String>();
 63  
 
 64  0
         uniqueKeys.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channelid);
 65  0
         uniqueKeys.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, userid);
 66  
 
 67  0
         UserChannelSubscription subscription = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, uniqueKeys);
 68  
 
 69  0
         return subscription; 
 70  
     }
 71  
 
 72  
     /**
 73  
      * @see org.kuali.rice.ken.service.UserPreferenceService#subscribeToChannel(org.kuali.rice.ken.bo.UserChannelSubscription)
 74  
      */
 75  
     public void subscribeToChannel(UserChannelSubscription userChannelSubscription) {
 76  0
         LOG.info("Saving channel subscription");
 77  
         try {
 78  0
             businessObjectDao.save(userChannelSubscription);
 79  0
         } catch(Exception e) {
 80  0
             LOG.error("Exception when saving userChannelSubscription");                    
 81  0
         }
 82  0
         LOG.debug("Channel subscription saved");
 83  0
     }
 84  
 
 85  
     /**
 86  
      * @see org.kuali.rice.ken.service.UserPreferenceService#unsubscribeFromChannel(org.kuali.rice.ken.bo.UserChannelSubscription)
 87  
      */
 88  
     public void unsubscribeFromChannel(UserChannelSubscription userChannelSubscription) {
 89  0
         LOG.info("unsubscribing from channel"); 
 90  
         try {
 91  0
             businessObjectDao.delete(userChannelSubscription);
 92  0
         } catch(Exception e) {
 93  0
             LOG.error("Exception when deleting userChannelSubscription");                    
 94  0
         }
 95  
 
 96  0
     }
 97  
 }