From c92c331f65b7f8a2c4fee81568f8768749822684 Mon Sep 17 00:00:00 2001 From: Klaudio Sinani Date: Wed, 15 Dec 2021 11:00:35 +0100 Subject: [PATCH] SONAR-15805 Add new endpoints for addition and removal of application branches --- .../org/sonar/db/portfolio/PortfolioDao.java | 7 +++-- .../sonar/db/portfolio/PortfolioMapper.java | 4 ++- .../sonar/db/portfolio/PortfolioMapper.xml | 7 +++++ .../sonar/db/portfolio/PortfolioDaoTest.java | 27 ++++++++++++++++++- .../sonar/db/component/ComponentDbTester.java | 2 +- .../java/org/sonar/server/ws/KeyExamples.java | 2 ++ 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java index a51da341d13..8e5a8bed10e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.System2; import org.sonar.core.util.UuidFactory; @@ -125,7 +124,7 @@ public class PortfolioDao implements Dao { /* * Portfolio references */ - public void addReference(DbSession dbSession, String portfolioUuid, String referenceUuid, @Nullable String branchUuid) { + public void addReferenceBranch(DbSession dbSession, String portfolioUuid, String referenceUuid, String branchUuid) { mapper(dbSession).insertReference(uuidFactory.create(), portfolioUuid, referenceUuid, branchUuid, system2.now()); } @@ -169,6 +168,10 @@ public class PortfolioDao implements Dao { mapper(dbSession).deleteAllReferences(); } + public int deleteReferenceBranch(DbSession dbSession, String portfolioUuid, String referenceUuid, String branchUuid) { + return mapper(dbSession).deleteReferenceBranch(portfolioUuid, referenceUuid, branchUuid); + } + public int deleteReference(DbSession dbSession, String portfolioUuid, String referenceUuid) { return mapper(dbSession).deleteReference(portfolioUuid, referenceUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java index 18eb88c66b6..d345a46ef5e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java @@ -44,7 +44,7 @@ public interface PortfolioMapper { void deleteReferencesByPortfolioOrReferenceUuids(@Param("uuids") Set uuids); void insertReference(@Param("uuid") String uuid, @Param("portfolioUuid") String portfolioUuid, @Param("referenceUuid") String referenceUuid, - @Nullable @Param("branchUuid") String branchUuid, @Param("createdAt") long createdAt); + @Nullable @Param("branchUuid") String branchUuid, @Param("createdAt") long createdAt); void insertProject(@Param("uuid") String uuid, @Param("portfolioUuid") String portfolioUuid, @Param("projectUuid") String projectUuid, @Param("createdAt") long createdAt); @@ -104,4 +104,6 @@ public interface PortfolioMapper { @Param("createdAt") long createdAt); List selectAllDirectChildApplications(@Param("portfolioUuid") String portfolioUuid); + + int deleteReferenceBranch(@Param("portfolioUuid") String portfolioUuid, @Param("referenceUuid") String referenceUuid, @Param("branchUuid") String branchUuid); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml index 5c43e2eba7d..1ab2f4ae208 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml @@ -233,6 +233,13 @@ AND reference_uuid = #{referenceUuid,jdbcType=VARCHAR} + + DELETE FROM portfolio_references + WHERE portfolio_uuid = #{portfolioUuid,jdbcType=VARCHAR} + AND reference_uuid = #{referenceUuid,jdbcType=VARCHAR} + AND branch_uuid = #{branchUuid,jdbcType=VARCHAR} + +