]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13999 Remove organizations from Portfolio WS
authorMichal Duda <michal.duda@sonarsource.com>
Mon, 21 Dec 2020 14:21:40 +0000 (15:21 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 22 Dec 2020 20:09:39 +0000 (20:09 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java

index 8d2509cf4491c147c5bbca365bf71f5c8223c66b..62842a312836b355aac401768e67f08dad68975a 100644 (file)
@@ -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) {
index c2fafe6a8f3801d5297869407e7517b3759ef823..9e67ccebb2be90c96e52772ff23e629499326913 100644 (file)
@@ -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();
index dfc9c9d51fcddc4be3da8a8b24b6ecd2a1d0e5f0..99a1bcfc86bfc24854656db269dc8c4cf8d5bb26 100644 (file)
       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">
index 0d451498d13e4a962b7531293ec15469d6ad9e0a..888fae2299d029a32b6957108b6ca18847230ae8 100644 (file)
@@ -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
index 9dc6ad909021db4fcee0e0e6b83882c186b63823..e1b3a57c1589913d399e1f199ed908688e64953b 100644 (file)
@@ -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() {
index 3c5992e37b5ce10d013803b4c2d36f78a14fc4ac..57409686f6ba6f49c1346e08b5dc379d5da5042d 100644 (file)
@@ -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() {
index 1a7bf0d94b8b0f70a4ba4dfd81b8714377670dd5..4445f7863d8dde2e03d3b697e5515175355ede11 100644 (file)
@@ -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)