}
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) {
.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
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()));
}
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()));
}