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.HashMap; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import javax.servlet.ServletException; |
24 | |
import javax.servlet.http.HttpServletRequest; |
25 | |
import javax.servlet.http.HttpServletResponse; |
26 | |
|
27 | |
import org.apache.log4j.Logger; |
28 | |
import org.kuali.rice.ken.bo.Notification; |
29 | |
import org.kuali.rice.ken.bo.NotificationMessageDelivery; |
30 | |
import org.kuali.rice.ken.bo.NotificationRecipient; |
31 | |
import org.kuali.rice.ken.bo.NotificationSender; |
32 | |
import org.kuali.rice.ken.service.NotificationMessageDeliveryService; |
33 | |
import org.kuali.rice.ken.service.NotificationService; |
34 | |
import org.kuali.rice.ken.service.NotificationWorkflowDocumentService; |
35 | |
import org.kuali.rice.ken.util.NotificationConstants; |
36 | |
import org.kuali.rice.ken.util.Util; |
37 | |
import org.kuali.rice.kew.util.KEWConstants; |
38 | |
import org.springframework.web.servlet.ModelAndView; |
39 | |
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; |
40 | |
import org.springframework.web.servlet.view.RedirectView; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class NotificationController extends MultiActionController { |
48 | |
|
49 | 0 | private static final Logger LOG = Logger.getLogger(NotificationController.class); |
50 | |
|
51 | |
protected NotificationService notificationService; |
52 | |
protected NotificationWorkflowDocumentService notificationWorkflowDocService; |
53 | |
protected NotificationMessageDeliveryService messageDeliveryService; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public void setNotificationService(NotificationService notificationService) { |
60 | 0 | this.notificationService = notificationService; |
61 | 0 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public void setNotificationWorkflowDocumentService(NotificationWorkflowDocumentService s) { |
68 | 0 | this.notificationWorkflowDocService = s; |
69 | 0 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public void setMessageDeliveryService(NotificationMessageDeliveryService messageDeliveryService) { |
76 | 0 | this.messageDeliveryService = messageDeliveryService; |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public ModelAndView displayHome(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
88 | 0 | String view = "HomePage"; |
89 | 0 | LOG.debug("remoteUser: "+request.getRemoteUser()); |
90 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
91 | 0 | return new ModelAndView(view, model); |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public ModelAndView displayNotificationsSent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
103 | 0 | String view = "NotificationsSent"; |
104 | 0 | LOG.debug("remoteUser: "+request.getRemoteUser()); |
105 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
106 | 0 | model.put("userId", request.getRemoteUser()); |
107 | 0 | return new ModelAndView(view, model); |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
public ModelAndView displaySearch(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
119 | 0 | String view = "Search"; |
120 | 0 | LOG.debug("remoteUser: "+request.getRemoteUser()); |
121 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
122 | 0 | return new ModelAndView(view, model); |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public ModelAndView displayLookupUsers(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
134 | 0 | String view = "LookupUsers"; |
135 | 0 | LOG.debug("remoteUser: "+request.getRemoteUser()); |
136 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
137 | 0 | return new ModelAndView(view, model); |
138 | |
} |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
public ModelAndView displayLookupWorkgroups(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
149 | 0 | String view = "LookupWorkgroups"; |
150 | 0 | LOG.debug("remoteUser: "+request.getRemoteUser()); |
151 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
152 | 0 | return new ModelAndView(view, model); |
153 | |
} |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
protected NotificationMessageDelivery determineMessageFromRequest(HttpServletRequest request) { |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | 0 | String messageDeliveryId = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.MSG_DELIVERY_ID); |
170 | 0 | String delivererId = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.DELIVERER_ID); |
171 | 0 | if (delivererId == null) { |
172 | 0 | delivererId = request.getParameter(KEWConstants.DOCUMENT_ID_PARAMETER); |
173 | |
} |
174 | |
|
175 | |
NotificationMessageDelivery messageDelivery; |
176 | 0 | if (messageDeliveryId != null) { |
177 | 0 | LOG.debug("Looking up notification with messageDeliveryId: "+messageDeliveryId); |
178 | |
try { |
179 | 0 | messageDelivery = messageDeliveryService.getNotificationMessageDelivery(new Long(messageDeliveryId)); |
180 | 0 | } catch (Exception e) { |
181 | 0 | throw new RuntimeException("Error getting message with id: " + messageDeliveryId, e); |
182 | 0 | } |
183 | 0 | } else if (delivererId != null) { |
184 | 0 | LOG.debug("Looking up notification with workflowId: "+delivererId); |
185 | |
try { |
186 | 0 | messageDelivery = messageDeliveryService.getNotificationMessageDeliveryByDelivererId(delivererId); |
187 | 0 | } catch (Exception e) { |
188 | 0 | LOG.error("Error getting message with from deliverer id: " + delivererId, e); |
189 | 0 | throw new RuntimeException("Error getting message with deliverer id: " + delivererId, e); |
190 | 0 | } |
191 | |
} else { |
192 | 0 | throw new RuntimeException("Neither message ('" + NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.MSG_DELIVERY_ID |
193 | |
+ "') nor deliverer id ('" + NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.DELIVERER_ID + "') were specified in the request"); |
194 | |
} |
195 | |
|
196 | 0 | return messageDelivery; |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
protected boolean requestIsFromKEW(HttpServletRequest req) { |
204 | 0 | return req.getParameter(KEWConstants.DOCUMENT_ID_PARAMETER) != null; |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
public ModelAndView displayNotificationDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
216 | 0 | String view = "NotificationDetail"; |
217 | |
|
218 | 0 | String user = request.getRemoteUser(); |
219 | 0 | String command = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.COMMAND); |
220 | 0 | String standaloneWindow = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW); |
221 | |
|
222 | 0 | NotificationMessageDelivery messageDelivery = determineMessageFromRequest(request); |
223 | |
|
224 | 0 | Notification notification = messageDelivery.getNotification(); |
225 | 0 | boolean actionable = false; |
226 | |
|
227 | 0 | if (requestIsFromKEW(request)) { |
228 | |
|
229 | 0 | if(command != null && |
230 | |
(command.equals(NotificationConstants.NOTIFICATION_DETAIL_VIEWS.NORMAL_VIEW) || |
231 | |
command.equals(NotificationConstants.NOTIFICATION_DETAIL_VIEWS.DOC_SEARCH_VIEW))) { |
232 | 0 | standaloneWindow = "true"; |
233 | |
} |
234 | |
|
235 | |
|
236 | 0 | command = NotificationConstants.NOTIFICATION_DETAIL_VIEWS.INLINE; |
237 | |
} |
238 | |
|
239 | 0 | actionable = user.equals(messageDelivery.getUserRecipientId()) && NotificationConstants.MESSAGE_DELIVERY_STATUS.DELIVERED.equals(messageDelivery.getMessageDeliveryStatus()); |
240 | |
|
241 | 0 | List<NotificationSender> senders = notification.getSenders(); |
242 | 0 | List<NotificationRecipient> recipients = notification.getRecipients(); |
243 | |
|
244 | 0 | String contenthtml = Util.transformContent(notification); |
245 | |
|
246 | |
|
247 | 0 | if (command != null && command.equals(NotificationConstants.NOTIFICATION_DETAIL_VIEWS.INLINE)) { |
248 | 0 | view = "NotificationDetailInline"; |
249 | |
} |
250 | |
|
251 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
252 | 0 | model.put("notification", notification); |
253 | 0 | model.put("senders", senders); |
254 | 0 | model.put("recipients", recipients); |
255 | 0 | model.put("contenthtml", contenthtml); |
256 | 0 | model.put("messageDeliveryId", messageDelivery.getId()); |
257 | 0 | model.put("command", command); |
258 | 0 | model.put("actionable", actionable); |
259 | 0 | model.put(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW, standaloneWindow); |
260 | 0 | return new ModelAndView(view, model); |
261 | |
} |
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
public ModelAndView dismissMessage(HttpServletRequest request, HttpServletResponse response) { |
270 | 0 | String command = request.getParameter("action"); |
271 | 0 | if (command == null) throw new RuntimeException("Dismissal command not specified"); |
272 | |
|
273 | 0 | if (NotificationConstants.ACK_CAUSE.equals(command)) { |
274 | 0 | return dismissMessage(command, "Notificaton acknowledged. Please refresh your action list.", request, response); |
275 | 0 | } else if (NotificationConstants.FYI_CAUSE.equals(command)) { |
276 | 0 | return dismissMessage(command, "Action Taken. Please refresh your action list.", request, response); |
277 | |
} else { |
278 | 0 | throw new RuntimeException("Unknown dismissal command: " + command); |
279 | |
} |
280 | |
} |
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
private ModelAndView dismissMessage(String action, String message, HttpServletRequest request, HttpServletResponse response) { |
292 | 0 | String view = "NotificationDetail"; |
293 | |
|
294 | 0 | String user = request.getRemoteUser(); |
295 | 0 | String messageDeliveryId = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.MSG_DELIVERY_ID); |
296 | 0 | String command = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.COMMAND); |
297 | 0 | String standaloneWindow = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW); |
298 | |
|
299 | 0 | if (messageDeliveryId == null) { |
300 | 0 | throw new RuntimeException("A null messageDeliveryId was provided."); |
301 | |
} |
302 | |
|
303 | 0 | LOG.debug("messageDeliveryId: "+messageDeliveryId); |
304 | 0 | LOG.debug("command: "+command); |
305 | |
|
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | 0 | NotificationMessageDelivery delivery = messageDeliveryService.getNotificationMessageDelivery(Long.decode(messageDeliveryId)); |
312 | 0 | if (delivery == null) { |
313 | 0 | throw new RuntimeException("Could not find message delivery with id " + messageDeliveryId); |
314 | |
} |
315 | 0 | Notification notification = delivery.getNotification(); |
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | 0 | notificationService.dismissNotificationMessageDelivery(delivery.getId(), user, action); |
321 | |
|
322 | 0 | List<NotificationSender> senders = notification.getSenders(); |
323 | 0 | List<NotificationRecipient> recipients = notification.getRecipients(); |
324 | |
|
325 | 0 | String contenthtml = Util.transformContent(notification); |
326 | |
|
327 | |
|
328 | 0 | if(standaloneWindow != null && standaloneWindow.equals("true")) { |
329 | 0 | view = "NotificationActionTakenCloseWindow"; |
330 | |
} else { |
331 | 0 | if (command != null && command.equals(NotificationConstants.NOTIFICATION_DETAIL_VIEWS.INLINE)) { |
332 | 0 | view = "NotificationDetailInline"; |
333 | |
} |
334 | |
} |
335 | |
|
336 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
337 | 0 | model.put("notification", notification); |
338 | 0 | model.put("message", message); |
339 | 0 | model.put("senders", senders); |
340 | 0 | model.put("recipients", recipients); |
341 | 0 | model.put("contenthtml", contenthtml); |
342 | 0 | model.put("messageDeliveryId", messageDeliveryId); |
343 | 0 | model.put("command", command); |
344 | 0 | model.put(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW, standaloneWindow); |
345 | 0 | return new ModelAndView(view, model); |
346 | |
} |
347 | |
} |