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 org.apache.log4j.Logger;
19 import org.kuali.rice.ken.bo.NotificationBo;
20 import org.kuali.rice.ken.bo.NotificationContentTypeBo;
21 import org.kuali.rice.ken.exception.ErrorList;
22 import org.kuali.rice.ken.util.NotificationConstants;
23 import org.kuali.rice.ken.util.Util;
24 import org.springframework.web.servlet.ModelAndView;
25
26 import javax.servlet.ServletException;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import java.io.IOException;
30 import java.util.Map;
31
32 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
33
34
35
36
37
38
39 public class SendNotificationMessageController extends BaseSendNotificationController {
40
41 private static final Logger LOG = Logger.getLogger(SendNotificationMessageController.class);
42
43
44
45
46
47
48
49
50
51
52
53 public ModelAndView sendSimpleNotificationMessage(HttpServletRequest request, HttpServletResponse response)
54 throws ServletException, IOException {
55 String view = "SendSimpleNotificationMessage";
56
57 LOG.debug("remoteUser: " + request.getRemoteUser());
58
59 Map<String, Object> model = setupModelForSendNotification(request);
60 model.put("errors", new ErrorList());
61
62 return new ModelAndView(view, model);
63 }
64
65
66
67
68
69
70
71
72
73
74
75 public ModelAndView submitSimpleNotificationMessage(HttpServletRequest request, HttpServletResponse response)
76 throws ServletException, IOException {
77 String routeMessage = "This message was submitted via the simple notification message submission form by user ";
78 String viewName = "SendSimpleNotificationMessage";
79
80 return submitNotificationMessage(request, routeMessage, viewName);
81 }
82
83
84
85
86
87
88 @Override
89 protected NotificationBo createNotification(HttpServletRequest request, Map<String, Object> model,
90 ErrorList errors) throws ErrorList {
91 NotificationBo notification = super.createNotification(request, model, errors);
92
93 String message = getParameter(request, "message", model, errors, "You must fill in a message.");
94
95
96 if (!errors.getErrors().isEmpty()) {
97 throw errors;
98 }
99
100 NotificationContentTypeBo contentType = Util.retrieveFieldReference("contentType", "name",
101 NotificationConstants.CONTENT_TYPES.SIMPLE_CONTENT_TYPE, NotificationContentTypeBo.class,
102 dataObjectService, Boolean.TRUE);
103 notification.setContentType(contentType);
104
105 notification.setContent(NotificationConstants.XML_MESSAGE_CONSTANTS.CONTENT_SIMPLE_OPEN
106 + NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_OPEN
107 + message
108 + NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_CLOSE
109 + NotificationConstants.XML_MESSAGE_CONSTANTS.CONTENT_CLOSE);
110
111 return notification;
112 }
113 }