1.1 --- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Fri Oct 09 19:06:51 2020 +0200 1.2 +++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Fri Oct 09 19:07:05 2020 +0200 1.3 @@ -282,11 +282,15 @@ 1.4 viewModel.setIssue(issue); 1.5 viewModel.configureVersionSelectors(viewModel.getProjectInfo().getVersions()); 1.6 viewModel.setUsers(dao.getUserDao().list()); 1.7 + if (issue.getId() >= 0) { 1.8 + viewModel.setComments(dao.getIssueDao().listComments(issue)); 1.9 + } 1.10 } 1.11 1.12 @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET) 1.13 public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException { 1.14 final var viewModel = new IssueEditView(); 1.15 + populate(viewModel, req, dao); 1.16 1.17 final var issueParam = getParameter(req, Integer.class, "issue"); 1.18 if (issueParam.isPresent()) { 1.19 @@ -294,10 +298,8 @@ 1.20 final var issue = issueDao.find(issueParam.get()); 1.21 issueDao.joinVersionInformation(issue); 1.22 req.getSession().setAttribute(SESSION_ATTR_SELECTED_PROJECT, issue.getProject().getId()); 1.23 - populate(viewModel, req, dao); 1.24 configure(viewModel, issue, dao); 1.25 } else { 1.26 - populate(viewModel, req, dao); 1.27 configure(viewModel, new Issue(-1), dao); 1.28 } 1.29 1.30 @@ -305,7 +307,7 @@ 1.31 } 1.32 1.33 @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST) 1.34 - public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException { 1.35 + public ResponseType commitIssue(HttpServletRequest req, DataAccessObjects dao) throws SQLException { 1.36 Issue issue = new Issue(-1); 1.37 try { 1.38 issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow()); 1.39 @@ -335,16 +337,57 @@ 1.40 // specifying the issue parameter keeps the edited issue as menu item 1.41 setRedirectLocation(req, "./projects/view?pid=" + issue.getProject().getId()); 1.42 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 1.43 + 1.44 + return ResponseType.HTML; 1.45 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { 1.46 // TODO: set request attribute with error text 1.47 LOG.warn("Form validation failure: {}", ex.getMessage()); 1.48 LOG.debug("Details:", ex); 1.49 final var viewModel = new IssueEditView(); 1.50 + populate(viewModel, req, dao); 1.51 configure(viewModel, issue, dao); 1.52 // TODO: set Error Text 1.53 return forwardView(req, viewModel, "issue-form"); 1.54 } 1.55 + } 1.56 1.57 - return ResponseType.HTML; 1.58 + @RequestMapping(requestPath = "issues/comment", method = HttpMethod.POST) 1.59 + public ResponseType commentIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException { 1.60 + final var issueIdParam = getParameter(req, Integer.class, "issueid"); 1.61 + if (issueIdParam.isEmpty()) { 1.62 + resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Detected manipulated form."); 1.63 + return ResponseType.NONE; 1.64 + } 1.65 + final var issue = new Issue(issueIdParam.get()); 1.66 + try { 1.67 + final var issueComment = new IssueComment(getParameter(req, Integer.class, "commentid").orElse(-1), issue); 1.68 + issueComment.setComment(getParameter(req, String.class, "comment").orElse("")); 1.69 + 1.70 + if (issueComment.getComment().isBlank()) { 1.71 + throw new IllegalArgumentException("comment.null"); 1.72 + } 1.73 + 1.74 + LOG.debug("User {} is commenting on issue #{}", req.getRemoteUser(), issue.getId()); 1.75 + if (req.getRemoteUser() != null) { 1.76 + dao.getUserDao().findByUsername(req.getRemoteUser()).ifPresent(issueComment::setAuthor); 1.77 + } 1.78 + 1.79 + dao.getIssueDao().saveComment(issueComment); 1.80 + 1.81 + // specifying the issue parameter keeps the edited issue as menu item 1.82 + setRedirectLocation(req, "./projects/issues/edit?issue=" + issue.getId()); 1.83 + setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 1.84 + 1.85 + return ResponseType.HTML; 1.86 + } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { 1.87 + // TODO: set request attribute with error text 1.88 + LOG.warn("Form validation failure: {}", ex.getMessage()); 1.89 + LOG.debug("Details:", ex); 1.90 + final var viewModel = new IssueEditView(); 1.91 + populate(viewModel, req, dao); 1.92 + configure(viewModel, issue, dao); 1.93 + // TODO: set Error Text 1.94 + return forwardView(req, viewModel, "issue-form"); 1.95 + } 1.96 } 1.97 }