264 setContentPage(req, "project-details"); |
264 setContentPage(req, "project-details"); |
265 |
265 |
266 return ResponseType.HTML; |
266 return ResponseType.HTML; |
267 } |
267 } |
268 |
268 |
269 private void configureEditVersionForm(HttpServletRequest req, SessionSelection selection) { |
269 private void configureEditVersionForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { |
|
270 req.setAttribute("projects", dao.getProjectDao().list()); |
270 req.setAttribute("version", selection.version); |
271 req.setAttribute("version", selection.version); |
271 req.setAttribute("versionStatusEnum", VersionStatus.values()); |
272 req.setAttribute("versionStatusEnum", VersionStatus.values()); |
272 |
273 |
273 setContentPage(req, "version-form"); |
274 setContentPage(req, "version-form"); |
274 setBreadcrumbs(req, getBreadcrumbs(2, selection)); |
275 setBreadcrumbs(req, getBreadcrumbs(2, selection)); |
275 } |
276 } |
276 |
277 |
277 @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET) |
278 @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET) |
278 public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { |
279 public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { |
279 final var sessionSelection = new SessionSelection(req, dao); |
280 final var sessionSelection = new SessionSelection(req, dao); |
280 if (sessionSelection.project == null) { |
|
281 // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh version |
|
282 resp.sendError(HttpServletResponse.SC_FORBIDDEN); |
|
283 return ResponseType.NONE; |
|
284 } |
|
285 |
281 |
286 sessionSelection.selectVersion(findByParameter(req, Integer.class, "id", dao.getVersionDao()::find) |
282 sessionSelection.selectVersion(findByParameter(req, Integer.class, "id", dao.getVersionDao()::find) |
287 .orElse(new Version(-1, sessionSelection.project))); |
283 .orElse(new Version(-1, sessionSelection.project))); |
288 configureEditVersionForm(req, sessionSelection); |
284 configureEditVersionForm(req, dao, sessionSelection); |
289 |
285 |
290 return ResponseType.HTML; |
286 return ResponseType.HTML; |
291 } |
287 } |
292 |
288 |
293 @RequestMapping(requestPath = "versions/commit", method = HttpMethod.POST) |
289 @RequestMapping(requestPath = "versions/commit", method = HttpMethod.POST) |
294 public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { |
290 public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { |
295 final var sessionSelection = new SessionSelection(req, dao); |
291 final var sessionSelection = new SessionSelection(req, dao); |
296 if (sessionSelection.project == null) { |
|
297 // TODO: remove this bullshit and retrieve project id from hidden field |
|
298 resp.sendError(HttpServletResponse.SC_FORBIDDEN); |
|
299 return ResponseType.NONE; |
|
300 } |
|
301 |
292 |
302 var version = new Version(-1, sessionSelection.project); |
293 var version = new Version(-1, sessionSelection.project); |
303 try { |
294 try { |
304 version = new Version(getParameter(req, Integer.class, "id").orElseThrow(), sessionSelection.project); |
295 version = new Version(getParameter(req, Integer.class, "id").orElseThrow(), sessionSelection.project); |
305 version.setName(getParameter(req, String.class, "name").orElseThrow()); |
296 version.setName(getParameter(req, String.class, "name").orElseThrow()); |
314 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { |
305 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { |
315 // TODO: set request attribute with error text |
306 // TODO: set request attribute with error text |
316 LOG.warn("Form validation failure: {}", ex.getMessage()); |
307 LOG.warn("Form validation failure: {}", ex.getMessage()); |
317 LOG.debug("Details:", ex); |
308 LOG.debug("Details:", ex); |
318 sessionSelection.selectVersion(version); |
309 sessionSelection.selectVersion(version); |
319 configureEditVersionForm(req, sessionSelection); |
310 configureEditVersionForm(req, dao, sessionSelection); |
320 } |
311 } |
321 |
312 |
322 return ResponseType.HTML; |
313 return ResponseType.HTML; |
323 } |
314 } |
324 |
315 |
325 private void configureEditIssueForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { |
316 private void configureEditIssueForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { |
|
317 req.setAttribute("projects", dao.getProjectDao().list()); |
326 req.setAttribute("issue", selection.issue); |
318 req.setAttribute("issue", selection.issue); |
327 req.setAttribute("issueStatusEnum", IssueStatus.values()); |
319 req.setAttribute("issueStatusEnum", IssueStatus.values()); |
328 req.setAttribute("issueCategoryEnum", IssueCategory.values()); |
320 req.setAttribute("issueCategoryEnum", IssueCategory.values()); |
329 req.setAttribute("versions", dao.getVersionDao().list(selection.project)); |
|
330 req.setAttribute("users", dao.getUserDao().list()); |
321 req.setAttribute("users", dao.getUserDao().list()); |
331 |
322 |
332 setContentPage(req, "issue-form"); |
323 setContentPage(req, "issue-form"); |
333 setBreadcrumbs(req, getBreadcrumbs(3, selection)); |
324 setBreadcrumbs(req, getBreadcrumbs(3, selection)); |
334 } |
325 } |
335 |
326 |
336 @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET) |
327 @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET) |
337 public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { |
328 public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { |
338 final var sessionSelection = new SessionSelection(req, dao); |
329 final var sessionSelection = new SessionSelection(req, dao); |
339 if (sessionSelection.project == null) { |
|
340 // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh issue |
|
341 resp.sendError(HttpServletResponse.SC_FORBIDDEN); |
|
342 return ResponseType.NONE; |
|
343 } |
|
344 |
330 |
345 sessionSelection.selectIssue(findByParameter(req, Integer.class, "id", |
331 sessionSelection.selectIssue(findByParameter(req, Integer.class, "id", |
346 dao.getIssueDao()::find).orElse(new Issue(-1, sessionSelection.project))); |
332 dao.getIssueDao()::find).orElse(new Issue(-1, sessionSelection.project))); |
347 configureEditIssueForm(req, dao, sessionSelection); |
333 configureEditIssueForm(req, dao, sessionSelection); |
348 |
334 |
349 return ResponseType.HTML; |
335 return ResponseType.HTML; |
350 } |
336 } |
351 |
337 |
352 @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST) |
338 @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST) |
353 public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { |
339 public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { |
354 // TODO: remove this bullshit and store the project ID as hidden field |
340 final var sessionSelection = new SessionSelection(req, dao); |
355 final var sessionSelection = new SessionSelection(req, dao); |
|
356 if (sessionSelection.project == null) { |
|
357 resp.sendError(HttpServletResponse.SC_FORBIDDEN); |
|
358 return ResponseType.NONE; |
|
359 } |
|
360 |
341 |
361 Issue issue = new Issue(-1, sessionSelection.project); |
342 Issue issue = new Issue(-1, sessionSelection.project); |
362 try { |
343 try { |
363 issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow(), sessionSelection.project); |
344 issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow(), sessionSelection.project); |
364 getParameter(req, String.class, "category").map(IssueCategory::valueOf).ifPresent(issue::setCategory); |
345 getParameter(req, String.class, "category").map(IssueCategory::valueOf).ifPresent(issue::setCategory); |