1   package org.kuali.ole.module.purap.document.web.struts;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.rice.ken.bo.NotificationBo;
5   import org.kuali.rice.ken.bo.NotificationMessageDelivery;
6   import org.kuali.rice.ken.bo.NotificationRecipientBo;
7   import org.kuali.rice.ken.bo.NotificationSenderBo;
8   import org.kuali.rice.ken.util.NotificationConstants;
9   import org.kuali.rice.ken.util.Util;
10  import org.kuali.rice.ken.web.spring.NotificationController;
11  import org.kuali.rice.krad.util.GlobalVariables;
12  import org.springframework.web.servlet.ModelAndView;
13  
14  import javax.servlet.http.HttpServletRequest;
15  import javax.servlet.http.HttpServletResponse;
16  import java.util.HashMap;
17  import java.util.List;
18  import java.util.Map;
19  
20  public class OleNotificationController extends NotificationController {
21      
22  
23  
24      private static final Logger LOG = Logger.getLogger(NotificationController.class);
25  
26      
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37      private ModelAndView dismissMessage(String action, String message, HttpServletRequest request, HttpServletResponse response) {
38          String view = "NotificationDetail";
39          String userName = request.getRemoteUser();
40          String user = null;
41          if (GlobalVariables.getUserSession() != null) {
42              user = GlobalVariables.getUserSession().getPrincipalId();
43          }
44          String messageDeliveryId = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.MSG_DELIVERY_ID);
45          String command = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.COMMAND);
46          String standaloneWindow = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW);
47          if (messageDeliveryId == null) {
48              throw new RuntimeException("A null messageDeliveryId was provided.");
49          }
50  
51          LOG.debug("messageDeliveryId: " + messageDeliveryId);
52          LOG.debug("command: " + command);
53  
54          
55  
56  
57  
58  
59          NotificationMessageDelivery delivery = messageDeliveryService.getNotificationMessageDelivery(Long.decode(messageDeliveryId));
60          if (delivery == null) {
61              throw new RuntimeException("Could not find message delivery with id " + messageDeliveryId);
62          }
63          NotificationBo notification = delivery.getNotification();
64  
65          
66  
67  
68  
69          notificationService.dismissNotificationMessageDelivery(delivery.getId(), user, action);
70  
71  
72          List<NotificationSenderBo> senders = notification.getSenders();
73          List<NotificationRecipientBo> recipients = notification.getRecipients();
74  
75          String contenthtml = Util.transformContent(notification);
76  
77          
78          if (standaloneWindow != null && standaloneWindow.equals("true")) {
79              view = "NotificationActionTakenCloseWindow";
80          } else { 
81              if (command != null && command.equals(NotificationConstants.NOTIFICATION_DETAIL_VIEWS.INLINE)) {
82                  view = "NotificationDetailInline";
83              }
84          }
85  
86          Map<String, Object> model = new HashMap<String, Object>();
87          model.put("notification", notification);
88          model.put("message", message);
89          model.put("senders", senders);
90          model.put("recipients", recipients);
91          model.put("contenthtml", contenthtml);
92          model.put("messageDeliveryId", messageDeliveryId);
93          model.put("command", command);
94          model.put(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW, standaloneWindow);
95          return new ModelAndView(view, model);
96      }
97  }