View Javadoc
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       * Logger for this class and subclasses
23       */
24      private static final Logger LOG = Logger.getLogger(NotificationController.class);
25  
26      /**
27       * This method takes an action on the message delivery - dismisses it with the action/cause that comes from the
28       * UI layer
29       *
30       * @param action   the action or cause of the dismissal
31       * @param message  the message to display to the user
32       * @param request  the HttpServletRequest
33       * @param response the HttpServletResponse
34       * @return an appropriate ModelAndView
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           * We can get the notification object given a workflow ID or a notification
56           * Id.  This method might be called either from a workflow action list or
57           * as a link from a message deliverer endpoint such as an email message.  
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           * dismiss the message delivery
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          // first check to see if this is a standalone window, b/c if it is, we'll want to close
78          if (standaloneWindow != null && standaloneWindow.equals("true")) {
79              view = "NotificationActionTakenCloseWindow";
80          } else { // otherwise check to see if the details need to be rendered in line (no stuff around them)
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  }