return session.getMapper(ComponentMapper.class);
}
- public ComponentDto selectOrFailById(DbSession session, long id) {
- Optional<ComponentDto> componentDto = selectById(session, id);
- if (!componentDto.isPresent()) {
- throw new RowNotFoundException(String.format("Component id does not exist: %d", id));
- }
- return componentDto.get();
- }
-
public Optional<ComponentDto> selectById(DbSession session, long id) {
return Optional.fromNullable(mapper(session).selectById(id));
}
.collect(MoreCollectors.toList());
}
- public List<IssueChangeDto> selectChangelogOfNonClosedIssuesByComponent(DbSession session, String componentUuid) {
- IssueChangeMapper mapper = mapper(session);
- return mapper.selectChangelogOfNonClosedIssuesByComponent(componentUuid, IssueChangeDto.TYPE_FIELD_CHANGE);
- }
-
public List<IssueChangeDto> selectByTypeAndIssueKeys(DbSession session, Collection<String> issueKeys, String changeType) {
return executeLargeInputs(issueKeys, issueKeys1 -> mapper(session).selectByIssuesAndType(issueKeys1, changeType));
}
private Long id;
private String kee;
private String issueKey;
- private String userLogin;
+ /**
+ * The column USER_LOGIN hasn't been renamed to USER_UUID because we don't know yet the cost of renaming a column on a table that can contain huge number of data
+ */
+ private String userUuid;
private String changeType;
private String changeData;
dto.setKey(comment.key());
dto.setChangeType(IssueChangeDto.TYPE_COMMENT);
dto.setChangeData(comment.markdownText());
- dto.setUserLogin(comment.userLogin());
+ dto.setUserUuid(comment.userUuid());
Date createdAt = requireNonNull(comment.createdAt(), "Comment created at must not be null");
dto.setIssueChangeCreationDate(createdAt.getTime());
return dto;
IssueChangeDto dto = newDto(issueKey);
dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE);
dto.setChangeData(diffs.toString());
- dto.setUserLogin(diffs.userLogin());
+ dto.setUserUuid(diffs.userUuid());
Date createdAt = requireNonNull(diffs.creationDate(), "Diffs created at must not be null");
dto.setIssueChangeCreationDate(createdAt.getTime());
return dto;
}
@CheckForNull
- public String getUserLogin() {
- return userLogin;
+ public String getUserUuid() {
+ return userUuid;
}
- public IssueChangeDto setUserLogin(@Nullable String userLogin) {
- this.userLogin = userLogin;
+ public IssueChangeDto setUserUuid(@Nullable String userUuid) {
+ this.userUuid = userUuid;
return this;
}
.setKey(kee)
.setCreatedAt(new Date(getIssueChangeCreationDate()))
.setUpdatedAt(updatedAt == null ? null : new Date(updatedAt))
- .setUserLogin(userLogin)
+ .setUserUuid(userUuid)
.setIssueKey(issueKey)
.setNew(false);
}
public FieldDiffs toFieldDiffs() {
return FieldDiffs.parse(changeData)
- .setUserLogin(userLogin)
+ .setUserUuid(userUuid)
.setCreationDate(new Date(getIssueChangeCreationDate()))
.setIssueKey(issueKey);
}
List<IssueChangeDto> selectByIssues(@Param("issueKeys") List<String> issueKeys);
- List<IssueChangeDto> selectChangelogOfNonClosedIssuesByComponent(@Param("componentUuid") String componentUuid, @Param("changeType") String changeType);
}
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.apache.commons.lang.math.RandomUtils.nextInt;
+import static org.apache.commons.lang.math.RandomUtils.nextLong;
public class IssueTesting {
.setUpdatedAt(System.currentTimeMillis() - 500);
}
+ public static IssueChangeDto newIssuechangeDto(IssueDto issue) {
+ return new IssueChangeDto()
+ .setKey("uuid_" + randomAlphabetic(10))
+ .setIssueKey(issue.getKey())
+ .setChangeData("data_" + randomAlphanumeric(40))
+ .setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE)
+ .setUserUuid("userUuid_" + randomAlphanumeric(40))
+ .setIssueChangeCreationDate(nextLong())
+ .setCreatedAt(nextLong())
+ .setUpdatedAt(nextLong());
+ }
+
/**
* @deprecated use newIssue(...)
*/
c.id,
c.kee as kee,
c.issue_key as issueKey,
- c.user_login as userLogin,
+ c.user_login as userUuid,
c.change_type as changeType,
c.change_data as changeData,
c.created_at as createdAt,
<insert id="insert" parameterType="IssueChange" useGeneratedKeys="false" keyProperty="id">
INSERT INTO issue_changes (kee, issue_key, user_login, change_type, change_data, created_at, updated_at,
issue_change_creation_date)
- VALUES (#{kee,jdbcType=VARCHAR}, #{issueKey,jdbcType=VARCHAR}, #{userLogin,jdbcType=VARCHAR},
+ VALUES (#{kee,jdbcType=VARCHAR}, #{issueKey,jdbcType=VARCHAR}, #{userUuid,jdbcType=VARCHAR},
#{changeType,jdbcType=VARCHAR}, #{changeData,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT},
#{updatedAt,jdbcType=BIGINT}, #{issueChangeCreationDate,jdbcType=BIGINT})
</insert>
order by created_at asc
</select>
- <select id="selectChangelogOfNonClosedIssuesByComponent" parameterType="map" resultType="IssueChange">
- select
- <include refid="issueChangeColumns"/>
- from issue_changes c
- inner join issues i on i.kee = c.issue_key
- where i.component_uuid=#{componentUuid,jdbcType=VARCHAR}
- and c.change_type=#{changeType,jdbcType=VARCHAR}
- and i.status <> 'CLOSED'
- </select>
</mapper>
public void get_by_id() {
ComponentDto project = db.components().insertPrivateProject();
- assertThat(underTest.selectOrFailById(dbSession, project.getId())).isNotNull();
+ assertThat(underTest.selectById(dbSession, project.getId())).isNotNull();
}
@Test
assertThat(result.get().isEnabled()).isFalse();
}
- @Test
- public void fail_to_get_by_id_when_project_not_found() {
- ComponentDto project = db.components().insertPrivateProject();
-
- expectedException.expect(RowNotFoundException.class);
-
- underTest.selectOrFailById(dbSession, 0L);
- }
-
@Test
public void get_nullable_by_id() {
ComponentDto project = db.components().insertPrivateProject();
*/
package org.sonar.db.issue;
-import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.junit.Rule;
import org.sonar.core.issue.FieldDiffs;
import org.sonar.db.DbTester;
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.sonar.db.issue.IssueChangeDto.TYPE_COMMENT;
+import static org.sonar.db.issue.IssueChangeDto.TYPE_FIELD_CHANGE;
public class IssueChangeDaoTest {
@Test
public void select_issue_changelog_from_issue_key() {
- db.prepareDbUnit(getClass(), "shared.xml");
+ IssueDto issue1 = db.issues().insertIssue();
+ db.issues().insertChange(issue1, c -> c.setChangeType(TYPE_FIELD_CHANGE).setChangeData("severity=MAJOR|BLOCKER"));
+ IssueDto issue2 = db.issues().insertIssue();
+ db.issues().insertChange(issue2);
+
+ List<FieldDiffs> changelog = underTest.selectChangelogByIssue(db.getSession(), issue1.getKey());
- List<FieldDiffs> changelog = underTest.selectChangelogByIssue(db.getSession(), "1000");
assertThat(changelog).hasSize(1);
assertThat(changelog.get(0).diffs()).hasSize(1);
assertThat(changelog.get(0).diffs().get("severity").newValue()).isEqualTo("BLOCKER");
assertThat(changelog.get(0).diffs().get("severity").oldValue()).isEqualTo("MAJOR");
+
+ assertThat(underTest.selectChangelogByIssue(db.getSession(), "unknown")).isEmpty();
}
@Test
- public void select_issue_changes_from_issues_key() {
- db.prepareDbUnit(getClass(), "shared.xml");
+ 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()));
- List<IssueChangeDto> changelog = underTest.selectByIssueKeys(db.getSession(), Arrays.asList("1000", "1001"));
assertThat(changelog).hasSize(5);
- }
- @Test
- public void selectChangelogOfNonClosedIssuesByComponent() {
- db.prepareDbUnit(getClass(), "selectChangelogOfNonClosedIssuesByComponent.xml");
-
- List<IssueChangeDto> dtos = underTest.selectChangelogOfNonClosedIssuesByComponent(db.getSession(), "FILE_1");
- // no need to have ordered results (see NewDebtCalculator)
- assertThat(dtos).extracting("id").containsOnly(100L, 103L);
+ assertThat(underTest.selectByIssueKeys(db.getSession(), singletonList("unknown"))).isEmpty();
+ assertThat(underTest.selectByIssueKeys(db.getSession(), emptyList())).isEmpty();
}
@Test
public void select_comment_by_key() {
- IssueDto issueDto = db.issues().insertIssue();
- IssueChangeDto comment = db.issues().insertComment(issueDto, "john", "some comment");
+ IssueDto issue = db.issues().insertIssue();
+ IssueChangeDto issueChange = db.issues().insertChange(issue, c -> c.setChangeType(TYPE_COMMENT));
+ db.issues().insertChange(issue, c -> c.setChangeType(TYPE_COMMENT));
- Optional<IssueChangeDto> issueChangeDto = underTest.selectCommentByKey(db.getSession(), comment.getKey());
+ Optional<IssueChangeDto> issueChangeDto = underTest.selectCommentByKey(db.getSession(), issueChange.getKey());
assertThat(issueChangeDto).isPresent();
- assertThat(issueChangeDto.get().getKey()).isEqualTo(comment.getKey());
- assertThat(issueChangeDto.get().getChangeType()).isEqualTo(IssueChangeDto.TYPE_COMMENT);
- assertThat(issueChangeDto.get().getUserLogin()).isEqualTo("john");
- assertThat(issueChangeDto.get().getChangeData()).isEqualTo("some comment");
+ assertThat(issueChangeDto.get().getKey()).isEqualTo(issueChange.getKey());
+ assertThat(issueChangeDto.get().getChangeType()).isEqualTo(TYPE_COMMENT);
+ assertThat(issueChangeDto.get().getUserUuid()).isEqualTo(issueChange.getUserUuid());
+ assertThat(issueChangeDto.get().getChangeData()).isEqualTo(issueChange.getChangeData());
assertThat(issueChangeDto.get().getIssueChangeCreationDate()).isNotNull();
assertThat(issueChangeDto.get().getCreatedAt()).isNotNull();
assertThat(issueChangeDto.get().getUpdatedAt()).isNotNull();
@Test
public void delete() {
- db.prepareDbUnit(getClass(), "delete.xml");
+ IssueDto issue = db.issues().insertIssue();
+ IssueChangeDto issueChange1 = db.issues().insertChange(issue);
+ IssueChangeDto issueChange2 = db.issues().insertChange(issue);
- assertThat(underTest.delete(db.getSession(), "COMMENT-2")).isTrue();
- db.commit();
+ assertThat(underTest.delete(db.getSession(), issueChange1.getKey())).isTrue();
- db.assertDbUnit(getClass(), "delete-result.xml", "issue_changes");
+ assertThat(db.countRowsOfTable(db.getSession(), "issue_changes")).isEqualTo(1);
}
@Test
public void delete_unknown_key() {
- db.prepareDbUnit(getClass(), "delete.xml");
+ IssueDto issue = db.issues().insertIssue();
+ db.issues().insertChange(issue);
assertThat(underTest.delete(db.getSession(), "UNKNOWN")).isFalse();
}
@Test
public void insert() {
+ IssueDto issue = db.issues().insertIssue();
IssueChangeDto changeDto = new IssueChangeDto()
.setKey("EFGH")
- .setUserLogin("emmerik")
+ .setUserUuid("user_uuid")
.setChangeData("Some text")
.setChangeType("comment")
- .setIssueKey("ABCDE")
+ .setIssueKey(issue.getKey())
.setCreatedAt(1_500_000_000_000L)
.setUpdatedAt(1_501_000_000_000L)
.setIssueChangeCreationDate(1_502_000_000_000L);
underTest.insert(db.getSession(), changeDto);
db.getSession().commit();
- db.assertDbUnit(getClass(), "insert-result.xml", new String[] {"id"}, "issue_changes");
+ 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("EFGH", issue.getKey(), "Some text", TYPE_COMMENT, 1_502_000_000_000L, 1_500_000_000_000L, 1_501_000_000_000L));
}
@Test
public void update() {
- db.prepareDbUnit(getClass(), "update.xml");
-
- IssueChangeDto change = new IssueChangeDto();
- change.setKey("COMMENT-2");
-
- // Only the following fields can be updated:
- change.setChangeData("new comment");
- change.setUpdatedAt(1_500_000_000_000L);
-
- assertThat(underTest.update(db.getSession(), change)).isTrue();
+ IssueDto issue = db.issues().insertIssue();
+ IssueChangeDto issueChange = db.issues().insertChange(issue);
+
+ assertThat(underTest.update(db.getSession(), new IssueChangeDto()
+ .setKey(issueChange.getKey())
+ // Only the following fields can be updated:
+ .setChangeData("new comment")
+ .setUpdatedAt(1_500_000_000_000L)
+ // Should not be taking into account
+ .setIssueKey("other_issue_uuid")
+ .setUserUuid("other_user_uuid")
+ .setCreatedAt(10_000_000_000L)
+ .setIssueChangeCreationDate(30_000_000_000L))).isTrue();
db.commit();
- db.assertDbUnit(getClass(), "update-result.xml", "issue_changes");
+ 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(), "new comment", issueChange.getChangeType(), issueChange.getIssueChangeCreationDate(), issueChange.getCreatedAt(),
+ 1_500_000_000_000L));
}
@Test
public void update_unknown_key() {
- db.prepareDbUnit(getClass(), "update.xml");
-
- IssueChangeDto change = new IssueChangeDto();
- change.setKey("UNKNOWN");
- change.setChangeData("new comment");
- change.setUpdatedAt(DateUtils.parseDate("2013-06-30").getTime());
-
- assertThat(underTest.update(db.getSession(), change)).isFalse();
+ 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()));
}
}
@Test
public void create_from_comment() {
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
IssueChangeDto dto = IssueChangeDto.of(comment);
assertThat(dto.getUpdatedAt()).isNotNull();
assertThat(dto.getIssueChangeCreationDate()).isNotNull();
assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
- assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+ assertThat(dto.getUserUuid()).isEqualTo("user_uuid");
}
@Test
public void create_from_comment_with_created_at() {
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
comment.setCreatedAt(parseDate("2015-01-13"));
IssueChangeDto dto = IssueChangeDto.of(comment);
public void create_from_diff() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "INFO", "BLOCKER");
- diffs.setUserLogin("emmerik");
+ diffs.setUserUuid("user_uuid");
diffs.setCreationDate(parseDate("2015-01-13"));
IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
assertThat(dto.getCreatedAt()).isNotNull();
assertThat(dto.getUpdatedAt()).isNotNull();
assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
- assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+ assertThat(dto.getUserUuid()).isEqualTo("user_uuid");
assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
}
public void create_from_diff_with_created_at() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "INFO", "BLOCKER");
- diffs.setUserLogin("emmerik");
+ diffs.setUserUuid("user_uuid");
diffs.setCreationDate(parseDate("2015-01-13"));
IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
public void to_comment() {
IssueChangeDto changeDto = new IssueChangeDto()
.setKey("EFGH")
- .setUserLogin("emmerik")
+ .setUserUuid("user_uuid")
.setChangeData("Some text")
.setIssueKey("ABCDE")
.setCreatedAt(System2.INSTANCE.now())
assertThat(comment.markdownText()).isEqualTo("Some text");
assertThat(comment.createdAt()).isNotNull();
assertThat(comment.updatedAt()).isNotNull();
- assertThat(comment.userLogin()).isEqualTo("emmerik");
+ assertThat(comment.userUuid()).isEqualTo("user_uuid");
assertThat(comment.issueKey()).isEqualTo("ABCDE");
}
public void to_field_diffs_with_issue_creation_date() {
IssueChangeDto changeDto = new IssueChangeDto()
.setKey("EFGH")
- .setUserLogin("emmerik")
+ .setUserUuid("user_uuid")
.setChangeData("Some text")
.setIssueKey("ABCDE")
.setIssueChangeCreationDate(System2.INSTANCE.now());
FieldDiffs diffs = changeDto.toFieldDiffs();
- assertThat(diffs.userLogin()).isEqualTo("emmerik");
+ assertThat(diffs.userUuid()).isEqualTo("user_uuid");
assertThat(diffs.issueKey()).isEqualTo("ABCDE");
assertThat(diffs.creationDate()).isNotNull();
}
public void to_field_diffs_with_create_at() {
IssueChangeDto changeDto = new IssueChangeDto()
.setKey("EFGH")
- .setUserLogin("emmerik")
+ .setUserUuid("user_uuid")
.setChangeData("Some text")
.setIssueKey("ABCDE")
.setCreatedAt(System2.INSTANCE.now());
FieldDiffs diffs = changeDto.toFieldDiffs();
- assertThat(diffs.userLogin()).isEqualTo("emmerik");
+ assertThat(diffs.userUuid()).isEqualTo("user_uuid");
assertThat(diffs.issueKey()).isEqualTo("ABCDE");
assertThat(diffs.creationDate()).isNotNull();
}
public void getIssueChangeCreationDate_fallback_to_createAt_when_null() {
IssueChangeDto changeDto = new IssueChangeDto()
.setKey("EFGH")
- .setUserLogin("emmerik")
+ .setUserUuid("user_uuid")
.setChangeData("Some text")
.setIssueKey("ABCDE")
.setCreatedAt(10_000_000L)
@Test
public void to_string() {
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
IssueChangeDto dto = IssueChangeDto.of(comment);
assertThat(dto.toString()).contains("ABCDE");
}
public void insert_diff() {
IssueChangeDto dto = new IssueChangeDto();
dto.setKey(null /* no key on field changes */);
- dto.setUserLogin("emmerik");
+ dto.setUserUuid("user_uuid");
dto.setIssueKey("ABCDE");
dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE);
dto.setChangeData("severity=INFO|BLOCKER");
public void insert_comment() {
IssueChangeDto dto = new IssueChangeDto();
dto.setKey("COMMENT-1234");
- dto.setUserLogin("emmerik");
+ dto.setUserUuid("user_uuid");
dto.setIssueKey("ABCDE");
dto.setChangeType(IssueChangeDto.TYPE_COMMENT);
dto.setChangeData("the comment");
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.user.UserDto;
+import static java.util.Arrays.stream;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.issue.IssueTesting.newIssue;
this.db = db;
}
- public IssueDto insert(RuleDefinitionDto rule, ComponentDto project, ComponentDto file) {
+ @SafeVarargs
+ public final IssueDto insert(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, Consumer<IssueDto>... populators) {
IssueDto issue = newIssue(rule, project, file);
- return insertIssue(issue);
- }
-
- public IssueDto insert(RuleDefinitionDto rule, ComponentDto project, ComponentDto file, Consumer<IssueDto> populator) {
- IssueDto issue = newIssue(rule, project, file);
- populator.accept(issue);
+ stream(populators).forEach(p -> p.accept(issue));
return insertIssue(issue);
}
return issueDto;
}
- public IssueDto insertIssue() {
- return insertIssue(issueDto -> {
- });
- }
-
- public IssueDto insertIssue(Consumer<IssueDto> populateIssueDto) {
+ @SafeVarargs
+ public final IssueDto insertIssue(Consumer<IssueDto>... populateIssueDto) {
return insertIssue(db.getDefaultOrganization(), populateIssueDto);
}
- public IssueDto insertIssue(OrganizationDto organizationDto) {
- return insertIssue(organizationDto, issueDto -> {
- });
- }
-
- public IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto> populateIssueDto) {
+ @SafeVarargs
+ public final IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto>... populators) {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject(organizationDto);
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = newIssue(rule, project, file);
- populateIssueDto.accept(issue);
+ stream(populators).forEach(p -> p.accept(issue));
return insertIssue(issue);
}
+ @SafeVarargs
+ public final IssueChangeDto insertChange(IssueDto issueDto, Consumer<IssueChangeDto>... populators) {
+ IssueChangeDto dto = IssueTesting.newIssuechangeDto(issueDto);
+ stream(populators).forEach(p -> p.accept(dto));
+ return insertChange(dto);
+ }
+
public IssueChangeDto insertChange(IssueChangeDto issueChangeDto) {
db.getDbClient().issueChangeDao().insert(db.getSession(), issueChangeDto);
db.commit();
return issueChangeDto;
}
- public IssueChangeDto insertComment(IssueDto issueDto, @Nullable String login, String text) {
- IssueChangeDto issueChangeDto = IssueChangeDto.of(DefaultIssueComment.create(issueDto.getKey(), login, text));
+ public IssueChangeDto insertComment(IssueDto issueDto, @Nullable UserDto user, String text) {
+ IssueChangeDto issueChangeDto = IssueChangeDto.of(DefaultIssueComment.create(issueDto.getKey(), user == null ? null : user.getUuid(), text));
return insertChange(issueChangeDto);
}
+++ /dev/null
-<dataset>
-
- <issue_changes
- id="100"
- kee="COMMENT-1"
- issue_key="ISSUE-1"
- user_login="arthur"
- change_type="comment"
- change_data="old comment"
- created_at="1356994800000"
- updated_at="1356994800000"
- issue_change_creation_date="[null]"
- />
-
- <issue_changes
- id="101"
- kee="[null]"
- issue_key="1000"
- user_login="arthur"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1359759600000"
- updated_at="1359759600000"
- issue_change_creation_date="1359759600000"
- />
-
- <!--
- DELETED
-
- <issue_changes
- id="102"
- kee="COMMENT-2"
- issue_key="ISSUE-1"
- user_login="arthur"
- change_type="comment"
- change_data="recent comment"
- created_at="1367704800000"
- updated_at="1367704800000"
- issue_change_creation_date="1367704800000"
- />
- -->
-</dataset>
+++ /dev/null
-<dataset>
-
- <issue_changes
- id="100"
- kee="COMMENT-1"
- issue_key="ISSUE-1"
- user_login="arthur"
- change_type="comment"
- change_data="old comment"
- created_at="1356994800000"
- updated_at="1356994800000"
- issue_change_creation_date="[null]"
- />
-
- <issue_changes
- id="101"
- kee="[null]"
- issue_key="1000"
- user_login="arthur"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1359759600000"
- updated_at="1359759600000"
- issue_change_creation_date="1359759600000"
- />
-
- <issue_changes
- id="102"
- kee="COMMENT-2"
- issue_key="ISSUE-1"
- user_login="arthur"
- change_type="comment"
- change_data="recent comment"
- created_at="1367704800000"
- updated_at="1367704800000"
- issue_change_creation_date="1367704800000"
- />
-</dataset>
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <issue_changes
- id="1"
- kee="EFGH"
- issue_key="ABCDE"
- user_login="emmerik"
- change_type="comment"
- change_data="Some text"
- created_at="1500000000000"
- updated_at="1501000000000"
- issue_change_creation_date="1502000000000"
- />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- Unresolved. To be included -->
- <issues
- id="1"
- kee="UNRESOLVED_ON_FILE_1"
- component_uuid="FILE_1"
- project_uuid="PROJECT_1"
- resolution="[null]"
- status="OPEN"
- rule_id="500"
- severity="BLOCKER"
- manual_severity="[false]"
- message="[null]"
- line="200"
- gap="[null]"
- checksum="[null]"
- reporter="[null]"
- assignee="user"
- author_login="[null]"
- issue_attributes="[null]"
- issue_creation_date="1366063200000"
- issue_update_date="1366063200000"
- issue_close_date="1366063200000"
- created_at="1400000000000"
- updated_at="[null]"
- locations="[null]"
- />
-
- <!-- diff -->
- <issue_changes
- id="100"
- kee="100"
- issue_key="UNRESOLVED_ON_FILE_1"
- user_login="arthur"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1410213600000"
- updated_at="1410213600000"
- issue_change_creation_date="1410213600000"
- />
-
- <!-- comment -->
- <issue_changes
- id="102"
- kee="102"
- issue_key="UNRESOLVED_ON_FILE_1"
- user_login="arthur"
- change_type="comment"
- change_data="recent comment"
- created_at="1410213600000"
- updated_at="1410213600000"
- issue_change_creation_date="[null]"
- />
-
- <!-- Resolved but not closed. To be included -->
- <issues
- id="2"
- kee="RESOLVED_ON_FILE_1"
- component_uuid="FILE_1"
- project_uuid="PROJECT_1"
- resolution="FIXED"
- status="RESOLVED"
- rule_id="501"
- severity="MAJOR"
- manual_severity="[false]"
- message="[null]"
- line="120"
- gap="[null]"
- checksum="[null]"
- reporter="[null]"
- assignee="user"
- author_login="[null]"
- issue_attributes="[null]"
- issue_creation_date="1366063200000"
- issue_update_date="1366063200000"
- issue_close_date="1366063200000"
- created_at="1400000000000"
- updated_at="[null]"
- locations="[null]"
- />
-
- <issue_changes
- id="103"
- kee="103"
- issue_key="RESOLVED_ON_FILE_1"
- user_login="arthur"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1410213600000"
- updated_at="1410213600000"
- issue_change_creation_date="1410213600000"
- />
-
- <!-- Closed. To be excluded -->
- <issues
- id="3"
- kee="CLOSED_ON_FILE_1"
- component_uuid="FILE_1"
- project_uuid="PROJECT_1"
- resolution="FIXED"
- status="CLOSED"
- rule_id="501"
- severity="MAJOR"
- manual_severity="[false]"
- message="[null]"
- line="120"
- gap="[null]"
- checksum="[null]"
- reporter="[null]"
- assignee="user"
- author_login="[null]"
- issue_attributes="[null]"
- issue_creation_date="1366063200000"
- issue_update_date="1366063200000"
- issue_close_date="1366063200000"
- created_at="1400000000000"
- updated_at="[null]"
- locations="[null]"
- />
-
- <issue_changes
- id="104"
- kee="104"
- issue_key="CLOSED_ON_FILE_1"
- user_login="arthur"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1410213600000"
- updated_at="1410213600000"
- issue_change_creation_date="1410213600000"
- />
-
- <!-- Unresolved on other file -->
- <issues
- id="4"
- kee="UNRESOLVED_ON_FILE_2"
- component_uuid="FILE_2"
- project_uuid="PROJECT_1"
- resolution="[null]"
- status="OPEN"
- rule_id="500"
- severity="BLOCKER"
- manual_severity="[false]"
- message="[null]"
- line="200"
- gap="[null]"
- checksum="[null]"
- reporter="[null]"
- assignee="user"
- author_login="[null]"
- issue_attributes="[null]"
- issue_creation_date="1366063200000"
- issue_update_date="1366063200000"
- issue_close_date="1366063200000"
- created_at="1400000000000"
- updated_at="[null]"
- locations="[null]"
- />
-
- <!-- diff -->
- <issue_changes
- id="105"
- kee="105"
- issue_key="UNRESOLVED_ON_FILE_2"
- user_login="arthur"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1410213600000"
- updated_at="1410213600000"
- issue_change_creation_date="1410213600000"
- />
-
- <!-- comment -->
- <issue_changes
- id="106"
- kee="106"
- issue_key="UNRESOLVED_ON_FILE_2"
- user_login="arthur"
- change_type="comment"
- change_data="recent comment"
- created_at="1410213600000"
- updated_at="1410213600000"
- issue_change_creation_date="[null]"
- />
-</dataset>
+++ /dev/null
-<dataset>
-
- <issue_changes
- id="100"
- kee="ABCDE"
- issue_key="1000"
- user_login="arthur"
- change_type="comment"
- change_data="old comment"
- created_at="1356994800000"
- updated_at="1356994800000"
- issue_change_creation_date="[null]"
- />
-
- <issue_changes
- id="101"
- kee="[null]"
- issue_key="1000"
- user_login="arthur"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1359759600000"
- updated_at="1359759600000"
- issue_change_creation_date="1359759600000"
- />
-
- <issue_changes
- id="102"
- kee="FGHIJ"
- issue_key="1000"
- user_login="arthur"
- change_type="comment"
- change_data="recent comment"
- created_at="1367704800000"
- updated_at="1367704800000"
- issue_change_creation_date="[null]"
- />
-
- <issue_changes
- id="103"
- kee="KLMN"
- issue_key="1001"
- user_login="arthur"
- change_type="diff"
- change_data="actionPlan=1.0|1.1"
- created_at="1359759600000"
- updated_at="1359759600000"
- issue_change_creation_date="1359759600000"
- />
-
- <issue_changes
- id="104"
- kee="OPQR"
- issue_key="1001"
- user_login="henry"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1356994800000"
- updated_at="1356994800000"
- issue_change_creation_date="1356994800000"
- />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <issue_changes
- id="100"
- kee="COMMENT-1"
- issue_key="ISSUE-1"
- user_login="arthur"
- change_type="comment"
- change_data="old comment"
- created_at="1356994800000"
- updated_at="1356994800000"
- issue_change_creation_date="[null]"
- />
-
- <issue_changes
- id="101"
- kee="[null]"
- issue_key="1000"
- user_login="arthur"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1359759600000"
- updated_at="1359759600000"
- issue_change_creation_date="1359759600000"
- />
-
- <issue_changes
- id="102"
- kee="COMMENT-2"
- issue_key="ISSUE-1"
- user_login="arthur"
- change_type="comment"
- change_data="new comment"
- created_at="1367704800000"
- updated_at="1500000000000"
- issue_change_creation_date="[null]"
- />
-</dataset>
+++ /dev/null
-<dataset>
-
- <issue_changes
- id="100"
- kee="COMMENT-1"
- issue_key="ISSUE-1"
- user_login="arthur"
- change_type="comment"
- change_data="old comment"
- created_at="1356994800000"
- updated_at="1356994800000"
- issue_change_creation_date="[null]"
- />
-
- <issue_changes
- id="101"
- kee="[null]"
- issue_key="1000"
- user_login="arthur"
- change_type="diff"
- change_data="severity=MAJOR|BLOCKER"
- created_at="1359759600000"
- updated_at="1359759600000"
- issue_change_creation_date="1359759600000"
- />
-
- <issue_changes
- id="102"
- kee="COMMENT-2"
- issue_key="ISSUE-1"
- user_login="arthur"
- change_type="comment"
- change_data="old value"
- created_at="1367704800000"
- updated_at="1367704800000"
- issue_change_creation_date="[null]"
- />
-</dataset>
id="1"
kee="COMMENT-1234"
issue_key="ABCDE"
- user_login="emmerik"
+ user_login="user_uuid"
change_type="comment"
change_data="the comment"
created_at="1500000000000"
id="1"
kee="[null]"
issue_key="ABCDE"
- user_login="emmerik"
+ user_login="user_uuid"
change_type="diff"
change_data="severity=INFO|BLOCKER"
created_at="1500000000000"
issue_key="ABCDE"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="this is a comment"/>
issue_key="ABCDF"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"/>
issue_key="ISSUE-3"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-4"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-1"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-2"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-3"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-4"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-5"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-3"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-4"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-5"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-1"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-2"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-3"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-4"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
issue_key="ISSUE-5"
created_at="[null]"
updated_at="[null]"
- user_login="admin"
+ user_login="admin_uuid"
change_type="comment"
change_data="abc"
issue_change_creation_date="[null]"/>
import java.util.Date;
import java.util.Optional;
import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.IssueComment;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.DefaultIssueComment;
import org.sonar.core.issue.FieldDiffs;
}
private static void copyChanges(DefaultIssue raw, DefaultIssue base) {
- base.comments().forEach(c -> raw.addComment(copy(raw.key(), c)));
+ base.defaultIssueComments().forEach(c -> raw.addComment(copy(raw.key(), c)));
base.changes().forEach(c -> copy(raw.key(), c).ifPresent(raw::addChange));
}
/**
* Copy a comment from another issue
*/
- private static DefaultIssueComment copy(String issueKey, IssueComment c) {
+ private static DefaultIssueComment copy(String issueKey, DefaultIssueComment c) {
DefaultIssueComment comment = new DefaultIssueComment();
comment.setIssueKey(issueKey);
comment.setKey(Uuids.create());
- comment.setUserLogin(c.userLogin());
+ comment.setUserUuid(c.userUuid());
comment.setMarkdownText(c.markdownText());
comment.setCreatedAt(c.createdAt()).setUpdatedAt(c.updatedAt());
comment.setNew(true);
private static Optional<FieldDiffs> copy(String issueKey, FieldDiffs c) {
FieldDiffs result = new FieldDiffs();
result.setIssueKey(issueKey);
- result.setUserLogin(c.userLogin());
+ result.setUserUuid(c.userUuid());
result.setCreationDate(c.creationDate());
// Don't copy "file" changelogs as they refer to file uuids that might later be purged
c.diffs().entrySet().stream().filter(e -> !e.getKey().equals(IssueFieldsSetter.FILE))
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nullable;
-
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.ServerSide;
}
return false;
}
+
public boolean assign(DefaultIssue issue, @Nullable UserDto user, IssueChangeContext context) {
String assigneeUuid = user != null ? user.getUuid() : null;
if (!Objects.equals(assigneeUuid, issue.assignee())) {
- issue.setFieldChange(context, ASSIGNEE, UNUSED, user != null ? user.getUuid() : null);
+ String newAssigneeName = user == null ? null : user.getName();
+ issue.setFieldChange(context, ASSIGNEE, UNUSED, newAssigneeName);
issue.setAssigneeUuid(user != null ? user.getUuid() : null);
issue.setUpdateDate(context.date());
issue.setChanged(true);
}
public void addComment(DefaultIssue issue, String text, IssueChangeContext context) {
- issue.addComment(DefaultIssueComment.create(issue.key(), context.login(), text));
+ issue.addComment(DefaultIssueComment.create(issue.key(), context.userUuid(), text));
issue.setUpdateDate(context.date());
issue.setChanged(true);
}
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.IssueComment;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.utils.System2;
protected abstract IssueDto doUpdate(DbSession batchSession, long now, DefaultIssue issue);
public static void insertChanges(IssueChangeMapper mapper, DefaultIssue issue) {
- for (IssueComment comment : issue.comments()) {
- DefaultIssueComment c = (DefaultIssueComment) comment;
- if (c.isNew()) {
- IssueChangeDto changeDto = IssueChangeDto.of(c);
+ for (DefaultIssueComment comment : issue.defaultIssueComments()) {
+ if (comment.isNew()) {
+ IssueChangeDto changeDto = IssueChangeDto.of(comment);
mapper.insert(changeDto);
}
}
import org.sonar.server.issue.ws.SearchResponseData;
import org.sonar.server.notification.NotificationManager;
+import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
Optional<RuleDefinitionDto> rule = getRuleByKey(dbSession, issue.getRuleKey());
ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.projectUuid());
- ComponentDto component = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.componentUuid());
+ ComponentDto component = getComponent(dbSession, issue, issue.componentUuid());
IssueDto issueDto = doSaveIssue(dbSession, issue, context, comment, rule, project, component);
SearchResponseData result = new SearchResponseData(issueDto);
public IssueDto saveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) {
Optional<RuleDefinitionDto> rule = getRuleByKey(session, issue.getRuleKey());
- ComponentDto project = dbClient.componentDao().selectOrFailByUuid(session, issue.projectUuid());
- ComponentDto component = dbClient.componentDao().selectOrFailByUuid(session, issue.componentUuid());
+ ComponentDto project = getComponent(session, issue, issue.projectUuid());
+ ComponentDto component = getComponent(session, issue, issue.componentUuid());
return doSaveIssue(session, issue, context, comment, rule, project, component);
}
IssueDto issueDto = issueStorage.save(session, issue);
String assigneeUuid = issue.assignee();
UserDto assignee = assigneeUuid == null ? null : dbClient.userDao().selectByUuid(session, assigneeUuid);
+ String authorUuid = context.userUuid();
+ UserDto author = authorUuid == null ? null : dbClient.userDao().selectByUuid(session, authorUuid);
notificationService.scheduleForSending(new IssueChangeNotification()
.setIssue(issue)
.setAssignee(assignee)
- .setChangeAuthorLogin(context.login())
+ .setChangeAuthor(author)
.setRuleName(rule.map(RuleDefinitionDto::getName).orElse(null))
.setProject(project)
.setComponent(component)
return issueDto;
}
+ private ComponentDto getComponent(DbSession dbSession, DefaultIssue issue, @Nullable String componentUuid) {
+ String issueKey = issue.key();
+ checkState(componentUuid != null, "Issue '%s' has no component", issueKey);
+ ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orNull();
+ checkState(component != null, "Component uuid '%s' for issue key '%s' cannot be found", componentUuid, issueKey);
+ return component;
+ }
+
private Optional<RuleDefinitionDto> getRuleByKey(DbSession session, RuleKey ruleKey) {
Optional<RuleDefinitionDto> rule = dbClient.ruleDao().selectDefinitionByKey(session, ruleKey);
return (rule.isPresent() && rule.get().getStatus() != RuleStatus.REMOVED) ? rule : Optional.empty();
return this;
}
- public IssueChangeNotification setChangeAuthorLogin(@Nullable String s) {
- if (s != null) {
- setFieldValue("changeAuthor", s);
+ public IssueChangeNotification setChangeAuthor(@Nullable UserDto author) {
+ if (author == null) {
+ return this;
}
+ setFieldValue("changeAuthor", author.getLogin());
return this;
}
AddCommentRequest wsRequest = toWsRequest(request);
try (DbSession dbSession = dbClient.openSession(false)) {
IssueDto issueDto = issueFinder.getByKey(dbSession, wsRequest.getIssue());
- IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
DefaultIssue defaultIssue = issueDto.toDefaultIssue();
issueFieldsSetter.addComment(defaultIssue, wsRequest.getText(), context);
SearchResponseData preloadedSearchResponseData = issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, defaultIssue, context, wsRequest.getText(), false);
if (user != null) {
checkMembership(dbSession, issueDto, user);
}
- IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
if (issueFieldsSetter.assign(issue, user, context)) {
return issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, issue, context, null, false);
}
import org.sonarqube.ws.Issues;
import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableMap.of;
import static java.lang.String.format;
+import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;
private BulkChangeResult executeBulkChange(DbSession dbSession, Request request) {
BulkChangeData bulkChangeData = new BulkChangeData(dbSession, request);
BulkChangeResult result = new BulkChangeResult(bulkChangeData.issues.size());
- IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+ IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
List<DefaultIssue> items = bulkChangeData.issues.stream()
.filter(bulkChange(issueChangeContext, bulkChangeData, result))
Set<String> assigneeUuids = items.stream().map(DefaultIssue::assignee).filter(Objects::nonNull).collect(toSet());
Map<String, UserDto> userDtoByUuid = dbClient.userDao().selectByUuids(dbSession, assigneeUuids).stream().collect(toMap(UserDto::getUuid, u -> u));
-
- items.forEach(sendNotification(issueChangeContext, bulkChangeData, userDtoByUuid));
+ String authorUuid = requireNonNull(userSession.getUuid(), "User uuid cannot be null");
+ UserDto author = dbClient.userDao().selectByUuid(dbSession, authorUuid);
+ checkState(author != null, "User with uuid '%s' does not exist");
+ items.forEach(sendNotification(bulkChangeData, userDtoByUuid, author));
return result;
}
bulkChangeData.getCommentAction().ifPresent(action -> action.execute(bulkChangeData.getProperties(action.key()), actionContext));
}
- private Consumer<DefaultIssue> sendNotification(IssueChangeContext issueChangeContext, BulkChangeData bulkChangeData,
- Map<String, UserDto> userDtoByUuid) {
+ private Consumer<DefaultIssue> sendNotification(BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, UserDto author) {
return issue -> {
if (bulkChangeData.sendNotification) {
notificationService.scheduleForSending(new IssueChangeNotification()
.setIssue(issue)
.setAssignee(userDtoByUuid.get(issue.assignee()))
- .setChangeAuthorLogin(issueChangeContext.login())
+ .setChangeAuthor(author)
.setRuleName(bulkChangeData.rulesByKey.get(issue.ruleKey()).getName())
.setProject(bulkChangeData.projectsByUuid.get(issue.projectUuid()))
.setComponent(bulkChangeData.componentsByUuid.get(issue.componentUuid())));
private Function<FieldDiffs, Changelog> toWsChangelog(ChangeLogResults results) {
return change -> {
- String userLogin = change.userLogin();
+ String userUUuid = change.userUuid();
Changelog.Builder changelogBuilder = Changelog.newBuilder();
changelogBuilder.setCreationDate(formatDateTime(change.creationDate()));
- UserDto user = userLogin == null ? null : results.users.get(userLogin);
+ UserDto user = userUUuid == null ? null : results.users.get(userUUuid);
if (user != null) {
changelogBuilder.setUser(user.getLogin());
changelogBuilder.setUserName(user.getName());
ChangeLogResults(DbSession dbSession, String issueKey) {
IssueDto dbIssue = issueFinder.getByKey(dbSession, issueKey);
this.changes = dbClient.issueChangeDao().selectChangelogByIssue(dbSession, dbIssue.getKey());
- List<String> logins = changes.stream().filter(change -> change.userLogin() != null).map(FieldDiffs::userLogin).collect(MoreCollectors.toList());
- this.users = dbClient.userDao().selectByLogins(dbSession, logins).stream().collect(MoreCollectors.uniqueIndex(UserDto::getLogin));
+ 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()));
}
.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.getUserLogin(), userSession.getLogin()), "You can only delete your own comments");
+ checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only delete your own comments");
}
IssueChangeDto getIssueChangeDto() {
import org.sonar.server.issue.IssueUpdater;
import org.sonar.server.issue.TransitionService;
import org.sonar.server.user.UserSession;
+
import static org.sonar.server.ws.WsUtils.checkRequest;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_DO_TRANSITION;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUE;
private SearchResponseData doTransition(DbSession session, IssueDto issueDto, String transitionKey) {
DefaultIssue defaultIssue = issueDto.toDefaultIssue();
- IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
transitionService.checkTransitionPermission(transitionKey, defaultIssue);
if (transitionService.doTransition(defaultIssue, context, transitionKey)) {
return issueUpdater.saveIssueAndPreloadSearchResponseData(session, defaultIssue, context, null, true);
.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.getUserLogin(), userSession.getLogin()), "You can only edit your own comments");
+ checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only edit your own comments");
}
IssueChangeDto getIssueChangeDto() {
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Sets.newHashSet;
import static java.lang.String.format;
.filter(FACETS_REQUIRING_PROJECT_OR_ORGANIZATION::contains)
.collect(toSet());
checkArgument(facetsRequiringProjectOrOrganizationParameter.isEmpty() ||
- (!query.projectUuids().isEmpty()) || query.organizationUuid() != null, "Facet(s) '%s' require to also filter by project or organization",
+ (!query.projectUuids().isEmpty()) || query.organizationUuid() != null, "Facet(s) '%s' require to also filter by project or organization",
COMA_JOINER.join(facetsRequiringProjectOrOrganizationParameter));
}
SearchResponseData preloadedData = new SearchResponseData(emptyList());
}
LinkedHashMap<String, Long> newAssigneeFacets = new LinkedHashMap<>();
- assigneeFacets.forEach((k, v) -> newAssigneeFacets.put(nullToEmpty(data.getLoginByUserUuid(k)), v));
+ assigneeFacets
+ .forEach((userUuid, v) -> {
+ UserDto user = data.getUserByUuid(userUuid);
+ newAssigneeFacets.put(user == null ? "" : user.getLogin(), v);
+ });
assigneeFacets.clear();
assigneeFacets.putAll(newAssigneeFacets);
}
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ListMultimap;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDto;
}
@CheckForNull
- public String getLoginByUserUuid(@Nullable String userUuid) {
+ public UserDto getUserByUuid(@Nullable String userUuid) {
UserDto userDto = usersByUuid.get(userUuid);
- if (userDto != null) {
- return userDto.getLogin();
+ if (userDto == null) {
+ return null;
}
- return null;
+ return userDto;
}
}
issueBuilder.setExternalRuleEngine(engineNameFrom(dto.getRuleKey()));
}
issueBuilder.setSeverity(Common.Severity.valueOf(dto.getSeverity()));
- setNullable(data.getLoginByUserUuid(dto.getAssigneeUuid()), issueBuilder::setAssignee);
+ setNullable(data.getUserByUuid(dto.getAssigneeUuid()), assignee -> issueBuilder.setAssignee(assignee.getLogin()));
setNullable(emptyToNull(dto.getResolution()), issueBuilder::setResolution);
issueBuilder.setStatus(dto.getStatus());
issueBuilder.setMessage(nullToEmpty(dto.getMessage()));
wsComment
.clear()
.setKey(comment.getKey())
- .setLogin(nullToEmpty(data.getLoginByUserUuid(comment.getUserLogin())))
.setUpdatable(data.isUpdatableComment(comment.getKey()))
.setCreatedAt(DateUtils.formatDateTime(new Date(comment.getIssueChangeCreationDate())));
+ setNullable(data.getUserByUuid(comment.getUserUuid()), user -> wsComment.setLogin(user.getLogin()));
if (markdown != null) {
wsComment
.setHtmlText(Markdown.convertToHtml(markdown))
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.difference;
import static java.util.Collections.emptyList;
+import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;
import static java.util.stream.Stream.concat;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
List<IssueChangeDto> comments = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbSession, collector.getIssueKeys(), IssueChangeDto.TYPE_COMMENT);
result.setComments(comments);
for (IssueChangeDto comment : comments) {
- // TODO GJT when addressing ticket on IssueChangesUuid
- collector.add(USERS, comment.getUserLogin());
+ collector.add(USERS, comment.getUserUuid());
if (canEditOrDelete(comment)) {
result.addUpdatableComment(comment.getKey());
}
}
private boolean canEditOrDelete(IssueChangeDto dto) {
- return userSession.isLoggedIn() && userSession.getLogin().equals(dto.getUserLogin());
+ return userSession.isLoggedIn() && requireNonNull(userSession.getUuid(), "User uuid should not be null").equals(dto.getUserUuid());
}
private void loadOrganizations(DbSession dbSession, SearchResponseData result) {
DefaultIssue issue = issueDto.toDefaultIssue();
userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
- IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid());
if (issueFieldsSetter.setManualSeverity(issue, severity, context)) {
return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, true);
}
try (DbSession session = dbClient.openSession(false)) {
IssueDto issueDto = issueFinder.getByKey(session, issueKey);
DefaultIssue issue = issueDto.toDefaultIssue();
- IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid());
if (issueFieldsSetter.setTags(issue, tags, context)) {
return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, false);
}
DefaultIssue issue = issueDto.toDefaultIssue();
userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
- IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getLogin());
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), userSession.getUuid());
if (issueFieldsSetter.setType(issue, ruleType, context)) {
return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null, true);
}
import java.util.Date;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.issue.IssueComment;
import org.sonar.api.utils.Duration;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.DefaultIssueComment;
public class IssueLifecycleTest {
- static final Date DEFAULT_DATE = new Date();
+ private static final Date DEFAULT_DATE = new Date();
- static final Duration DEFAULT_DURATION = Duration.create(10);
+ private static final Duration DEFAULT_DURATION = Duration.create(10);
- IssueChangeContext issueChangeContext = IssueChangeContext.createUser(DEFAULT_DATE, "julien");
+ @Rule
+ public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
- IssueWorkflow workflow = mock(IssueWorkflow.class);
+ private IssueChangeContext issueChangeContext = IssueChangeContext.createUser(DEFAULT_DATE, "default_user_uuid");
- IssueFieldsSetter updater = mock(IssueFieldsSetter.class);
+ private IssueWorkflow workflow = mock(IssueWorkflow.class);
- DebtCalculator debtCalculator = mock(DebtCalculator.class);
+ private IssueFieldsSetter updater = mock(IssueFieldsSetter.class);
+
+ private DebtCalculator debtCalculator = mock(DebtCalculator.class);
- @Rule
- public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
- IssueLifecycle underTest = new IssueLifecycle(analysisMetadataHolder, issueChangeContext, workflow, updater, debtCalculator);
+ private IssueLifecycle underTest = new IssueLifecycle(analysisMetadataHolder, issueChangeContext, workflow, updater, debtCalculator);
@Test
public void initNewOpenIssue() {
fromShort.addComment(new DefaultIssueComment()
.setIssueKey("short")
.setCreatedAt(commentDate)
- .setUserLogin("user")
+ .setUserUuid("user_uuid")
.setMarkdownText("A comment"));
Date diffDate = new Date();
fromShort.addChange(new FieldDiffs()
.setCreationDate(diffDate)
.setIssueKey("short")
- .setUserLogin("user")
+ .setUserUuid("user_uuid")
.setDiff("file", "uuidA1", "uuidB1"));
// file diff with another field
fromShort.addChange(new FieldDiffs()
.setCreationDate(diffDate)
.setIssueKey("short")
- .setUserLogin("user")
+ .setUserUuid("user_uuid")
.setDiff("severity", "MINOR", "MAJOR")
.setDiff("file", "uuidA2", "uuidB2"));
assertThat(raw.resolution()).isEqualTo("resolution");
assertThat(raw.status()).isEqualTo("status");
- assertThat(raw.comments()).extracting(IssueComment::issueKey, IssueComment::createdAt, IssueComment::userLogin, IssueComment::markdownText)
- .containsOnly(tuple("raw", commentDate, "user", "A comment"));
+ assertThat(raw.defaultIssueComments()).extracting(DefaultIssueComment::issueKey, DefaultIssueComment::createdAt, DefaultIssueComment::userUuid, DefaultIssueComment::markdownText)
+ .containsOnly(tuple("raw", commentDate, "user_uuid", "A comment"));
assertThat(raw.changes()).hasSize(2);
assertThat(raw.changes().get(0).creationDate()).isEqualTo(diffDate);
- assertThat(raw.changes().get(0).userLogin()).isEqualTo("user");
+ assertThat(raw.changes().get(0).userUuid()).isEqualTo("user_uuid");
assertThat(raw.changes().get(0).issueKey()).isEqualTo("raw");
assertThat(raw.changes().get(0).diffs()).containsOnlyKeys("severity");
- assertThat(raw.changes().get(1).userLogin()).isEqualTo("julien");
+ assertThat(raw.changes().get(1).userUuid()).isEqualTo("default_user_uuid");
assertThat(raw.changes().get(1).diffs()).containsOnlyKeys(IssueFieldsSetter.FROM_SHORT_BRANCH);
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_SHORT_BRANCH).oldValue()).isEqualTo("feature/foo");
assertThat(raw.changes().get(1).get(IssueFieldsSetter.FROM_SHORT_BRANCH).newValue()).isEqualTo("master");
.setResolution(RESOLUTION_FIXED)
.setStatus(STATUS_CLOSED)
.setSeverity(BLOCKER)
- .setAssigneeUuid("base assignee")
+ .setAssigneeUuid("base assignee uuid")
.setAuthorLogin("base author")
.setTags(newArrayList("base tag"))
.setOnDisabledRule(true)
assertThat(raw.closeDate()).isEqualTo(base.closeDate());
assertThat(raw.resolution()).isEqualTo(RESOLUTION_FIXED);
assertThat(raw.status()).isEqualTo(STATUS_CLOSED);
- assertThat(raw.assignee()).isEqualTo("base assignee");
+ assertThat(raw.assignee()).isEqualTo("base assignee uuid");
assertThat(raw.authorLogin()).isEqualTo("base author");
assertThat(raw.tags()).containsOnly("base tag");
assertThat(raw.debt()).isEqualTo(DEFAULT_DURATION);
.setResolution(RESOLUTION_FIXED)
.setStatus(STATUS_CLOSED)
.setSeverity(BLOCKER)
- .setAssigneeUuid("base assignee")
+ .setAssigneeUuid("base assignee uuid")
.setAuthorLogin("base author")
.setTags(newArrayList("base tag"))
.setOnDisabledRule(true)
assertThat(raw.closeDate()).isEqualTo(base.closeDate());
assertThat(raw.resolution()).isEqualTo(RESOLUTION_FIXED);
assertThat(raw.status()).isEqualTo(STATUS_CLOSED);
- assertThat(raw.assignee()).isEqualTo("base assignee");
+ assertThat(raw.assignee()).isEqualTo("base assignee uuid");
assertThat(raw.authorLogin()).isEqualTo("base author");
assertThat(raw.tags()).containsOnly("base tag");
assertThat(raw.debt()).isEqualTo(DEFAULT_DURATION);
ArgumentCaptor<IssueChangeContext> issueChangeContextCaptor = ArgumentCaptor.forClass(IssueChangeContext.class);
verify(issue).setFieldChange(issueChangeContextCaptor.capture(), eq("file"), eq(originalFile.getUuid()), eq(FILE.getUuid()));
assertThat(issueChangeContextCaptor.getValue().date()).isEqualTo(new Date(ANALYSIS_DATE));
- assertThat(issueChangeContextCaptor.getValue().login()).isNull();
+ assertThat(issueChangeContextCaptor.getValue().userUuid()).isNull();
assertThat(issueChangeContextCaptor.getValue().scan()).isFalse();
}
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.IssueTesting;
import org.sonar.db.rule.RuleDefinitionDto;
+import org.sonar.db.user.UserDto;
import org.sonar.server.computation.task.projectanalysis.component.ShortBranchComponentsWithIssues;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
@Test
public void lazy_load_changes() {
+ UserDto user1 = db.users().insertUser();
IssueDto issue1 = db.issues()
.insertIssue(IssueTesting.newIssue(rule, branch1Dto, fileOnBranch1Dto).setKee("issue1").setStatus(Issue.STATUS_REOPENED).setLine(1).setChecksum("checksum"));
- db.issues().insertComment(issue1, "user1", "A comment 1");
+ db.issues().insertComment(issue1, user1, "A comment 1");
db.issues().insertFieldDiffs(issue1, FieldDiffs.parse("severity=BLOCKER|INFO,assignee=toto|titi").setCreationDate(new Date()));
+ UserDto user2 = db.users().insertUser();
IssueDto issue2 = db.issues()
.insertIssue(IssueTesting.newIssue(rule, branch2Dto, fileOnBranch2Dto).setKee("issue2").setStatus(Issue.STATUS_CONFIRMED).setLine(1).setChecksum("checksum"));
- db.issues().insertComment(issue2, "user2", "A comment 2");
+ db.issues().insertComment(issue2, user2, "A comment 2");
db.issues().insertFieldDiffs(issue2, FieldDiffs.parse("severity=BLOCKER|MINOR,assignee=foo|bar").setCreationDate(new Date()));
DefaultIssue newIssue = createIssue("newIssue", rule.getKey(), Issue.STATUS_OPEN, null, new Date());
verify(issueLifecycle).mergeConfirmedOrResolvedFromShortLivingBranch(eq(newIssue), issueToMerge.capture(), eq("myBranch2"));
assertThat(issueToMerge.getValue().key()).isEqualTo("issue2");
- assertThat(issueToMerge.getValue().comments()).isNotEmpty();
+ assertThat(issueToMerge.getValue().defaultIssueComments()).isNotEmpty();
assertThat(issueToMerge.getValue().changes()).isNotEmpty();
}
.addComment(new DefaultIssueComment()
.setKey("COMMENT")
.setIssueKey("ISSUE")
- .setUserLogin("john")
+ .setUserUuid("john_uuid")
.setMarkdownText("Some text")
.setCreatedAt(new Date(NOW))
.setNew(true))
.setCurrentChange(
new FieldDiffs()
.setIssueKey("ISSUE")
- .setUserLogin("john")
+ .setUserUuid("john_uuid")
.setDiff("technicalDebt", null, 1L)
.setCreationDate(new Date(NOW))))
.close();
.addComment(new DefaultIssueComment()
.setKey("COMMENT")
.setIssueKey("ISSUE")
- .setUserLogin("john")
+ .setUserUuid("john_uuid")
.setMarkdownText("Some text")
.setCreatedAt(new Date(NOW))
.setNew(true))
.setCurrentChange(new FieldDiffs()
.setIssueKey("ISSUE")
- .setUserLogin("john")
+ .setUserUuid("john_uuid")
.setDiff("technicalDebt", null, 1L)
.setCreationDate(new Date(NOW))))
.close();
.addComment(new DefaultIssueComment()
.setKey("COMMENT")
.setIssueKey(issue.getKey())
- .setUserLogin("john")
+ .setUserUuid("john_uuid")
.setMarkdownText("Some text")
.setCreatedAt(new Date(NOW))
.setNew(true)))
IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0);
assertThat(issueChangeDto)
- .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserLogin, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
+ .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserUuid, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
IssueChangeDto::getIssueChangeCreationDate)
- .containsOnly(IssueChangeDto.TYPE_COMMENT, "john", "Some text", issue.getKey(), NOW);
+ .containsOnly(IssueChangeDto.TYPE_COMMENT, "john_uuid", "Some text", issue.getKey(), NOW);
}
@Test
.setChanged(true)
.setCurrentChange(new FieldDiffs()
.setIssueKey("ISSUE")
- .setUserLogin("john")
+ .setUserUuid("john_uuid")
.setDiff("technicalDebt", null, 1L)
.setCreationDate(new Date(NOW))))
.close();
IssueChangeDto issueChangeDto = db.getDbClient().issueChangeDao().selectByIssueKeys(db.getSession(), singletonList(issue.getKey())).get(0);
assertThat(issueChangeDto)
- .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserLogin, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
+ .extracting(IssueChangeDto::getChangeType, IssueChangeDto::getUserUuid, IssueChangeDto::getChangeData, IssueChangeDto::getIssueKey,
IssueChangeDto::getIssueChangeCreationDate)
- .containsOnly(IssueChangeDto.TYPE_FIELD_CHANGE, "john", "technicalDebt=1", issue.getKey(), NOW);
+ .containsOnly(IssueChangeDto.TYPE_FIELD_CHANGE, "john_uuid", "technicalDebt=1", issue.getKey(), NOW);
}
}
@Rule
public DbTester db = DbTester.create();
- private IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(), "emmerik");
+ private IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(), "user_uuid");
private DefaultIssue issue = new DefaultIssue().setKey("ABC").setAssigneeUuid(ISSUE_CURRENT_ASSIGNEE_UUID);
private ComponentDto project;
private Action.Context context;
public ExpectedException thrown = none();
private DefaultIssue issue = new DefaultIssue();
- private IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik");
+ private IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
private IssueFieldsSetter underTest = new IssueFieldsSetter();
@Test
assertThat(issue.mustSendNotifications()).isTrue();
FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE);
assertThat(diff.oldValue()).isEqualTo(UNUSED);
- assertThat(diff.newValue()).isEqualTo(user.getUuid());
+ assertThat(diff.newValue()).isEqualTo(user.getName());
}
@Test
public void unassign() {
- issue.setAssigneeUuid("morgan");
+ issue.setAssigneeUuid("user_uuid");
boolean updated = underTest.assign(issue, null, context);
assertThat(updated).isTrue();
assertThat(issue.assignee()).isNull();
public void change_assignee() {
UserDto user = newUserDto().setLogin("emmerik").setName("Emmerik");
- issue.setAssigneeUuid("morgan");
+ issue.setAssigneeUuid("user_uuid");
boolean updated = underTest.assign(issue, user, context);
assertThat(updated).isTrue();
assertThat(issue.assignee()).isEqualTo(user.getUuid());
assertThat(issue.mustSendNotifications()).isTrue();
FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE);
assertThat(diff.oldValue()).isEqualTo(UNUSED);
- assertThat(diff.newValue()).isEqualTo(user.getUuid());
+ assertThat(diff.newValue()).isEqualTo(user.getName());
}
@Test
@Test
public void set_new_assignee() {
- boolean updated = underTest.setNewAssignee(issue, "simon", context);
+ boolean updated = underTest.setNewAssignee(issue, "user_uuid", context);
assertThat(updated).isTrue();
- assertThat(issue.assignee()).isEqualTo("simon");
+ assertThat(issue.assignee()).isEqualTo("user_uuid");
assertThat(issue.mustSendNotifications()).isTrue();
FieldDiffs.Diff diff = issue.currentChange().get(ASSIGNEE);
assertThat(diff.oldValue()).isEqualTo(UNUSED);
- assertThat(diff.newValue()).isEqualTo("simon");
+ assertThat(diff.newValue()).isEqualTo("user_uuid");
}
@Test
@Test
public void fail_with_ISE_when_setting_new_assignee_on_already_assigned_issue() {
- issue.setAssigneeUuid("simon");
+ issue.setAssigneeUuid("user_uuid");
thrown.expect(IllegalStateException.class);
thrown.expectMessage("It's not possible to update the assignee with this method, please use assign()");
- underTest.setNewAssignee(issue, "julien", context);
+ underTest.setNewAssignee(issue, "another_user_uuid", context);
}
@Test
private static final System2 system2 = System2.INSTANCE;
@org.junit.Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE);
- private IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), "emmerik");
+ private IssueChangeContext context = IssueChangeContext.createUser(new Date(system2.now()), "user_uuid");
- private DbClient dbClient = dbTester.getDbClient();
+ private DbClient dbClient = db.getDbClient();
@Test
public void batch_insert_new_issues() {
FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
// override generated key
comment.setKey("FGHIJ");
saver.save(issue);
- dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
+ db.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
}
public void batch_insert_new_issues_with_session() {
FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
// override generated key
comment.setKey("FGHIJ");
.setProjectUuid("uuid-10")
.setComponentKey("struts:Action");
- saver.save(dbTester.getSession(), issue);
- dbTester.getSession().commit();
+ saver.save(db.getSession(), issue);
+ db.getSession().commit();
- dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
+ db.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
}
ComponentDto component = new ComponentDto().setId(100L).setUuid("uuid-100");
FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project);
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
// override generated key
comment.setKey("FGHIJ");
.setComponentUuid("component-uuid")
.setProjectUuid("project-uuid");
- saver.save(dbTester.getSession(), issue);
- dbTester.getSession().commit();
+ saver.save(db.getSession(), issue);
+ db.getSession().commit();
- dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml",
- new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
+ db.assertDbUnit(getClass(), "should_insert_new_issues-result.xml", new String[] {"id", "created_at", "updated_at",
+ "issue_change_creation_date"}, "issues", "issue_changes");
}
@Test
public void batch_update_issues() {
- dbTester.prepareDbUnit(getClass(), "should_update_issues.xml");
+ db.prepareDbUnit(getClass(), "should_update_issues.xml");
FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder());
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
// override generated key
comment.setKey("FGHIJ");
saver.save(issue);
- dbTester.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
+ db.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
}
@Test
public void server_update_issues() {
- dbTester.prepareDbUnit(getClass(), "should_update_issues.xml");
+ db.prepareDbUnit(getClass(), "should_update_issues.xml");
ComponentDto project = new ComponentDto().setId(10L).setUuid("whatever-uuid");
ComponentDto component = new ComponentDto().setId(100L).setUuid("whatever-uuid-2");
FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project);
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
// override generated key
comment.setKey("FGHIJ");
saver.save(issue);
- dbTester.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
+ db.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes");
}
static class FakeBatchSaver extends IssueStorage {
import org.sonar.core.issue.IssueChangeContext;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.issue.IssueDbTester;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.IssueTesting;
-import org.sonar.db.rule.RuleDbTester;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.user.UserDto;
import static org.sonar.api.rule.Severity.BLOCKER;
import static org.sonar.api.rule.Severity.MAJOR;
import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.issue.IssueTesting.newDto;
-import static org.sonar.db.rule.RuleTesting.newRuleDto;
public class IssueUpdaterTest {
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public DbTester dbTester = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester es = EsTester.create();
- private DbClient dbClient = dbTester.getDbClient();
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
+ private DbClient dbClient = db.getDbClient();
+ private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private RuleDbTester ruleDbTester = new RuleDbTester(dbTester);
- private IssueDbTester issueDbTester = new IssueDbTester(dbTester);
- private ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
private IssueFieldsSetter issueFieldsSetter = new IssueFieldsSetter();
private NotificationManager notificationManager = mock(NotificationManager.class);
private ArgumentCaptor<IssueChangeNotification> notificationArgumentCaptor = ArgumentCaptor.forClass(IssueChangeNotification.class);
@Test
public void update_issue() {
- DefaultIssue issue = issueDbTester.insertIssue(newIssue().setSeverity(MAJOR)).toDefaultIssue();
- IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+ DefaultIssue issue = db.issues().insertIssue(i -> i.setSeverity(MAJOR)).toDefaultIssue();
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
- underTest.saveIssue(dbTester.getSession(), issue, context, null);
+ underTest.saveIssue(db.getSession(), issue, context, null);
- IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issue.key()).get();
+ IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issue.key()).get();
assertThat(issueReloaded.getSeverity()).isEqualTo(BLOCKER);
}
@Test
public void verify_notification() {
- UserDto user = dbTester.users().insertUser();
- RuleDto rule = ruleDbTester.insertRule(newRuleDto());
- ComponentDto project = componentDbTester.insertPrivateProject();
- ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
- DefaultIssue issue = issueDbTester.insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file))
+ UserDto assignee = db.users().insertUser();
+ RuleDto rule = db.rules().insertRule();
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
+ DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file))
.setSeverity(MAJOR)
- .setAssigneeUuid(user.getUuid())
+ .setAssigneeUuid(assignee.getUuid())
.toDefaultIssue();
- IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+ UserDto changeAuthor = db.users().insertUser();
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
- underTest.saveIssue(dbTester.getSession(), issue, context, "increase severity");
+ underTest.saveIssue(db.getSession(), issue, context, "increase severity");
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue();
assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.getDbKey());
assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name());
assertThat(issueChangeNotification.getFieldValue("ruleName")).isEqualTo(rule.getName());
- assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo("john");
+ assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo(changeAuthor.getLogin());
assertThat(issueChangeNotification.getFieldValue("comment")).isEqualTo("increase severity");
- assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(user.getLogin());
+ assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(assignee.getLogin());
}
@Test
public void verify_notification_on_branch() {
- RuleDto rule = ruleDbTester.insertRule(newRuleDto());
- ComponentDto project = componentDbTester.insertMainBranch();
- ComponentDto branch = componentDbTester.insertProjectBranch(project);
- ComponentDto file = componentDbTester.insertComponent(newFileDto(branch));
- DefaultIssue issue = issueDbTester.insertIssue(IssueTesting.newIssue(rule.getDefinition(), branch, file)).setSeverity(MAJOR).toDefaultIssue();
- IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+ RuleDto rule = db.rules().insertRule();
+ ComponentDto project = db.components().insertMainBranch();
+ ComponentDto branch = db.components().insertProjectBranch(project);
+ ComponentDto file = db.components().insertComponent(newFileDto(branch));
+ DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), branch, file)).setSeverity(MAJOR).toDefaultIssue();
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
- underTest.saveIssue(dbTester.getSession(), issue, context, "increase severity");
+ underTest.saveIssue(db.getSession(), issue, context, "increase severity");
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue();
@Test
public void verify_notification_when_issue_is_linked_on_removed_rule() {
- RuleDto rule = ruleDbTester.insertRule(newRuleDto().setStatus(RuleStatus.REMOVED));
- ComponentDto project = componentDbTester.insertPrivateProject();
- ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
- DefaultIssue issue = issueDbTester.insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file)).setSeverity(MAJOR).toDefaultIssue();
- IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+ RuleDto rule = db.rules().insertRule(r -> r.setStatus(RuleStatus.REMOVED));
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
+ DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file)).setSeverity(MAJOR).toDefaultIssue();
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
- underTest.saveIssue(dbTester.getSession(), issue, context, null);
+ underTest.saveIssue(db.getSession(), issue, context, null);
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
assertThat(notificationArgumentCaptor.getValue().getFieldValue("ruleName")).isNull();
}
- private IssueDto newIssue() {
- RuleDto rule = ruleDbTester.insertRule(newRuleDto());
- ComponentDto project = componentDbTester.insertPrivateProject();
- ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
- return newDto(rule, file, project);
+ @Test
+ public void verify_notification_when_assignee_has_changed() {
+ UserDto oldAssignee = db.users().insertUser();
+ RuleDto rule = db.rules().insertRule();
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
+ DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file))
+ .setAssigneeUuid(oldAssignee.getUuid())
+ .toDefaultIssue();
+ UserDto changeAuthor = db.users().insertUser();
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
+ UserDto newAssignee = db.users().insertUser();
+ issueFieldsSetter.assign(issue, newAssignee, context);
+
+ underTest.saveIssue(db.getSession(), issue, context, null);
+
+ verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
+ IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue();
+ assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key());
+ assertThat(issueChangeNotification.getFieldValue("new.assignee")).isEqualTo(newAssignee.getName());
+ assertThat(issueChangeNotification.getFieldValue("old.assignee")).isNull();
+ assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(newAssignee.getLogin());
}
@Test
public void saveIssue_populates_specified_SearchResponseData_with_rule_project_and_component_retrieved_from_DB() {
- RuleDto rule = ruleDbTester.insertRule(newRuleDto());
- ComponentDto project = componentDbTester.insertPrivateProject();
- ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
+ RuleDto rule = db.rules().insertRule();
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issueDto = IssueTesting.newIssue(rule.getDefinition(), project, file);
- DefaultIssue issue = issueDbTester.insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue();
- IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+ DefaultIssue issue = db.issues().insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue();
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
- SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(dbTester.getSession(), issue, context, null, true);
+ SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, null, true);
assertThat(preloadedSearchResponseData.getIssues())
.hasSize(1);
@Test
public void saveIssue_populates_specified_SearchResponseData_with_no_rule_but_with_project_and_component_if_rule_is_removed() {
- RuleDto rule = ruleDbTester.insertRule(newRuleDto().setStatus(RuleStatus.REMOVED));
- ComponentDto project = componentDbTester.insertPrivateProject();
- ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
+ RuleDto rule = db.rules().insertRule(r -> r.setStatus(RuleStatus.REMOVED));
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issueDto = IssueTesting.newIssue(rule.getDefinition(), project, file);
- DefaultIssue issue = issueDbTester.insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue();
- IssueChangeContext context = IssueChangeContext.createUser(new Date(), "john");
+ DefaultIssue issue = db.issues().insertIssue(issueDto).setSeverity(MAJOR).toDefaultIssue();
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
- SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(dbTester.getSession(), issue, context, null, false);
+ SearchResponseData preloadedSearchResponseData = underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, null, false);
assertThat(preloadedSearchResponseData.getIssues())
.hasSize(1);
.extracting(ComponentDto::uuid)
.containsOnly(project.uuid(), file.uuid());
}
+
}
public void should_insert_new_issues() {
dbTester.prepareDbUnit(getClass(), "should_insert_new_issues.xml");
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
// override generated key
comment.setKey("FGHIJ");
public void should_update_issues() {
dbTester.prepareDbUnit(getClass(), "should_update_issues.xml");
- IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik");
+ IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
- DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+ DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment");
// override generated key
comment.setKey("FGHIJ");
IssueDto issueDto = newIssue().setSeverity(MAJOR);
DefaultIssue issue = issueDto.toDefaultIssue();
setUserWithBrowseAndAdministerIssuePermission(issueDto);
- BulkChangeAction.ActionContext context = new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getLogin()), null);
+ BulkChangeAction.ActionContext context = new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getUuid()), null);
action.execute(ImmutableMap.of("severity", MINOR), context);
setUserWithBrowseAndAdministerIssuePermission(issueDto);
action.execute(ImmutableMap.of("type", VULNERABILITY.name()),
- new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getLogin()), null));
+ new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getUuid()), null));
assertThat(issue.type()).isEqualTo(VULNERABILITY);
assertThat(issue.isChanged()).isTrue();
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
-
import java.util.Date;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
public void setUp() throws Exception {
workflow.start();
when(context.issue()).thenReturn(issue);
- when(context.issueChangeContext()).thenReturn(IssueChangeContext.createUser(new Date(), "john"));
+ when(context.issueChangeContext()).thenReturn(IssueChangeContext.createUser(new Date(), "user_uuid"));
}
@Test
public void do_transition() {
DefaultIssue issue = newIssue().setStatus(STATUS_OPEN).setResolution(null).toDefaultIssue();
- boolean result = underTest.doTransition(issue, IssueChangeContext.createUser(new Date(), "john"), "confirm");
+ boolean result = underTest.doTransition(issue, IssueChangeContext.createUser(new Date(), "user_uuid"), "confirm");
assertThat(result).isTrue();
assertThat(issue.status()).isEqualTo(STATUS_CONFIRMED);
public class IssueChangeNotificationTest {
- IssueChangeNotification notification = new IssueChangeNotification();
+ private IssueChangeNotification notification = new IssueChangeNotification();
@Test
public void set_issue() {
@Test
public void set_change_author_login() {
- IssueChangeNotification result = notification.setChangeAuthorLogin("stephane");
- assertThat(result.getFieldValue("changeAuthor")).isEqualTo("stephane");
+ UserDto user = newUserDto();
+ IssueChangeNotification result = notification.setChangeAuthor(user);
+ assertThat(result.getFieldValue("changeAuthor")).isEqualTo(user.getLogin());
}
@Test
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.notifications.Notification;
import org.sonar.db.DbTester;
+import org.sonar.db.user.UserDto;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.CoreProperties.SERVER_BASE_URL;
-import static org.sonar.db.user.UserTesting.newUserDto;
public class IssueChangesEmailTemplateTest {
@Test
public void notification_sender_should_be_the_author_of_change() {
- db.users().insertUser(newUserDto().setLogin("simon").setName("Simon"));
+ UserDto user = db.users().insertUser();
Notification notification = new IssueChangeNotification()
- .setChangeAuthorLogin("simon")
+ .setChangeAuthor(user)
.setProject("Struts", "org.apache:struts", null, null);
EmailMessage message = underTest.format(notification);
- assertThat(message.getFrom()).isEqualTo("Simon");
+ assertThat(message.getFrom()).isEqualTo(user.getName());
}
@Test
public void notification_contains_user_login_when_user_is_removed() {
- db.users().insertUser(newUserDto().setLogin("simon").setName("Simon").setActive(false));
+ UserDto user = db.users().insertDisabledUser();
Notification notification = new IssueChangeNotification()
- .setChangeAuthorLogin("simon")
+ .setChangeAuthor(user)
.setProject("Struts", "org.apache:struts", null, null);
EmailMessage message = underTest.format(notification);
- assertThat(message.getFrom()).isEqualTo("simon");
+ assertThat(message.getFrom()).isEqualTo(user.getLogin());
}
private static Notification generateNotification() {
IssueChangeDto issueComment = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbTester.getSession(), singletonList(issueDto.getKey()), TYPE_COMMENT).get(0);
assertThat(issueComment.getKey()).isNotNull();
- assertThat(issueComment.getUserLogin()).isEqualTo("john");
+ assertThat(issueComment.getUserUuid()).isEqualTo(userSession.getUuid());
assertThat(issueComment.getChangeType()).isEqualTo(TYPE_COMMENT);
assertThat(issueComment.getChangeData()).isEqualTo("please fix it");
assertThat(issueComment.getCreatedAt()).isNotNull();
checkResponse(response, 1, 1, 0, 0);
IssueChangeDto issueComment = dbClient.issueChangeDao().selectByTypeAndIssueKeys(db.getSession(), singletonList(issueDto.getKey()), TYPE_COMMENT).get(0);
- assertThat(issueComment.getUserLogin()).isEqualTo("john");
+ assertThat(issueComment.getUserUuid()).isEqualTo(user.getUuid());
assertThat(issueComment.getChangeData()).isEqualTo("type was badly defined");
verifyPostProcessorCalled(file);
@Test
public void bulk_change_many_issues() {
setUserProjectPermissions(USER, ISSUE_ADMIN);
- UserDto userToAssign = db.users().insertUser("arthur");
+ UserDto userToAssign = db.users().insertUser();
db.organizations().addMember(organization, user);
db.organizations().addMember(organization, userToAssign);
IssueDto issue1 = db.issues().insertIssue(newUnresolvedIssue().setAssigneeUuid(user.getUuid())).setType(BUG).setSeverity(MINOR);
UserDto user = insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
- db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
+ db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
ChangelogWsResponse result = call(issueDto.getKey());
UserDto user = db.users().insertUser(UserTesting.newUserDto("john", "John", null));
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
- db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
+ db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
ChangelogWsResponse result = call(issueDto.getKey());
public void return_changelog_not_having_user() {
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
- db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(null).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
+ db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(null).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
ChangelogWsResponse result = call(issueDto.getKey());
public void return_changelog_on_none_existing_user() {
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
- db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin("UNKNOWN").setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
+ db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid("UNKNOWN").setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()));
ChangelogWsResponse result = call(issueDto.getKey());
UserDto user = insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
- db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin())
+ db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid())
.setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date())
.setDiff("status", "RESOLVED", "CLOSED").setCreationDate(new Date()));
UserDto user = insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
- db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", null, "BLOCKER").setCreationDate(new Date()));
+ db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", null, "BLOCKER").setCreationDate(new Date()));
ChangelogWsResponse result = call(issueDto.getKey());
UserDto user = insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
- db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", null).setCreationDate(new Date()));
+ db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", "MAJOR", null).setCreationDate(new Date()));
ChangelogWsResponse result = call(issueDto.getKey());
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
db.issues().insertFieldDiffs(issueDto,
- new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()),
+ new FieldDiffs().setUserUuid(user.getUuid()).setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date()),
new FieldDiffs().setDiff("status", "RESOLVED", "CLOSED").setCreationDate(new Date()));
ChangelogWsResponse result = call(issueDto.getKey());
UserDto user = insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
- db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("technicalDebt", "10", "20").setCreationDate(new Date()));
+ db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserUuid(user.getUuid()).setDiff("technicalDebt", "10", "20").setCreationDate(new Date()));
ChangelogWsResponse result = call(issueDto.getKey());
IssueDto issueDto = db.issues().insertIssue(newIssue());
userSession.logIn("john").addProjectPermission(USER, project, file);
db.issues().insertFieldDiffs(issueDto, new FieldDiffs()
- .setUserLogin(user.getLogin())
+ .setUserUuid(user.getUuid())
.setDiff("severity", "MAJOR", "BLOCKER").setCreationDate(new Date())
.setCreationDate(DateUtils.parseDateTime("2014-03-04T23:03:44+0100")));
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDbTester;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
@Test
public void delete_comment() {
IssueDto issueDto = issueDbTester.insertIssue();
- IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- loginAndAddProjectPermission("john", issueDto, USER);
+ UserDto user = dbTester.users().insertUser();
+ IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+ loginAndAddProjectPermission(user, issueDto, USER);
call(commentDto.getKey());
@Test
public void delete_comment_using_deprecated_key_parameter() {
IssueDto issueDto = issueDbTester.insertIssue();
- IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- loginAndAddProjectPermission("john", issueDto, USER);
+ UserDto user = dbTester.users().insertUser();
+ IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+ loginAndAddProjectPermission(user, issueDto, USER);
tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute();
@Test
public void fail_when_comment_does_not_belong_to_current_user() {
IssueDto issueDto = issueDbTester.insertIssue();
- IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- loginAndAddProjectPermission("another", issueDto, USER);
+ UserDto user = dbTester.users().insertUser();
+ IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+ UserDto another = dbTester.users().insertUser();
+ loginAndAddProjectPermission(another, issueDto, USER);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("You can only delete your own comments");
@Test
public void fail_when_comment_has_not_user() {
IssueDto issueDto = issueDbTester.insertIssue();
+ UserDto user = dbTester.users().insertUser();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, null, "please fix it");
- loginAndAddProjectPermission("john", issueDto, USER);
+ loginAndAddProjectPermission(user, issueDto, USER);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("You can only delete your own comments");
@Test
public void fail_when_not_enough_permission() {
IssueDto issueDto = issueDbTester.insertIssue();
- IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- loginAndAddProjectPermission("john", issueDto, CODEVIEWER);
+ UserDto user = dbTester.users().insertUser();
+ IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+ loginAndAddProjectPermission(user, issueDto, CODEVIEWER);
expectedException.expect(ForbiddenException.class);
call(commentDto.getKey());
return request.execute();
}
- private void loginAndAddProjectPermission(String login, IssueDto issueDto, String permission) {
- userSession.logIn(login).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
+ private void loginAndAddProjectPermission(UserDto user, IssueDto issueDto, String permission) {
+ userSession.logIn(user).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
}
}
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDbTester;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
@Test
public void edit_comment() {
IssueDto issueDto = issueDbTester.insertIssue();
- IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- loginWithBrowsePermission("john", USER, issueDto);
+ 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");
@Test
public void edit_comment_using_deprecated_key_parameter() {
IssueDto issueDto = issueDbTester.insertIssue();
- IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- loginWithBrowsePermission("john", USER, issueDto);
+ UserDto user = dbTester.users().insertUser();
+ IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+ loginWithBrowsePermission(user, USER, issueDto);
tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute();
@Test
public void fail_when_comment_does_not_belong_to_current_user() {
IssueDto issueDto = issueDbTester.insertIssue();
- IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- loginWithBrowsePermission("another", USER, issueDto);
+ UserDto user = dbTester.users().insertUser();
+ IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+ UserDto another = dbTester.users().insertUser();
+ loginWithBrowsePermission(another, USER, issueDto);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("You can only edit your own comments");
@Test
public void fail_when_comment_has_not_user() {
IssueDto issueDto = issueDbTester.insertIssue();
+ UserDto user = dbTester.users().insertUser();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, null, "please fix it");
- loginWithBrowsePermission("john", USER, issueDto);
+ loginWithBrowsePermission(user, USER, issueDto);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("You can only edit your own comments");
@Test
public void fail_when_empty_comment_text() {
IssueDto issueDto = issueDbTester.insertIssue();
- IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- loginWithBrowsePermission("john", USER, issueDto);
+ UserDto user = dbTester.users().insertUser();
+ IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+ loginWithBrowsePermission(user, USER, issueDto);
expectedException.expect(IllegalArgumentException.class);
call(commentDto.getKey(), "");
@Test
public void fail_when_not_enough_permission() {
IssueDto issueDto = issueDbTester.insertIssue();
- IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- loginWithBrowsePermission("john", CODEVIEWER, issueDto);
+ UserDto user = dbTester.users().insertUser();
+ IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it");
+ loginWithBrowsePermission(user, CODEVIEWER, issueDto);
expectedException.expect(ForbiddenException.class);
call(commentDto.getKey(), "please have a look");
return request.execute();
}
- private void loginWithBrowsePermission(String login, String permission, IssueDto issueDto) {
- userSession.logIn(login).addProjectPermission(permission,
+ private void loginWithBrowsePermission(UserDto user, String permission, IssueDto issueDto) {
+ userSession.logIn(user).addProjectPermission(permission,
dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get(),
dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getComponentUuid()).get());
}
import java.time.Clock;
import java.util.Arrays;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.issue.Issue;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.server.ws.WebService;
}
@Test
- @Ignore // TODO GJT when adressing ticket on IssueChangesUuid
public void issue_with_comments() {
UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John"));
UserDto fabrice = db.users().insertUser(u -> u.setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
.setKey("COMMENT-ABCD")
.setChangeData("*My comment*")
.setChangeType(IssueChangeDto.TYPE_COMMENT)
- .setUserLogin(john.getUuid())
+ .setUserUuid(john.getUuid())
.setIssueChangeCreationDate(DateUtils.parseDateTime("2014-09-09T12:00:00+0000").getTime()));
dbClient.issueChangeDao().insert(session,
new IssueChangeDto().setIssueKey(issue.getKey())
.setKey("COMMENT-ABCE")
.setChangeData("Another comment")
.setChangeType(IssueChangeDto.TYPE_COMMENT)
- .setUserLogin(fabrice.getUuid())
+ .setUserUuid(fabrice.getUuid())
.setIssueChangeCreationDate(DateUtils.parseDateTime("2014-09-10T12:00:00+0000").getTime()));
session.commit();
indexIssues();
@Test
public void issue_with_comment_hidden() {
- db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com"));
- db.users().insertUser(u -> u.setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
+ UserDto john = db.users().insertUser(u -> u.setLogin("john").setName("John").setEmail("john@email.com"));
+ UserDto fabrice = db.users().insertUser(u -> u.setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
ComponentDto project = insertComponent(ComponentTesting.newPublicProjectDto(otherOrganization1, "PROJECT_ID").setDbKey("PROJECT_KEY"));
indexPermissions();
.setKey("COMMENT-ABCD")
.setChangeData("*My comment*")
.setChangeType(IssueChangeDto.TYPE_COMMENT)
- .setUserLogin("john")
+ .setUserUuid(john.getUuid())
.setCreatedAt(DateUtils.parseDateTime("2014-09-09T12:00:00+0000").getTime()));
dbClient.issueChangeDao().insert(session,
new IssueChangeDto().setIssueKey(issue.getKey())
.setKey("COMMENT-ABCE")
.setChangeData("Another comment")
.setChangeType(IssueChangeDto.TYPE_COMMENT)
- .setUserLogin("fabrice")
+ .setUserUuid(fabrice.getUuid())
.setCreatedAt(DateUtils.parseDateTime("2014-09-10T19:10:03+0000").getTime()));
session.commit();
indexIssues();
- userSessionRule.logIn("john");
+ userSessionRule.logIn(john);
TestResponse result = ws.newRequest().setParam(PARAM_HIDE_COMMENTS, "true").execute();
result.assertJson(this.getClass(), "issue_with_comment_hidden.json");
- assertThat(result.getInput()).doesNotContain("fabrice");
+ assertThat(result.getInput()).doesNotContain(fabrice.getLogin());
}
@Test
issue_type="2"
/>
- <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik"
+ <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="user_uuid"
change_data="the comment"
created_at="[null]" updated_at="[null]" issue_change_creation_date="[null]"/>
issue_type="2"
/>
- <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik"
+ <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="user_uuid"
change_data="the comment" created_at="[null]" updated_at="[null]" issue_change_creation_date="[null]"/>
- <issue_changes id="2" kee="[null]" issue_key="ABCDE" change_type="diff" user_login="emmerik"
+ <issue_changes id="2" kee="[null]" issue_key="ABCDE" change_type="diff" user_login="user_uuid"
change_data="severity=INFO|BLOCKER" created_at="[null]" updated_at="[null]"
issue_change_creation_date="[null]"/>
</dataset>
issue_type="2"
/>
- <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik"
+ <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="user_uuid"
change_data="the comment"
created_at="[null]" updated_at="[null]" issue_change_creation_date="[null]"/>
kee="FGHIJ"
issue_key="ABCDE"
change_type="comment"
- user_login="emmerik"
+ user_login="user_uuid"
change_data="the comment"
created_at="[null]"
updated_at="[null]"
kee="[null]"
issue_key="ABCDE"
change_type="diff"
- user_login="emmerik"
+ user_login="user_uuid"
change_data="severity=INFO|BLOCKER"
created_at="[null]"
updated_at="[null]"
private String checksum;
private Map<String, String> attributes = null;
private String authorLogin = null;
- private List<IssueComment> comments = null;
+ private List<DefaultIssueComment> comments = null;
private Set<String> tags = null;
// temporarily an Object as long as DefaultIssue is used by sonar-batch
private Object locations = null;
if (!Objects.equals(oldValue, newValue)) {
if (currentChange == null) {
currentChange = new FieldDiffs();
- currentChange.setUserLogin(context.login());
+ currentChange.setUserUuid(context.userUuid());
currentChange.setCreationDate(context.date());
}
currentChange.setDiff(field, oldValue, newValue);
return this;
}
+ /**
+ * @deprecated since 7.2, comments are not more available
+ */
@Override
+ @Deprecated
public List<IssueComment> comments() {
+ return Collections.emptyList();
+ }
+
+ public List<DefaultIssueComment> defaultIssueComments() {
if (comments == null) {
return Collections.emptyList();
}
import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.sonar.api.issue.IssueComment;
import org.sonar.core.util.Uuids;
/**
- * PLUGINS MUST NOT BE USED THIS CLASS, EXCEPT FOR UNIT TESTING.
+ * PLUGINS MUST NOT BE USED THIS CLASS
*
* @since 3.6
*/
-public class DefaultIssueComment implements Serializable, IssueComment {
+public class DefaultIssueComment implements Serializable {
private String issueKey;
- private String userLogin;
+ private String userUuid;
private Date createdAt;
private Date updatedAt;
private String key;
private String markdownText;
private boolean isNew;
- public static DefaultIssueComment create(String issueKey, @Nullable String login, String markdownText) {
+ public static DefaultIssueComment create(String issueKey, @Nullable String userUuid, String markdownText) {
DefaultIssueComment comment = new DefaultIssueComment();
comment.setIssueKey(issueKey);
comment.setKey(Uuids.create());
Date now = new Date();
- comment.setUserLogin(login);
+ comment.setUserUuid(userUuid);
comment.setMarkdownText(markdownText);
comment.setCreatedAt(now).setUpdatedAt(now);
comment.setNew(true);
return comment;
}
- @Override
public String markdownText() {
return markdownText;
}
return this;
}
- @Override
public String issueKey() {
return issueKey;
}
return this;
}
- @Override
public String key() {
return key;
}
}
/**
- * The user who created the comment. Null if it was automatically generated during project scan.
+ * The user uuid who created the comment. Null if it was automatically generated during project scan.
*/
- @Override
@CheckForNull
- public String userLogin() {
- return userLogin;
+ public String userUuid() {
+ return userUuid;
}
- public DefaultIssueComment setUserLogin(@Nullable String userLogin) {
- this.userLogin = userLogin;
+ public DefaultIssueComment setUserUuid(@Nullable String userUuid) {
+ this.userUuid = userUuid;
return this;
}
- @Override
public Date createdAt() {
return createdAt;
}
return this;
}
- @Override
public Date updatedAt() {
return updatedAt;
}
public static final Splitter FIELDS_SPLITTER = Splitter.on(',').omitEmptyStrings();
private String issueKey;
- private String userLogin;
+ private String userUuid;
private Date creationDate;
private final Map<String, Diff> diffs = Maps.newLinkedHashMap();
}
@CheckForNull
- public String userLogin() {
- return userLogin;
+ public String userUuid() {
+ return userUuid;
}
- public FieldDiffs setUserLogin(@Nullable String s) {
- this.userLogin = s;
+ public FieldDiffs setUserUuid(@Nullable String s) {
+ this.userUuid = s;
return this;
}
public class IssueChangeContext implements Serializable {
- private final String login;
+ private final String userUuid;
private final Date date;
private final boolean scan;
- private IssueChangeContext(@Nullable String login, Date date, boolean scan) {
- this.login = login;
+ private IssueChangeContext(@Nullable String userUuid, Date date, boolean scan) {
+ this.userUuid = userUuid;
this.date = date;
this.scan = scan;
}
@CheckForNull
- public String login() {
- return login;
+ public String userUuid() {
+ return userUuid;
}
public Date date() {
return new IssueChangeContext(null, date, true);
}
- public static IssueChangeContext createUser(Date date, @Nullable String login) {
- return new IssueChangeContext(login, date, false);
+ public static IssueChangeContext createUser(Date date, @Nullable String userUuid) {
+ return new IssueChangeContext(userUuid, date, false);
}
@Override
}
IssueChangeContext that = (IssueChangeContext) o;
return scan == that.scan &&
- Objects.equals(login, that.login) &&
+ Objects.equals(userUuid, that.userUuid) &&
Objects.equals(date, that.date);
}
@Override
public int hashCode() {
- return Objects.hash(login, date, scan);
+ return Objects.hash(userUuid, date, scan);
}
@Override
public String toString() {
return "IssueChangeContext{" +
- "login='" + login + '\'' +
+ "userUuid='" + userUuid + '\'' +
", date=" + date +
", scan=" + scan +
'}';
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.IssueComment;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.Duration;
}
@Test
- public void test_attributes() throws Exception {
+ public void test_attributes() {
assertThat(issue.attribute("foo")).isNull();
issue.setAttribute("foo", "bar");
assertThat(issue.attribute("foo")).isEqualTo("bar");
}
@Test
- public void test_nullable_fields() throws Exception {
+ public void test_nullable_fields() {
issue.setGap(null).setSeverity(null).setLine(null);
assertThat(issue.gap()).isNull();
assertThat(issue.severity()).isNull();
}
@Test
- public void test_equals_and_hashCode() throws Exception {
+ public void test_equals_and_hashCode() {
DefaultIssue a1 = new DefaultIssue().setKey("AAA");
DefaultIssue a2 = new DefaultIssue().setKey("AAA");
DefaultIssue b = new DefaultIssue().setKey("BBB");
public void comments_should_not_be_modifiable() {
DefaultIssue issue = new DefaultIssue().setKey("AAA");
- List<IssueComment> comments = issue.comments();
+ List<DefaultIssueComment> comments = issue.defaultIssueComments();
assertThat(comments).isEmpty();
try {
public class IssueChangeContextTest {
@Test
- public void test_scan_context() throws Exception {
+ public void test_scan_context() {
Date now = new Date();
IssueChangeContext context = IssueChangeContext.createScan(now);
assertThat(context.scan()).isTrue();
- assertThat(context.login()).isNull();
+ assertThat(context.userUuid()).isNull();
assertThat(context.date()).isEqualTo(now);
}
@Test
- public void test_end_user_context() throws Exception {
+ public void test_end_user_context() {
Date now = new Date();
- IssueChangeContext context = IssueChangeContext.createUser(now, "emmerik");
+ IssueChangeContext context = IssueChangeContext.createUser(now, "user_uuid");
assertThat(context.scan()).isFalse();
- assertThat(context.login()).isEqualTo("emmerik");
+ assertThat(context.userUuid()).isEqualTo("user_uuid");
assertThat(context.date()).isEqualTo(now);
}
}
* <br>
* IMPORTANT: existing comments are not loaded when this method is called when analyzing project
* (from {@link ScannerSide}).
+ *
+ * @deprecated since 7.2, comments are not more available
*/
+ @Deprecated
List<IssueComment> comments();
/**
*/
package org.sonar.api.issue;
-import javax.annotation.CheckForNull;
import java.util.Date;
+import javax.annotation.CheckForNull;
+/**
+ * @deprecated since 7.2, comments are no more available
+ */
+@Deprecated
public interface IssueComment {
String markdownText();
import java.util.List;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.sonar.wsclient.issue.Issue;
import org.sonarqube.ws.Issues;
}
@Test
- @Ignore // TODO GJT when adressing ticket on IssueChangesUuid
public void update_changelog_when_assigning_issue_by_user() {
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");
Issue issue = searchRandomIssue();
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.qa.util.Tester;
}
@Test
- @Ignore // TODO GJT when adressing ticket on IssueChangesUuid
public void notification_for_ChangesOnMyIssue() throws Exception {
String version = RandomStringUtils.randomAlphanumeric(10);
Project project = tester.projects().provision();
import org.sonarqube.qa.util.Tester;
import org.sonarqube.qa.util.TesterSession;
import org.sonarqube.ws.Ce;
-import org.sonarqube.ws.Issues;
import org.sonarqube.ws.Issues.Issue;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.Projects;
import org.sonarqube.ws.client.ce.ActivityRequest;
import org.sonarqube.ws.client.ce.TaskRequest;
import org.sonarqube.ws.client.custommeasures.CreateRequest;
+import org.sonarqube.ws.client.issues.AddCommentRequest;
import org.sonarqube.ws.client.issues.AssignRequest;
import org.sonarqube.ws.client.organizations.AddMemberRequest;
import org.sonarqube.ws.client.organizations.SearchRequest;
String oldLogin = tester.users().generateLogin();
String providerId = tester.users().generateProviderId();
- // Create user using authentication
+ // Create user using authentication, and set user as member of the organization
authenticate(oldLogin, providerId);
-
- // Set user as member of the organization
Organization organization = tester.organizations().generate();
tester.organizations().service().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(oldLogin));
+
+ // Execute analysis and assign an issue to the user
Projects.CreateWsResponse.Project project = tester.projects().provision(organization);
Qualityprofiles.CreateWsResponse.QualityProfile profile = tester.qProfiles().createXooProfile(organization);
tester.qProfiles().assignQProfileToProject(profile, project);
tester.qProfiles().activateRule(profile.getKey(), "xoo:OneIssuePerLine");
-
- // Execute project and assignee an issue to the user
orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"),
"sonar.organization", organization.getKey(),
"sonar.projectKey", project.getKey(),
"sonar.login", "admin",
"sonar.password", "admin"));
- Issues.Issue issue = tester.wsClient().issues().search(new org.sonarqube.ws.client.issues.SearchRequest().setOrganization(organization.getKey())).getIssuesList().get(0);
+ Issue issue = tester.wsClient().issues().search(new org.sonarqube.ws.client.issues.SearchRequest().setOrganization(organization.getKey())).getIssuesList().get(0);
tester.wsClient().issues().assign(new AssignRequest().setIssue(issue.getKey()).setAssignee(oldLogin));
+ assertThat(getIssue(organization, issue.getKey()).getAssignee()).isEqualTo(oldLogin);
// Update login during authentication, check issue is assigned to new login
String newLogin = tester.users().generateLogin();
authenticate(newLogin, providerId);
- tester.wsClient().issues().assign(new AssignRequest().setIssue(issue.getKey()).setAssignee(newLogin));
+ assertThat(getIssue(organization, issue.getKey()).getAssignee()).isEqualTo(newLogin);
+ }
+
+ @Test
+ public void issue_changes_after_login_update() {
+ String oldLogin = tester.users().generateLogin();
+ String providerId = tester.users().generateProviderId();
+
+ // Create user using authentication
+ authenticate(oldLogin, providerId);
+ Organization organization = tester.organizations().generate();
+ tester.organizations().service().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(oldLogin));
+ String userToken = tester.wsClient().userTokens().generate(new GenerateRequest().setLogin(oldLogin).setName("token")).getToken();
+ WsClient userWsClient = tester.as(userToken, null).wsClient();
+
+ // Execute analysis, then the user assign an issue to himself and add a comment
+ Projects.CreateWsResponse.Project project = tester.projects().provision(organization);
+ Qualityprofiles.CreateWsResponse.QualityProfile profile = tester.qProfiles().createXooProfile(organization);
+ tester.qProfiles().assignQProfileToProject(profile, project);
+ tester.qProfiles().activateRule(profile.getKey(), "xoo:OneIssuePerLine");
+ orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"),
+ "sonar.organization", organization.getKey(),
+ "sonar.projectKey", project.getKey(),
+ "sonar.login", "admin",
+ "sonar.password", "admin"));
+ Issue issue = tester.wsClient().issues().search(new org.sonarqube.ws.client.issues.SearchRequest().setOrganization(organization.getKey())).getIssuesList().get(0);
+ userWsClient.issues().assign(new AssignRequest().setIssue(issue.getKey()).setAssignee(oldLogin));
+ userWsClient.issues().addComment(new AddCommentRequest().setIssue(issue.getKey()).setText("some comment"));
+
+ // Comment and changelog contain old login
+ assertThat(getIssue(organization, issue.getKey()).getComments().getComments(0).getLogin()).isEqualTo(oldLogin);
+ assertThat(tester.wsClient().issues().changelog(new org.sonarqube.ws.client.issues.ChangelogRequest().setIssue(issue.getKey()))
+ .getChangelog(0).getUser()).isEqualTo(oldLogin);
+
+ // Update login during authentication, check comment and issue changelog contain new login
+ String newLogin = tester.users().generateLogin();
+ authenticate(newLogin, providerId);
+ assertThat(getIssue(organization, issue.getKey()).getComments().getComments(0).getLogin()).isEqualTo(newLogin);
+ assertThat(tester.wsClient().issues().changelog(new org.sonarqube.ws.client.issues.ChangelogRequest().setIssue(issue.getKey()))
+ .getChangelog(0).getUser()).isEqualTo(newLogin);
}
@Test