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.Date;
31 import java.util.Map;
32
33
34
35
36
37
38 public class SendEventNotificationMessageController extends BaseSendNotificationController {
39
40 private static final Logger LOG = Logger.getLogger(SendEventNotificationMessageController.class);
41
42
43
44
45
46
47
48
49
50
51
52 public ModelAndView sendEventNotificationMessage(HttpServletRequest request,
53 HttpServletResponse response) throws ServletException, IOException {
54 String view = "SendEventNotificationMessage";
55
56 LOG.debug("remoteUser: " + request.getRemoteUser());
57
58 Map<String, Object> model = setupModelForSendNotification(request);
59 model.put("errors", new ErrorList());
60
61 return new ModelAndView(view, model);
62 }
63
64
65
66
67
68
69
70
71
72
73
74 public ModelAndView submitEventNotificationMessage(HttpServletRequest request,
75 HttpServletResponse response) throws ServletException, IOException {
76 String routeMessage = "This message was submitted via the event notification message submission form by user ";
77 String viewName = "SendEventNotificationMessage";
78
79 return submitNotificationMessage(request, routeMessage, viewName);
80 }
81
82
83
84
85
86
87 @Override
88 protected Map<String, Object> setupModelForSendNotification(HttpServletRequest request) {
89 Map<String, Object> model = super.setupModelForSendNotification(request);
90
91 model.put("summary", request.getParameter("summary"));
92 model.put("description", request.getParameter("description"));
93 model.put("location", request.getParameter("location"));
94 model.put("startDateTime", request.getParameter("startDateTime"));
95 model.put("stopDateTime", request.getParameter("stopDateTime"));
96
97 return model;
98 }
99
100
101
102
103
104
105 @Override
106 protected NotificationBo createNotification(HttpServletRequest request, Map<String, Object> model,
107 ErrorList errors) throws ErrorList {
108 NotificationBo notification = super.createNotification(request, model, errors);
109
110 String message = getParameter(request, "message", model, errors, "You must fill in a message.");
111
112 String summary = getParameter(request, "summary", model, errors, "You must fill in a summary.");
113 String description = getParameter(request, "description", model, errors, "You must fill in a description.");
114 String location = getParameter(request, "location", model, errors, "You must fill in a location.");
115
116 String startDateTime = request.getParameter("startDateTime");
117 Date startDate = getDate(startDateTime, errors,
118 "You specified an invalid start date and time. Please use the calendar picker.");
119 if (startDate != null) {
120 model.put("startDateTime", startDateTime);
121 }
122
123 String stopDateTime = request.getParameter("stopDateTime");
124 Date stopDate = getDate(stopDateTime, errors,
125 "You specified an invalid start date and time. Please use the calendar picker.");
126 if (stopDate != null) {
127 model.put("stopDateTime", stopDateTime);
128 } else {
129
130 }
131
132 if (stopDate != null && startDate != null) {
133 if (stopDate.before(startDate)) {
134 errors.addError("Event Stop Date/Time cannot be before Event Start Date/Time.");
135 }
136 }
137
138
139 if (!errors.getErrors().isEmpty()) {
140 throw errors;
141 }
142
143 NotificationContentTypeBo contentType = Util.retrieveFieldReference("contentType", "name",
144 NotificationConstants.CONTENT_TYPES.EVENT_CONTENT_TYPE, NotificationContentTypeBo.class,
145 dataObjectService, Boolean.TRUE);
146 notification.setContentType(contentType);
147
148 notification.setContent(NotificationConstants.XML_MESSAGE_CONSTANTS.CONTENT_EVENT_OPEN
149 + NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_OPEN
150 + message
151 + NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_CLOSE
152 + "<event>\n"
153 + " <summary>"
154 + summary
155 + "</summary>\n"
156 + " <description>"
157 + description
158 + "</description>\n"
159 + " <location>"
160 + location
161 + "</location>\n"
162 + " <startDateTime>"
163 + Util.toUIDateTimeString(startDate)
164 + "</startDateTime>\n"
165 + " <stopDateTime>"
166 + Util.toUIDateTimeString(stopDate)
167 + "</stopDateTime>\n"
168 + "</event>"
169 + NotificationConstants.XML_MESSAGE_CONSTANTS.CONTENT_CLOSE);
170
171 return notification;
172 }
173 }