]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15498 Compute manually selected projects in portfolio
authorJacek <jacek.poreda@sonarsource.com>
Tue, 26 Oct 2021 09:58:48 +0000 (11:58 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 9 Nov 2021 20:03:15 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioProjectDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v92/CreatePortfolioProjectBranchesTable.java

index 4682d92edfd034e7ace3a8683993f91ba6060cea..6c008b9186aef2893866aff56555414cfd751f88 100644 (file)
@@ -202,12 +202,12 @@ public class PortfolioDao implements Dao {
     return mapper(dbSession).selectBranches(portfolioProjectUuid);
   }
 
-  public void addBranch(DbSession dbSession, String portfolioProjectUuid, String branchKey) {
-    mapper(dbSession).insertBranch(uuidFactory.create(), portfolioProjectUuid, branchKey, system2.now());
+  public void addBranch(DbSession dbSession, String portfolioProjectUuid, String branchUuid) {
+    mapper(dbSession).insertBranch(uuidFactory.create(), portfolioProjectUuid, branchUuid, system2.now());
   }
 
-  public void deleteBranch(DbSession dbSession, String portfolioUuid, String projectUuid, String branchKey) {
-    mapper(dbSession).deleteBranch(portfolioUuid, projectUuid, branchKey);
+  public void deleteBranch(DbSession dbSession, String portfolioUuid, String projectUuid, String branchUuid) {
+    mapper(dbSession).deleteBranch(portfolioUuid, projectUuid, branchUuid);
   }
 
   /*
index 02052e05db82526ffeeecef9572637406c5a5d48..0e848ccb50a2b1c370b287f7a4decc973e9c0af3 100644 (file)
@@ -94,11 +94,11 @@ public interface PortfolioMapper {
 
   List<ReferenceDto> selectAllReferencesInHierarchy(String rootUuid);
 
-  void deleteBranch(@Param("portfolioProjectUuid") String portfolioProjectUuid, @Param("branchKey") String branchKey);
+  void deleteBranch(@Param("portfolioProjectUuid") String portfolioProjectUuid, @Param("branchUuid") String branchUuid);
 
-  void deleteBranch(@Param("portfolioUuid") String portfolioUuid, @Param("projectUuid") String projectUuid, @Param("branchKey") String branchKey);
+  void deleteBranch(@Param("portfolioUuid") String portfolioUuid, @Param("projectUuid") String projectUuid, @Param("branchUuid") String branchUuid);
 
-  void insertBranch(@Param("uuid") String uuid, @Param("portfolioProjectUuid") String portfolioProjectUuid, @Param("branchKey") String branchKey,
+  void insertBranch(@Param("uuid") String uuid, @Param("portfolioProjectUuid") String portfolioProjectUuid, @Param("branchUuid") String branchUuid,
     @Param("createdAt") long createdAt);
 
   Set<String> selectBranches(String portfolioProjectUuid);
index e78de8efbe665bcefb2360f13051061ae8f22c67..aa6f374ff0fdcc10d711ddaf3877bf78a6909547 100644 (file)
@@ -27,7 +27,7 @@ public class PortfolioProjectDto {
   private String portfolioKey;
   private String projectUuid;
   private String projectKey;
-  private Set<String> branchKeys;
+  private Set<String> branchUuids;
   private long createdAt;
 
   public String getUuid() {
@@ -84,11 +84,11 @@ public class PortfolioProjectDto {
     return this;
   }
 
-  public Set<String> getBranchKeys() {
-    return branchKeys;
+  public Set<String> getBranchUuids() {
+    return branchUuids;
   }
 
-  public void setBranchKeys(Set<String> branchKeys) {
-    this.branchKeys = branchKeys;
+  public void setBranchUuids(Set<String> branchUuids) {
+    this.branchUuids = branchUuids;
   }
 }
index 519d19ea78590ab6647e3239f186399c7565dd9f..a07f7f293a796502f2dfd08395665f9d6b3e66df 100644 (file)
     pp.project_uuid as projectUuid,
     p.kee as projectKey,
     pp.created_at as createdAt,
-    ppb.branch_key as branchKey
+    ppb.branch_uuid as branchUuid
   </sql>
 
   <resultMap id="portfolioProjectResult" type="PortfolioProject" autoMapping="true">
     <id property="uuid" column="portfolioProject_uuid" />
-    <collection property="branchKeys" ofType="string">
-      <result column="branchKey" />
+    <collection property="branchUuids" ofType="string">
+      <result column="branchUuid" />
     </collection>
   </resultMap>
 
   </select>
 
   <select id="selectPortfolioProjectBranches" resultType="string">
-    SELECT ppb.branch_key
+    SELECT ppb.branch_uuid
     FROM portfolio_proj_branches ppb
     WHERE ppb.portfolio_project_uuid = #{id}
   </select>
     INSERT INTO portfolio_proj_branches (
       uuid,
       portfolio_project_uuid,
-      branch_key,
+      branch_uuid,
       created_at
     )
     VALUES (
       #{uuid,jdbcType=VARCHAR},
       #{portfolioProjectUuid,jdbcType=VARCHAR},
-      #{branchKey,jdbcType=VARCHAR},
+      #{branchUuid,jdbcType=VARCHAR},
       #{createdAt,jdbcType=BIGINT}
     )
   </insert>
       (select uuid from portfolio_projects
       where portfolio_uuid = #{portfolioUuid,jdbcType=VARCHAR}
       and project_uuid = #{projectUuid,jdbcType=VARCHAR})
-      and branch_key = #{branchKey,jdbcType=VARCHAR}
+      and branch_uuid = #{branchUuid,jdbcType=VARCHAR}
   </delete>
 
   <update id="update" parameterType="Portfolio">
index 8591380930a8c5d502b219e335d3f0f0e09d01a5..f2720a1e7e1b2e843c74e6887107c7d9225bb705 100644 (file)
@@ -567,7 +567,7 @@ CREATE UNIQUE INDEX "PLUGINS_KEY" ON "PLUGINS"("KEE");
 CREATE TABLE "PORTFOLIO_PROJ_BRANCHES"(
     "UUID" VARCHAR(40) NOT NULL,
     "PORTFOLIO_PROJECT_UUID" VARCHAR(40) NOT NULL,
-    "BRANCH_KEY" VARCHAR(255) NOT NULL,
+    "BRANCH_UUID" VARCHAR(40) NOT NULL,
     "CREATED_AT" BIGINT NOT NULL
 );
 ALTER TABLE "PORTFOLIO_PROJ_BRANCHES" ADD CONSTRAINT "PK_PORTFOLIO_PROJ_BRANCHES" PRIMARY KEY("UUID");
index 83a30202e65a92f151125245e5374961f76185be..c8c086f392be26b9c4f247de7fc2f3125b6b8581 100644 (file)
@@ -173,7 +173,7 @@ public class PortfolioDaoTest {
     portfolioDao.delete(session, p1);
     portfolioDao.delete(session, p3);
 
-    assertThat(db.select(session, "select branch_key from portfolio_proj_branches")).extracting(m -> m.values().iterator().next())
+    assertThat(db.select(session, "select branch_uuid from portfolio_proj_branches")).extracting(m -> m.values().iterator().next())
       .containsOnly("branch2");
     assertThat(db.select(session, "select uuid from portfolios")).extracting(m -> m.values().iterator().next())
       .containsOnly("p2", "p4");
@@ -423,16 +423,16 @@ public class PortfolioDaoTest {
     db.components().addPortfolioProject(portfolio1, project1);
 
     assertThat(db.countRowsOfTable(db.getSession(), "portfolio_proj_branches")).isZero();
-    assertThat(portfolioDao.selectPortfolioProjectOrFail(db.getSession(), portfolio1.getUuid(), project1.getUuid()).getBranchKeys()).isEmpty();
+    assertThat(portfolioDao.selectPortfolioProjectOrFail(db.getSession(), portfolio1.getUuid(), project1.getUuid()).getBranchUuids()).isEmpty();
 
     db.components().addPortfolioProjectBranch(portfolio1, project1, "branch1");
     assertThat(db.countRowsOfTable(db.getSession(), "portfolio_proj_branches")).isOne();
     PortfolioProjectDto portfolioProject = portfolioDao.selectPortfolioProjectOrFail(db.getSession(), portfolio1.getUuid(), project1.getUuid());
-    assertThat(portfolioProject.getBranchKeys()).containsOnly("branch1");
+    assertThat(portfolioProject.getBranchUuids()).containsOnly("branch1");
 
     portfolioDao.deleteBranch(db.getSession(), portfolio1.getUuid(), project1.getUuid(), "branch1");
     assertThat(db.countRowsOfTable(db.getSession(), "portfolio_proj_branches")).isZero();
-    assertThat(portfolioDao.selectPortfolioProjectOrFail(db.getSession(), portfolio1.getUuid(), project1.getUuid()).getBranchKeys()).isEmpty();
+    assertThat(portfolioDao.selectPortfolioProjectOrFail(db.getSession(), portfolio1.getUuid(), project1.getUuid()).getBranchUuids()).isEmpty();
   }
 
   @Test
@@ -482,7 +482,7 @@ public class PortfolioDaoTest {
     session.commit();
 
     assertThat(portfolioDao.selectAllProjectsInHierarchy(session, root.getUuid()))
-      .extracting(PortfolioProjectDto::getProjectUuid, PortfolioProjectDto::getBranchKeys)
+      .extracting(PortfolioProjectDto::getProjectUuid, PortfolioProjectDto::getBranchUuids)
       .containsExactlyInAnyOrder(tuple("p1", Set.of("branch1")), tuple("p2", emptySet()), tuple("p3", emptySet()));
     assertThat(portfolioDao.selectAllProjectsInHierarchy(session, "nonexisting")).isEmpty();
   }
index b47fe7a9d99d660464fa68296934ff76d1cf402a..a08cc4ee0382bc430769e282f6c0676655abc2d1 100644 (file)
@@ -302,9 +302,17 @@ public class ComponentDbTester {
     db.commit();
   }
 
-  public void addPortfolioProjectBranch(PortfolioDto portfolio, ProjectDto project, String branchKey) {
-    PortfolioProjectDto portfolioProject = dbClient.portfolioDao().selectPortfolioProjectOrFail(dbSession, portfolio.getUuid(), project.getUuid());
-    dbClient.portfolioDao().addBranch(db.getSession(), portfolioProject.getUuid(), branchKey);
+  public void addPortfolioProjectBranch(PortfolioDto portfolio, ProjectDto project, String branchUuid) {
+    addPortfolioProjectBranch(portfolio, project.getUuid(), branchUuid);
+  }
+
+  public void addPortfolioProjectBranch(PortfolioDto portfolio, String projectUuid, String branchUuid) {
+    addPortfolioProjectBranch(portfolio.getUuid(), projectUuid, branchUuid);
+  }
+
+  public void addPortfolioProjectBranch(String portfolioUuid, String projectUuid, String branchUuid) {
+    PortfolioProjectDto portfolioProject = dbClient.portfolioDao().selectPortfolioProjectOrFail(dbSession, portfolioUuid, projectUuid);
+    dbClient.portfolioDao().addBranch(db.getSession(), portfolioProject.getUuid(), branchUuid);
     db.commit();
   }
 
index bbb8cc5996b257a207566495dd081796e59ae4aa..2c2b98615da9a25855f0c08c658f7aa1ee0b502b 100644 (file)
@@ -30,7 +30,7 @@ import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_S
 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
 
 public class CreatePortfolioProjectBranchesTable extends DdlChange {
-  private final static String TABLE_NAME = "portfolio_proj_branches";
+  private static final String TABLE_NAME = "portfolio_proj_branches";
 
   public CreatePortfolioProjectBranchesTable(Database db) {
     super(db);
@@ -42,7 +42,7 @@ public class CreatePortfolioProjectBranchesTable extends DdlChange {
       context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
         .addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
         .addColumn(newVarcharColumnDefBuilder().setColumnName("portfolio_project_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
-        .addColumn(newVarcharColumnDefBuilder().setColumnName("branch_key").setIsNullable(false).setLimit(255).build())
+        .addColumn(newVarcharColumnDefBuilder().setColumnName("branch_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
         .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
         .build());
     }