1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
30
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
40
41
42
43 public UserPreferenceServiceImpl(GenericDao businessObjectDao, NotificationChannelService notificationChannelService) {
44 this.businessObjectDao = businessObjectDao;
45 this.notificationChannelService = notificationChannelService;
46 }
47
48
49
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
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
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
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 }