import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Collections.singleton;
-import static java.util.stream.Collectors.groupingBy;
-import static java.util.stream.Collectors.mapping;
-import static java.util.stream.Collectors.toSet;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class PortfolioDao implements Dao {
return mapper(dbSession).selectProjects(portfolioUuid);
}
- public Map<String, Set<String>> getAllProjectsInHierarchy(DbSession dbSession, String rootUuid) {
- return mapper(dbSession).selectAllProjectsInHierarchy(rootUuid)
- .stream()
- .collect(groupingBy(
- PortfolioProjectDto::getProjectUuid,
- mapping(PortfolioProjectDto::getPortfolioUuid, toSet())));
+ public List<PortfolioProjectDto> getAllProjectsInHierarchy(DbSession dbSession, String rootUuid) {
+ return mapper(dbSession).selectAllProjectsInHierarchy(rootUuid);
}
public void addProject(DbSession dbSession, String portfolioUuid, String projectUuid) {
public void deleteAllProjects(DbSession dbSession) {
mapper(dbSession).deleteAllProjects();
}
-
+
public List<PortfolioProjectDto> selectAllProjectsOfPortfolios(DbSession dbSession) {
return mapper(dbSession).selectAllProjectsOfPortfolios();
}
+ public List<ReferenceDto> selectAllReferencesInHierarchy(DbSession dbSession, String uuid) {
+ return mapper(dbSession).selectAllReferencesInHierarchy(uuid);
+ }
+
+ public List<PortfolioDto> selectByUuids(DbSession dbSession, Set<String> uuidsToRefresh) {
+ return mapper(dbSession).selectByUuids(uuidsToRefresh);
+ }
+
private static PortfolioMapper mapper(DbSession session) {
return session.getMapper(PortfolioMapper.class);
}
-
}
List<ReferenceDto> selectAllReferencesToApplications();
- Set<PortfolioProjectDto> selectAllProjectsInHierarchy(String rootUuid);
+ List<PortfolioProjectDto> selectAllProjectsInHierarchy(String rootUuid);
List<PortfolioDto> selectByUuids(@Param("uuids") Collection<String> uuids);
List<ReferenceDto> selectAllReferencesOfPortfolios();
+ List<ReferenceDto> selectAllReferencesInHierarchy(String rootUuid);
}
INNER JOIN projects target ON pr.reference_uuid = target.uuid where target.qualifier = 'APP'
</select>
+ <select id="selectAllReferencesInHierarchy" resultType="org.sonar.db.portfolio.ReferenceDto">
+ (SELECT
+ source.uuid as sourceUuid,
+ source.root_uuid as sourceRootUuid,
+ target.uuid as targetUuid,
+ target.root_uuid as targetRootUuid
+ 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
+ source.uuid as sourceUuid,
+ source.root_uuid as sourceRootUuid,
+ target.uuid as targetUuid,
+ target.uuid as targetRootUuid
+ 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})
+ </select>
+
<delete id="deletePortfoliosByUuids" parameterType="String">
DELETE FROM portfolios WHERE uuid in
<foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach>
portfolioDao.addProject(session, root2.getUuid(), "p4");
session.commit();
- assertThat(portfolioDao.getAllProjectsInHierarchy(session, root.getUuid()).keySet()).containsExactly("p1", "p2", "p3");
+ assertThat(portfolioDao.getAllProjectsInHierarchy(session, root.getUuid()))
+ .extracting(PortfolioProjectDto::getProjectUuid).containsExactly("p1", "p2", "p3");
assertThat(portfolioDao.getAllProjectsInHierarchy(session, "nonexisting")).isEmpty();
}
return insertComponentAndPortfolio(ComponentTesting.newPortfolio().setPrivate(true), true, dtoPopulator, portfolioPopulator);
}
- public void addPortfolioReference(ComponentDto portfolio, String... referencerUuids) {
+ public void addPortfolioReference(String portfolioUuid, String... referencerUuids) {
for (String uuid : referencerUuids) {
- dbClient.portfolioDao().addReference(dbSession, portfolio.uuid(), uuid);
+ dbClient.portfolioDao().addReference(dbSession, portfolioUuid, uuid);
}
db.commit();
}
+ public void addPortfolioReference(ComponentDto portfolio, String... referencerUuids) {
+ addPortfolioReference(portfolio.uuid(), referencerUuids);
+ }
+
public void addPortfolioReference(PortfolioDto portfolio, String... referencerUuids) {
- for (String uuid : referencerUuids) {
- dbClient.portfolioDao().addReference(dbSession, portfolio.getUuid(), uuid);
- }
- db.commit();
+ addPortfolioReference(portfolio.getUuid(), referencerUuids);
}
- public void addPortfolioProject(ComponentDto portfolio, String... projectUuids) {
+ public void addPortfolioProject(String portfolioUuid, String... projectUuids) {
for (String uuid : projectUuids) {
- dbClient.portfolioDao().addProject(dbSession, portfolio.uuid(), uuid);
+ dbClient.portfolioDao().addProject(dbSession, portfolioUuid, uuid);
}
db.commit();
}
+ public void addPortfolioProject(ComponentDto portfolio, String... projectUuids) {
+ addPortfolioProject(portfolio.uuid(), projectUuids);
+ }
+
public void addPortfolioProject(ComponentDto portfolio, ComponentDto... projects) {
addPortfolioProject(portfolio, Arrays.stream(projects).map(ComponentDto::uuid).toArray(String[]::new));
}