}
public void insert(DbSession dbSession, PortfolioDto portfolio) {
- if (portfolio.getUuid() == null) {
- portfolio.setUuid(uuidFactory.create());
- }
mapper(dbSession).insert(portfolio);
}
return executeLargeInputs(uuids, uuids1 -> mapper(dbSession).selectByUuids(uuids1)).stream()
.collect(Collectors.toMap(PortfolioDto::getUuid, PortfolioDto::getKey));
}
+
+ public void deleteAllDescendantPortfolios(DbSession dbSession, String rootUuid) {
+ mapper(dbSession).deleteAllDescendantPortfolios(rootUuid);
+ }
+
+ public void deleteAllReferences(DbSession dbSession) {
+ mapper(dbSession).deleteAllReferences();
+
+ }
+
+ public void deleteAllProjects(DbSession dbSession) {
+ mapper(dbSession).deleteAllProjects();
+ }
+
+ public List<PortfolioProjectDto> selectAllProjectsOfPortfolios(DbSession dbSession) {
+ return mapper(dbSession).selectAllProjectsOfPortfolios();
+ }
+
}
void deleteProjects(String portfolioUuid);
void deleteProject(@Param("portfolioUuid") String portfolioUuid, @Param("projectUuid") String projectUuid);
+
+ void deleteAllDescendantPortfolios(String rootUuid);
+
+ void deleteAllReferences();
+
+ void deleteAllProjects();
+
+ List<PortfolioProjectDto> selectAllProjectsOfPortfolios();
+
+ List<ReferenceDto> selectAllReferencesOfPortfolios();
+
}
p.kee=#{kee,jdbcType=VARCHAR}
</select>
- <select id="selectAllRoots" resultType="Portfolio">
+ <select id="selectAll" resultType="Portfolio">
SELECT
- <include refid="portfolioColumns"/>
+ <include refid="portfolioColumns"/>
FROM portfolios p
- where
- p.parent_uuid is null
</select>
- <select id="selectAll" resultType="Portfolio">
+ <select id="selectAllRoots" resultType="Portfolio">
SELECT
<include refid="portfolioColumns"/>
FROM portfolios p
+ where
+ p.parent_uuid is null
</select>
<select id="selectProjects" resultType="Project">
pp.portfolio_uuid=#{portfolioUuid,jdbcType=VARCHAR}
</select>
+ <select id="selectAllProjectsOfPortfolios" resultType="org.sonar.db.portfolio.PortfolioProjectDto">
+ SELECT
+ pp.uuid,
+ pp.project_uuid as projectUuid,
+ pp.portfolio_uuid as portfolioUuid,
+ pp.project_uuid as projectUuid,
+ pp.created_at as createdAt
+ FROM portfolio_projects pp
+ INNER JOIN projects p on p.uuid = pp.project_uuid
+ </select>
+
<select id="selectAllProjectsInHierarchy" resultType="org.sonar.db.portfolio.PortfolioProjectDto">
SELECT
pp.uuid,
<foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach>
</delete>
+ <delete id="deleteAllDescendantPortfolios" parameterType="String">
+ DELETE FROM portfolios WHERE root_uuid = #{rootUuid,jdbcType=VARCHAR} and parent_uuid is not null
+ </delete>
+
+ <delete id="deleteAllReferences" parameterType="String">
+ DELETE FROM portfolio_references
+ </delete>
+
+ <delete id="deleteAllProjects" parameterType="String">
+ DELETE FROM portfolio_projects
+ </delete>
+
<insert id="insertReference" parameterType="PortfolioReference">
INSERT INTO portfolio_references (
uuid,
assertThat(portfolioDao.getAllProjectsInHierarchy(db.getSession(), "nonexisting")).isEmpty();
}
+ @Test
+ public void deleteAllDescendantPortfolios() {
+ createPortfolio("root", null, "root");
+ createPortfolio("child1", null, "root");
+ createPortfolio("child11", "child1", "root");
+
+ createPortfolio("root2", null, "root2");
+
+ portfolioDao.deleteAllDescendantPortfolios(db.getSession(), "root");
+ portfolioDao.deleteAllDescendantPortfolios(db.getSession(), "root2");
+
+ assertThat(db.countSql(db.getSession(), "select count(*) from portfolios where parent_uuid is not null")).isZero();
+ }
+
+ @Test
+ public void deleteAllReferences() {
+ createPortfolio("root", null, "root");
+ createPortfolio("child1", null, "root");
+ createPortfolio("child11", "child1", "root");
+
+ createPortfolio("root2", null, "root2");
+ createPortfolio("root3", null, "root3");
+ createPortfolio("root4", null, "root4");
+
+ portfolioDao.addReference(db.getSession(), "child1", "root2");
+ portfolioDao.addReference(db.getSession(), "root3", "root4");
+
+ portfolioDao.deleteAllReferences(db.getSession());
+
+ assertThat(db.countSql(db.getSession(), "select count(*) from portfolio_references")).isZero();
+ }
+
+ @Test
+ public void deleteAllProjects() {
+ db.components().insertPrivateProject("p1");
+ db.components().insertPrivateProject("p2");
+ db.components().insertPrivateProject("p3");
+ db.components().insertPrivateProject("p4");
+
+ createPortfolio("root", null, "root");
+ createPortfolio("child1", null, "root");
+ createPortfolio("child11", "child1", "root");
+
+ createPortfolio("root2", null, "root2");
+
+ portfolioDao.addProject(db.getSession(), "root", "p1");
+ portfolioDao.addProject(db.getSession(), "child1", "p2");
+ portfolioDao.addProject(db.getSession(), "child11", "p3");
+ portfolioDao.addProject(db.getSession(), "root2", "p4");
+
+ portfolioDao.deleteAllProjects(db.getSession());
+
+ assertThat(db.countSql(db.getSession(), "select count(*) from portfolio_projects")).isZero();
+ }
+
private PortfolioDto createPortfolio(String uuid, @Nullable String parentUuid, String rootUuid) {
PortfolioDto p = new PortfolioDto()
.setName("name_" + uuid)
return insertComponentAndPortfolio(ComponentTesting.newPortfolio().setPrivate(true), true, dtoPopulator, portfolioPopulator);
}
+ public void addPortfolioReference(ComponentDto portfolio, String... referencerUuids) {
+ for (String uuid : referencerUuids) {
+ dbClient.portfolioDao().addReference(dbSession, portfolio.uuid(), uuid);
+ }
+ db.commit();
+ }
+
public void addPortfolioProject(ComponentDto portfolio, String... projectUuids) {
for (String uuid : projectUuids) {
dbClient.portfolioDao().addProject(dbSession, portfolio.uuid(), uuid);