From 766b715e8f3621d252b1771d12c9a4c13948e331 Mon Sep 17 00:00:00 2001 From: Eric Giffon Date: Tue, 17 Oct 2023 15:17:16 +0200 Subject: [PATCH] SONAR-20572 Rework how issues are fetched in export --- .../java/org/sonar/db/issue/IssueDaoIT.java | 22 +++++++++---------- .../java/org/sonar/db/issue/IssueDao.java | 4 ---- .../java/org/sonar/db/issue/IssueMapper.java | 3 --- .../org/sonar/db/issue/IssueMapper.xml | 21 +++--------------- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java index aed7b86fd84..f65f56f6129 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java @@ -51,6 +51,7 @@ import org.sonar.db.component.ComponentTesting; import org.sonar.db.protobuf.DbIssues; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; +import org.sonar.db.user.UserDto; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; @@ -92,6 +93,7 @@ public class IssueDaoIT { private static final String ISSUE_KEY1 = "I1"; private static final String ISSUE_KEY2 = "I2"; private static final String TEST_CONTEXT_KEY = "test_context_key"; + private static final String USER_LOGIN = "user_login"; private static final RuleType[] RULE_TYPES_EXCEPT_HOTSPOT = Stream.of(RuleType.values()) .filter(r -> r != RuleType.SECURITY_HOTSPOT) @@ -110,6 +112,7 @@ public class IssueDaoIT { private final IssueDao underTest = db.getDbClient().issueDao(); private ComponentDto projectDto; + private UserDto userDto; @Before public void setup() { @@ -118,6 +121,7 @@ public class IssueDaoIT { db.rules().insert(RULE.setIsExternal(true)); projectDto = db.components().insertPrivateProject(t -> t.setUuid(PROJECT_UUID).setKey(PROJECT_KEY)).getMainBranchComponent(); db.components().insertComponent(newFileDto(projectDto).setUuid(FILE_UUID).setKey(FILE_KEY)); + userDto = db.users().insertUser(USER_LOGIN); } @Test @@ -142,7 +146,8 @@ public class IssueDaoIT { .setResolution("FIXED") .setChecksum("123456789") .setAuthorLogin("morgan") - .setAssigneeUuid("karadoc") + .setAssigneeUuid(userDto.getUuid()) + .setAssigneeLogin(USER_LOGIN) .setCreatedAt(1_440_000_000_000L) .setUpdatedAt(1_440_000_000_000L) .setRule(RULE) @@ -194,6 +199,9 @@ public class IssueDaoIT { List issues = underTest.selectByKeys(db.getSession(), asList("I1", "I2", "I3")); assertThat(issues).extracting(IssueDto::getKey).containsExactlyInAnyOrder("I1", "I2"); + assertThat(issues).filteredOn(issueDto -> issueDto.getKey().equals("I1")) + .extracting(IssueDto::getAssigneeLogin) + .containsExactly(USER_LOGIN); assertThat(issues).filteredOn(issueDto -> issueDto.getKey().equals("I1")) .extracting(IssueDto::getImpacts) .flatMap(issueImpactDtos -> issueImpactDtos) @@ -365,17 +373,6 @@ public class IssueDaoIT { tuple("issueB1", STATUS_RESOLVED)); } - @Test - public void selectByComponentUuidPaginated() { - // contains I1 and I2 - prepareTables(); - - List issues = underTest.selectByComponentUuidPaginated(db.getSession(), PROJECT_UUID, 1); - - // results are not ordered, so do not use "containsExactly" - assertThat(issues).extracting("key").containsOnly("I1", "I2"); - } - @Test public void selectOpenByComponentUuid() { RuleDto rule = db.rules().insert(); @@ -949,6 +946,7 @@ public class IssueDaoIT { .setRuleUuid(RULE.getUuid()) .setComponentUuid(FILE_UUID) .setProjectUuid(PROJECT_UUID) + .setAssigneeUuid(userDto.getUuid()) .addImpact(newIssueImpact(RELIABILITY, MEDIUM)) .addImpact(newIssueImpact(SECURITY, LOW))); underTest.insert(db.getSession(), newIssueDto(ISSUE_KEY2) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java index 91ac8a2848b..1bd9aa15abd 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java @@ -78,10 +78,6 @@ public class IssueDao implements Dao { includingRepositories, excludingRepositories, languages, Pagination.forPage(page).andSize(BIG_PAGE_SIZE)); } - public List selectByComponentUuidPaginated(DbSession session, String componentUuid, int page) { - return mapper(session).selectByComponentUuidPaginated(componentUuid, Pagination.forPage(page).andSize(DEFAULT_PAGE_SIZE)); - } - public Set selectComponentUuidsOfOpenIssuesForProjectUuid(DbSession session, String projectUuid) { return mapper(session).selectComponentUuidsOfOpenIssuesForProjectUuid(projectUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java index 93951e438e6..83b12e68db5 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java @@ -50,9 +50,6 @@ public interface IssueMapper { @Param("excludingRepositories") List excludingRepositories, @Param("languages") List languages, @Param("pagination") Pagination pagination); - List selectByComponentUuidPaginated(@Param("componentUuid") String componentUuid, - @Param("pagination") Pagination pagination); - List selectByKeysIfNotUpdatedAt(@Param("keys") List keys, @Param("updatedAt") long updatedAt); List selectOpenByComponentUuids(List componentUuids); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml index 92b92927bb3..5332d687721 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml @@ -401,11 +401,13 @@ - - i.kee as kee, i.rule_uuid as ruleUuid, -- 2.39.5