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