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;
// 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);
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;
return mapper(dbSession).selectAllRoots();
}
+ /**
+ * select all application projects belong to the hierarchy of a portfolio
+ *
+ * @param dbSession
+ * @param rootPortfolioUuid
+ * @return
+ */
+ public List<ApplicationProjectDto> selectAllApplicationProjects(DbSession dbSession, String rootPortfolioUuid) {
+ return mapper(dbSession).selectAllApplicationProjects(rootPortfolioUuid);
+ }
+
public List<PortfolioDto> selectAll(DbSession dbSession) {
return mapper(dbSession).selectAll();
}
import java.util.Set;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
+import org.sonar.db.project.ApplicationProjectDto;
public interface PortfolioMapper {
@CheckForNull
List<PortfolioDto> selectAllRoots();
+ List<ApplicationProjectDto> selectAllApplicationProjects(String rootPortfolioUuid);
+
List<PortfolioDto> selectAll();
List<PortfolioDto> selectRootOfReferencers(String referenceUuid);
--- /dev/null
+/*
+ * 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;
+ }
+
+}
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
</sql>
<resultMap id="portfolioProjectResult" type="PortfolioProject" autoMapping="true">
- <id property="uuid" column="portfolioProject_uuid" />
+ <id property="uuid" column="portfolioProject_uuid"/>
<collection property="branchUuids" ofType="string">
- <result column="branchUuid" />
+ <result column="branchUuid"/>
</collection>
</resultMap>
<select id="selectReferenceUuids" resultType="String">
SELECT
- p.reference_uuid
+ p.reference_uuid
FROM portfolio_references p
where
- p.portfolio_uuid=#{portfolioUuid,jdbcType=VARCHAR}
+ p.portfolio_uuid=#{portfolioUuid,jdbcType=VARCHAR}
</select>
<select id="selectRootOfReferencers" resultType="Portfolio">
- SELECT distinct <include refid="portfolioColumns"/>
+ SELECT distinct
+ <include refid="portfolioColumns"/>
FROM portfolios c
INNER JOIN portfolio_references pr on pr.portfolio_uuid = c.uuid
INNER JOIN portfolios p on p.uuid = c.root_uuid
where
- pr.reference_uuid=#{referenceUuid,jdbcType=VARCHAR}
+ pr.reference_uuid=#{referenceUuid,jdbcType=VARCHAR}
+ </select>
+
+ <sql id="applicationProjectColumns">
+ ap.application_uuid as appUuid,
+ ap.project_uuid as projectUuid,
+ p.kee as appKey
+ </sql>
+
+ <select id="selectAllApplicationProjects" parameterType="String" resultType="ApplicationProject">
+ SELECT
+ <include refid="applicationProjectColumns"/>
+ FROM portfolio_references pr
+ INNER JOIN projects p ON p.uuid = pr.reference_uuid
+ INNER JOIN portfolios pf ON pr.portfolio_uuid = pf.uuid
+ INNER JOIN app_projects ap ON ap.application_uuid = p.uuid
+ WHERE pf.root_uuid = #{rootPortfolioUuid}
</select>
<select id="selectTree" parameterType="String" resultType="Portfolio">
- SELECT <include refid="portfolioColumns"/>
+ SELECT
+ <include refid="portfolioColumns"/>
FROM portfolios p
INNER JOIN portfolios p2 ON p.root_uuid = p2.root_uuid
WHERE p2.uuid=#{portfolioUuid,jdbcType=VARCHAR}
</select>
- <select id="selectReferencers" resultType="Portfolio">
+ <select id="selectReferencers" resultType="Portfolio">
SELECT
- <include refid="portfolioColumns"/>
+ <include refid="portfolioColumns"/>
FROM portfolios p
INNER JOIN portfolio_references pr ON p.uuid = pr.portfolio_uuid
WHERE pr.reference_uuid=#{referenceUuid,jdbcType=VARCHAR}
<delete id="deleteReference">
DELETE FROM portfolio_references
WHERE
- portfolio_uuid = #{portfolioUuid,jdbcType=VARCHAR}
+ portfolio_uuid = #{portfolioUuid,jdbcType=VARCHAR}
AND reference_uuid = #{referenceUuid,jdbcType=VARCHAR}
</delete>
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;
.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();