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 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 | |
|
30 | |
|
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 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public UserPreferenceServiceImpl(GenericDao businessObjectDao, NotificationChannelService notificationChannelService) { |
44 | 0 | this.businessObjectDao = businessObjectDao; |
45 | 0 | this.notificationChannelService = notificationChannelService; |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
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 | |
|
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 | |
|
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 | |
|
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 | |
} |