1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ken.web.spring; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
import java.util.Collection; |
20 | |
import java.util.HashMap; |
21 | |
import java.util.Iterator; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import javax.servlet.ServletException; |
25 | |
import javax.servlet.http.HttpServletRequest; |
26 | |
import javax.servlet.http.HttpServletResponse; |
27 | |
|
28 | |
import org.apache.log4j.Logger; |
29 | |
import org.kuali.rice.ken.bo.NotificationChannel; |
30 | |
import org.kuali.rice.ken.bo.UserChannelSubscription; |
31 | |
import org.kuali.rice.ken.deliverer.NotificationMessageDeliverer; |
32 | |
import org.kuali.rice.ken.exception.ErrorList; |
33 | |
import org.kuali.rice.ken.service.NotificationChannelService; |
34 | |
import org.kuali.rice.ken.service.UserPreferenceService; |
35 | |
import org.springframework.web.servlet.ModelAndView; |
36 | |
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class UserPreferencesController extends MultiActionController { |
43 | |
|
44 | 0 | private static String view = ""; |
45 | |
|
46 | |
|
47 | 0 | private static final Logger LOG = Logger.getLogger(UserPreferencesController.class); |
48 | |
|
49 | |
protected NotificationChannelService notificationChannelService; |
50 | |
protected UserPreferenceService userPreferenceService; |
51 | |
protected Object notificationMessageDelivererRegistryService; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public void setNotificationChannelService(NotificationChannelService notificationChannelService) { |
59 | 0 | this.notificationChannelService = notificationChannelService; |
60 | 0 | } |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public void setUserPreferenceService(UserPreferenceService userPreferenceService) { |
67 | 0 | this.userPreferenceService = userPreferenceService; |
68 | 0 | } |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public void setNotificationMessageDelivererRegistryService(Object notificationMessageDelivererRegistryService) { |
75 | 0 | this.notificationMessageDelivererRegistryService = notificationMessageDelivererRegistryService; |
76 | 0 | } |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public ModelAndView displayActionListPreferences(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
87 | 0 | view = "ActionListPreferences"; |
88 | 0 | LOG.debug("remoteUser: "+request.getRemoteUser()); |
89 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
90 | 0 | return new ModelAndView(view, model); |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public ModelAndView displayUserPreferences(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
102 | |
|
103 | 0 | view = "UserPreferencesForm"; |
104 | 0 | String userid = request.getRemoteUser(); |
105 | 0 | LOG.debug("remoteUser: "+userid); |
106 | |
|
107 | 0 | Collection<NotificationChannel> channels = this.notificationChannelService.getSubscribableChannels(); |
108 | |
|
109 | 0 | Collection<UserChannelSubscription> subscriptions = this.userPreferenceService.getCurrentSubscriptions(userid); |
110 | 0 | Map<String, Object> currentsubs = new HashMap<String, Object>(); |
111 | 0 | Iterator<UserChannelSubscription> i = subscriptions.iterator(); |
112 | 0 | while (i.hasNext()) { |
113 | 0 | UserChannelSubscription sub = i.next(); |
114 | 0 | String subid = Long.toString(sub.getChannel().getId()); |
115 | 0 | currentsubs.put(subid, subid); |
116 | 0 | LOG.debug("currently subscribed to: "+sub.getChannel().getId()); |
117 | 0 | } |
118 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
119 | 0 | model.put("channels", channels); |
120 | 0 | model.put("currentsubs", currentsubs); |
121 | |
|
122 | 0 | return new ModelAndView(view, model); |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public ModelAndView subscribeToChannel(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
134 | |
|
135 | 0 | view = "UserPreferencesForm"; |
136 | 0 | String userid = request.getRemoteUser(); |
137 | 0 | LOG.debug("remoteUser: "+userid); |
138 | 0 | String channelid = request.getParameter("channelid"); |
139 | 0 | NotificationChannel newChannel = this.notificationChannelService.getNotificationChannel(channelid); |
140 | 0 | LOG.debug("newChannel name:"+newChannel.getName()); |
141 | 0 | UserChannelSubscription newSub = new UserChannelSubscription(); |
142 | 0 | newSub.setUserId(userid); |
143 | 0 | newSub.setChannel(newChannel); |
144 | 0 | LOG.debug("Calling service to subscribe to channel: "+newChannel.getName()); |
145 | 0 | this.userPreferenceService.subscribeToChannel(newSub); |
146 | |
|
147 | |
|
148 | 0 | Collection<UserChannelSubscription> subscriptions = this.userPreferenceService.getCurrentSubscriptions(userid); |
149 | 0 | Map<String, Object> currentsubs = new HashMap<String, Object>();; |
150 | 0 | Iterator<UserChannelSubscription> i = subscriptions.iterator(); |
151 | 0 | while (i.hasNext()) { |
152 | 0 | UserChannelSubscription sub = i.next(); |
153 | 0 | String subid = Long.toString(sub.getChannel().getId()); |
154 | 0 | currentsubs.put(subid, subid); |
155 | 0 | LOG.debug("currently subscribed to: "+sub.getChannel().getId()); |
156 | 0 | } |
157 | |
|
158 | |
|
159 | 0 | Collection<NotificationChannel> channels = this.notificationChannelService.getSubscribableChannels(); |
160 | |
|
161 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
162 | 0 | model.put("channels", channels); |
163 | 0 | model.put("currentsubs", currentsubs); |
164 | 0 | return new ModelAndView(view, model); |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
public ModelAndView unsubscribeFromChannel(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
176 | 0 | view = "UserPreferencesForm"; |
177 | 0 | String userid = request.getRemoteUser(); |
178 | 0 | LOG.debug("remoteUser: "+userid); |
179 | 0 | String channelid = request.getParameter("channelid"); |
180 | |
|
181 | 0 | NotificationChannel newChannel = this.notificationChannelService.getNotificationChannel(channelid); |
182 | 0 | LOG.debug("getting channel (id, user): "+channelid+","+userid); |
183 | 0 | UserChannelSubscription oldsub = this.userPreferenceService.getSubscription(channelid, userid); |
184 | 0 | oldsub.setChannel(newChannel); |
185 | |
|
186 | 0 | LOG.debug("Calling service to unsubscribe: "+newChannel.getName()); |
187 | 0 | this.userPreferenceService.unsubscribeFromChannel(oldsub); |
188 | 0 | LOG.debug("Finished unsubscribe service: "+newChannel.getName()); |
189 | |
|
190 | |
|
191 | 0 | Collection<UserChannelSubscription> subscriptions = this.userPreferenceService.getCurrentSubscriptions(userid); |
192 | 0 | Map<String, Object> currentsubs = new HashMap<String, Object>(); |
193 | 0 | Iterator<UserChannelSubscription> i = subscriptions.iterator(); |
194 | 0 | while (i.hasNext()) { |
195 | 0 | UserChannelSubscription sub = i.next(); |
196 | 0 | String subid = Long.toString(sub.getChannel().getId()); |
197 | 0 | currentsubs.put(subid, subid); |
198 | 0 | LOG.debug("currently subscribed to: "+sub.getChannel().getId()); |
199 | 0 | } |
200 | |
|
201 | |
|
202 | 0 | Collection<NotificationChannel> channels = this.notificationChannelService.getSubscribableChannels(); |
203 | |
|
204 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
205 | 0 | model.put("channels", channels); |
206 | 0 | model.put("currentsubs", currentsubs); |
207 | 0 | return new ModelAndView(view, model); |
208 | |
|
209 | |
} |
210 | |
} |