diff options
author | Michal Duda <michal.duda@sonarsource.com> | 2020-12-21 15:21:40 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-12-22 20:09:39 +0000 |
commit | 255d1fb82f78f046ef95f2e7a45cc5d4ba94c97e (patch) | |
tree | 39a75e83d8e86aa516942328312c197d9adb84c6 /server | |
parent | 967d9ad59cdf8f5c0f0dde3646f4dee950ec05bc (diff) | |
download | sonarqube-255d1fb82f78f046ef95f2e7a45cc5d4ba94c97e.tar.gz sonarqube-255d1fb82f78f046ef95f2e7a45cc5d4ba94c97e.zip |
SONAR-13999 Remove organizations from Portfolio WS
Diffstat (limited to 'server')
7 files changed, 53 insertions, 99 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java index 8d2509cf449..62842a31283 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java @@ -50,7 +50,7 @@ public class ProjectDao implements Dao { return Optional.ofNullable(mapper(session).selectProjectOrAppByKey(key)); } - public List<ProjectDto> selectAllApplications(DbSession session){ + public List<ProjectDto> selectAllApplications(DbSession session) { return mapper(session).selectAllApplications(); } @@ -76,12 +76,8 @@ public class ProjectDao implements Dao { return Optional.ofNullable(mapper(session).selectByUuid(uuid)); } - public List<ProjectDto> selectByOrganizationUuid(DbSession session, String organizationUuid) { - return mapper(session).selectByOrganizationUuid(organizationUuid); - } - - public List<ProjectDto> selectProjectsByOrganizationUuid(DbSession session, String organizationUuid) { - return mapper(session).selectProjectsByOrganizationUuid(organizationUuid); + public List<ProjectDto> selectAll(DbSession session) { + return mapper(session).selectAll(); } public List<ProjectDto> selectByUuids(DbSession session, Set<String> uuids) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java index c2fafe6a8f3..9e67ccebb2b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java @@ -44,7 +44,7 @@ public interface ProjectMapper { List<ProjectDto> selectByUuids(@Param("uuids") Collection<String> uuids); - List<ProjectDto> selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid); + List<ProjectDto> selectAll(); void updateKey(@Param("uuid") String uuid, @Param("newKey") String newKey, @Param("updatedAt") long updatedAt); @@ -54,8 +54,6 @@ public interface ProjectMapper { List<ProjectDto> selectProjects(); - List<ProjectDto> selectProjectsByOrganizationUuid(String organizationUuid); - void updateVisibility(@Param("uuid") String uuid, @Param("isPrivate") boolean isPrivate, @Param("updatedAt") long updatedAt); List<ProjectDto> selectAllApplications(); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml index dfc9c9d51fc..99a1bcfc86b 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml @@ -66,21 +66,10 @@ p.qualifier='TRK' </select> - <select id="selectByOrganizationUuid" parameterType="String" resultType="Project"> + <select id="selectAll" resultType="Project"> select <include refid="projectColumns"/> from projects p - where - p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} - </select> - - <select id="selectProjectsByOrganizationUuid" parameterType="String" resultType="Project"> - select - <include refid="projectColumns"/> - from projects p - where - p.qualifier='TRK' and - p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR} </select> <select id="selectAllApplications" resultType="Project"> diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java index 0d451498d13..888fae2299d 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java @@ -27,24 +27,22 @@ import java.util.Optional; import javax.annotation.Nullable; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.impl.utils.AlwaysIncreasingSystem2; import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; public class ProjectDaoTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private System2 system2 = new AlwaysIncreasingSystem2(1000L); + private final System2 system2 = new AlwaysIncreasingSystem2(1000L); @Rule public DbTester db = DbTester.create(system2); - private ProjectDao projectDao = new ProjectDao(system2); + private final ProjectDao projectDao = new ProjectDao(system2); @Test public void should_insert_and_select_by_uuid() { @@ -82,7 +80,7 @@ public class ProjectDaoTest { } @Test - public void select_by_organization_uuid() { + public void select_all() { ProjectDto dto1 = createProject("o1", "p1"); ProjectDto dto2 = createProject("o1", "p2"); ProjectDto dto3 = createProject("o2", "p1"); @@ -91,10 +89,14 @@ public class ProjectDaoTest { projectDao.insert(db.getSession(), dto2); projectDao.insert(db.getSession(), dto3); - List<ProjectDto> projectsByOrg = projectDao.selectByOrganizationUuid(db.getSession(), "org_o1"); - assertThat(projectsByOrg).hasSize(2); - assertProject(projectsByOrg.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false); - assertProject(projectsByOrg.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2", false); + List<ProjectDto> projectsByOrg = projectDao.selectAll(db.getSession()); + assertThat(projectsByOrg) + .extracting(ProjectDto::getName, ProjectDto::getKey, ProjectDto::getOrganizationUuid, ProjectDto::getUuid, ProjectDto::getDescription, + ProjectDto::getTagsString, ProjectDto::isPrivate) + .containsExactlyInAnyOrder( + tuple("projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false), + tuple("projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2", false), + tuple("projectName_p1", "projectKee_o2_p1", "org_o2", "uuid_o2_p1", "desc_p1", "tag1,tag2", false)); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java index 9dc6ad90902..e1b3a57c158 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java @@ -46,8 +46,6 @@ import org.sonar.db.duplication.DuplicationUnitDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.metric.MetricDto; import org.sonar.db.newcodeperiod.NewCodePeriodType; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.organization.OrganizationTesting; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.project.ProjectDto; import org.sonar.db.rule.RuleDefinitionDto; @@ -71,10 +69,10 @@ public class PurgeCommandsTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - private AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2(); - private PurgeProfiler profiler = new PurgeProfiler(); - private Random random = new Random(); - private PurgeCommands underTest = new PurgeCommands(dbTester.getSession(), profiler, system2); + private final AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2(); + private final PurgeProfiler profiler = new PurgeProfiler(); + private final Random random = new Random(); + private final PurgeCommands underTest = new PurgeCommands(dbTester.getSession(), profiler, system2); /** * Required because there is no autogenerated keys for analysis_properties @@ -129,10 +127,9 @@ public class PurgeCommandsTest { @Test @UseDataProvider("projects") - public void deleteComponents_delete_tree_of_components_of_a_project(OrganizationDto organizationDto, ComponentDto project) { - dbTester.organizations().insert(organizationDto); + public void deleteComponents_delete_tree_of_components_of_a_project(ComponentDto project) { dbTester.components().insertComponent(project); - ComponentDto otherProject = dbTester.components().insertPrivateProject(organizationDto); + ComponentDto otherProject = dbTester.components().insertPrivateProject(); Stream.of(project, otherProject).forEach(prj -> { ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(prj)); ComponentDto directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(module, "a")); @@ -151,8 +148,7 @@ public class PurgeCommandsTest { @Test @UseDataProvider("projects") - public void deleteComponentsByMainBranchProjectUuid_deletes_all_branches_of_a_project(OrganizationDto organizationDto, ComponentDto project) { - dbTester.organizations().insert(organizationDto); + public void deleteComponentsByMainBranchProjectUuid_deletes_all_branches_of_a_project(ComponentDto project) { dbTester.components().insertComponent(project); ComponentDto branch = dbTester.components().insertProjectBranch(project); Stream.of(project, branch).forEach(prj -> { @@ -173,10 +169,9 @@ public class PurgeCommandsTest { @Test @UseDataProvider("views") - public void deleteComponents_delete_tree_of_components_of_a_view(OrganizationDto organizationDto, ComponentDto view) { - dbTester.organizations().insert(organizationDto); + public void deleteComponents_delete_tree_of_components_of_a_view(ComponentDto view) { dbTester.components().insertComponent(view); - ComponentDto otherView = dbTester.components().insertPrivatePortfolio(organizationDto); + ComponentDto otherView = dbTester.components().insertPrivatePortfolio(); Stream.of(view, otherView).forEach(vw -> { dbTester.components().insertSubView(vw); dbTester.components().insertComponent(newProjectCopy(dbTester.components().insertPrivateProject(), vw)); @@ -520,8 +515,7 @@ public class PurgeCommandsTest { @Test public void deletePermissions_deletes_permissions_of_public_project() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPublicProject(organization); + ComponentDto project = dbTester.components().insertPublicProject(); addPermissions(project); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2); @@ -557,8 +551,7 @@ public class PurgeCommandsTest { @Test public void deleteNewCodePeriodsByRootUuid_deletes_branch_new_code_periods() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); BranchDto branch = newBranchDto(project); dbTester.components().insertProjectBranch(project, branch); @@ -580,8 +573,7 @@ public class PurgeCommandsTest { @Test public void deleteNewCodePeriodsByRootUuid_deletes_project_new_code_periods() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); BranchDto branch = newBranchDto(project); dbTester.components().insertProjectBranch(project, branch); @@ -603,8 +595,7 @@ public class PurgeCommandsTest { @Test public void deleteNewCodePeriodsByRootUuid_should_not_delete_any_if_root_uuid_is_null() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); BranchDto branch = newBranchDto(project); dbTester.components().insertProjectBranch(project, branch); @@ -758,28 +749,22 @@ public class PurgeCommandsTest { } @DataProvider - public static Object[][] projects() { - OrganizationDto organization = OrganizationTesting.newOrganizationDto(); - return new Object[][] { - {organization, ComponentTesting.newPrivateProjectDto(organization)}, - {organization, ComponentTesting.newPublicProjectDto(organization)}, + public static Object[] projects() { + return new Object[] { + ComponentTesting.newPrivateProjectDto(), ComponentTesting.newPublicProjectDto(), }; } @DataProvider - public static Object[][] views() { - OrganizationDto organization = OrganizationTesting.newOrganizationDto(); - return new Object[][] { - {organization, ComponentTesting.newView(organization)}, - {organization, ComponentTesting.newApplication(organization)} + public static Object[] views() { + return new Object[] { + ComponentTesting.newView(), ComponentTesting.newApplication() }; } @DataProvider - public static Object[][] projectsAndViews() { - return Stream.concat(Arrays.stream(views()), Arrays.stream(projects())) - .map(t -> new Object[] {t[1]}) - .toArray(Object[][]::new); + public static Object[] projectsAndViews() { + return Stream.concat(Arrays.stream(views()), Arrays.stream(projects())).toArray(Object[]::new); } private Consumer<SnapshotDto> randomLastAndStatus() { diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java index 3c5992e37b5..57409686f6b 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java @@ -248,6 +248,7 @@ public class ComponentDbTester { * @see #insertPublicPortfolio(java.util.function.Consumer) * @deprecated since 6.6 */ + @Deprecated public ComponentDto insertView(Consumer<ComponentDto> dtoPopulator) { return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()), false, dtoPopulator); } @@ -306,28 +307,30 @@ public class ComponentDbTester { return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(false), false, dtoPopulator); } + // TODO remove after getting rid of organization code + @Deprecated + public final ComponentDto insertPublicPortfolio(OrganizationDto organization, String uuid, Consumer<ComponentDto> dtoPopulator) { + return insertComponentImpl(ComponentTesting.newView(organization, uuid).setPrivate(false), false, dtoPopulator); + } + + public final ComponentDto insertPublicPortfolio(String uuid, Consumer<ComponentDto> dtoPopulator) { + return insertComponentImpl(ComponentTesting.newView(uuid).setPrivate(false), false, dtoPopulator); + } + public final ComponentDto insertPublicPortfolio(Consumer<ComponentDto> dtoPopulator) { return insertComponentImpl(ComponentTesting.newView().setPrivate(false), false, dtoPopulator); } public final ComponentDto insertPrivatePortfolio() { - return insertPrivatePortfolio(db.getDefaultOrganization()); + return insertComponentImpl(ComponentTesting.newView().setPrivate(true), true, defaults()); } - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPrivatePortfolio(OrganizationDto organization) { - return insertPrivatePortfolio(organization, defaults()); + public final ComponentDto insertPrivatePortfolio(String uuid, Consumer<ComponentDto> dtoPopulator) { + return insertComponentImpl(ComponentTesting.newView(uuid).setPrivate(true), true, dtoPopulator); } public final ComponentDto insertPrivatePortfolio(Consumer<ComponentDto> dtoPopulator) { - return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()).setPrivate(true), true, dtoPopulator); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPrivatePortfolio(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) { - return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(true), true, dtoPopulator); + return insertComponentImpl(ComponentTesting.newView().setPrivate(true), true, dtoPopulator); } public final ComponentDto insertPublicApplication() { diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java index 1a7bf0d94b8..4445f7863d8 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java @@ -131,12 +131,6 @@ public class ComponentTesting { return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), true); } - // TODO remove after getting rid of organization code - @Deprecated - public static ProjectDto createPrivateProjectDto(OrganizationDto organizationDto) { - return createProjectDto(organizationDto.getUuid(), Uuids.createFast(), true); - } - public static ComponentDto newPrivateProjectDto(String uuid) { return newProjectDto(uuid, true); } @@ -167,19 +161,6 @@ public class ComponentTesting { return newProjectDto(organizationDto.getUuid(), uuid, false); } - // TODO remove organizationUuid parameter after getting rid of organization code - @Deprecated - private static ProjectDto createProjectDto(String organizationUuid, String uuid, boolean isPrivate) { - return new ProjectDto() - .setOrganizationUuid(organizationUuid) - .setUuid(uuid) - .setKey("KEY_" + uuid) - .setQualifier(Qualifiers.PROJECT) - .setName("NAME_" + uuid) - .setDescription("DESCRIPTION_" + uuid) - .setPrivate(isPrivate); - } - private static ComponentDto newProjectDto(String uuid, boolean isPrivate) { return new ComponentDto() .setUuid(uuid) |