From: Zipeng WU Date: Thu, 2 Dec 2021 16:59:56 +0000 (+0100) Subject: SONAR-15726 Inform previously selected projects in applications within the portfolio... X-Git-Tag: 9.3.0.51899~134 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9f9854b22fab9b1be8f9df641d1bc7fa67fdc429;p=sonarqube.git SONAR-15726 Inform previously selected projects in applications within the portfolio hierarchy --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index 4db01625cce..bb512f589f6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -100,6 +100,7 @@ import org.sonar.db.portfolio.PortfolioDto; import org.sonar.db.portfolio.PortfolioMapper; import org.sonar.db.portfolio.PortfolioProjectDto; import org.sonar.db.portfolio.PortfolioReferenceDto; +import org.sonar.db.project.ApplicationProjectDto; import org.sonar.db.project.ProjectBadgeTokenDto; import org.sonar.db.project.ProjectBadgeTokenMapper; import org.sonar.db.project.ProjectDto; @@ -179,6 +180,7 @@ public class MyBatis implements Startable { // DTO aliases, keep them sorted alphabetically confBuilder.loadAlias("ActiveRule", ActiveRuleDto.class); confBuilder.loadAlias("ActiveRuleParam", ActiveRuleParamDto.class); + confBuilder.loadAlias("ApplicationProject", ApplicationProjectDto.class); confBuilder.loadAlias("CeTaskCharacteristic", CeTaskCharacteristicDto.class); confBuilder.loadAlias("Component", ComponentDto.class); confBuilder.loadAlias("ComponentWithModuleUuid", ComponentWithModuleUuidDto.class); 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 0b8209472f8..d69f36e8c1a 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 @@ -30,6 +30,7 @@ import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.ComponentNewValue; +import org.sonar.db.project.ApplicationProjectDto; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; @@ -55,6 +56,17 @@ public class PortfolioDao implements Dao { return mapper(dbSession).selectAllRoots(); } + /** + * select all application projects belong to the hierarchy of a portfolio + * + * @param dbSession + * @param rootPortfolioUuid + * @return + */ + public List selectAllApplicationProjects(DbSession dbSession, String rootPortfolioUuid) { + return mapper(dbSession).selectAllApplicationProjects(rootPortfolioUuid); + } + public List selectAll(DbSession dbSession) { return mapper(dbSession).selectAll(); } 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 0554a04213d..fe77eabae7a 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 @@ -24,6 +24,7 @@ import java.util.List; import java.util.Set; import javax.annotation.CheckForNull; import org.apache.ibatis.annotations.Param; +import org.sonar.db.project.ApplicationProjectDto; public interface PortfolioMapper { @CheckForNull @@ -66,6 +67,8 @@ public interface PortfolioMapper { List selectAllRoots(); + List selectAllApplicationProjects(String rootPortfolioUuid); + List selectAll(); List selectRootOfReferencers(String referenceUuid); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ApplicationProjectDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ApplicationProjectDto.java new file mode 100644 index 00000000000..069fc47eb48 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ApplicationProjectDto.java @@ -0,0 +1,43 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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.project; + +public class ApplicationProjectDto { + private String appUuid; + private String appKey; + private String projectUuid; + + public ApplicationProjectDto() { + // Do Nothing + } + + public String getAppUuid() { + return appUuid; + } + + public String getAppKey() { + return appKey; + } + + public String getProjectUuid() { + return projectUuid; + } + +} 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 08789406dd4..e894c7afecd 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 @@ -34,16 +34,15 @@ pp.project_uuid as projectUuid, pp.portfolio_uuid as portfolioUuid, pf.kee as portfolioKey, - pp.project_uuid as projectUuid, p.kee as projectKey, pp.created_at as createdAt, ppb.branch_uuid as branchUuid - + - + @@ -151,31 +150,49 @@ + + + ap.application_uuid as appUuid, + ap.project_uuid as projectUuid, + p.kee as appKey + + + - SELECT - + FROM portfolios p INNER JOIN portfolio_references pr ON p.uuid = pr.portfolio_uuid WHERE pr.reference_uuid=#{referenceUuid,jdbcType=VARCHAR} @@ -184,7 +201,7 @@ DELETE FROM portfolio_references WHERE - portfolio_uuid = #{portfolioUuid,jdbcType=VARCHAR} + portfolio_uuid = #{portfolioUuid,jdbcType=VARCHAR} AND reference_uuid = #{referenceUuid,jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java index b4ca9c42ee7..74d282a5b04 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java @@ -28,6 +28,7 @@ import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.audit.AuditPersister; +import org.sonar.db.project.ApplicationProjectDto; import org.sonar.db.project.ProjectDto; import static java.util.Collections.emptySet; @@ -248,6 +249,26 @@ public class PortfolioDaoTest { .containsOnly(tuple("portfolio3", app1.getUuid())); } + @Test + public void selectAllApplicationProjectsBelongToTheSamePortfolio() { + var portfolio = db.components().insertPrivatePortfolioDto("portfolio1"); + var app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1")); + var app2 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app2")); + var project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:one").setName("Projet Un")); + var project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("project:two").setName("Projet Deux")); + + db.components().addApplicationProject(app1, project1); + db.components().addApplicationProject(app2, project2); + db.components().addPortfolioReference(portfolio, app1.getUuid()); + db.components().addPortfolioReference(portfolio, app2.getUuid()); + + assertThat(portfolioDao.selectAllApplicationProjects(session, portfolio.getRootUuid())) + .extracting(ApplicationProjectDto::getAppUuid, ApplicationProjectDto::getAppKey, ApplicationProjectDto::getProjectUuid) + .containsOnly( + tuple(app1.getUuid(), "app1", project1.getUuid()), + tuple(app2.getUuid(), "app2", project2.getUuid())); + } + @Test public void add_and_select_references_by_uuid() { assertThat(portfolioDao.selectPortfolioProjects(session, "portfolio1")).isEmpty();