]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20572 Rework how issues are fetched in export
authorEric Giffon <eric.giffon@sonarsource.com>
Tue, 17 Oct 2023 13:17:16 +0000 (15:17 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 18 Oct 2023 20:03:06 +0000 (20:03 +0000)
server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml

index aed7b86fd84ae07e1e4b9b04fea9e904618e1422..f65f56f6129becc889381f62ea9736c85a838f99 100644 (file)
@@ -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<IssueDto> 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<IssueDto> 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)
index 91ac8a2848b1446ad1ee450995322623872c74d5..1bd9aa15abd61d85302fbb0e89370b489c510fa1 100644 (file)
@@ -78,10 +78,6 @@ public class IssueDao implements Dao {
       includingRepositories, excludingRepositories, languages, Pagination.forPage(page).andSize(BIG_PAGE_SIZE));
   }
 
-  public List<IssueDto> selectByComponentUuidPaginated(DbSession session, String componentUuid, int page) {
-    return mapper(session).selectByComponentUuidPaginated(componentUuid, Pagination.forPage(page).andSize(DEFAULT_PAGE_SIZE));
-  }
-
   public Set<String> selectComponentUuidsOfOpenIssuesForProjectUuid(DbSession session, String projectUuid) {
     return mapper(session).selectComponentUuidsOfOpenIssuesForProjectUuid(projectUuid);
   }
index 93951e438e6a1b98667079d0d3912e6f219c9094..83b12e68db52f39604b8b802d0d7d374e0a760da 100644 (file)
@@ -50,9 +50,6 @@ public interface IssueMapper {
     @Param("excludingRepositories") List<String> excludingRepositories,
     @Param("languages") List<String> languages, @Param("pagination") Pagination pagination);
 
-  List<IssueDto> selectByComponentUuidPaginated(@Param("componentUuid") String componentUuid,
-    @Param("pagination") Pagination pagination);
-
   List<IssueDto> selectByKeysIfNotUpdatedAt(@Param("keys") List<String> keys, @Param("updatedAt") long updatedAt);
 
   List<PrIssueDto> selectOpenByComponentUuids(List<String> componentUuids);
index 92b92927bb3166675e107ec367494f958b493ec1..5332d6877218d277adb7ef3cde33c022d6a82a6f 100644 (file)
 
   <select id="selectByKeys" parameterType="map" resultMap="issueResultMap">
     select
-    <include refid="issueColumns"/>
+    <include refid="issueColumns"/>,
+    u.login as assigneeLogin
     from issues i
     inner join rules r on r.uuid=i.rule_uuid
     inner join components p on p.uuid=i.component_uuid
     inner join components root on root.uuid=i.project_uuid
+    left join users u on i.assignee = u.uuid
     left join new_code_reference_issues n on i.kee = n.issue_key
     left outer join issues_impacts ii on i.kee = ii.issue_key
     left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
     <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
-  <select id="selectByComponentUuidPaginated" parameterType="map" resultMap="issueResultMap">
-    select
-    <include refid="issueColumns"/>,
-    u.login as assigneeLogin
-    from issues i
-    inner join rules r on r.uuid=i.rule_uuid
-    inner join components p on p.uuid=i.component_uuid
-    inner join components root on root.uuid=i.project_uuid
-    left join users u on i.assignee = u.uuid
-    left join new_code_reference_issues n on i.kee = n.issue_key
-    left outer join issues_impacts ii on i.kee = ii.issue_key
-    left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
-    where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
-    order by i.issue_creation_date ASC
-    <include refid="org.sonar.db.common.Common.pagination"/>
-  </select>
-
   <sql id="selectByBranchColumns">
     i.kee as kee,
     i.rule_uuid as ruleUuid,