From 8bce129e9efa0cd8573e8f817ac32979fd43cfcc Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 4 Dec 2017 16:51:34 +0100 Subject: [PATCH] SONAR-10134 Add organization parameter in api/qualitygates/list --- .../sonar/db/qualitygate/QualityGateDao.java | 4 +- .../db/qualitygate/QualityGateMapper.java | 2 +- .../db/qualitygate/QualityGateMapper.xml | 12 +-- .../db/qualitygate/QualityGateDaoTest.java | 70 ++++++++------- .../server/qualitygate/ws/ListAction.java | 15 ++-- .../qualitygate/ws/QualityGatesWsSupport.java | 27 ------ .../qualitygate/RegisterQualityGatesTest.java | 60 +++++-------- .../server/qualitygate/ws/ListActionTest.java | 89 ++++++++++++++----- 8 files changed, 141 insertions(+), 138 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java index 11a5a704ca2..4c109c56ba9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java @@ -38,8 +38,8 @@ public class QualityGateDao implements Dao { mapper(dbSession).insertOrgQualityGate(uuid, organization.getUuid(), qualityGate.getUuid()); } - public Collection selectAll(DbSession session) { - return mapper(session).selectAll(); + public Collection selectAll(DbSession session, OrganizationDto organization) { + return mapper(session).selectAll(organization.getUuid()); } @CheckForNull diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java index e60464e237c..4d2d37058a5 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java @@ -28,7 +28,7 @@ public interface QualityGateMapper { void insertOrgQualityGate(@Param("uuid") String uuid, @Param("organizationUuid") String organizationUuid, @Param("qualityGateUuid") String qualityGateUuuid); - List selectAll(); + List selectAll(@Param("organizationUuid") String organizationUuid); QualityGateDto selectByName(String name); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml index ad1cedba967..ef19f754d53 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml @@ -27,11 +27,13 @@ VALUES (#{uuid, jdbcType=VARCHAR}, #{organizationUuid, jdbcType=VARCHAR}, #{qualityGateUuid, jdbcType=VARCHAR}) - + SELECT + + FROM quality_gates qg + INNER JOIN + org_quality_gates oqg ON oqg.quality_gate_uuid = qg.uuid AND oqg.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} + ORDER BY qg.name ASC