From fa6663db4630550b3c27c71bb62fea4c4b9c262c Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 4 Dec 2017 11:46:07 +0100 Subject: [PATCH] SONAR-10134 Add organization parameter in api/qualitygates/show --- .../sonar/db/qualitygate/QualityGateDao.java | 5 + .../db/qualitygate/QualityGateMapper.java | 2 + .../db/qualitygate/QualityGateMapper.xml | 41 +++-- .../db/qualitygate/QualityGateDaoTest.java | 25 +++ .../db/qualitygate/QualityGateDbTester.java | 11 +- .../server/qualitygate/QualityGateFinder.java | 11 -- .../qualitygate/ws/QualityGatesWsSupport.java | 36 ++++- .../server/qualitygate/ws/ShowAction.java | 25 ++- .../qualitygate/QualityGateFinderTest.java | 31 ---- .../server/qualitygate/ws/ShowActionTest.java | 151 ++++++++++++++---- 10 files changed, 243 insertions(+), 95 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 f27486a2c0c..11a5a704ca2 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 @@ -56,6 +56,11 @@ public class QualityGateDao implements Dao { return mapper(dbSession).selectByUuidAndOrganization(qualityGateUuid, organization.getUuid()); } + @CheckForNull + public QGateWithOrgDto selectByOrganizationAndName(DbSession session, OrganizationDto organization, String name) { + return mapper(session).selectByNameAndOrganization(name, organization.getUuid()); + } + public void delete(QualityGateDto qGate, DbSession session) { mapper(session).delete(qGate.getId()); } 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 bdaa78e1d4a..e60464e237c 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 @@ -36,6 +36,8 @@ public interface QualityGateMapper { QGateWithOrgDto selectByUuidAndOrganization(@Param("qualityGateUuid") String qualityGateUuid, @Param("organizationUuid") String organizationUuid); + QGateWithOrgDto selectByNameAndOrganization(@Param("name") String name, @Param("organizationUuid") String organizationUuid); + QualityGateDto selectBuiltIn(); void delete(long id); 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 00070e4180c..ad1cedba967 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 @@ -3,6 +3,20 @@ + + id, name, uuid, is_built_in as isBuiltIn, created_at as createdAt, updated_at as updatedAt + + + + qg.id as id, + qg.uuid as uuid, + qg.name as name, + qg.is_built_in as isBuiltIn, + oqg.organization_uuid as organizationUuid, + qg.created_at as createdAt, + qg.updated_at as updatedAd + + insert into quality_gates (uuid, name, is_built_in, created_at, updated_at) values (#{uuid, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{isBuiltIn, jdbcType=BOOLEAN}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}) @@ -13,10 +27,6 @@ VALUES (#{uuid, jdbcType=VARCHAR}, #{organizationUuid, jdbcType=VARCHAR}, #{qualityGateUuid, jdbcType=VARCHAR}) - - id, name, uuid, is_built_in as isBuiltIn, created_at as createdAt, updated_at as updatedAt - - SELECT - qg.id as id, - qg.uuid as uuid, - qg.name as name, - qg.is_built_in as isBuiltIn, - oqg.organization_uuid as organizationUuid, - qg.created_at as createdAt, - qg.updated_at as updatedAd + FROM quality_gates qg INNER JOIN - org_quality_gates oqg ON oqg.quality_gate_uuid = qg.uuid + org_quality_gates oqg ON oqg.quality_gate_uuid = qg.uuid AND oqg.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} WHERE - qg.uuid = #{qualityGateUuid, jdbcType=VARCHAR} AND - oqg.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} + qg.uuid = #{qualityGateUuid, jdbcType=VARCHAR} +