View Javadoc

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