From 94d3f4100cd4e78b5597381ad0bd6b5d43eb209a Mon Sep 17 00:00:00 2001 From: Belen Pruvost Date: Fri, 10 Sep 2021 15:56:06 +0200 Subject: [PATCH] SONAR-15335 - Avoid returning duplicates in Export Findings --- .../src/main/java/org/sonar/db/issue/IssueDao.java | 4 ++++ .../main/java/org/sonar/db/issue/IssueMapper.java | 2 ++ .../resources/org/sonar/db/issue/IssueMapper.xml | 14 +++++++++++--- .../test/java/org/sonar/db/issue/IssueDaoTest.java | 12 ++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) 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 ac729b3bb04..52ef7a4f10c 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 @@ -58,6 +58,10 @@ public class IssueDao implements Dao { return executeLargeInputs(keys, mapper(session)::selectByKeys); } + public Set selectIssueKeysByComponentUuid(DbSession session, String componentUuid) { + return mapper(session).selectIssueKeysByComponentUuid(componentUuid); + } + public List selectByComponentUuidPaginated(DbSession session, String componentUuid, int page) { return mapper(session).selectByComponentUuidPaginated(componentUuid, Pagination.forPage(page).andSize(DEFAULT_PAGE_SIZE)); } 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 9fa98e1f391..80ea1be570c 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 @@ -37,6 +37,8 @@ public interface IssueMapper { List selectByKeys(List keys); + Set selectIssueKeysByComponentUuid(@Param("componentUuid") String componentUuid); + List selectByComponentUuidPaginated(@Param("componentUuid") String componentUuid, @Param("pagination") Pagination pagination); 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 ff5dc7f5735..059c6f76c53 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 @@ -353,6 +353,14 @@ group by i2.issue_type, i2.severity, i2.resolution, i2.status, i2.inLeak + + @@ -370,7 +378,7 @@ from (select - row_number() over(order by i.kee) as row_number, + row_number() over(order by i.issue_creation_date ASC) as row_number, from issues i where i.project_uuid=#{componentUuid,jdbcType=VARCHAR} @@ -392,7 +400,7 @@ from issues i where i.project_uuid=#{componentUuid,jdbcType=VARCHAR} - order by i.kee + order by i.issue_creation_date ASC ) t ) i where diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java index 691dea2e504..7541739759f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.stream.Stream; import org.junit.Rule; import org.junit.Test; @@ -128,6 +129,17 @@ public class IssueDaoTest { assertThat(issues).extracting("key").containsOnly("I1", "I2"); } + @Test + public void selectIssueKeysByComponentUuid() { + // contains I1 and I2 + prepareTables(); + + Set issues = underTest.selectIssueKeysByComponentUuid(db.getSession(), PROJECT_UUID); + + // results are not ordered, so do not use "containsExactly" + assertThat(issues).containsOnly("I1", "I2"); + } + @Test public void selectByComponentUuidPaginated() { // contains I1 and I2 -- 2.39.5