public void setComments(@Nullable List<IssueChangeDto> comments) { for (IssueChangeDto comment : comments) { commentsByIssueKey.put(comment.getIssueKey(), comment); } }
CommentData(DbSession dbSession, String commentKey) { this.issueChangeDto = dbClient.issueChangeDao().selectCommentByKey(dbSession, commentKey) .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", commentKey))); // Load issue now to quickly fail if user hasn't permission to see it this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey()); checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only delete your own comments"); }
@Override public void handleResult(ResultContext<? extends IssueChangeDto> resultContext) { IssueChangeDto issueChangeDto = resultContext.getResultObject(); if (currentIssue == null || !currentIssue.key().equals(issueChangeDto.getIssueKey())) { currentIssue = issuesByKey.get(issueChangeDto.getIssueKey()); previousStatusFound = false; previousResolutionFound = false; } if (currentIssue != null) { FieldDiffs fieldDiffs = issueChangeDto.toFieldDiffs(); boolean hasPreviousStatus = fieldDiffs.get("status") != null; boolean hasPreviousResolution = fieldDiffs.get("resolution") != null; if ((!previousStatusFound && hasPreviousStatus) || (!previousResolutionFound && hasPreviousResolution)) { currentIssue.addChange(fieldDiffs); } previousStatusFound |= hasPreviousStatus; previousResolutionFound |= hasPreviousResolution; } } });
CommentData(DbSession dbSession, EditCommentRequest request) { this.request = request; this.issueChangeDto = dbClient.issueChangeDao().selectCommentByKey(dbSession, request.getComment()) .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", request.getComment()))); // Load issue now to quickly fail if user hasn't permission to see it this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey()); checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only edit your own comments"); }
@Test public void create_from_comment() { DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment"); IssueChangeDto dto = IssueChangeDto.of(comment); assertThat(dto.getChangeData()).isEqualTo("the comment"); assertThat(dto.getChangeType()).isEqualTo("comment"); assertThat(dto.getCreatedAt()).isNotNull(); assertThat(dto.getUpdatedAt()).isNotNull(); assertThat(dto.getIssueChangeCreationDate()).isNotNull(); assertThat(dto.getIssueKey()).isEqualTo("ABCDE"); assertThat(dto.getUserUuid()).isEqualTo("user_uuid"); }
@Test public void create_from_diff() { FieldDiffs diffs = new FieldDiffs(); diffs.setDiff("severity", "INFO", "BLOCKER"); diffs.setUserUuid("user_uuid"); diffs.setCreationDate(parseDate("2015-01-13")); IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs); assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER"); assertThat(dto.getChangeType()).isEqualTo("diff"); assertThat(dto.getCreatedAt()).isNotNull(); assertThat(dto.getUpdatedAt()).isNotNull(); assertThat(dto.getIssueKey()).isEqualTo("ABCDE"); assertThat(dto.getUserUuid()).isEqualTo("user_uuid"); assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime()); }
@Test public void add_comment() { IssueDto issueDto = issueDbTester.insertIssue(); loginWithBrowsePermission(issueDto, USER); call(issueDto.getKey(), "please fix it"); verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); verifyContentOfPreloadedSearchResponseData(issueDto); IssueChangeDto issueComment = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbTester.getSession(), singletonList(issueDto.getKey()), TYPE_COMMENT).get(0); assertThat(issueComment.getKey()).isNotNull(); assertThat(issueComment.getUserUuid()).isEqualTo(userSession.getUuid()); assertThat(issueComment.getChangeType()).isEqualTo(TYPE_COMMENT); assertThat(issueComment.getChangeData()).isEqualTo("please fix it"); assertThat(issueComment.getCreatedAt()).isNotNull(); assertThat(issueComment.getUpdatedAt()).isNotNull(); assertThat(issueComment.getIssueKey()).isEqualTo(issueDto.getKey()); assertThat(issueComment.getIssueChangeCreationDate()).isNotNull(); IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get(); assertThat(issueReloaded.getIssueUpdateTime()).isEqualTo(NOW); assertThat(issueChangePostProcessor.wasCalled()).isFalse(); }
public void setComments(@Nullable List<IssueChangeDto> comments) { for (IssueChangeDto comment : comments) { commentsByIssueKey.put(comment.getIssueKey(), comment); } }
CommentData(DbSession dbSession, String commentKey) { this.issueChangeDto = dbClient.issueChangeDao().selectCommentByKey(dbSession, commentKey) .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", commentKey))); // Load issue now to quickly fail if user hasn't permission to see it this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey()); checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only delete your own comments"); }
CommentData(DbSession dbSession, EditCommentRequest request) { this.request = request; this.issueChangeDto = dbClient.issueChangeDao().selectCommentByKey(dbSession, request.getComment()) .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", request.getComment()))); // Load issue now to quickly fail if user hasn't permission to see it this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey()); checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only edit your own comments"); }