From: Eric Hartmann Date: Fri, 1 Dec 2017 17:49:27 +0000 (+0100) Subject: SONAR-10134 Allow creating quality gates in organization (wip) X-Git-Tag: 7.0-RC1~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5dc6808e0f139cc8468f0f8e20f42bbf0156800a;p=sonarqube.git SONAR-10134 Allow creating quality gates in organization (wip) --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QGateWithOrgDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QGateWithOrgDto.java new file mode 100644 index 00000000000..78e96ec2cbb --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QGateWithOrgDto.java @@ -0,0 +1,75 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.qualitygate; + +import java.util.Date; + +/** + * This Dto is a join between QualityGates and Organizations. + * + * Tables : QUALITY_GATES joined with ORG_QUALITY_GATES + */ +public class QGateWithOrgDto extends QualityGateDto { + private String organizationUuid; + + public String getOrganizationUuid() { + return organizationUuid; + } + + public void setOrganizationUuid(String organizationUuid) { + this.organizationUuid = organizationUuid; + } + + @Override + public QGateWithOrgDto setUuid(String uuid) { + super.setUuid(uuid); + return this; + } + + @Override + public QGateWithOrgDto setId(Long id) { + super.setId(id); + return this; + } + + @Override + public QGateWithOrgDto setName(String name) { + super.setName(name); + return this; + } + + @Override + public QGateWithOrgDto setBuiltIn(boolean builtIn) { + super.setBuiltIn(builtIn); + return this; + } + + @Override + public QGateWithOrgDto setCreatedAt(Date createdAt) { + super.setCreatedAt(createdAt); + return this; + } + + @Override + public QGateWithOrgDto setUpdatedAt(Date updatedAt) { + super.setUpdatedAt(updatedAt); + return this; + } +} 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 0a9d4e314a5..f27486a2c0c 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 @@ -24,15 +24,20 @@ import java.util.Date; import javax.annotation.CheckForNull; import org.sonar.db.Dao; import org.sonar.db.DbSession; +import org.sonar.db.organization.OrganizationDto; public class QualityGateDao implements Dao { public QualityGateDto insert(DbSession session, QualityGateDto newQualityGate) { - mapper(session).insert(newQualityGate.setCreatedAt(new Date())); + mapper(session).insertQualityGate(newQualityGate.setCreatedAt(new Date())); return newQualityGate; } + public void associate(DbSession dbSession, String uuid, OrganizationDto organization, QualityGateDto qualityGate) { + mapper(dbSession).insertOrgQualityGate(uuid, organization.getUuid(), qualityGate.getUuid()); + } + public Collection selectAll(DbSession session) { return mapper(session).selectAll(); } @@ -47,6 +52,10 @@ public class QualityGateDao implements Dao { return mapper(session).selectById(id); } + public QGateWithOrgDto selectByOrganizationAndUuid(DbSession dbSession, OrganizationDto organization, String qualityGateUuid) { + return mapper(dbSession).selectByUuidAndOrganization(qualityGateUuid, 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 39d91acd1f3..bdaa78e1d4a 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 @@ -20,10 +20,13 @@ package org.sonar.db.qualitygate; import java.util.List; +import org.apache.ibatis.annotations.Param; public interface QualityGateMapper { - void insert(QualityGateDto qualityGate); + void insertQualityGate(QualityGateDto qualityGate); + + void insertOrgQualityGate(@Param("uuid") String uuid, @Param("organizationUuid") String organizationUuid, @Param("qualityGateUuid") String qualityGateUuuid); List selectAll(); @@ -31,6 +34,8 @@ public interface QualityGateMapper { QualityGateDto selectById(long id); + QGateWithOrgDto selectByUuidAndOrganization(@Param("qualityGateUuid") String qualityGateUuid, @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 35bd1ace13e..32eeef3b838 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,9 +3,14 @@ - - insert into quality_gates (name, uuid, is_built_in, created_at, updated_at) - values (#{name}, #{uuid}, #{isBuiltIn}, #{createdAt}, #{updatedAt}) + + insert into quality_gates (uuid, name, is_built_in, created_at, updated_at) + values (#{uuid}, #{name}, #{isBuiltIn}, #{createdAt}, #{updatedAt}) + + + + INSERT INTO org_quality_gates (uuid, organization_uuid, quality_gate_uuid) + VALUES (#{uuid}, #{organizationUuid}, #{qualityGateUuid}) @@ -26,6 +31,25 @@ where name=#{name} + + +