]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18275 Fix App stats present in projects-general-stats telemetry payload
authorAntoine Vinot <antoine.vinot@sonarsource.com>
Mon, 30 Jan 2023 11:33:54 +0000 (12:33 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 3 Feb 2023 14:41:21 +0000 (14:41 +0000)
server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java

index 03d57e505bcd66562953a68f1ba15144d5051579..2612e083b46ce8ffda8a6703d04f4f7bf5265dc0 100644 (file)
@@ -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">
index 1da38dd2e0628f032e24cb97e4f078c97b9700ab..6e295c489cd3220d2e756333134ba8286dfc3677 100644 (file)
@@ -18,6 +18,7 @@
     SELECT
       p.uuid as uuid
     FROM projects p
+    where p.qualifier = 'TRK'
   </select>
 
   <select id="selectByUuid" parameterType="String" resultType="Project">
index aba81a1f63e05436d5c9afd78fe38da9dc3d26e4..04f12e74729b4c83369f203707d8aa14a621a85c 100644 (file)
@@ -168,6 +168,24 @@ public class LiveMeasureDaoTest {
     assertThat(selected).isEmpty();
   }
 
+  @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());
index 0e5d37716e386c180e82cb0faee623465da38f4b..51476f1449f040f45c0e38876d8e31d9b9d59537 100644 (file)
@@ -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);