aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorZipeng WU <zipeng.wu@sonarsource.com>2021-12-20 12:36:27 +0100
committersonartech <sonartech@sonarsource.com>2021-12-27 20:02:47 +0000
commit5ab4879d3fbfe97e2fd4f29cab57c7c415576b35 (patch)
tree537a2ceda9889b92a5a108afb43ba78767b334f2 /server/sonar-db-dao
parent861150353a67955c0e81ab8e0d0be4d3a9d69c1d (diff)
downloadsonarqube-5ab4879d3fbfe97e2fd4f29cab57c7c415576b35.tar.gz
sonarqube-5ab4879d3fbfe97e2fd4f29cab57c7c415576b35.zip
SONAR-15802 Update computation of portfolios
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsDao.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsMapper.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java26
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java17
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ApplicationProjectsMapper.xml37
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml52
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ApplicationProjectsDaoTest.java14
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java102
8 files changed, 195 insertions, 65 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsDao.java
index 2247ea08e94..7aebe16a83d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsDao.java
@@ -82,8 +82,12 @@ public class ApplicationProjectsDao implements Dao {
getMapper(dbSession).removeProjectBranchFromAppBranch(applicationBranchUuid, projectBranchUuid);
}
- public Set<BranchDto> selectProjectBranchesFromAppBranch(DbSession dbSession, String applicationBranchUuid) {
- return getMapper(dbSession).selectProjectBranchesFromAppBranch(applicationBranchUuid);
+ public Set<BranchDto> selectProjectBranchesFromAppBranchUuid(DbSession dbSession, String applicationBranchUuid) {
+ return getMapper(dbSession).selectProjectBranchesFromAppBranchUuid(applicationBranchUuid);
+ }
+
+ public Set<BranchDto> selectProjectBranchesFromAppBranchKey(DbSession dbSession, String applicationUuid, String applicationBranchKey) {
+ return getMapper(dbSession).selectProjectBranchesFromAppBranchKey(applicationUuid, applicationBranchKey);
}
public Set<ProjectDto> selectApplicationsFromProjectBranch(DbSession dbSession, String projectUuid, String branchKey) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsMapper.java
index 261d377b1d0..0764b951a1a 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ApplicationProjectsMapper.java
@@ -55,7 +55,9 @@ public interface ApplicationProjectsMapper {
void removeProjectBranchFromAppBranch(@Param("applicationBranchUuid") String applicationBranchUuid, @Param("projectBranchUuid") String projectBranchUuid);
- Set<BranchDto> selectProjectBranchesFromAppBranch(@Param("applicationBranchUuid") String applicationBranchUuid);
+ Set<BranchDto> selectProjectBranchesFromAppBranchUuid(@Param("applicationBranchUuid") String applicationBranchUuid);
+
+ Set<BranchDto> selectProjectBranchesFromAppBranchKey(@Param("applicationUuid") String applicationUuid, @Param("applicationBranchKey") String applicationBranchKey);
int countApplicationProjects(@Param("applicationUuid") String applicationUuid);
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 8e5a8bed10e..35a56b845ac 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
@@ -31,7 +31,6 @@ 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 org.sonar.db.project.ProjectDto;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
@@ -140,16 +139,20 @@ public class PortfolioDao implements Dao {
return mapper(dbSession).selectAllReferencesToApplications();
}
- public List<ProjectDto> selectAllDirectChildApplications(DbSession dbSession, String portfolioUuid) {
- return mapper(dbSession).selectAllDirectChildApplications(portfolioUuid);
+ public List<ReferenceDto> selectAllReferencesToPortfoliosInHierarchy(DbSession dbSession, String rootUuid) {
+ return mapper(dbSession).selectAllReferencesToPortfoliosInHierarchy(rootUuid);
}
- public Set<String> selectReferenceUuids(DbSession dbSession, String portfolioUuid) {
- return mapper(dbSession).selectReferenceUuids(portfolioUuid);
+ public List<ReferenceDto> selectAllReferencesToApplicationsInHierarchy(DbSession dbSession, String rootUuid) {
+ return mapper(dbSession).selectAllReferencesToApplicationsInHierarchy(rootUuid);
+ }
+
+ public List<String> selectApplicationReferenceUuids(DbSession dbSession, String portfolioUuid) {
+ return mapper(dbSession).selectApplicationReferenceUuids(portfolioUuid);
}
- public List<ReferenceDto> selectAllReferencesInHierarchy(DbSession dbSession, String uuid) {
- return mapper(dbSession).selectAllReferencesInHierarchy(uuid);
+ public Set<String> selectReferenceUuids(DbSession dbSession, String portfolioUuid) {
+ return mapper(dbSession).selectReferenceUuids(portfolioUuid);
}
public List<PortfolioDto> selectReferencers(DbSession dbSession, String referenceUuid) {
@@ -160,6 +163,14 @@ public class PortfolioDao implements Dao {
return mapper(dbSession).selectRootOfReferencers(referenceUuid);
}
+ public List<PortfolioDto> selectRootOfReferencersToMainBranch(DbSession dbSession, String referenceUuid) {
+ return mapper(dbSession).selectRootOfReferencersToMainBranch(referenceUuid);
+ }
+
+ public List<PortfolioDto> selectRootOfReferencersToAppBranch(DbSession dbSession, String appUuid, String appBranchKey) {
+ return mapper(dbSession).selectRootOfReferencersToAppBranch(appUuid, appBranchKey);
+ }
+
public void deleteReferencesTo(DbSession dbSession, String referenceUuid) {
mapper(dbSession).deleteReferencesTo(referenceUuid);
}
@@ -251,4 +262,5 @@ public class PortfolioDao implements Dao {
private static String qualifier(PortfolioDto portfolioDto) {
return portfolioDto.isRoot() ? Qualifiers.VIEW : Qualifiers.SUBVIEW;
}
+
}
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 d345a46ef5e..201e3eff0bd 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
@@ -26,7 +26,6 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
import org.sonar.db.project.ApplicationProjectDto;
-import org.sonar.db.project.ProjectDto;
public interface PortfolioMapper {
@CheckForNull
@@ -44,7 +43,7 @@ public interface PortfolioMapper {
void deleteReferencesByPortfolioOrReferenceUuids(@Param("uuids") Set<String> 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);
@@ -76,6 +75,8 @@ public interface PortfolioMapper {
List<PortfolioDto> selectRootOfReferencers(String referenceUuid);
+ List<PortfolioDto> selectRootOfReferencersToMainBranch(String referenceUuid);
+
void deleteReferencesTo(String referenceUuid);
void deleteProjects(String portfolioUuid);
@@ -96,14 +97,18 @@ public interface PortfolioMapper {
List<PortfolioProjectDto> selectAllPortfolioProjects();
- List<ReferenceDto> selectAllReferencesInHierarchy(String rootUuid);
-
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("branchUuid") String branchUuid,
- @Param("createdAt") long createdAt);
+ @Param("createdAt") long createdAt);
- List<ProjectDto> selectAllDirectChildApplications(@Param("portfolioUuid") String portfolioUuid);
+ List<String> selectApplicationReferenceUuids(@Param("portfolioUuid") String portfolioUuid);
int deleteReferenceBranch(@Param("portfolioUuid") String portfolioUuid, @Param("referenceUuid") String referenceUuid, @Param("branchUuid") String branchUuid);
+
+ List<ReferenceDto> selectAllReferencesToPortfoliosInHierarchy(String rootUuid);
+
+ List<ReferenceDto> selectAllReferencesToApplicationsInHierarchy(String rootUuid);
+
+ List<PortfolioDto> selectRootOfReferencersToAppBranch(@Param("appUuid") String appUuid, @Param("appBranchKey") String appBranchKey);
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ApplicationProjectsMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ApplicationProjectsMapper.xml
index 6a8f8a7011f..747ce122c2b 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ApplicationProjectsMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ApplicationProjectsMapper.xml
@@ -117,26 +117,45 @@
app_branch_project_branch.project_branch_uuid = #{projectBranchUuid,jdbcType=VARCHAR}
</delete>
- <select id="selectProjectBranchesFromAppBranch" parameterType="String" resultType="org.sonar.db.component.BranchDto">
+ <select id="selectProjectBranchesFromAppBranchUuid" parameterType="String" resultType="org.sonar.db.component.BranchDto">
SELECT
- <include refid="branchColumns"/>
+ <include refid="branchColumns"/>
FROM
- app_branch_project_branch
+ app_branch_project_branch
INNER JOIN
- project_branches pb
+ project_branches pb
ON
- app_branch_project_branch.project_branch_uuid = pb.uuid
+ app_branch_project_branch.project_branch_uuid = pb.uuid
WHERE
- app_branch_project_branch.application_branch_uuid = #{applicationBranchUuid,jdbcType=VARCHAR}
+ app_branch_project_branch.application_branch_uuid = #{applicationBranchUuid,jdbcType=VARCHAR}
+ </select>
+
+ <select id="selectProjectBranchesFromAppBranchKey" resultType="org.sonar.db.component.BranchDto">
+ SELECT
+ <include refid="branchColumns"/>
+ FROM
+ app_branch_project_branch
+ INNER JOIN
+ project_branches pb
+ ON
+ app_branch_project_branch.project_branch_uuid = pb.uuid
+ INNER JOIN
+ project_branches ab
+ ON
+ app_branch_project_branch.application_branch_uuid = ab.uuid
+ WHERE
+ ab.kee = #{applicationBranchKey,jdbcType=VARCHAR}
+ AND
+ app_branch_project_branch.application_uuid = #{applicationUuid,jdbcType=VARCHAR}
</select>
<select id="countApplicationProjects" parameterType="String" resultType="int">
select
- count(1)
+ count(1)
FROM
- app_projects ap
+ app_projects ap
WHERE
- ap.application_uuid = #{applicationUuid,jdbcType=VARCHAR}
+ ap.application_uuid = #{applicationUuid,jdbcType=VARCHAR}
</select>
<update id="updateApplicationBranchName" parameterType="String">
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 1ab2f4ae208..be38d220f1b 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
@@ -194,6 +194,34 @@
pr.reference_uuid=#{referenceUuid,jdbcType=VARCHAR}
</select>
+ <select id="selectRootOfReferencersToMainBranch" resultType="Portfolio">
+ 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}
+ AND
+ (pr.branch_uuid is null
+ OR
+ pr.branch_uuid=#{referenceUuid,jdbcType=VARCHAR}
+ )
+ </select>
+
+ <select id="selectRootOfReferencersToAppBranch" resultType="Portfolio">
+ 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
+ INNER JOIN project_branches pb on pb.uuid = pr.branch_uuid
+ WHERE
+ pr.reference_uuid=#{appUuid,jdbcType=VARCHAR}
+ AND
+ pb.kee = #{appBranchKey,jdbcType=VARCHAR}
+ </select>
+
<sql id="applicationProjectColumns">
ap.application_uuid as appUuid,
ap.project_uuid as projectUuid,
@@ -308,29 +336,31 @@
WHERE target.qualifier = 'APP'
</select>
- <select id="selectAllDirectChildApplications" resultType="Project">
+ <select id="selectAllReferencesToPortfoliosInHierarchy" resultMap="referenceResult">
SELECT
- <include refid="projectColumns"/>
- FROM portfolio_references pr
- JOIN projects p ON p.uuid = pr.reference_uuid
- WHERE pr.portfolio_uuid = #{portfolioUuid,jdbcType=VARCHAR}
- </select>
-
- <select id="selectAllReferencesInHierarchy" resultMap="referenceResult">
- (SELECT
<include refid="portfolioReferenceColumns"/>
FROM portfolio_references pr
INNER JOIN portfolios source ON pr.portfolio_uuid = source.uuid
INNER JOIN portfolios target ON pr.reference_uuid = target.uuid
WHERE source.root_uuid = #{rootUuid,jdbcType=VARCHAR}
- UNION
+ </select>
+
+ <select id="selectAllReferencesToApplicationsInHierarchy" resultMap="referenceResult">
SELECT
<include refid="appReferenceColumns"/>
FROM portfolio_references pr
INNER JOIN portfolios source ON pr.portfolio_uuid = source.uuid
INNER JOIN projects target ON pr.reference_uuid = target.uuid
WHERE target.qualifier = 'APP'
- AND source.root_uuid = #{rootUuid,jdbcType=VARCHAR})
+ AND source.root_uuid = #{rootUuid,jdbcType=VARCHAR}
+ </select>
+
+ <select id="selectApplicationReferenceUuids" resultType="String">
+ SELECT
+ p.uuid
+ FROM portfolio_references pr
+ JOIN projects p ON p.uuid = pr.reference_uuid
+ WHERE pr.portfolio_uuid = #{portfolioUuid,jdbcType=VARCHAR}
</select>
<sql id="deletePortfolioQuery">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ApplicationProjectsDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ApplicationProjectsDaoTest.java
index 2978143ebda..35914872d8c 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ApplicationProjectsDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ApplicationProjectsDaoTest.java
@@ -74,7 +74,19 @@ public class ApplicationProjectsDaoTest {
insertApplication("app1");
insertBranch("app1", "app-b1");
underTest.addProjectBranchToAppBranch(dbSession, "app1", "app-b1", "p1", "b1");
- assertThat(underTest.selectProjectBranchesFromAppBranch(dbSession, "app-b1")).extracting(BranchDto::getUuid).containsOnly("b1");
+ assertThat(underTest.selectProjectBranchesFromAppBranchUuid(dbSession, "app-b1")).extracting(BranchDto::getUuid).containsOnly("b1");
+ }
+
+ @Test
+ public void select_project_branches_from_application_branch() {
+ var project = db.components().insertPublicProjectDto(p -> p.setDbKey("project"));
+ var projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch"));
+ var app = db.components().insertPrivateApplicationDto(a -> a.setDbKey("app1"));
+ var appBranch = db.components().insertProjectBranch(app, b -> b.setKey("app-branch"));
+ db.components().addApplicationProject(app, project);
+ underTest.addProjectBranchToAppBranch(dbSession, app.getUuid(), appBranch.getUuid(), project.getUuid(), projectBranch.getUuid());
+ assertThat(underTest.selectProjectBranchesFromAppBranchUuid(dbSession, appBranch.getUuid())).extracting(BranchDto::getKey).containsOnly("project-branch");
+ assertThat(underTest.selectProjectBranchesFromAppBranchKey(dbSession, app.getUuid(), appBranch.getKey())).extracting(BranchDto::getKey).containsOnly("project-branch");
}
@Test
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 29e28520900..45aebe2513c 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
@@ -267,17 +267,50 @@ public class PortfolioDaoTest {
portfolioDao.addReference(session, "portfolio2", app2.getUuid());
portfolioDao.addReference(session, "portfolio3", app3.getUuid());
- assertThat(portfolioDao.selectAllDirectChildApplications(session, p1.getUuid()))
- .extracting(ProjectDto::getKee)
- .containsOnly("app1");
+ assertThat(portfolioDao.selectApplicationReferenceUuids(session, p1.getUuid()))
+ .containsOnly(app1.getUuid());
- assertThat(portfolioDao.selectAllDirectChildApplications(session, p2.getUuid()))
- .extracting(ProjectDto::getKee)
- .containsOnly("app2");
+ assertThat(portfolioDao.selectApplicationReferenceUuids(session, p2.getUuid()))
+ .containsOnly(app2.getUuid());
- assertThat(portfolioDao.selectAllDirectChildApplications(session, p3.getUuid()))
- .extracting(ProjectDto::getKee)
- .containsOnly("app3");
+ assertThat(portfolioDao.selectApplicationReferenceUuids(session, p3.getUuid()))
+ .containsOnly(app3.getUuid());
+ }
+
+ @Test
+ public void selectAllReferencesToApplicationsInHierarchy() {
+ var p1 = db.components().insertPrivatePortfolioDto("portfolio1");
+ var p2 = db.components().insertPrivatePortfolioDto("portfolio2", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid()));
+ var p3 = db.components().insertPrivatePortfolioDto("portfolio3", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid()));
+ ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1"));
+ ProjectDto app2 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app2"));
+ ProjectDto app3 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app3"));
+
+ portfolioDao.addReference(session, "portfolio1", app1.getUuid());
+ portfolioDao.addReference(session, "portfolio2", app2.getUuid());
+ portfolioDao.addReference(session, "portfolio3", app3.getUuid());
+
+ assertThat(portfolioDao.selectAllReferencesToApplicationsInHierarchy(session, p1.getUuid()))
+ .extracting(ReferenceDto::getTargetUuid)
+ .containsExactlyInAnyOrder(app1.getUuid(), app2.getUuid(), app3.getUuid());
+ }
+
+ @Test
+ public void selectAllReferencesToPortfoliosInHierarchy() {
+ var p1 = db.components().insertPrivatePortfolioDto("portfolio1");
+ var p2 = db.components().insertPrivatePortfolioDto("portfolio2", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid()));
+ var p3 = db.components().insertPrivatePortfolioDto("portfolio3", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid()));
+ var p4 = db.components().insertPrivatePortfolioDto("portfolio4");
+ var p5 = db.components().insertPrivatePortfolioDto("portfolio5");
+ var p6 = db.components().insertPrivatePortfolioDto("portfolio6");
+
+ portfolioDao.addReference(session, "portfolio1", p4.getUuid());
+ portfolioDao.addReference(session, "portfolio2", p5.getUuid());
+ portfolioDao.addReference(session, "portfolio3", p6.getUuid());
+
+ assertThat(portfolioDao.selectAllReferencesToPortfoliosInHierarchy(session, p1.getUuid()))
+ .extracting(ReferenceDto::getTargetUuid)
+ .containsExactlyInAnyOrder(p4.getUuid(), p5.getUuid(), p6.getUuid());
}
@Test
@@ -356,6 +389,38 @@ public class PortfolioDaoTest {
}
@Test
+ public void select_root_reference_to_app_main_branch() {
+ PortfolioDto portfolio1 = db.components().insertPrivatePortfolioDto("portfolio1");
+ ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1"));
+ db.components().addPortfolioReference(portfolio1, app1.getUuid());
+
+ assertThat(portfolioDao.selectRootOfReferencersToMainBranch(db.getSession(), app1.getUuid()))
+ .extracting(PortfolioDto::getKey)
+ .containsExactly(portfolio1.getKey());
+
+ PortfolioDto portfolio2 = db.components().insertPrivatePortfolioDto("portfolio2");
+ ProjectDto app2 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app2"));
+ db.components().addPortfolioApplicationBranch(portfolio2.getUuid(), app2.getUuid(), app2.getUuid());
+
+ assertThat(portfolioDao.selectRootOfReferencersToMainBranch(db.getSession(), app2.getUuid()))
+ .extracting(PortfolioDto::getKey)
+ .containsExactly(portfolio2.getKey());
+ }
+
+ @Test
+ public void select_root_reference_to_app_with_branches() {
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1");
+ ProjectDto app = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app").setName("app"));
+ BranchDto branch = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true));
+
+ db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app.getUuid(), branch.getUuid());
+
+ assertThat(portfolioDao.selectRootOfReferencersToAppBranch(db.getSession(), app.getUuid(), branch.getKey()))
+ .extracting(PortfolioDto::getKey)
+ .containsExactly(portfolio.getKey());
+ }
+
+ @Test
public void select_reference_to_portfolio_by_key() {
PortfolioDto portfolio1 = db.components().insertPrivatePortfolioDto("portfolio1");
PortfolioDto portfolio2 = db.components().insertPrivatePortfolioDto("portfolio2");
@@ -374,25 +439,6 @@ public class PortfolioDaoTest {
}
@Test
- public void selectAllReferencesInHierarchy() {
- PortfolioDto root1 = db.components().insertPrivatePortfolioDto("root1");
- PortfolioDto root2 = db.components().insertPrivatePortfolioDto("root2");
- PortfolioDto sub1 = addPortfolio(root1, "sub1");
- PortfolioDto sub11 = addPortfolio(sub1, "sub11");
- ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setUuid("app1"));
-
- db.components().addPortfolioReference("root1", "app1");
- db.components().addPortfolioReference("root2", "app1");
- db.components().addPortfolioReference("sub11", "root2");
-
- assertThat(portfolioDao.selectAllReferencesInHierarchy(session, root1.getUuid()))
- .extracting(ReferenceDto::getSourceUuid, ReferenceDto::getTargetUuid)
- .containsOnly(
- tuple(root1.getUuid(), app1.getUuid()),
- tuple(sub11.getUuid(), root2.getUuid()));
- }
-
- @Test
public void selectReferencers() {
PortfolioDto portfolio1 = db.components().insertPrivatePortfolioDto("portfolio1");
PortfolioDto portfolio2 = db.components().insertPrivatePortfolioDto("portfolio2");