diff options
author | Michal Duda <michal.duda@sonarsource.com> | 2020-12-17 00:13:33 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-12-22 20:09:38 +0000 |
commit | 52845e663cfc638d3aecef53223f50f8fed3f135 (patch) | |
tree | 0b997106c33f49f6f52d98e7c81df894242dca89 /server/sonar-db-migration | |
parent | 65556c25122bf9fc25e6750420cdea849e3fa53d (diff) | |
download | sonarqube-52845e663cfc638d3aecef53223f50f8fed3f135.tar.gz sonarqube-52845e663cfc638d3aecef53223f50f8fed3f135.zip |
SONAR-13999 remove orgs from application WS
Diffstat (limited to 'server/sonar-db-migration')
4 files changed, 0 insertions, 204 deletions
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; - } -} |