/** * 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(); }
public static PostComment getModifiedPostComment() { PostComment comment3 = new PostComment(); comment3.setAuthor(persist(ObjectsFactory.getRandomUser())); comment3.setBody("Comment3 body"); comment3.setCreationDate(new DateTime(3)); comment3.setPost(getDefaultPost()); comment3.setUserChanged(persist(ObjectsFactory.getRandomUser())); comment3.setModificationDate(new DateTime(4)); return comment3; }
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(); }
/** * Return first code review comment from persisted code review. * * @return first code review comment from persisted code review. */ public static PostComment getDefaultPostComment() { PostComment comment2 = new PostComment(); comment2.setAuthor(persist(ObjectsFactory.getRandomUser())); comment2.setBody("Comment2 body"); comment2.setCreationDate(new DateTime(2)); comment2.setPost(getDefaultPost()); return comment2; }
/** * {@inheritDoc} */ @Override public PostComment addComment(Long postId, Map<String, String> attributes, String body) throws NotFoundException { Post targetPost = get(postId); JCUser currentUser = userService.getCurrentUser(); assertCommentAllowed(targetPost.getTopic()); PostComment comment = new PostComment(); comment.putAllAttributes(attributes); comment.setBody(body); comment.setCreationDate(new DateTime(System.currentTimeMillis())); comment.setAuthor(currentUser); if (currentUser.isAutosubscribe()) { targetPost.getTopic().getSubscribers().add(currentUser); } targetPost.addComment(comment); getDao().saveOrUpdate(targetPost); /** * Notify subscribers of topic if comment added */ notificationService.subscribedEntityChanged(targetPost.getTopic()); return comment; }
/** * {@inheritDoc} */ public PostComment updateComment(long id, String body, long branchId) throws NotFoundException { PostComment comment = get(id); checkHasUpdatePermission(comment, branchId); comment.setBody(body); comment.setUserChanged(userService.getCurrentUser()); comment.setModificationDate(DateTime.now()); getDao().saveOrUpdate(comment); return comment; }
@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)); }
/** * Determines whether specified user is the author of this comment. * * @param user a user to define whether she is the author, can be null * @return true if the specified user is the author, or false if the author is null or the specified user is null or * the specified user is simply not the author */ public boolean isCreatedBy(JCUser user) { return this.getAuthor() != null && ObjectUtils.nullSafeEquals(this.getAuthor(), user); }
/** * 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 static Post getPostWithComments() { Post post = new Post(getDefaultUser(), "test"); post.addComment(new PostComment()); post.addComment(new PostComment()); return post; } }
/** * 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); }
return new JsonResponse(JsonResponseStatus.SUCCESS, new CommentDto(comment, dateTimeTool) .withRenderBody(getPluginBbCodeService().convertBbToHtml(comment.getBody())));