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.UserChannelSubscription;
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<UserChannelSubscription> getCurrentSubscriptions(String userid) {
52 UserChannelSubscription userChannelSubscription = new UserChannelSubscription();
53 userChannelSubscription.setUserId(userid);
54
55 return businessObjectDao.findMatchingByExample(userChannelSubscription);
56 }
57
58
59
60
61 public UserChannelSubscription 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 UserChannelSubscription subscription = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, uniqueKeys);
68
69 return subscription;
70 }
71
72
73
74
75 public void subscribeToChannel(UserChannelSubscription userChannelSubscription) {
76 LOG.info("Saving channel subscription");
77 try {
78 businessObjectDao.save(userChannelSubscription);
79 } catch(Exception e) {
80 LOG.error("Exception when saving userChannelSubscription");
81 }
82 LOG.debug("Channel subscription saved");
83 }
84
85
86
87
88 public void unsubscribeFromChannel(UserChannelSubscription userChannelSubscription) {
89 LOG.info("unsubscribing from channel");
90 try {
91 businessObjectDao.delete(userChannelSubscription);
92 } catch(Exception e) {
93 LOG.error("Exception when deleting userChannelSubscription");
94 }
95
96 }
97 }