aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2020-12-17 00:13:33 +0100
committersonartech <sonartech@sonarsource.com>2020-12-22 20:09:38 +0000
commit52845e663cfc638d3aecef53223f50f8fed3f135 (patch)
tree0b997106c33f49f6f52d98e7c81df894242dca89
parent65556c25122bf9fc25e6750420cdea849e3fa53d (diff)
downloadsonarqube-52845e663cfc638d3aecef53223f50f8fed3f135.tar.gz
sonarqube-52845e663cfc638d3aecef53223f50f8fed3f135.zip
SONAR-13999 remove orgs from application WS
-rw-r--r--server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java6
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java45
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java6
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java18
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java4
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml15
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java258
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java29
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java10
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java6
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java72
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java29
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProvider.java41
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImpl.java55
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImplTest.java63
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/TestDefaultOrganizationUuidProvider.java45
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/organization/DefaultOrganizationProviderImpl.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java5
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java10
-rw-r--r--server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/DefaultOrganizationEnforcer.java2
21 files changed, 226 insertions, 501 deletions
diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java
index a60cda39df7..428326a8ee9 100644
--- a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java
+++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTask.java
@@ -93,9 +93,9 @@ public class CeTask {
@Override
public String toString() {
return "User{" +
- "uuid='" + uuid + '\'' +
- ", login='" + login + '\'' +
- '}';
+ "uuid='" + uuid + '\'' +
+ ", login='" + login + '\'' +
+ '}';
}
@Override
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
index 03e1b31e89d..f9591ffcfad 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -41,7 +41,6 @@ import org.sonar.db.RowNotFoundException;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Collections.emptyList;
-import static java.util.Objects.requireNonNull;
import static org.sonar.core.util.stream.MoreCollectors.toList;
import static org.sonar.core.util.stream.MoreCollectors.toSet;
import static org.sonar.db.DatabaseUtils.checkThatNotTooManyConditions;
@@ -52,21 +51,20 @@ import static org.sonar.db.component.ComponentDto.generateBranchKey;
import static org.sonar.db.component.ComponentDto.generatePullRequestKey;
public class ComponentDao implements Dao {
-
- private static List<ComponentDto> selectByQueryImpl(DbSession session, @Nullable String organizationUuid, ComponentQuery query, int offset, int limit) {
+ private static List<ComponentDto> selectByQueryImpl(DbSession session, ComponentQuery query, int offset, int limit) {
if (query.hasEmptySetOfComponents()) {
return emptyList();
}
checkThatNotTooManyComponents(query);
- return mapper(session).selectByQuery(organizationUuid, query, new RowBounds(offset, limit));
+ return mapper(session).selectByQuery(query, new RowBounds(offset, limit));
}
- private static int countByQueryImpl(DbSession session, @Nullable String organizationUuid, ComponentQuery query) {
+ private static int countByQueryImpl(DbSession session, ComponentQuery query) {
if (query.hasEmptySetOfComponents()) {
return 0;
}
checkThatNotTooManyComponents(query);
- return mapper(session).countByQuery(organizationUuid, query);
+ return mapper(session).countByQuery(query);
}
private static ComponentMapper mapper(DbSession session) {
@@ -86,29 +84,12 @@ public class ComponentDao implements Dao {
}
/**
- * Same as {@link #selectByQuery(DbSession, String, ComponentQuery, int, int)} except
- * that the filter on organization is disabled.
- */
- public List<ComponentDto> selectByQuery(DbSession session, ComponentQuery query, int offset, int limit) {
- return selectByQueryImpl(session, null, query, offset, limit);
- }
-
- /**
* @throws IllegalArgumentException if parameter query#getComponentIds() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values
* @throws IllegalArgumentException if parameter query#getComponentKeys() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values
* @throws IllegalArgumentException if parameter query#getMainComponentUuids() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values
*/
- public List<ComponentDto> selectByQuery(DbSession dbSession, String organizationUuid, ComponentQuery query, int offset, int limit) {
- requireNonNull(organizationUuid, "organizationUuid can't be null");
- return selectByQueryImpl(dbSession, organizationUuid, query, offset, limit);
- }
-
- /**
- * Same as {@link #countByQuery(DbSession, String, ComponentQuery)} except
- * that the filter on organization is disabled.
- */
- public int countByQuery(DbSession session, ComponentQuery query) {
- return countByQueryImpl(session, null, query);
+ public List<ComponentDto> selectByQuery(DbSession dbSession, ComponentQuery query, int offset, int limit) {
+ return selectByQueryImpl(dbSession, query, offset, limit);
}
/**
@@ -116,9 +97,8 @@ public class ComponentDao implements Dao {
* @throws IllegalArgumentException if parameter query#getComponentKeys() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values
* @throws IllegalArgumentException if parameter query#getMainComponentUuids() has more than {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE} values
*/
- public int countByQuery(DbSession session, String organizationUuid, ComponentQuery query) {
- requireNonNull(organizationUuid, "organizationUuid can't be null");
- return countByQueryImpl(session, organizationUuid, query);
+ public int countByQuery(DbSession session, ComponentQuery query) {
+ return countByQueryImpl(session, query);
}
public List<ComponentDto> selectSubProjectsByComponentUuids(DbSession session, Collection<String> uuids) {
@@ -285,15 +265,6 @@ public class ComponentDao implements Dao {
}
/**
- * Select all projects for a given organization.
- * <p>
- * Branches are not returned
- */
- public List<ComponentDto> selectProjectsByOrganization(DbSession dbSession, String organizationUuid) {
- return mapper(dbSession).selectProjectsByOrganization(organizationUuid);
- }
-
- /**
* Selects all components that are relevant for indexing. The result is not returned (since it is usually too big), but handed over to the <code>handler</code>
*
* @param session the database session
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
index 0dc9a85540c..946d48585ac 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
@@ -156,10 +156,14 @@ public class ComponentDto {
return buildLikeValue(formatUuidPathFromParent(this), WildcardPosition.AFTER);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public String getOrganizationUuid() {
return organizationUuid;
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ComponentDto setOrganizationUuid(String organizationUuid) {
this.organizationUuid = organizationUuid;
return this;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
index 3604655853d..b712a8d0af1 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
@@ -71,9 +71,9 @@ public interface ComponentMapper {
*/
int countComponentByOrganizationAndUuid(@Param("organizationUuid") String organizationUuid, @Param("componentUuid") String componentUuid);
- List<ComponentDto> selectByQuery(@Nullable @Param("organizationUuid") String organizationUuid, @Param("query") ComponentQuery query, RowBounds rowBounds);
+ List<ComponentDto> selectByQuery(@Param("query") ComponentQuery query, RowBounds rowBounds);
- int countByQuery(@Nullable @Param("organizationUuid") String organizationUuid, @Param("query") ComponentQuery query);
+ int countByQuery(@Param("query") ComponentQuery query);
List<ComponentDto> selectDescendants(@Param("query") ComponentTreeQuery query, @Param("baseUuid") String baseUuid, @Param("baseUuidPath") String baseUuidPath);
@@ -84,8 +84,6 @@ public interface ComponentMapper {
*/
List<ComponentDto> selectProjects();
- List<ComponentDto> selectProjectsByOrganization(@Param("organizationUuid") String organizationUuid);
-
/**
* Return all descendant modules (including itself) from a given component uuid and scope
*/
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
index 9ed7907c22c..8a71d78a42e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
@@ -30,19 +30,28 @@ import org.sonar.db.Pagination;
import org.sonar.db.alm.ALM;
import org.sonar.db.component.BranchType;
import org.sonar.db.permission.template.DefaultTemplates;
+import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.user.GroupDto;
+import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
import static org.sonar.db.DatabaseUtils.executeLargeUpdates;
public class OrganizationDao implements Dao {
+ /**
+ * The UUID of the default organization.
+ * Can't be null unless SQ is strongly corrupted.
+ */
+ public static final String DEFAULT_ORGANIZATION = "organization.default";
private final System2 system2;
+ private final InternalPropertiesDao internalPropertiesDao;
- public OrganizationDao(System2 system2) {
+ public OrganizationDao(System2 system2, InternalPropertiesDao internalPropertiesDao) {
this.system2 = system2;
+ this.internalPropertiesDao = internalPropertiesDao;
}
public void insert(DbSession dbSession, OrganizationDto organization, boolean newProjectPrivate) {
@@ -53,6 +62,13 @@ public class OrganizationDao implements Dao {
getMapper(dbSession).insert(organization, newProjectPrivate);
}
+ // TODO remove after getting rid of organization code
+ public OrganizationDto getDefaultOrganization(DbSession dbSession) {
+ Optional<String> uuid = internalPropertiesDao.selectByKey(dbSession, DEFAULT_ORGANIZATION);
+ checkState(uuid.isPresent() && !uuid.get().isEmpty(), "No Default organization uuid configured");
+ return getMapper(dbSession).selectByUuid(uuid.get());
+ }
+
public int countByQuery(DbSession dbSession, OrganizationQuery organizationQuery) {
requireNonNull(organizationQuery, "organizationQuery can't be null");
return getMapper(dbSession).countByQuery(organizationQuery);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java
index 656fe8e67ae..8a36c2f2e6a 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java
@@ -128,10 +128,14 @@ public class ProjectDto {
return this;
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public String getOrganizationUuid() {
return organizationUuid;
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ProjectDto setOrganizationUuid(String organizationUuid) {
this.organizationUuid = organizationUuid;
return this;
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index d3a1d7ae509..ad1b37560aa 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -222,18 +222,6 @@
AND p.main_branch_project_uuid IS NULL
</select>
- <select id="selectProjectsByOrganization" resultType="Component">
- select
- <include refid="componentColumns"/>
- from components p
- where
- p.enabled=${_true}
- and p.scope='PRJ'
- and p.qualifier='TRK'
- and p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
- and p.main_branch_project_uuid IS NULL
- </select>
-
<select id="selectComponentsByQualifiers" resultType="Component">
SELECT
<include refid="componentColumns"/>
@@ -285,9 +273,6 @@
p.enabled=${_true}
AND p.main_branch_project_uuid is null
AND p.copy_component_uuid is null
- <if test="organizationUuid!=null">
- and p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
- </if>
<if test="query.qualifiers!=null">
and p.qualifier in
<foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=",">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index d7a05428468..9e07a000cf4 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -723,9 +723,8 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_returns_root_view_with_direct_copy_of_project(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = insertProject(organization);
- ComponentDto view = insertView(organization, rootViewQualifier);
+ ComponentDto project = insertProject();
+ ComponentDto view = insertView(rootViewQualifier);
insertProjectCopy(view, project);
Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project.uuid()));
@@ -739,14 +738,13 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_returns_root_views_with_direct_copy_of_projects(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = insertProject(organization);
- ComponentDto project2 = insertProject(organization);
- ComponentDto view = insertView(organization, rootViewQualifier);
+ ComponentDto project1 = insertProject();
+ ComponentDto project2 = insertProject();
+ ComponentDto view = insertView(rootViewQualifier);
insertProjectCopy(view, project1);
insertProjectCopy(view, project2);
- ComponentDto view2 = insertView(organization, rootViewQualifier);
- ComponentDto project3 = insertProject(organization);
+ ComponentDto view2 = insertView(rootViewQualifier);
+ ComponentDto project3 = insertProject();
insertProjectCopy(view2, project3);
assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project1.uuid())))
@@ -774,12 +772,11 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_does_not_return_root_view_with_direct_copy_of_other_project(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = insertProject(organization);
- ComponentDto project2 = insertProject(organization);
- ComponentDto view1 = insertView(organization, rootViewQualifier);
+ ComponentDto project1 = insertProject();
+ ComponentDto project2 = insertProject();
+ ComponentDto view1 = insertView(rootViewQualifier);
insertProjectCopy(view1, project1);
- ComponentDto view2 = insertView(organization, rootViewQualifier);
+ ComponentDto view2 = insertView(rootViewQualifier);
insertProjectCopy(view2, project2);
Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project2.uuid()));
@@ -793,11 +790,10 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_does_not_return_root_view_with_disabled_direct_copy_of_project(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = insertProject(organization);
- ComponentDto view1 = insertView(organization, rootViewQualifier);
+ ComponentDto project = insertProject();
+ ComponentDto view1 = insertView(rootViewQualifier);
insertProjectCopy(view1, project);
- ComponentDto view2 = insertView(organization, rootViewQualifier);
+ ComponentDto view2 = insertView(rootViewQualifier);
insertProjectCopy(view2, project, t -> t.setEnabled(false));
Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project.uuid()));
@@ -811,11 +807,10 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_does_not_return_disabled_root_view_with_direct_copy_of_project(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = insertProject(organization);
- ComponentDto view1 = insertView(organization, rootViewQualifier, t -> t.setEnabled(false));
+ ComponentDto project = insertProject();
+ ComponentDto view1 = insertView(rootViewQualifier, t -> t.setEnabled(false));
insertProjectCopy(view1, project);
- ComponentDto view2 = insertView(organization, rootViewQualifier);
+ ComponentDto view2 = insertView(rootViewQualifier);
insertProjectCopy(view2, project);
Set<String> keys = underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project.uuid()));
@@ -829,9 +824,8 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_returns_root_view_with_indirect_copy_of_project(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = insertProject(organization);
- ComponentDto view = insertView(organization, rootViewQualifier);
+ ComponentDto project = insertProject();
+ ComponentDto view = insertView(rootViewQualifier);
ComponentDto lowestSubview = insertSubviews(view);
insertProjectCopy(lowestSubview, project);
@@ -846,16 +840,15 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_returns_root_views_with_indirect_copy_of_projects(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = insertProject(organization);
- ComponentDto project2 = insertProject(organization);
- ComponentDto view1 = insertView(organization, rootViewQualifier);
+ ComponentDto project1 = insertProject();
+ ComponentDto project2 = insertProject();
+ ComponentDto view1 = insertView(rootViewQualifier);
ComponentDto lowestSubview1 = insertSubviews(view1);
insertProjectCopy(lowestSubview1, project1);
insertProjectCopy(lowestSubview1, project2);
- ComponentDto view2 = insertView(organization, rootViewQualifier);
+ ComponentDto view2 = insertView(rootViewQualifier);
ComponentDto lowestSubview2 = insertSubviews(view2);
- ComponentDto project3 = insertProject(organization);
+ ComponentDto project3 = insertProject();
insertProjectCopy(lowestSubview2, project3);
assertThat(underTest.selectViewKeysWithEnabledCopyOfProject(dbSession, singleton(project1.uuid())))
@@ -883,13 +876,12 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_does_not_return_root_view_with_indirect_copy_of_other_project(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = insertProject(organization);
- ComponentDto project2 = insertProject(organization);
- ComponentDto view1 = insertView(organization, rootViewQualifier);
+ ComponentDto project1 = insertProject();
+ ComponentDto project2 = insertProject();
+ ComponentDto view1 = insertView(rootViewQualifier);
ComponentDto lowestSubview1 = insertSubviews(view1);
insertProjectCopy(lowestSubview1, project1);
- ComponentDto view2 = insertView(organization, rootViewQualifier);
+ ComponentDto view2 = insertView(rootViewQualifier);
ComponentDto lowestSubview2 = insertSubviews(view2);
insertProjectCopy(lowestSubview2, project2);
@@ -904,12 +896,11 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_does_not_return_root_view_with_disabled_indirect_copy_of_project(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = insertProject(organization);
- ComponentDto view1 = insertView(organization, rootViewQualifier);
+ ComponentDto project = insertProject();
+ ComponentDto view1 = insertView(rootViewQualifier);
ComponentDto lowestSubview1 = insertSubviews(view1);
insertProjectCopy(lowestSubview1, project);
- ComponentDto view2 = insertView(organization, rootViewQualifier);
+ ComponentDto view2 = insertView(rootViewQualifier);
ComponentDto lowestSubview2 = insertSubviews(view2);
insertProjectCopy(lowestSubview2, project, t -> t.setEnabled(false));
@@ -924,12 +915,11 @@ public class ComponentDaoTest {
@Test
@UseDataProvider("portfolioOrApplicationRootViewQualifier")
public void selectViewKeysWithEnabledCopyOfProject_does_not_return_disabled_root_view_with_indirect_copy_of_project(String rootViewQualifier) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = insertProject(organization);
- ComponentDto view1 = insertView(organization, rootViewQualifier, t -> t.setEnabled(false));
+ ComponentDto project = insertProject();
+ ComponentDto view1 = insertView(rootViewQualifier, t -> t.setEnabled(false));
ComponentDto lowestSubview1 = insertSubviews(view1);
insertProjectCopy(lowestSubview1, project);
- ComponentDto view2 = insertView(organization, rootViewQualifier);
+ ComponentDto view2 = insertView(rootViewQualifier);
ComponentDto lowestSubview2 = insertSubviews(view2);
insertProjectCopy(lowestSubview2, project);
@@ -958,20 +948,20 @@ public class ComponentDaoTest {
return lowestView;
}
- private ComponentDto insertView(OrganizationDto organization, String rootViewQualifier) {
- return insertView(organization, rootViewQualifier, defaults());
+ private ComponentDto insertView(String rootViewQualifier) {
+ return insertView(rootViewQualifier, defaults());
}
- private ComponentDto insertView(OrganizationDto organization, String rootViewQualifier, Consumer<ComponentDto> dtoPopulators) {
+ private ComponentDto insertView(String rootViewQualifier, Consumer<ComponentDto> dtoPopulators) {
ComponentDbTester tester = db.components();
if (rootViewQualifier.equals(Qualifiers.VIEW)) {
- return random.nextBoolean() ? tester.insertPublicPortfolio(organization, dtoPopulators) : tester.insertPrivatePortfolio(organization, dtoPopulators);
+ return random.nextBoolean() ? tester.insertPublicPortfolio(dtoPopulators) : tester.insertPrivatePortfolio(dtoPopulators);
}
- return random.nextBoolean() ? tester.insertPublicApplication(organization, dtoPopulators) : tester.insertPrivatePortfolio(organization, dtoPopulators);
+ return random.nextBoolean() ? tester.insertPublicApplication(dtoPopulators) : tester.insertPrivatePortfolio(dtoPopulators);
}
- private ComponentDto insertProject(OrganizationDto organization) {
- return random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization);
+ private ComponentDto insertProject() {
+ return random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
}
@SafeVarargs
@@ -985,9 +975,9 @@ public class ComponentDaoTest {
public void select_projects_from_view() {
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPublicPortfolio();
db.components().insertComponent(newProjectCopy(project1, view));
- ComponentDto viewWithSubView = db.components().insertView();
+ ComponentDto viewWithSubView = db.components().insertPublicPortfolio();
db.components().insertComponent(newProjectCopy(project2, viewWithSubView));
ComponentDto subView = db.components().insertSubView(viewWithSubView);
db.components().insertComponent(newProjectCopy(project1, subView));
@@ -1002,12 +992,11 @@ public class ComponentDaoTest {
@Test
public void select_projects() {
- OrganizationDto organization = db.organizations().insert();
ComponentDto provisionedProject = db.components().insertPrivateProject();
- ComponentDto provisionedView = db.components().insertView(organization);
- String projectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)).getComponentUuid();
- String disabledProjectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization).setEnabled(false)).getComponentUuid();
- String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid();
+ ComponentDto provisionedView = db.components().insertView();
+ String projectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto()).getComponentUuid();
+ String disabledProjectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto().setEnabled(false)).getComponentUuid();
+ String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView()).getComponentUuid();
assertThat(underTest.selectProjects(dbSession))
.extracting(ComponentDto::uuid)
@@ -1016,7 +1005,6 @@ public class ComponentDaoTest {
@Test
public void select_projects_does_not_return_branches() {
- OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project);
@@ -1026,79 +1014,46 @@ public class ComponentDaoTest {
}
@Test
- public void select_projects_by_organization() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization);
- ComponentDto module = db.components().insertComponent(newModuleDto(project1));
- ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
- ComponentDto file = db.components().insertComponent(newFileDto(module, directory));
- ComponentDto project2 = db.components().insertPrivateProject(organization);
- ComponentDto view = db.components().insertView(organization);
- ComponentDto application = db.components().insertPublicApplication(organization);
- OrganizationDto otherOrganization = db.organizations().insert();
- ComponentDto projectOnOtherOrganization = db.components().insertPrivateProject(otherOrganization);
-
- assertThat(underTest.selectProjectsByOrganization(dbSession, organization.getUuid()))
- .extracting(ComponentDto::uuid)
- .containsExactlyInAnyOrder(project1.uuid(), project2.uuid())
- .doesNotContain(view.uuid(), application.uuid());
- }
-
- @Test
- public void select_projects_by_organization_does_not_return_branches() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPublicProject(organization);
- ComponentDto branch = db.components().insertProjectBranch(project);
-
- assertThat(underTest.selectProjectsByOrganization(dbSession, organization.getUuid()))
- .extracting(ComponentDto::uuid)
- .containsExactlyInAnyOrder(project.uuid())
- .doesNotContain(branch.uuid());
- }
-
- @Test
public void selectByQuery_provisioned() {
- OrganizationDto organization = db.organizations().insert();
-
ComponentDto provisionedProject = db.components()
- .insertPrivateProject(organization, p -> p.setDbKey("provisioned.project").setName("Provisioned Project"));
- ComponentDto provisionedPortfolio = db.components().insertPrivatePortfolio(organization);
+ .insertPrivateProject(p -> p.setDbKey("provisioned.project").setName("Provisioned Project"));
+ ComponentDto provisionedPortfolio = db.components().insertPrivatePortfolio();
- SnapshotDto analyzedProject = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization));
- SnapshotDto analyzedDisabledProject = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)
+ SnapshotDto analyzedProject = db.components().insertProjectAndSnapshot(newPrivateProjectDto());
+ SnapshotDto analyzedDisabledProject = db.components().insertProjectAndSnapshot(newPrivateProjectDto()
.setEnabled(false));
- SnapshotDto analyzedPortfolio = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization));
+ SnapshotDto analyzedPortfolio = db.components().insertProjectAndSnapshot(ComponentTesting.newView());
Supplier<ComponentQuery.Builder> query = () -> ComponentQuery.builder().setQualifiers(PROJECT).setOnProvisionedOnly(true);
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, query.get().build(), 0, 10))
.extracting(ComponentDto::uuid)
.containsOnly(provisionedProject.uuid());
// pagination
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 2, 10)).isEmpty();
+ assertThat(underTest.selectByQuery(dbSession, query.get().build(), 2, 10)).isEmpty();
// filter on qualifiers
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setQualifiers("XXX").build(), 0, 10)).isEmpty();
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(PROJECT, "XXX").build(), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, query.get().setQualifiers("XXX").build(), 0, 10)).isEmpty();
+ assertThat(underTest.selectByQuery(dbSession, query.get().setQualifiers(PROJECT, "XXX").build(), 0, 10))
.extracting(ComponentDto::uuid)
.containsOnly(provisionedProject.uuid());
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(PROJECT, Qualifiers.VIEW).build(), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, query.get().setQualifiers(PROJECT, Qualifiers.VIEW).build(), 0, 10))
.extracting(ComponentDto::uuid)
.containsOnly(provisionedProject.uuid(), provisionedPortfolio.uuid());
// match key
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery(provisionedProject.getDbKey()).build(), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, query.get().setNameOrKeyQuery(provisionedProject.getDbKey()).build(), 0, 10))
.extracting(ComponentDto::uuid)
.containsExactly(provisionedProject.uuid());
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery("pROvisiONed.proJEcT").setPartialMatchOnKey(true).build(), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, query.get().setNameOrKeyQuery("pROvisiONed.proJEcT").setPartialMatchOnKey(true).build(), 0, 10))
.extracting(ComponentDto::uuid)
.containsExactly(provisionedProject.uuid());
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery("missing").setPartialMatchOnKey(true).build(), 0, 10)).isEmpty();
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery("to be escaped '\"\\%").setPartialMatchOnKey(true).build(), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, query.get().setNameOrKeyQuery("missing").setPartialMatchOnKey(true).build(), 0, 10)).isEmpty();
+ assertThat(underTest.selectByQuery(dbSession, query.get().setNameOrKeyQuery("to be escaped '\"\\%").setPartialMatchOnKey(true).build(), 0, 10))
.isEmpty();
// match name
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery("ned proj").setPartialMatchOnKey(true).build(), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, query.get().setNameOrKeyQuery("ned proj").setPartialMatchOnKey(true).build(), 0, 10))
.extracting(ComponentDto::uuid)
.containsExactly(provisionedProject.uuid());
}
@@ -1110,9 +1065,8 @@ public class ComponentDaoTest {
.setOnProvisionedOnly(true);
// the project does not have any analysis
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPublicProject(organization);
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10))
+ ComponentDto project = db.components().insertPublicProject();
+ assertThat(underTest.selectByQuery(dbSession, query.get().build(), 0, 10))
.extracting(ComponentDto::uuid)
.containsOnly(project.uuid());
@@ -1121,27 +1075,25 @@ public class ComponentDaoTest {
ComponentDto branchWithoutAnalysis = db.components().insertProjectBranch(project);
ComponentDto branchWithAnalysis = db.components().insertProjectBranch(project);
db.components().insertSnapshot(branchWithAnalysis);
- assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, query.get().build(), 0, 10))
.isEmpty();
}
@Test
public void selectByQuery_verify_order() {
- OrganizationDto organization = db.organizations().insert();
-
Date firstDate = new Date(system2.now());
Date secondDate = new Date(system2.now());
Date thirdDate = new Date(system2.now());
- ComponentDto project3 = db.components().insertPrivateProject(organization, "project3", componentDto -> componentDto.setCreatedAt(thirdDate));
- ComponentDto project1 = db.components().insertPrivateProject(organization, "project1", componentDto -> componentDto.setCreatedAt(firstDate));
- ComponentDto project2 = db.components().insertPrivateProject(organization, "project2", componentDto -> componentDto.setCreatedAt(secondDate));
+ ComponentDto project3 = db.components().insertPrivateProject("project3", componentDto -> componentDto.setCreatedAt(thirdDate));
+ ComponentDto project1 = db.components().insertPrivateProject("project1", componentDto -> componentDto.setCreatedAt(firstDate));
+ ComponentDto project2 = db.components().insertPrivateProject("project2", componentDto -> componentDto.setCreatedAt(secondDate));
Supplier<ComponentQuery.Builder> query = () -> ComponentQuery.builder()
.setQualifiers(PROJECT)
.setOnProvisionedOnly(true);
- List<ComponentDto> results = underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10);
+ List<ComponentDto> results = underTest.selectByQuery(dbSession, query.get().build(), 0, 10);
assertThat(results)
.extracting(ComponentDto::uuid)
.containsExactly(
@@ -1152,22 +1104,14 @@ public class ComponentDaoTest {
@Test
public void count_provisioned() {
- OrganizationDto organization = db.organizations().insert();
- db.components().insertPrivateProject(organization);
- db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization));
- db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization));
+ db.components().insertPrivateProject();
+ db.components().insertProjectAndSnapshot(newPrivateProjectDto());
+ db.components().insertProjectAndSnapshot(ComponentTesting.newView());
Supplier<ComponentQuery.Builder> query = () -> ComponentQuery.builder().setOnProvisionedOnly(true);
- assertThat(underTest.countByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(PROJECT).build())).isEqualTo(1);
- assertThat(underTest.countByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(Qualifiers.VIEW).build())).isZero();
- assertThat(underTest.countByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(PROJECT, Qualifiers.VIEW).build())).isEqualTo(1);
- }
-
- @Test
- public void countByQuery_with_organization_throws_NPE_of_organizationUuid_is_null() {
- assertThatThrownBy(() -> underTest.countByQuery(dbSession, null, ALL_PROJECTS_COMPONENT_QUERY))
- .isInstanceOf(NullPointerException.class)
- .hasMessage("organizationUuid can't be null");
+ assertThat(underTest.countByQuery(dbSession, query.get().setQualifiers(PROJECT).build())).isEqualTo(1);
+ assertThat(underTest.countByQuery(dbSession, query.get().setQualifiers(Qualifiers.VIEW).build())).isZero();
+ assertThat(underTest.countByQuery(dbSession, query.get().setQualifiers(PROJECT, Qualifiers.VIEW).build())).isEqualTo(1);
}
@Test
@@ -1367,13 +1311,6 @@ public class ComponentDaoTest {
}
@Test
- public void selectByQuery_with_organization_throws_NPE_of_organizationUuid_is_null() {
- assertThatThrownBy(() -> underTest.selectByQuery(dbSession, null, ALL_PROJECTS_COMPONENT_QUERY, 1, 1))
- .isInstanceOf(NullPointerException.class)
- .hasMessage("organizationUuid can't be null");
- }
-
- @Test
public void selectByQuery_throws_IAE_if_too_many_component_keys() {
Set<String> keys = IntStream.range(0, 1_010).mapToObj(String::valueOf).collect(toSet());
ComponentQuery.Builder query = ComponentQuery.builder()
@@ -1402,11 +1339,10 @@ public class ComponentDaoTest {
@Test
public void selectByQuery_with_paging_query_and_qualifiers() {
- OrganizationDto organizationDto = db.organizations().insert();
- db.components().insertProjectAndSnapshot(newPrivateProjectDto(organizationDto).setName("aaaa-name"));
- db.components().insertProjectAndSnapshot(newView(organizationDto));
+ db.components().insertProjectAndSnapshot(newPrivateProjectDto().setName("aaaa-name"));
+ db.components().insertProjectAndSnapshot(newView());
for (int i = 9; i >= 1; i--) {
- db.components().insertProjectAndSnapshot(newPrivateProjectDto(organizationDto).setName("project-" + i));
+ db.components().insertProjectAndSnapshot(newPrivateProjectDto().setName("project-" + i));
}
ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("oJect").setQualifiers(PROJECT).build();
@@ -1416,27 +1352,6 @@ public class ComponentDaoTest {
assertThat(result).hasSize(3);
assertThat(count).isEqualTo(9);
assertThat(result).extracting(ComponentDto::name).containsExactly("project-2", "project-3", "project-4");
- assertThat(result).extracting(ComponentDto::getOrganizationUuid).containsOnly(organizationDto.getUuid());
- }
-
- @Test
- public void selectByQuery_with_organization_filters_on_specified_organization() {
- OrganizationDto organization1 = db.organizations().insert();
- OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization1);
- ComponentDto project2 = db.components().insertPrivateProject(organization2);
-
- assertThat(underTest.selectByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY, 0, 2))
- .extracting(ComponentDto::uuid)
- .containsOnly(project1.uuid(), project2.uuid());
- assertThat(underTest.selectByQuery(dbSession, organization1.getUuid(), ALL_PROJECTS_COMPONENT_QUERY, 0, 2))
- .extracting(ComponentDto::uuid)
- .containsOnly(project1.uuid());
- assertThat(underTest.selectByQuery(dbSession, organization2.getUuid(), ALL_PROJECTS_COMPONENT_QUERY, 0, 2))
- .extracting(ComponentDto::uuid)
- .containsOnly(project2.uuid());
- assertThat(underTest.selectByQuery(dbSession, "non existent organization uuid", ALL_PROJECTS_COMPONENT_QUERY, 0, 2))
- .isEmpty();
}
@Test
@@ -1457,23 +1372,6 @@ public class ComponentDaoTest {
}
@Test
- public void countByQuery_with_organization_filters_on_specified_organization() {
- OrganizationDto organization1 = db.organizations().insert();
- OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization1);
- ComponentDto project2 = db.components().insertPrivateProject(organization2);
-
- assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY))
- .isEqualTo(2);
- assertThat(underTest.countByQuery(dbSession, organization1.getUuid(), ALL_PROJECTS_COMPONENT_QUERY))
- .isEqualTo(1);
- assertThat(underTest.countByQuery(dbSession, organization2.getUuid(), ALL_PROJECTS_COMPONENT_QUERY))
- .isEqualTo(1);
- assertThat(underTest.countByQuery(dbSession, "non existent organization uuid", ALL_PROJECTS_COMPONENT_QUERY))
- .isZero();
- }
-
- @Test
public void selectByQuery_name_with_special_characters() {
db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization()).setName("project-\\_%/-name"));
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java
index 209b77d019b..0ab9489941b 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java
@@ -35,7 +35,6 @@ import org.junit.runner.RunWith;
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.source.FileSourceDto;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
@@ -62,16 +61,14 @@ public class ScrollForFileMoveComponentDaoTest {
@Test
public void scrollAllFilesForFileMove_has_no_effect_if_project_has_no_file() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization);
+ ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultContext -> fail("handler should not be called"));
}
@Test
public void scrollAllFilesForFileMove_ignores_files_with_null_path() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization);
+ ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
ComponentAndSource file = insertFileAndSource(project, FILE);
ComponentAndSource ut = insertFileAndSource(project, UNIT_TEST_FILE);
ComponentDto fileNoPath = db.components().insertComponent(ComponentTesting.newFileDto(project).setPath(null).setQualifier(FILE));
@@ -89,8 +86,7 @@ public class ScrollForFileMoveComponentDaoTest {
@Test
public void scrollAllFilesForFileMove_ignores_files_without_source() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization);
+ ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
ComponentAndSource file = insertFileAndSource(project, FILE);
ComponentAndSource ut = insertFileAndSource(project, UNIT_TEST_FILE);
ComponentDto fileNoSource = db.components().insertComponent(ComponentTesting.newFileDto(project).setPath(null).setQualifier(FILE));
@@ -106,8 +102,7 @@ public class ScrollForFileMoveComponentDaoTest {
@Test
public void scrollAllFilesForFileMove_scrolls_files_of_project() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization);
+ ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1));
ComponentAndSource file1 = insertFileAndSource(project, FILE);
@@ -125,8 +120,7 @@ public class ScrollForFileMoveComponentDaoTest {
@Test
public void scrollAllFilesForFileMove_scrolls_large_number_of_files_and_uts() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization);
+ ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
List<ComponentAndSource> files = IntStream.range(0, 300 + random.nextInt(500))
.mapToObj(i -> {
String qualifier = random.nextBoolean() ? FILE : UNIT_TEST_FILE;
@@ -145,8 +139,7 @@ public class ScrollForFileMoveComponentDaoTest {
@Test
public void scrollAllFilesForFileMove_scrolls_unit_tests_of_project() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization);
+ ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
ComponentAndSource ut = insertFileAndSource(project, UNIT_TEST_FILE);
RecordingResultHandler resultHandler = new RecordingResultHandler();
@@ -159,8 +152,7 @@ public class ScrollForFileMoveComponentDaoTest {
@Test
@UseDataProvider("branchTypes")
public void scrollAllFilesForFileMove_scrolls_files_and_unit_tests_of_branch(BranchType branchType) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization);
+ ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(branchType));
ComponentAndSource file = insertFileAndSource(branch, FILE);
ComponentAndSource ut = insertFileAndSource(branch, UNIT_TEST_FILE);
@@ -183,8 +175,7 @@ public class ScrollForFileMoveComponentDaoTest {
@Test
public void scrollAllFilesForFileMove_ignores_non_file_and_non_ut_component_with_source() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization);
+ ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject() : db.components().insertPublicProject();
db.fileSources().insertFileSource(project);
ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
db.fileSources().insertFileSource(module);
@@ -192,11 +183,11 @@ public class ScrollForFileMoveComponentDaoTest {
db.fileSources().insertFileSource(dir);
ComponentAndSource file = insertFileAndSource(module, FILE);
ComponentAndSource ut = insertFileAndSource(dir, UNIT_TEST_FILE);
- ComponentDto portfolio = random.nextBoolean() ? db.components().insertPublicPortfolio(organization) : db.components().insertPrivatePortfolio(organization);
+ ComponentDto portfolio = random.nextBoolean() ? db.components().insertPublicPortfolio() : db.components().insertPrivatePortfolio();
db.fileSources().insertFileSource(portfolio);
ComponentDto subView = db.components().insertSubView(portfolio);
db.fileSources().insertFileSource(subView);
- ComponentDto application = random.nextBoolean() ? db.components().insertPrivateApplication(organization) : db.components().insertPublicApplication(organization);
+ ComponentDto application = random.nextBoolean() ? db.components().insertPrivateApplication() : db.components().insertPublicApplication();
db.fileSources().insertFileSource(application);
RecordingResultHandler resultHandler = new RecordingResultHandler();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java
index 366f3cd8147..c9185f275e5 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java
@@ -29,7 +29,6 @@ import org.sonar.core.util.UuidFactoryFast;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -171,11 +170,10 @@ public class InternalComponentPropertiesDaoTest {
@Test
public void loadDbKey_loads_dbKeys_for_all_components_with_given_property_and_value() {
- OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto portfolio1 = dbTester.components().insertPublicPortfolio(organizationDto);
- ComponentDto portfolio2 = dbTester.components().insertPublicPortfolio(organizationDto);
- ComponentDto portfolio3 = dbTester.components().insertPublicPortfolio(organizationDto);
- ComponentDto portfolio4 = dbTester.components().insertPublicPortfolio(organizationDto);
+ ComponentDto portfolio1 = dbTester.components().insertPublicPortfolio();
+ ComponentDto portfolio2 = dbTester.components().insertPublicPortfolio();
+ ComponentDto portfolio3 = dbTester.components().insertPublicPortfolio();
+ ComponentDto portfolio4 = dbTester.components().insertPublicPortfolio();
underTest.insertOrUpdate(dbSession, portfolio1.uuid(), SOME_KEY, SOME_VALUE);
underTest.insertOrUpdate(dbSession, portfolio2.uuid(), SOME_KEY, "bar");
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 290461b7a36..9dc6ad90902 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
@@ -533,8 +533,7 @@ public class PurgeCommandsTest {
@Test
public void deletePermissions_deletes_permissions_of_private_project() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
addPermissions(project);
PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
@@ -546,8 +545,7 @@ public class PurgeCommandsTest {
@Test
public void deletePermissions_deletes_permissions_of_view() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPublicPortfolio(organization);
+ ComponentDto project = dbTester.components().insertPublicPortfolio();
addPermissions(project);
PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
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 5e8134243d7..3c5992e37b5 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
@@ -110,30 +110,42 @@ public class ComponentDbTester {
projectDtoPopulator);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator) {
return insertPrivateProject(organizationDto, componentDtoPopulator, defaults());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator,
Consumer<ProjectDto> projectDtoPopulator) {
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, defaults(),
componentDtoPopulator, projectDtoPopulator);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator) {
return insertPublicProject(organizationDto, componentDtoPopulator, defaults());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator,
Consumer<ProjectDto> projectDtoPopulator) {
return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false, defaults(), componentDtoPopulator,
projectDtoPopulator);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ComponentDto insertPrivateProject(OrganizationDto organizationDto) {
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ComponentDto insertPublicProject(OrganizationDto organizationDto) {
return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false);
}
@@ -148,6 +160,8 @@ public class ComponentDbTester {
return getProjectDto(componentDto);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ProjectDto insertPublicProjectDto(OrganizationDto organization) {
ComponentDto componentDto = insertPublicProject(organization);
return getProjectDto(componentDto);
@@ -158,11 +172,15 @@ public class ComponentDbTester {
return getProjectDto(componentDto);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ProjectDto insertPublicProjectDto(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
ComponentDto componentDto = insertPublicProject(organization, dtoPopulator);
return getProjectDto(componentDto);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ProjectDto insertPrivateProjectDto(OrganizationDto organization) {
ComponentDto componentDto = insertPrivateProject(organization);
return getProjectDto(componentDto);
@@ -181,19 +199,27 @@ public class ComponentDbTester {
return insertPrivateProject(db.getDefaultOrganization(), uuid, dtoPopulator);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ProjectDto insertPrivateProjectDto(OrganizationDto organization, Consumer<BranchDto> branchConsumer) {
ComponentDto componentDto = insertPrivateProjectWithCustomBranch(organization, branchConsumer, defaults());
return getProjectDto(componentDto);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid) {
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ComponentDto insertPublicProject(OrganizationDto organizationDto, String uuid) {
return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto, uuid), false);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid, Consumer<ComponentDto> dtoPopulator) {
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, defaults(), dtoPopulator);
}
@@ -202,17 +228,15 @@ public class ComponentDbTester {
return insertPrivateProjectWithCustomBranch(db.getDefaultOrganization(), b -> b.setBranchType(BRANCH).setKey(branchKey), defaults());
}
- public final ComponentDto insertPrivateProjectWithCustomBranch(OrganizationDto organizationDto, Consumer<BranchDto> branchPopulator) {
- return insertPrivateProjectWithCustomBranch(organizationDto, branchPopulator, defaults());
- }
-
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPrivateProjectWithCustomBranch(OrganizationDto organizationDto, Consumer<BranchDto> branchPopulator,
Consumer<ComponentDto> componentPopulator) {
return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, branchPopulator, componentPopulator);
}
/**
- * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
+ * @see #insertPublicPortfolio(java.util.function.Consumer)
* @deprecated since 6.6
*/
@Deprecated
@@ -221,7 +245,7 @@ public class ComponentDbTester {
}
/**
- * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
+ * @see #insertPublicPortfolio(java.util.function.Consumer)
* @deprecated since 6.6
*/
public ComponentDto insertView(Consumer<ComponentDto> dtoPopulator) {
@@ -229,23 +253,27 @@ public class ComponentDbTester {
}
/**
- * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
+ * @see #insertPublicPortfolio(java.util.function.Consumer)
* @deprecated since 6.6
*/
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ComponentDto insertView(OrganizationDto organizationDto) {
return insertComponentImpl(ComponentTesting.newView(organizationDto), false, defaults());
}
/**
- * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
+ * @see #insertPublicPortfolio(java.util.function.Consumer)
* @deprecated since 6.6
*/
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ComponentDto insertView(OrganizationDto organizationDto, Consumer<ComponentDto> dtoPopulator) {
return insertComponentImpl(ComponentTesting.newView(organizationDto), false, dtoPopulator);
}
/**
- * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
+ * @see #insertPublicPortfolio(java.util.function.Consumer)
* @deprecated since 6.6
*/
public ComponentDto insertView(String uuid) {
@@ -253,9 +281,11 @@ public class ComponentDbTester {
}
/**
- * @see #insertPublicPortfolio(org.sonar.db.organization.OrganizationDto, java.util.function.Consumer)
+ * @see #insertPublicPortfolio(java.util.function.Consumer)
* @deprecated since 6.6
*/
+ // TODO remove after getting rid of organization code
+ @Deprecated
public ComponentDto insertView(OrganizationDto organizationDto, String uuid) {
return insertComponentImpl(ComponentTesting.newView(organizationDto, uuid), false, defaults());
}
@@ -264,18 +294,28 @@ public class ComponentDbTester {
return insertPublicPortfolio(db.getDefaultOrganization(), defaults());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPublicPortfolio(OrganizationDto organization) {
return insertPublicPortfolio(organization, defaults());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPublicPortfolio(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
return insertComponentImpl(ComponentTesting.newView(organization).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());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPrivatePortfolio(OrganizationDto organization) {
return insertPrivatePortfolio(organization, defaults());
}
@@ -284,6 +324,8 @@ public class ComponentDbTester {
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);
}
@@ -296,11 +338,13 @@ public class ComponentDbTester {
return insertPublicApplication(db.getDefaultOrganization(), dtoPopulator);
}
+ // TODO remove after getting rid of organization code
@Deprecated
public final ComponentDto insertPublicApplication(OrganizationDto organization) {
return insertPublicApplication(organization, defaults());
}
+ // TODO remove after getting rid of organization code
@Deprecated
public final ComponentDto insertPublicApplication(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(false), false, defaults(), dtoPopulator);
@@ -330,14 +374,20 @@ public class ComponentDbTester {
return insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, defaults());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPrivateApplication(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
return insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, defaults());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPrivateApplication(OrganizationDto organization) {
return insertPrivateApplication(organization, defaults(), defaults());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public final ComponentDto insertPrivateApplication(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator, Consumer<ProjectDto> projectPopulator) {
return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(true), true, defaults(), dtoPopulator, projectPopulator);
}
@@ -486,6 +536,8 @@ public class ComponentDbTester {
return branchDto;
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
@SafeVarargs
public final ComponentDto insertProjectBranch(OrganizationDto organization, Consumer<BranchDto>... dtoPopulators) {
ComponentDto project = ComponentTesting.newPrivateProjectDto(organization);
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 3685dd15774..1a7bf0d94b8 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
@@ -125,13 +125,13 @@ public class ComponentTesting {
return newProjectDto(Uuids.createFast(), true);
}
- // TODO remove
+ // TODO remove after getting rid of organization code
@Deprecated
public static ComponentDto newPrivateProjectDto(OrganizationDto organizationDto) {
return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), true);
}
- // TODO remove
+ // TODO remove after getting rid of organization code
@Deprecated
public static ProjectDto createPrivateProjectDto(OrganizationDto organizationDto) {
return createProjectDto(organizationDto.getUuid(), Uuids.createFast(), true);
@@ -141,7 +141,7 @@ public class ComponentTesting {
return newProjectDto(uuid, true);
}
- // TODO remove
+ // TODO remove after getting rid of organization code
@Deprecated
public static ComponentDto newPrivateProjectDto(OrganizationDto organizationDto, String uuid) {
return newProjectDto(organizationDto.getUuid(), uuid, true);
@@ -151,7 +151,7 @@ public class ComponentTesting {
return newProjectDto(Uuids.createFast(), false);
}
- // TODO remove
+ // TODO remove after getting rid of organization code
@Deprecated
public static ComponentDto newPublicProjectDto(OrganizationDto organizationDto) {
return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), false);
@@ -161,13 +161,13 @@ public class ComponentTesting {
return newProjectDto(uuid, false);
}
- // TODO remove
+ // TODO remove after getting rid of organization code
@Deprecated
public static ComponentDto newPublicProjectDto(OrganizationDto organizationDto, String uuid) {
return newProjectDto(organizationDto.getUuid(), uuid, false);
}
- // TODO remove
+ // TODO remove organizationUuid parameter after getting rid of organization code
@Deprecated
private static ProjectDto createProjectDto(String organizationUuid, String uuid, boolean isPrivate) {
return new ProjectDto()
@@ -199,6 +199,11 @@ public class ComponentTesting {
.setPrivate(isPrivate);
}
+ /**
+ * use {@link org.sonar.db.component.ComponentTesting#newProjectDto(java.lang.String, boolean)} instead
+ */
+ // TODO remove after getting rid of organization code
+ @Deprecated
private static ComponentDto newProjectDto(String organizationUuid, String uuid, boolean isPrivate) {
return new ComponentDto()
.setOrganizationUuid(organizationUuid)
@@ -231,11 +236,13 @@ public class ComponentTesting {
.setPrivate(false);
}
+ // TODO remove after getting rid of organization code
@Deprecated
public static ComponentDto newView(OrganizationDto organizationDto) {
return newView(organizationDto.getUuid(), Uuids.createFast());
}
+ // TODO remove after getting rid of organization code
@Deprecated
public static ComponentDto newView(OrganizationDto organizationDto, String uuid) {
return newPrivateProjectDto(organizationDto, uuid)
@@ -245,6 +252,8 @@ public class ComponentTesting {
.setPrivate(false);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
private static ComponentDto newView(String organizationUuid, String uuid) {
return newProjectDto(organizationUuid, uuid, false)
.setUuid(uuid)
@@ -256,18 +265,26 @@ public class ComponentTesting {
return newView(Uuids.createFast()).setQualifier(Qualifiers.APP);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public static ComponentDto newApplication(OrganizationDto organizationDto) {
return newApplication(organizationDto.getUuid());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public static ComponentDto newApplication(OrganizationDto organizationDto, String uuid) {
return newApplication(organizationDto.getUuid(), uuid);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public static ComponentDto newApplication(String organizationUuid) {
return newApplication(organizationUuid, Uuids.createFast());
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
public static ComponentDto newApplication(String organizationUuid, String uuid) {
return newView(organizationUuid, uuid).setQualifier(Qualifiers.APP);
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProvider.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProvider.java
deleted file mode 100644
index cc3eeb73f41..00000000000
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProvider.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version;
-
-import java.sql.SQLException;
-import org.sonar.server.platform.db.migration.step.DataChange;
-
-public interface DefaultOrganizationUuidProvider {
- /**
- * Retrieves the uuid of the default organization from table INTERNAL_PROPERTIES.
- *
- * @throws IllegalStateException if uuid of the default organization can't be retrieved
- */
- String get(DataChange.Context context) throws SQLException;
-
- /**
- * Retrieves the uuid of the default organization from table INTERNAL_PROPERTIES and ensure the specified organization
- * exists in table ORGANIZATIONS.
- *
- * @throws IllegalStateException if uuid of the default organization can't be retrieved
- * @throws IllegalStateException if the default organization does not exist
- */
- String getAndCheck(DataChange.Context context) throws SQLException;
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImpl.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImpl.java
deleted file mode 100644
index d5dccd5532c..00000000000
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImpl.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version;
-
-import java.sql.SQLException;
-import org.sonar.server.platform.db.migration.step.DataChange;
-import org.sonar.server.platform.db.migration.step.Select;
-
-import static com.google.common.base.Preconditions.checkState;
-
-/**
- * Component which can be injected in steps which provides access to the UUID of the default organization, it reads
- * directly from the BD.
- */
-public class DefaultOrganizationUuidProviderImpl implements DefaultOrganizationUuidProvider {
-
- private static final String INTERNAL_PROPERTY_DEFAULT_ORGANIZATION = "organization.default";
-
- @Override
- public String get(DataChange.Context context) throws SQLException {
- Select select = context.prepareSelect("select text_value from internal_properties where kee=?");
- select.setString(1, INTERNAL_PROPERTY_DEFAULT_ORGANIZATION);
- String uuid = select.get(row -> row.getString(1));
- checkState(uuid != null, "Default organization uuid is missing");
- return uuid;
- }
-
- @Override
- public String getAndCheck(DataChange.Context context) throws SQLException {
- String organizationUuid = get(context);
- Select select = context.prepareSelect("select uuid from organizations where uuid=?")
- .setString(1, organizationUuid);
- checkState(select.get(row -> row.getString(1)) != null,
- "Default organization with uuid '%s' does not exist in table ORGANIZATIONS",
- organizationUuid);
- return organizationUuid;
- }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImplTest.java
deleted file mode 100644
index c31a4bb3086..00000000000
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/DefaultOrganizationUuidProviderImplTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version;
-
-import java.sql.Connection;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DataChange;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultOrganizationUuidProviderImplTest {
- private static final String AN_ORG_UUID = "org1";
-
- @Rule
- public CoreDbTester dbTester = CoreDbTester.createForSchema(DefaultOrganizationUuidProviderImplTest.class, "internal_properties.sql");
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- private DefaultOrganizationUuidProvider underTest = new DefaultOrganizationUuidProviderImpl();
-
- @Test
- public void get_fails_with_ISE_if_default_organization_internal_property_is_not_set() throws Exception {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Default organization uuid is missing");
-
- callGet(underTest);
- }
-
- @Test
- public void get_returns_uuid_from_table_INTERNAL_PROPERTIES() throws Exception {
- dbTester.executeInsert("internal_properties", "kee", "organization.default", "is_empty", false, "text_value", AN_ORG_UUID);
-
- assertThat(callGet(underTest)).isEqualTo(AN_ORG_UUID);
- }
-
- private String callGet(DefaultOrganizationUuidProvider defaultOrganizationUuid) throws Exception {
- try (Connection connection = dbTester.openConnection()) {
- DataChange.Context context = new DataChange.Context(dbTester.database(), connection, connection);
- return defaultOrganizationUuid.get(context);
- }
- }
-
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/TestDefaultOrganizationUuidProvider.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/TestDefaultOrganizationUuidProvider.java
deleted file mode 100644
index e0300bac4fd..00000000000
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/TestDefaultOrganizationUuidProvider.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.db.migration.version;
-
-import org.sonar.server.platform.db.migration.step.DataChange;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * Implementation of {@link DefaultOrganizationUuidProvider} which never fails and returns the specified organization uuid.
- */
-public class TestDefaultOrganizationUuidProvider implements DefaultOrganizationUuidProvider {
- private final String organizationUuid;
-
- public TestDefaultOrganizationUuidProvider(String organizationUuid) {
- this.organizationUuid = requireNonNull(organizationUuid, "organizationUuid can't be null");
- }
-
- @Override
- public String get(DataChange.Context context) {
- return organizationUuid;
- }
-
- @Override
- public String getAndCheck(DataChange.Context context) {
- return organizationUuid;
- }
-}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/organization/DefaultOrganizationProviderImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/organization/DefaultOrganizationProviderImpl.java
index 207913fe827..d6361ac38b2 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/organization/DefaultOrganizationProviderImpl.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/organization/DefaultOrganizationProviderImpl.java
@@ -23,9 +23,9 @@ import java.util.Optional;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.server.property.InternalProperties;
import static com.google.common.base.Preconditions.checkState;
+import static org.sonar.db.organization.OrganizationDao.DEFAULT_ORGANIZATION;
public class DefaultOrganizationProviderImpl implements DefaultOrganizationProvider {
private final DbClient dbClient;
@@ -46,7 +46,7 @@ public class DefaultOrganizationProviderImpl implements DefaultOrganizationProvi
public static DefaultOrganization getDefaultOrganization(DbClient dbClient) {
try (DbSession dbSession = dbClient.openSession(false)) {
- Optional<String> uuid = dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.DEFAULT_ORGANIZATION);
+ Optional<String> uuid = dbClient.internalPropertiesDao().selectByKey(dbSession, DEFAULT_ORGANIZATION);
checkState(uuid.isPresent() && !uuid.get().isEmpty(), "No Default organization uuid configured");
Optional<OrganizationDto> dto = dbClient.organizationDao().selectByUuid(dbSession, uuid.get());
checkState(dto.isPresent(), "Default organization with uuid '%s' does not exist", uuid.get());
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java b/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java
index 05b45240d5d..4a7c0cd7ae8 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java
@@ -26,11 +26,6 @@ import javax.annotation.Nullable;
* Allows to read and write internal properties.
*/
public interface InternalProperties {
- /**
- * The UUID of the default organization.
- * Can't be null unless SQ is strongly corrupted.
- */
- String DEFAULT_ORGANIZATION = "organization.default";
String ORGANIZATION_ENABLED = "organization.enabled";
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java
index a7034d31356..d879f705589 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java
@@ -31,8 +31,8 @@ import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.db.organization.OrganizationDao.DEFAULT_ORGANIZATION;
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
-import static org.sonar.server.property.InternalProperties.DEFAULT_ORGANIZATION;
public class DefaultOrganizationProviderImplTest {
private static final OrganizationDto ORGANIZATION_DTO_1 = newOrganizationDto()
@@ -41,17 +41,17 @@ public class DefaultOrganizationProviderImplTest {
.setKey("the key 1");
private static final long DATE_1 = 1_999_888L;
- private System2 system2 = mock(System2.class);
+ private final System2 system2 = mock(System2.class);
@Rule
public DbTester dbTester = DbTester.create(system2).setDisableDefaultOrganization(true);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DbClient dbClient = dbTester.getDbClient();
- private DbSession dbSession = dbTester.getSession();
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final DbSession dbSession = dbTester.getSession();
- private DefaultOrganizationProviderImpl underTest = new DefaultOrganizationProviderImpl(dbClient);
+ private final DefaultOrganizationProviderImpl underTest = new DefaultOrganizationProviderImpl(dbClient);
@Test
public void get_fails_with_ISE_if_default_organization_internal_property_does_not_exist() {
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/DefaultOrganizationEnforcer.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/DefaultOrganizationEnforcer.java
index 752d55be190..6c1742ffa10 100644
--- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/DefaultOrganizationEnforcer.java
+++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/organization/DefaultOrganizationEnforcer.java
@@ -21,6 +21,8 @@ package org.sonar.server.organization;
import org.picocontainer.Startable;
+//TODO remove together with the default organization concept
+@Deprecated
public class DefaultOrganizationEnforcer implements Startable {
private final DefaultOrganizationProvider defaultOrganizationProvider;