81 } else { |
81 } else { |
82 candidates.entries.first().toPair() |
82 candidates.entries.first().toPair() |
83 } |
83 } |
84 } |
84 } |
85 |
85 |
|
86 private fun forwardIfRequested(req: HttpServletRequest, resp: HttpServletResponse) { |
|
87 val site = req.getAttribute(Constants.REQ_ATTR_JSP) |
|
88 if (site != null) { |
|
89 req.getRequestDispatcher(Constants.JSP_PATH_PREFIX + site + ".jsp").forward(req, resp) |
|
90 } |
|
91 } |
|
92 |
86 private fun invokeMapping( |
93 private fun invokeMapping( |
87 mapping: Pair<PathPattern, MappingMethod>, |
94 mapping: Pair<PathPattern, MappingMethod>, |
88 req: HttpServletRequest, |
95 req: HttpServletRequest, |
89 resp: HttpServletResponse, |
96 resp: HttpServletResponse, |
90 dao: DataAccessObject |
97 dao: DataAccessObject |
91 ) { |
98 ) { |
92 val params = mapping.first.obtainPathParameters(sanitizedRequestPath(req)) |
99 val params = mapping.first.obtainPathParameters(sanitizedRequestPath(req)) |
93 val method = mapping.second |
100 val method = mapping.second |
94 val authenticatedUser = req.remoteUser?.let(dao::findUserByName) |
101 val authenticatedUser = req.remoteUser?.let(dao::findUserByName) |
95 showWhatsNewPopup(authenticatedUser, req, dao) |
|
96 logger.trace("invoke {0}", method) |
102 logger.trace("invoke {0}", method) |
97 method(HttpRequest(authenticatedUser, req, resp, params), dao) |
103 method(HttpRequest(authenticatedUser, req, resp, params), dao) |
|
104 showWhatsNewPopup(authenticatedUser, req, resp, dao) |
|
105 forwardIfRequested(req, resp) |
98 } |
106 } |
99 |
107 |
100 private fun sanitizedRequestPath(req: HttpServletRequest) = req.pathInfo ?: "/" |
108 private fun sanitizedRequestPath(req: HttpServletRequest) = req.pathInfo ?: "/" |
101 |
109 |
102 protected fun sanitizeJson(str: String): String { |
110 protected fun sanitizeJson(str: String): String { |
211 logger.debug("Details: ", ex) |
219 logger.debug("Details: ", ex) |
212 resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Database Error - Code: " + ex.errorCode) |
220 resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Database Error - Code: " + ex.errorCode) |
213 } |
221 } |
214 } |
222 } |
215 |
223 |
216 private fun showWhatsNewPopup(user: User?, req: HttpServletRequest, dao: DataAccessObject) { |
224 private fun showWhatsNewPopup(user: User?, req: HttpServletRequest, resp: HttpServletResponse, dao: DataAccessObject) { |
|
225 // don't show to anonymous users |
217 if (user == null) return |
226 if (user == null) return |
|
227 |
|
228 // don't show if we aren't going to forward to the site JSP |
|
229 if (req.getAttribute(Constants.REQ_ATTR_JSP) != "site") return |
|
230 |
|
231 // don't show for different sources |
|
232 if (listOf("rss").contains(req.getParameter("source").orEmpty())) return |
|
233 |
|
234 // show the popup and remember that we've shown it |
218 logger.trace("show user with ID {0} what's new", user.id) |
235 logger.trace("show user with ID {0} what's new", user.id) |
219 val userKnowsUpdatesUntil = dao.untilWhenUserKnowsUpdates(user) |
236 val userKnowsUpdatesUntil = dao.untilWhenUserKnowsUpdates(user) |
220 if (userKnowsUpdatesUntil == null || userKnowsUpdatesUntil.before(SqlDate.valueOf(Constants.VERSION_DATE))) { |
237 if (userKnowsUpdatesUntil == null || userKnowsUpdatesUntil.before(SqlDate.valueOf(Constants.VERSION_DATE))) { |
221 dao.updateUserKnowsUpdates(user) |
238 dao.updateUserKnowsUpdates(user) |
222 req.setAttribute("showWhatsNew", true) |
239 req.setAttribute("showWhatsNew", true) |