@RequestMapping(value = "/review/comment/render/{commentId}", method = RequestMethod.GET) @ResponseBody public JsonResponse getCodeReviewCommentForRender(@PathVariable("commentId") Long commentId) throws NotFoundException { PostComment postComment = postCommentService.get(commentId); postComment.setBody(bbCodeService.convertBbToHtml(postComment.getBody())); return new JsonResponse(JsonResponseStatus.SUCCESS, new CodeReviewCommentDto(postComment)); }
/** * Adds CR comment to review * @param commentDto incoming DTO object from client * @param bindingResult object contains validation information * @param postId ID of post where add comment to * @return response with status 'success' and comment DTO object if comment * was added or 'fail' with no objects if there were some errors * @throws NotFoundException when no review with <code>reviewId</code>was found */ @RequestMapping(value="/reviewcomments/new", method = RequestMethod.POST) @ResponseBody public JsonResponse addComment( @Valid @ModelAttribute CodeReviewCommentDto commentDto, BindingResult bindingResult, @RequestParam("postId") Long postId) throws NotFoundException { if (bindingResult.hasErrors()) { return new FailValidationJsonResponse(bindingResult.getAllErrors()); } PostComment addedComment = postService.addComment(postId, commentDto.getCommentAttributes(), commentDto.getBody()); addedComment.setBody(bbCodeService.convertBbToHtml(addedComment.getBody())); CodeReviewCommentDto addedCommentDto = new CodeReviewCommentDto(addedComment); return new JsonResponse(JsonResponseStatus.SUCCESS, addedCommentDto); }
/** * Edits existence comment * * @param dto dto populated in form * @param result validation result * @param branchId id of a branch to check permission * * @return result in JSON format */ @RequestMapping(method = RequestMethod.POST, value = "editcomment") @ResponseBody JsonResponse editComment(@Valid @RequestBody CommentDto dto, BindingResult result, @RequestParam("branchId") long branchId) { if (result.hasErrors()) { return new FailValidationJsonResponse(result.getAllErrors()); } PostComment updatedComment; try { updatedComment = getCommentService().updateComment(dto.getId(), dto.getBody(), branchId); } catch (NotFoundException ex) { return new FailJsonResponse(JsonResponseReason.ENTITY_NOT_FOUND); } CommentDto commentDto = new CommentDto(updatedComment.getBody(), getPluginBbCodeService().convertBbToHtml(updatedComment.getBody())); return new JsonResponse(JsonResponseStatus.SUCCESS, commentDto); }
public CommentDto(PostComment postComment, JodaDateTimeTool dateTimeTool) { this.id = postComment.getId(); this.authorUsername = postComment.getAuthor().getUsername(); this.body = postComment.getBody(); this.formattedCreationDate = dateTimeTool.format(postComment.getCreationDate()); this.authorId = postComment.getAuthor().getId(); }
/** * Creates CodeReviewCommentDto from {@link PostComment} * * @param comment to create dto * @throws java.lang.NumberFormatException if comment have no line_number attribute * or if this attribute have invalid value */ public CodeReviewCommentDto(PostComment comment) { this.id = comment.getId(); this.lineNumber = Integer.parseInt(comment.getAttributes().get(LINE_NUMBER_PROPERTY_NAME)); this.body = comment.getBody(); this.authorId = comment.getAuthor().getId(); this.authorUsername = comment.getAuthor().getUsername(); if (comment.getUserChanged() != null) { this.editorId = comment.getUserChanged().getId(); this.editorUsername = comment.getUserChanged().getUsername(); } this.modificationDate = comment.getModificationDate(); }
return new JsonResponse(JsonResponseStatus.SUCCESS, new CommentDto(comment, dateTimeTool) .withRenderBody(getPluginBbCodeService().convertBbToHtml(comment.getBody())));