001package org.kuali.ole.module.purap.document.web.struts; 002 003import org.apache.log4j.Logger; 004import org.kuali.rice.ken.bo.NotificationBo; 005import org.kuali.rice.ken.bo.NotificationMessageDelivery; 006import org.kuali.rice.ken.bo.NotificationRecipientBo; 007import org.kuali.rice.ken.bo.NotificationSenderBo; 008import org.kuali.rice.ken.util.NotificationConstants; 009import org.kuali.rice.ken.util.Util; 010import org.kuali.rice.ken.web.spring.NotificationController; 011import org.kuali.rice.krad.util.GlobalVariables; 012import org.springframework.web.servlet.ModelAndView; 013 014import javax.servlet.http.HttpServletRequest; 015import javax.servlet.http.HttpServletResponse; 016import java.util.HashMap; 017import java.util.List; 018import java.util.Map; 019 020public class OleNotificationController extends NotificationController { 021 /** 022 * Logger for this class and subclasses 023 */ 024 private static final Logger LOG = Logger.getLogger(NotificationController.class); 025 026 /** 027 * This method takes an action on the message delivery - dismisses it with the action/cause that comes from the 028 * UI layer 029 * 030 * @param action the action or cause of the dismissal 031 * @param message the message to display to the user 032 * @param request the HttpServletRequest 033 * @param response the HttpServletResponse 034 * @return an appropriate ModelAndView 035 */ 036 037 private ModelAndView dismissMessage(String action, String message, HttpServletRequest request, HttpServletResponse response) { 038 String view = "NotificationDetail"; 039 String userName = request.getRemoteUser(); 040 String user = null; 041 if (GlobalVariables.getUserSession() != null) { 042 user = GlobalVariables.getUserSession().getPrincipalId(); 043 } 044 String messageDeliveryId = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.MSG_DELIVERY_ID); 045 String command = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.COMMAND); 046 String standaloneWindow = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW); 047 if (messageDeliveryId == null) { 048 throw new RuntimeException("A null messageDeliveryId was provided."); 049 } 050 051 LOG.debug("messageDeliveryId: " + messageDeliveryId); 052 LOG.debug("command: " + command); 053 054 /** 055 * We can get the notification object given a workflow ID or a notification 056 * Id. This method might be called either from a workflow action list or 057 * as a link from a message deliverer endpoint such as an email message. 058 */ 059 NotificationMessageDelivery delivery = messageDeliveryService.getNotificationMessageDelivery(Long.decode(messageDeliveryId)); 060 if (delivery == null) { 061 throw new RuntimeException("Could not find message delivery with id " + messageDeliveryId); 062 } 063 NotificationBo notification = delivery.getNotification(); 064 065 /* 066 * dismiss the message delivery 067 */ 068 069 notificationService.dismissNotificationMessageDelivery(delivery.getId(), user, action); 070 071 072 List<NotificationSenderBo> senders = notification.getSenders(); 073 List<NotificationRecipientBo> recipients = notification.getRecipients(); 074 075 String contenthtml = Util.transformContent(notification); 076 077 // first check to see if this is a standalone window, b/c if it is, we'll want to close 078 if (standaloneWindow != null && standaloneWindow.equals("true")) { 079 view = "NotificationActionTakenCloseWindow"; 080 } else { // otherwise check to see if the details need to be rendered in line (no stuff around them) 081 if (command != null && command.equals(NotificationConstants.NOTIFICATION_DETAIL_VIEWS.INLINE)) { 082 view = "NotificationDetailInline"; 083 } 084 } 085 086 Map<String, Object> model = new HashMap<String, Object>(); 087 model.put("notification", notification); 088 model.put("message", message); 089 model.put("senders", senders); 090 model.put("recipients", recipients); 091 model.put("contenthtml", contenthtml); 092 model.put("messageDeliveryId", messageDeliveryId); 093 model.put("command", command); 094 model.put(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW, standaloneWindow); 095 return new ModelAndView(view, model); 096 } 097}