public List<FieldDiffs> selectChangelogByIssue(DbSession session, String issueKey) { return selectByTypeAndIssueKeys(session, singletonList(issueKey), IssueChangeDto.TYPE_FIELD_CHANGE) .stream() .map(IssueChangeDto::toFieldDiffs) .collect(MoreCollectors.toList()); }
public List<DefaultIssue> loadChanges(DbSession dbSession, Collection<DefaultIssue> issues) { Map<String, List<IssueChangeDto>> changeDtoByIssueKey = dbClient.issueChangeDao() .selectByIssueKeys(dbSession, issues.stream().map(DefaultIssue::key).collect(toList())) .stream() .collect(groupingBy(IssueChangeDto::getIssueKey)); return issues .stream() .peek(i -> setChanges(changeDtoByIssueKey, i)) .collect(toList()); }
ChangeLogResults(DbSession dbSession, String issueKey) { IssueDto issue = issueFinder.getByKey(dbSession, issueKey); if (isMember(dbSession, issue)) { this.changes = dbClient.issueChangeDao().selectChangelogByIssue(dbSession, issue.getKey()); List<String> userUuids = changes.stream().filter(change -> change.userUuid() != null).map(FieldDiffs::userUuid).collect(MoreCollectors.toList()); this.users = dbClient.userDao().selectByUuids(dbSession, userUuids).stream().collect(MoreCollectors.uniqueIndex(UserDto::getUuid)); this.files = dbClient.componentDao().selectByUuids(dbSession, getFileUuids(changes)).stream().collect(MoreCollectors.uniqueIndex(ComponentDto::uuid, Function.identity())); } else { changes = ImmutableList.of(); users = ImmutableMap.of(); files = ImmutableMap.of(); } }
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"); }
@Test public void update_unknown_key() { IssueDto issue = db.issues().insertIssue(); IssueChangeDto issueChange = db.issues().insertChange(issue); assertThat(underTest.update(db.getSession(), new IssueChangeDto() .setKey("UNKNOWN") .setIssueKey("other_issue_uuid") .setChangeData("new comment") .setUpdatedAt(DateUtils.parseDate("2013-06-30").getTime()))) .isFalse(); assertThat(underTest.selectByIssueKeys(db.getSession(), singletonList(issue.getKey()))) .extracting(IssueChangeDto::getKey, IssueChangeDto::getIssueKey, IssueChangeDto::getChangeData, IssueChangeDto::getChangeType, IssueChangeDto::getIssueChangeCreationDate, IssueChangeDto::getCreatedAt, IssueChangeDto::getUpdatedAt) .containsExactlyInAnyOrder( tuple(issueChange.getKey(), issue.getKey(), issueChange.getChangeData(), issueChange.getChangeType(), issueChange.getIssueChangeCreationDate(), issueChange.getCreatedAt(), issueChange.getUpdatedAt())); }
public boolean update(DbSession dbSession, IssueChangeDto change) { int count = mapper(dbSession).update(change); return count == 1; }
private Consumer<CommentData> deleteComment(DbSession dbSession) { return commentData -> { dbClient.issueChangeDao().delete(dbSession, commentData.getIssueChangeDto().getKey()); dbSession.commit(); }; }
private IssueChangeDto insertToClosedDiff(IssueDto issue, Date creationDate, String previousStatus, String nextStatus) { FieldDiffs diffs = new FieldDiffs() .setCreationDate(creationDate); IntStream.range(0, random.nextInt(3)).forEach(i -> diffs.setDiff("key_b" + i, "old_" + i, "new_" + i)); diffs.setDiff("status", previousStatus, nextStatus); IntStream.range(0, random.nextInt(3)).forEach(i -> diffs.setDiff("key_a" + i, "old_" + i, "new_" + i)); IssueChangeDto changeDto = IssueChangeDto.of(issue.getKey(), diffs); dbTester.getDbClient().issueChangeDao().insert(dbSession, changeDto); return changeDto; }
private Consumer<CommentData> updateComment(DbSession dbSession) { return commentData -> { commentData.getIssueChangeDto().setUpdatedAt(system2.now()); commentData.getIssueChangeDto().setChangeData(commentData.getRequest().getText()); dbClient.issueChangeDao().update(dbSession, commentData.getIssueChangeDto()); dbSession.commit(); }; }
.scrollDiffChangesOfIssues(dbSession, issuesByKey.keySet(), new ResultHandler<IssueChangeDto>() { private DefaultIssue currentIssue = null; private boolean previousStatusFound = false;
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"); }
public void insert(DbSession session, IssueChangeDto change) { mapper(session).insert(change); }
@Test public void delete_unknown_key() { IssueDto issue = db.issues().insertIssue(); db.issues().insertChange(issue); assertThat(underTest.delete(db.getSession(), "UNKNOWN")).isFalse(); }
public void insertFieldDiffs(IssueDto issueDto, FieldDiffs... diffs) { Arrays.stream(diffs).forEach(diff -> db.getDbClient().issueChangeDao().insert(db.getSession(), IssueChangeDto.of(issueDto.getKey(), diff))); db.commit(); }
private Consumer<CommentData> updateComment(DbSession dbSession) { return commentData -> { commentData.getIssueChangeDto().setUpdatedAt(system2.now()); commentData.getIssueChangeDto().setChangeData(commentData.getRequest().getText()); dbClient.issueChangeDao().update(dbSession, commentData.getIssueChangeDto()); dbSession.commit(); }; }
@Test public void scrollDiffChangesOfIssues_scrolls_only_diff_changes_of_selected_issues() { IssueDto issue1 = db.issues().insertIssue(); IssueChangeDto diffChange1 = db.issues().insertChange(issue1, t -> t.setChangeType(TYPE_FIELD_CHANGE)); db.issues().insertChange(issue1, t -> t.setChangeType(TYPE_COMMENT)); IssueDto issue2 = db.issues().insertIssue(); IssueChangeDto diffChange2 = db.issues().insertChange(issue2, t -> t.setChangeType(TYPE_FIELD_CHANGE)); db.issues().insertChange(issue2, t -> t.setChangeType(TYPE_COMMENT)); IssueDto issue3 = db.issues().insertIssue(); IssueChangeDto diffChange31 = db.issues().insertChange(issue3, t -> t.setChangeType(TYPE_FIELD_CHANGE)); IssueChangeDto diffChange32 = db.issues().insertChange(issue3, t -> t.setChangeType(TYPE_FIELD_CHANGE)); db.issues().insertChange(issue3, t -> t.setChangeType(TYPE_COMMENT)); RecordingIssueChangeDtoResultHandler recordingHandler = new RecordingIssueChangeDtoResultHandler(); underTest.scrollDiffChangesOfIssues(db.getSession(), of(), recordingHandler.clear()); assertThat(recordingHandler.getDtoKeys()).isEmpty(); underTest.scrollDiffChangesOfIssues(db.getSession(), of("fooBarCacahuete"), recordingHandler.clear()); assertThat(recordingHandler.getDtoKeys()).isEmpty(); underTest.scrollDiffChangesOfIssues(db.getSession(), of(issue1.getKee()), recordingHandler.clear()); assertThat(recordingHandler.getDtoKeys()).containsOnly(diffChange1.getKey()); underTest.scrollDiffChangesOfIssues(db.getSession(), of(issue2.getKee()), recordingHandler.clear()); assertThat(recordingHandler.getDtoKeys()).containsOnly(diffChange2.getKey()); underTest.scrollDiffChangesOfIssues(db.getSession(), of(issue1.getKee(), issue3.getKee()), recordingHandler.clear()); assertThat(recordingHandler.getDtoKeys()).containsOnly(diffChange1.getKey(), diffChange31.getKey(), diffChange32.getKey()); }
private void loadComments(Collector collector, DbSession dbSession, Set<SearchAdditionalField> fields, SearchResponseData result) { if (fields.contains(COMMENTS)) { List<IssueChangeDto> comments = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbSession, collector.getIssueKeys(), IssueChangeDto.TYPE_COMMENT); result.setComments(comments); for (IssueChangeDto comment : comments) { collector.addUserUuids(singletonList(comment.getUserUuid())); if (canEditOrDelete(comment)) { result.addUpdatableComment(comment.getKey()); } } } }
@Test public void edit_comment() { IssueDto issueDto = issueDbTester.insertIssue(); UserDto user = dbTester.users().insertUser(); IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it"); loginWithBrowsePermission(user, USER, issueDto); call(commentDto.getKey(), "please have a look"); verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); verifyContentOfPreloadedSearchResponseData(issueDto); IssueChangeDto issueComment = dbClient.issueChangeDao().selectCommentByKey(dbTester.getSession(), commentDto.getKey()).get(); assertThat(issueComment.getChangeData()).isEqualTo("please have a look"); assertThat(issueComment.getUpdatedAt()).isEqualTo(NOW); }
@Test public void insert_entry_in_changelog_when_setting_tags() { IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "new-tag"); List<FieldDiffs> fieldDiffs = dbClient.issueChangeDao().selectChangelogByIssue(db.getSession(), issueDto.getKey()); assertThat(fieldDiffs).hasSize(1); assertThat(fieldDiffs.get(0).diffs()).hasSize(1); assertThat(fieldDiffs.get(0).diffs().get("tags").oldValue()).isEqualTo("old-tag"); assertThat(fieldDiffs.get(0).diffs().get("tags").newValue()).isEqualTo("new-tag"); }
@Test public void select_issue_changes_from_issues_keys() { IssueDto issue1 = db.issues().insertIssue(); db.issues().insertChange(issue1); db.issues().insertChange(issue1); db.issues().insertChange(issue1); db.issues().insertChange(issue1); IssueDto issue2 = db.issues().insertIssue(); db.issues().insertChange(issue2); IssueDto issue3 = db.issues().insertIssue(); List<IssueChangeDto> changelog = underTest.selectByIssueKeys(db.getSession(), asList(issue1.getKey(), issue2.getKey(), issue3.getKey())); assertThat(changelog).hasSize(5); assertThat(underTest.selectByIssueKeys(db.getSession(), singletonList("unknown"))).isEmpty(); assertThat(underTest.selectByIssueKeys(db.getSession(), emptyList())).isEmpty(); }