aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Vinot <antoine.vinot@sonarsource.com>2023-01-30 12:33:54 +0100
committersonartech <sonartech@sonarsource.com>2023-02-03 14:41:21 +0000
commitc2953631e83ca0809c293202d0d12e32e47b07fa (patch)
treeb810f2418a41dd88a7b371d03a320b66e25fc619
parent7814557b79535357723ebc9c36e949915d2f70ed (diff)
downloadsonarqube-c2953631e83ca0809c293202d0d12e32e47b07fa.tar.gz
sonarqube-c2953631e83ca0809c293202d0d12e32e47b07fa.zip
SONAR-18275 Fix App stats present in projects-general-stats telemetry payload
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml3
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml1
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java18
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java12
4 files changed, 33 insertions, 1 deletions
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
index 03d57e505bc..2612e083b46 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
@@ -30,7 +30,8 @@
close=")">#{metricUuid, jdbcType=VARCHAR}</foreach>
and component_uuid in (SELECT
p.uuid as uuid
- FROM projects p)
+ FROM projects p
+ where p.qualifier = 'TRK')
</select>
<select id="selectByComponentUuidsAndMetricKeys" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
index 1da38dd2e06..6e295c489cd 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
@@ -18,6 +18,7 @@
SELECT
p.uuid as uuid
FROM projects p
+ where p.qualifier = 'TRK'
</select>
<select id="selectByUuid" parameterType="String" resultType="Project">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
index aba81a1f63e..04f12e74729 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
@@ -169,6 +169,24 @@ public class LiveMeasureDaoTest {
}
@Test
+ public void selectForProjectsByMetricUuids_shouldReturnProjectWithTRKQualifierOnly() {
+ MetricDto metric = db.measures().insertMetric();
+ ComponentDto application = db.components().insertPrivateApplication();
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto project2 = db.components().insertPrivateProject();
+ db.components().addApplicationProject(application, project, project2);
+ underTest.insert(db.getSession(), newLiveMeasure(application, metric).setValue(3.14).setData((String) null));
+ underTest.insert(db.getSession(), newLiveMeasure(project, metric).setValue(4.54).setData((String) null));
+ underTest.insert(db.getSession(), newLiveMeasure(project2, metric).setValue(5.56).setData((String) null));
+
+ List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), List.of(metric.getUuid()));
+
+ assertThat(selected)
+ .extracting(LiveMeasureDto::getProjectUuid)
+ .containsExactlyInAnyOrder(project.uuid(), project2.uuid());
+ }
+
+ @Test
public void selectByComponentUuidAndMetricKey() {
LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
index 0e5d37716e3..51476f1449f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
@@ -279,6 +279,18 @@ public class ProjectDaoTest {
.containsExactlyInAnyOrderElementsOf(extractComponentUuids(projects));
}
+ @Test
+ public void selectAllProjectUuids_shouldOnlyReturnProjectWithTRKQualifier() {
+ ComponentDto application = db.components().insertPrivateApplication();
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto project2 = db.components().insertPrivateProject();
+ db.components().addApplicationProject(application, project, project2);
+
+ List<String> projectUuids = projectDao.selectAllProjectUuids(db.getSession());
+
+ assertThat(projectUuids).containsExactlyInAnyOrder(project.uuid(), project2.uuid());
+ }
+
private void insertDefaultQualityProfile(String language) {
QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setIsBuiltIn(true).setLanguage(language));
db.qualityProfiles().setAsDefault(profile);