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