aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorZipeng WU <zipeng.wu@sonarsource.com>2021-12-08 12:19:43 +0100
committersonartech <sonartech@sonarsource.com>2021-12-27 20:02:47 +0000
commita0d5da0279568f7c91b924ce8a3e67ee3acebef0 (patch)
tree0e7ac6e8c0f5390512446c82455621123f8b9f30 /server/sonar-db-dao
parent1287e21c81358cde09f1143be96c70b963606e42 (diff)
downloadsonarqube-a0d5da0279568f7c91b924ce8a3e67ee3acebef0.tar.gz
sonarqube-a0d5da0279568f7c91b924ce8a3e67ee3acebef0.zip
SONAR-15808 api/views/applications must provide new info
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java5
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java5
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml8
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java26
4 files changed, 43 insertions, 1 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 d69f36e8c1a..5a4739fd23d 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,6 +31,7 @@ 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;
@@ -143,6 +144,10 @@ public class PortfolioDao implements Dao {
return mapper(dbSession).selectAllReferencesToApplications();
}
+ public List<ProjectDto> selectAllDirectChildApplications(DbSession dbSession, String portfolioUuid) {
+ return mapper(dbSession).selectAllDirectChildApplications(portfolioUuid);
+ }
+
public Set<String> selectReferenceUuids(DbSession dbSession, String portfolioUuid) {
return mapper(dbSession).selectReferenceUuids(portfolioUuid);
}
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 fe77eabae7a..57aa1060d8b 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
@@ -25,6 +25,7 @@ import java.util.Set;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
import org.sonar.db.project.ApplicationProjectDto;
+import org.sonar.db.project.ProjectDto;
public interface PortfolioMapper {
@CheckForNull
@@ -98,5 +99,7 @@ public interface PortfolioMapper {
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);
}
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 e894c7afecd..16b8d7c9904 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
@@ -288,6 +288,14 @@
INNER JOIN projects target ON pr.reference_uuid = target.uuid where target.qualifier = 'APP'
</select>
+ <select id="selectAllDirectChildApplications" resultType="Project">
+ 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" resultType="org.sonar.db.portfolio.ReferenceDto">
(SELECT
source.uuid as sourceUuid,
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 74d282a5b04..5a6c6b4818d 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
@@ -250,6 +250,32 @@ public class PortfolioDaoTest {
}
@Test
+ public void selectAllDirectChildApplications() {
+ 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.selectAllDirectChildApplications(session, p1.getUuid()))
+ .extracting(ProjectDto::getKee)
+ .containsOnly("app1");
+
+ assertThat(portfolioDao.selectAllDirectChildApplications(session, p2.getUuid()))
+ .extracting(ProjectDto::getKee)
+ .containsOnly("app2");
+
+ assertThat(portfolioDao.selectAllDirectChildApplications(session, p3.getUuid()))
+ .extracting(ProjectDto::getKee)
+ .containsOnly("app3");
+ }
+
+ @Test
public void selectAllApplicationProjectsBelongToTheSamePortfolio() {
var portfolio = db.components().insertPrivatePortfolioDto("portfolio1");
var app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1"));