aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorBelen Pruvost <belen.pruvost@sonarsource.com>2021-09-10 15:56:06 +0200
committersonartech <sonartech@sonarsource.com>2021-09-14 20:03:24 +0000
commit94d3f4100cd4e78b5597381ad0bd6b5d43eb209a (patch)
tree3a35f8197fd6d7526c588766fbcc521bc860b125 /server
parentd92d37119f295bf66b8622b2c7d3d08fcabc786a (diff)
downloadsonarqube-94d3f4100cd4e78b5597381ad0bd6b5d43eb209a.tar.gz
sonarqube-94d3f4100cd4e78b5597381ad0bd6b5d43eb209a.zip
SONAR-15335 - Avoid returning duplicates in Export Findings
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml14
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java12
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<String> selectIssueKeysByComponentUuid(DbSession session, String componentUuid) {
+ return mapper(session).selectIssueKeysByComponentUuid(componentUuid);
+ }
+
public List<IssueDto> 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<IssueDto> selectByKeys(List<String> keys);
+ Set<String> selectIssueKeysByComponentUuid(@Param("componentUuid") String componentUuid);
+
List<IssueDto> 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
</select>
+ <select id="selectIssueKeysByComponentUuid" parameterType="string" resultType="string">
+ select
+ i.kee
+ from issues i
+ where
+ i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
+ </select>
+
<select id="selectByComponentUuidPaginated" parameterType="map" resultType="Issue">
select
<include refid="issueColumns"/>
@@ -361,7 +369,7 @@
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
- order by i.kee
+ order by i.issue_creation_date ASC
limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
</select>
@@ -370,7 +378,7 @@
<include refid="issueColumns"/>
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,
<include refid="issueColumnsInInnerQuery" />
from issues i
where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
@@ -392,7 +400,7 @@
<include refid="issueColumnsInInnerQuery"/>
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;
@@ -129,6 +130,17 @@ public class IssueDaoTest {
}
@Test
+ public void selectIssueKeysByComponentUuid() {
+ // contains I1 and I2
+ prepareTables();
+
+ Set<String> 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
prepareTables();