From: Serhat Yenican <104850907+serhat-yenican-sonarsource@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:56:31 +0000 (+0100) Subject: CODEFIX-184 send ai suggestion enabled/disabled project count telemetry (#12228) X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=778a9b293e71eef256a1b3bb90beb79d5b1c075e;p=sonarqube.git CODEFIX-184 send ai suggestion enabled/disabled project count telemetry (#12228) --- diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java index 6de21b9cf7d..228bb206b34 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java @@ -38,6 +38,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.sonar.api.impl.utils.AlwaysIncreasingSystem2; import org.sonar.api.utils.System2; +import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.Pagination; import org.sonar.db.audit.AuditPersister; @@ -314,7 +315,7 @@ class ProjectDaoIT { } @ParameterizedTest - @ValueSource(booleans = { true, false }) + @ValueSource(booleans = {true, false}) void update_aiCodeFixEnabledForAllProjects(boolean aiCodeFixEnablement) { ProjectDto dto1 = createProject("o1", "p1").setAiCodeFixEnabled(true); ProjectDto dto2 = createProject("o1", "p2"); @@ -484,6 +485,23 @@ class ProjectDaoIT { assertThat(projectDao.countProjects(db.getSession())).isEqualTo(10); } + @Test + void countProjects_by_ai_codefix_enablement() { + var dto1 = createProject("o1", "p1").setAiCodeFixEnabled(true); + var dto2 = createProject("o1", "p2"); + var dto3 = createProject("o1", "p3"); + + DbSession dbSession = db.getSession(); + + projectDao.insert(dbSession, dto1); + projectDao.insert(dbSession, dto2); + projectDao.insert(dbSession, dto3); + + assertThat(projectDao.countProjects(db.getSession())).isEqualTo(3); + assertThat(projectDao.countAiCodeFixEnabledProjects(db.getSession())).isEqualTo(1); + assertThat(projectDao.countAiCodeFixDisabledProjects(db.getSession())).isEqualTo(2); + } + private void assertProject(ProjectDto dto, String name, String kee, String uuid, String desc, @Nullable String tags, boolean isPrivate) { assertProject(dto, name, kee, uuid, desc, tags, isPrivate, false); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java index 876c8a0ff28..7b8583787c6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java @@ -159,4 +159,12 @@ public class ProjectDao implements Dao { public int countProjects(DbSession session) { return mapper(session).countProjects(); } + + public int countAiCodeFixEnabledProjects(DbSession session) { + return mapper(session).countProjectsByAiCodeFixEnablement(true); + } + + public int countAiCodeFixDisabledProjects(DbSession session) { + return mapper(session).countProjectsByAiCodeFixEnablement(false); + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java index 4b899aab902..e994de456f6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java @@ -77,4 +77,6 @@ public interface ProjectMapper { int countIndexedProjects(); int countProjects(); + + int countProjectsByAiCodeFixEnablement(@Param("aiCodeFixEnabled") boolean aiCodeFixEnabled); } 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 aa87a5f8900..3ca1ab6709a 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 @@ -226,4 +226,12 @@ where p.qualifier = 'TRK' + +