aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorZipeng WU <zipeng.wu@sonarsource.com>2021-12-30 10:33:59 +0100
committersonartech <sonartech@sonarsource.com>2021-12-30 20:03:07 +0000
commit83b1e2d1b7aeee70413fb705eac2592f56b2ebe1 (patch)
tree150bce5d2e08b5425a3b968c4d3212c4e94c8d52 /server
parent25e7bb391c9c65dcec037910c72676b9ea12bb94 (diff)
downloadsonarqube-83b1e2d1b7aeee70413fb705eac2592f56b2ebe1.tar.gz
sonarqube-83b1e2d1b7aeee70413fb705eac2592f56b2ebe1.zip
SONAR-15866 Fix application master branch reference wrongly deselect when refresh
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java7
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/portfolio/PortfolioDaoTest.java8
2 files changed, 10 insertions, 5 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 35a56b845ac..43cd3f8f11c 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
@@ -128,7 +128,12 @@ public class PortfolioDao implements Dao {
}
public void addReference(DbSession dbSession, String portfolioUuid, String referenceUuid) {
- mapper(dbSession).insertReference(uuidFactory.create(), portfolioUuid, referenceUuid, null, system2.now());
+ PortfolioDto portfolio = mapper(dbSession).selectByUuid(referenceUuid);
+ if (portfolio == null) {
+ mapper(dbSession).insertReference(uuidFactory.create(), portfolioUuid, referenceUuid, referenceUuid, system2.now());
+ } else {
+ mapper(dbSession).insertReference(uuidFactory.create(), portfolioUuid, referenceUuid, null, system2.now());
+ }
}
public List<ReferenceDto> selectAllReferencesToPortfolios(DbSession dbSession) {
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 45aebe2513c..ed2ff995ea1 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
@@ -251,7 +251,7 @@ public class PortfolioDaoTest {
.extracting(ReferenceDto::getSourceUuid, ReferenceDto::getTargetUuid, ReferenceDto::getTargetRootUuid, ReferenceDto::getBranchUuids)
.containsOnly(
tuple("portfolio3", app1.getUuid(), app1.getUuid(), singleton("branch1")),
- tuple("portfolio2", app1.getUuid(), app1.getUuid(), emptySet()));
+ tuple("portfolio2", app1.getUuid(), app1.getUuid(), singleton(app1.getUuid())));
}
@Test
@@ -384,7 +384,7 @@ public class PortfolioDaoTest {
assertThat(appFromDb.get())
.extracting(ReferenceDto::getTargetKey, ReferenceDto::getTargetName, ReferenceDto::getBranchUuids)
- .containsExactly("app", "app", Set.of(branch1.getUuid(), branch2.getUuid()));
+ .containsExactly("app", "app", Set.of(branch1.getUuid(), branch2.getUuid(), app.getUuid()));
}
@@ -541,14 +541,14 @@ public class PortfolioDaoTest {
assertThat(portfolioDao.selectReferenceToApp(db.getSession(), portfolio.getUuid(), app.getKey()))
.isPresent()
.map(ReferenceDto::getBranchUuids)
- .contains(Set.of(branch1.getUuid(), branch2.getUuid()));
+ .contains(Set.of(branch1.getUuid(), branch2.getUuid(), app.getUuid()));
portfolioDao.deleteReferenceBranch(db.getSession(), portfolio.getUuid(), app.getUuid(), branch1.getUuid());
assertThat(portfolioDao.selectReferenceToApp(db.getSession(), portfolio.getUuid(), app.getKey()))
.isPresent()
.map(ReferenceDto::getBranchUuids)
- .contains(Set.of(branch2.getUuid()));
+ .contains(Set.of(branch2.getUuid(), app.getUuid()));
}