From: Matteo Mara Date: Wed, 18 Sep 2024 12:02:01 +0000 (+0200) Subject: SONAR-23064 Add POST endpoint api/projects/set_ai_code_assurance X-Git-Tag: 10.7.0.96327~51 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8f0de0706aafbffdd83cdfd91b845a49e61d4285;p=sonarqube.git SONAR-23064 Add POST endpoint api/projects/set_ai_code_assurance --- 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 b11f64c0a94..6209b00b976 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 @@ -262,6 +262,28 @@ class ProjectDaoIT { assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", true); } + @Test + void update_aiCodeAssurance() { + ProjectDto dto1 = createProject("o1", "p1").setAiCodeAssurance(true); + ProjectDto dto2 = createProject("o1", "p2"); + + projectDao.insert(db.getSession(), dto1); + projectDao.insert(db.getSession(), dto2); + + List projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); + assertThat(projectsByUuids).hasSize(2); + assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false, true); + assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false, false); + + projectDao.updateAiCodeAssurance(db.getSession(), dto1.getUuid(), false); + projectDao.updateAiCodeAssurance(db.getSession(), dto2.getUuid(), true); + + projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2"))); + assertThat(projectsByUuids).hasSize(2); + assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false, false); + assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false, true); + } + @Test void select_by_uuids() { ProjectDto dto1 = createProject("o1", "p1"); @@ -490,8 +512,12 @@ class ProjectDaoIT { } private void assertProject(ProjectDto dto, String name, String kee, String uuid, String desc, @Nullable String tags, boolean isPrivate) { - assertThat(dto).extracting("name", "kee", "key", "uuid", "description", "tagsString", "private") - .containsExactly(name, kee, kee, uuid, desc, tags, isPrivate); + assertProject(dto, name, kee, uuid, desc, tags, isPrivate, false); + } + + private void assertProject(ProjectDto dto, String name, String kee, String uuid, String desc, @Nullable String tags, boolean isPrivate, boolean isAiCodeAssurance) { + assertThat(dto).extracting("name", "kee", "key", "uuid", "description", "tagsString", "private", "aiCodeAssurance") + .containsExactly(name, kee, kee, uuid, desc, tags, isPrivate, isAiCodeAssurance); } private ProjectDto createProject(String org, String name) { 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 7da97de7eef..20f41f79227 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 @@ -123,6 +123,10 @@ public class ProjectDao implements Dao { mapper(session).updateVisibility(uuid, isPrivate, system2.now()); } + public void updateAiCodeAssurance(DbSession session, String uuid, boolean aiCodeAssurance) { + mapper(session).updateAiCodeAssurance(uuid, aiCodeAssurance, system2.now()); + } + public void updateTags(DbSession session, ProjectDto project) { mapper(session).updateTags(project); } 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 c31542346f4..3ee4d95435d 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 @@ -59,6 +59,8 @@ public interface ProjectMapper { void updateVisibility(@Param("uuid") String uuid, @Param("isPrivate") boolean isPrivate, @Param("updatedAt") long updatedAt); + void updateAiCodeAssurance(@Param("uuid") String uuid, @Param("aiCodeAssurance") boolean aiCodeAssurance, @Param("updatedAt") long updatedAt); + List selectAllApplications(); List selectApplicationsByKeys(@Param("kees") Collection kees); 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 47e09da2ec7..abfd58f2f88 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 @@ -219,6 +219,13 @@ uuid = #{uuid,jdbcType=VARCHAR} + + update projects set + ai_code_assurance = #{aiCodeAssurance,jdbcType=BOOLEAN}, + updated_at = #{updatedAt,jdbcType=BIGINT} + where + uuid = #{uuid,jdbcType=VARCHAR} + update projects set