From 967d9ad59cdf8f5c0f0dde3646f4dee950ec05bc Mon Sep 17 00:00:00 2001 From: Jacek Date: Mon, 21 Dec 2020 11:29:10 +0100 Subject: [PATCH] SONAR-13999 drop OrganizationAlmBinding class and related --- .../src/main/java/org/sonar/db/DaoModule.java | 4 - .../src/main/java/org/sonar/db/DbClient.java | 14 - .../src/main/java/org/sonar/db/MyBatis.java | 4 - .../src/main/java/org/sonar/db/alm/ALM.java | 35 -- .../org/sonar/db/alm/AlmAppInstallDao.java | 106 ------ .../org/sonar/db/alm/AlmAppInstallDto.java | 132 ------- .../org/sonar/db/alm/AlmAppInstallMapper.java | 53 --- .../java/org/sonar/db/alm/AlmTesting.java | 29 -- .../db/alm/OrganizationAlmBindingDao.java | 97 ----- .../db/alm/OrganizationAlmBindingDto.java | 138 ------- .../db/alm/OrganizationAlmBindingMapper.java | 46 --- .../db/organization/OrganizationDao.java | 5 - .../db/organization/OrganizationMapper.java | 3 - .../org/sonar/db/alm/AlmAppInstallMapper.xml | 106 ------ .../db/alm/OrganizationAlmBindingMapper.xml | 99 ----- .../db/organization/OrganizationMapper.xml | 11 - .../sonar/db/alm/AlmAppInstallDaoTest.java | 352 ------------------ .../db/alm/OrganizationAlmBindingDaoTest.java | 222 ----------- .../java/org/sonar/db/DbTester.java | 7 - .../java/org/sonar/db/alm/AlmDbTester.java | 62 --- 20 files changed, 1525 deletions(-) delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/alm/ALM.java delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmTesting.java delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDao.java delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDto.java delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingMapper.java delete mode 100644 server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml delete mode 100644 server/sonar-db-dao/src/main/resources/org/sonar/db/alm/OrganizationAlmBindingMapper.xml delete mode 100644 server/sonar-db-dao/src/test/java/org/sonar/db/alm/AlmAppInstallDaoTest.java delete mode 100644 server/sonar-db-dao/src/test/java/org/sonar/db/alm/OrganizationAlmBindingDaoTest.java delete mode 100644 server/sonar-db-dao/src/testFixtures/java/org/sonar/db/alm/AlmDbTester.java diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java index 9baeac01d08..84799ca2387 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java @@ -23,8 +23,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import org.sonar.core.platform.Module; -import org.sonar.db.alm.AlmAppInstallDao; -import org.sonar.db.alm.OrganizationAlmBindingDao; import org.sonar.db.alm.pat.AlmPatDao; import org.sonar.db.alm.setting.AlmSettingDao; import org.sonar.db.alm.setting.ProjectAlmSettingDao; @@ -121,7 +119,6 @@ public class DaoModule extends Module { GroupDao.class, GroupMembershipDao.class, GroupPermissionDao.class, - AlmAppInstallDao.class, AlmSettingDao.class, AlmPatDao.class, ProjectAlmSettingDao.class, @@ -134,7 +131,6 @@ public class DaoModule extends Module { MetricDao.class, NewCodePeriodDao.class, NotificationQueueDao.class, - OrganizationAlmBindingDao.class, OrganizationDao.class, PermissionTemplateCharacteristicDao.class, PermissionTemplateDao.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java index b63d1085963..30f0536b259 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java @@ -21,8 +21,6 @@ package org.sonar.db; import java.util.IdentityHashMap; import java.util.Map; -import org.sonar.db.alm.AlmAppInstallDao; -import org.sonar.db.alm.OrganizationAlmBindingDao; import org.sonar.db.alm.pat.AlmPatDao; import org.sonar.db.alm.setting.AlmSettingDao; import org.sonar.db.alm.setting.ProjectAlmSettingDao; @@ -103,7 +101,6 @@ public class DbClient { private final QualityProfileDao qualityProfileDao; private final QualityProfileExportDao qualityProfileExportDao; private final PropertiesDao propertiesDao; - private final AlmAppInstallDao almAppInstallDao; private final AlmSettingDao almSettingDao; private final AlmPatDao almPatDao; private final ProjectAlmSettingDao projectAlmSettingDao; @@ -159,7 +156,6 @@ public class DbClient { private final WebhookDao webhookDao; private final WebhookDeliveryDao webhookDeliveryDao; private final ProjectMappingsDao projectMappingsDao; - private final OrganizationAlmBindingDao organizationAlmBindingDao; private final NewCodePeriodDao newCodePeriodDao; private final ProjectDao projectDao; private final SessionTokensDao sessionTokensDao; @@ -176,7 +172,6 @@ public class DbClient { for (Dao dao : daos) { map.put(dao.getClass(), dao); } - almAppInstallDao = getDao(map, AlmAppInstallDao.class); almSettingDao = getDao(map, AlmSettingDao.class); almPatDao = getDao(map, AlmPatDao.class); projectAlmSettingDao = getDao(map, ProjectAlmSettingDao.class); @@ -237,7 +232,6 @@ public class DbClient { webhookDao = getDao(map, WebhookDao.class); webhookDeliveryDao = getDao(map, WebhookDeliveryDao.class); projectMappingsDao = getDao(map, ProjectMappingsDao.class); - organizationAlmBindingDao = getDao(map, OrganizationAlmBindingDao.class); internalComponentPropertiesDao = getDao(map, InternalComponentPropertiesDao.class); newCodePeriodDao = getDao(map, NewCodePeriodDao.class); projectDao = getDao(map, ProjectDao.class); @@ -255,10 +249,6 @@ public class DbClient { return database; } - public AlmAppInstallDao almAppInstallDao() { - return almAppInstallDao; - } - public AlmSettingDao almSettingDao() { return almSettingDao; } @@ -517,10 +507,6 @@ public class DbClient { return projectMappingsDao; } - public OrganizationAlmBindingDao organizationAlmBindingDao() { - return organizationAlmBindingDao; - } - public InternalComponentPropertiesDao internalComponentPropertiesDao() { return internalComponentPropertiesDao; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index c578a6b5028..42a3f7ae35f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -34,8 +34,6 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.apache.ibatis.session.TransactionIsolationLevel; import org.sonar.api.Startable; -import org.sonar.db.alm.AlmAppInstallMapper; -import org.sonar.db.alm.OrganizationAlmBindingMapper; import org.sonar.db.alm.pat.AlmPatMapper; import org.sonar.db.alm.setting.AlmSettingMapper; import org.sonar.db.alm.setting.ProjectAlmSettingMapper; @@ -225,7 +223,6 @@ public class MyBatis implements Startable { // keep them sorted alphabetically Class[] mappers = { ActiveRuleMapper.class, - AlmAppInstallMapper.class, AlmPatMapper.class, AlmSettingMapper.class, AnalysisPropertiesMapper.class, @@ -260,7 +257,6 @@ public class MyBatis implements Startable { MetricMapper.class, NewCodePeriodMapper.class, NotificationQueueMapper.class, - OrganizationAlmBindingMapper.class, OrganizationMapper.class, PermissionTemplateCharacteristicMapper.class, PermissionTemplateMapper.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ALM.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ALM.java deleted file mode 100644 index 12dc7fd0d03..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ALM.java +++ /dev/null @@ -1,35 +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.db.alm; - -import java.util.Locale; - -public enum ALM { - BITBUCKETCLOUD, - GITHUB; - - public static ALM fromId(String almId) { - return ALM.valueOf(almId.toUpperCase(Locale.ENGLISH)); - } - - public String getId() { - return this.name().toLowerCase(Locale.ENGLISH); - } -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java deleted file mode 100644 index c56a80a7404..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java +++ /dev/null @@ -1,106 +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.db.alm; - -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.Nullable; -import org.sonar.api.utils.System2; -import org.sonar.core.util.UuidFactory; -import org.sonar.db.Dao; -import org.sonar.db.DbSession; -import org.sonar.db.organization.OrganizationDto; - -import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Objects.requireNonNull; -import static org.apache.commons.lang.StringUtils.isNotEmpty; -import static org.sonar.db.DatabaseUtils.executeLargeInputs; - -/** - * Store instances of installed app in external ALM like GitHub or Bitbucket Cloud. - */ -public class AlmAppInstallDao implements Dao { - - private final System2 system2; - private final UuidFactory uuidFactory; - - public AlmAppInstallDao(System2 system2, UuidFactory uuidFactory) { - this.system2 = system2; - this.uuidFactory = uuidFactory; - } - - public Optional selectByUuid(DbSession dbSession, String uuid) { - AlmAppInstallMapper mapper = getMapper(dbSession); - return Optional.ofNullable(mapper.selectByUuid(uuid)); - } - - public Optional selectByOrganizationAlmId(DbSession dbSession, ALM alm, String organizationAlmId) { - checkAlm(alm); - checkOrganizationAlmId(organizationAlmId); - - AlmAppInstallMapper mapper = getMapper(dbSession); - return Optional.ofNullable(mapper.selectByOrganizationAlmId(alm.getId(), organizationAlmId)); - } - - public Optional selectByOrganization(DbSession dbSession, OrganizationDto organization) { - AlmAppInstallMapper mapper = getMapper(dbSession); - return Optional.ofNullable(mapper.selectByOrganizationUuid(organization.getUuid())); - } - - public List selectByOrganizations(DbSession dbSession, List organizations) { - Set organizationUuids = organizations.stream().map(OrganizationDto::getUuid).collect(Collectors.toSet()); - return executeLargeInputs(organizationUuids, uuids -> getMapper(dbSession).selectByOrganizationUuids(uuids)); - } - - public void insertOrUpdate(DbSession dbSession, ALM alm, String organizationAlmId, @Nullable Boolean isOwnerUser, String installId, @Nullable String userExternalId) { - checkAlm(alm); - checkOrganizationAlmId(organizationAlmId); - checkArgument(isNotEmpty(installId), "installId can't be null nor empty"); - - AlmAppInstallMapper mapper = getMapper(dbSession); - long now = system2.now(); - - if (mapper.update(alm.getId(), organizationAlmId, isOwnerUser, installId, userExternalId, now) == 0) { - mapper.insert(uuidFactory.create(), alm.getId(), organizationAlmId, isOwnerUser, installId, userExternalId, now); - } - } - - public void delete(DbSession dbSession, ALM alm, String organizationAlmId) { - checkAlm(alm); - checkOrganizationAlmId(organizationAlmId); - - AlmAppInstallMapper mapper = getMapper(dbSession); - mapper.delete(alm.getId(), organizationAlmId); - } - - private static void checkAlm(@Nullable ALM alm) { - requireNonNull(alm, "alm can't be null"); - } - - private static void checkOrganizationAlmId(@Nullable String organizationAlmId) { - checkArgument(isNotEmpty(organizationAlmId), "organizationAlmId can't be null nor empty"); - } - - private static AlmAppInstallMapper getMapper(DbSession dbSession) { - return dbSession.getMapper(AlmAppInstallMapper.class); - } -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java deleted file mode 100644 index 486a0b68078..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java +++ /dev/null @@ -1,132 +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.db.alm; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -public class AlmAppInstallDto { - - /** - * Technical unique identifier, can't be null - */ - private String uuid; - /** - * Identifier of the ALM, like 'bitbucketcloud' or 'github', can't be null. - * Note that the db column is named alm_id. - * - * @see ALM for the list of available values - */ - private String rawAlm; - /** - * ALM specific identifier of the organization, like team or user uuid for Bitbucket Cloud or organization id for Github, can't be null. - * Note that the column is badly named owner_id, in the first place it was only possible to install personal organizations. - * The column name has been kept to prevent doing a db migration. - */ - private String organizationAlmId; - /** - * ALM specific identifier of the app installation, can't be null - */ - private String installId; - /** - * Is owner a user, can be null - */ - private Boolean isOwnerUser; - /** - * The user ID provided by the ALM of the user who has installed the ALM installation. Can be null as some ALM doesn't provide this info. Max size is 255. - */ - private String userExternalId; - - private long createdAt; - private long updatedAt; - - public String getUuid() { - return uuid; - } - - public AlmAppInstallDto setUuid(String uuid) { - this.uuid = uuid; - return this; - } - - public ALM getAlm() { - return ALM.fromId(rawAlm); - } - - public AlmAppInstallDto setAlm(ALM alm) { - this.rawAlm = alm.getId(); - return this; - } - - public String getOrganizationAlmId() { - return organizationAlmId; - } - - public AlmAppInstallDto setOrganizationAlmId(String organizationAlmId) { - this.organizationAlmId = organizationAlmId; - return this; - } - - public String getInstallId() { - return installId; - } - - public AlmAppInstallDto setInstallId(String installId) { - this.installId = installId; - return this; - } - - public boolean isOwnerUser() { - return isOwnerUser; - } - - public AlmAppInstallDto setIsOwnerUser(boolean isOwnerUser) { - this.isOwnerUser = isOwnerUser; - return this; - } - - @CheckForNull - public String getUserExternalId() { - return userExternalId; - } - - public AlmAppInstallDto setUserExternalId(@Nullable String userExternalId) { - this.userExternalId = userExternalId; - return this; - } - - public long getCreatedAt() { - return createdAt; - } - - AlmAppInstallDto setCreatedAt(long createdAt) { - this.createdAt = createdAt; - return this; - } - - public long getUpdatedAt() { - return updatedAt; - } - - AlmAppInstallDto setUpdatedAt(long updatedAt) { - this.updatedAt = updatedAt; - return this; - } -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java deleted file mode 100644 index 0d83728b238..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java +++ /dev/null @@ -1,53 +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.db.alm; - -import java.util.Collection; -import java.util.List; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.apache.ibatis.annotations.Param; - -public interface AlmAppInstallMapper { - - @CheckForNull - AlmAppInstallDto selectByOrganizationAlmId(@Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId); - - @CheckForNull - AlmAppInstallDto selectByInstallationId(@Param("alm") String alm, @Param("installId") String installId); - - @CheckForNull - AlmAppInstallDto selectByUuid(@Param("uuid") String uuid); - - @CheckForNull - AlmAppInstallDto selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid); - - List selectUnboundByUserExternalId(@Param("userExternalId") String userExternalId); - - void insert(@Param("uuid") String uuid, @Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId, - @Nullable @Param("isOwnerUser") Boolean isOwnerUser, @Param("installId") String installId, @Nullable @Param("userExternalId") String userExternalId, @Param("now") long now); - - int update(@Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId, - @Nullable @Param("isOwnerUser") Boolean isOwnerUser, @Param("installId") String installId, @Nullable @Param("userExternalId") String userExternalId, @Param("now") long now); - - void delete(@Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId); - - List selectByOrganizationUuids(@Param("organizationUuids") Collection organizationUuids); -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmTesting.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmTesting.java deleted file mode 100644 index 0f142ff9a14..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmTesting.java +++ /dev/null @@ -1,29 +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.db.alm; - -public class AlmTesting { - - private AlmTesting() { - // only statics - } - - -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDao.java deleted file mode 100644 index 421ec3a45e7..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDao.java +++ /dev/null @@ -1,97 +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.db.alm; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import org.sonar.api.utils.System2; -import org.sonar.core.util.UuidFactory; -import org.sonar.db.Dao; -import org.sonar.db.DbSession; -import org.sonar.db.organization.OrganizationDto; - -import static java.util.Optional.ofNullable; -import static org.sonar.core.util.stream.MoreCollectors.toSet; -import static org.sonar.db.DatabaseUtils.executeLargeInputs; - -public class OrganizationAlmBindingDao implements Dao { - - private final System2 system2; - private final UuidFactory uuidFactory; - - public OrganizationAlmBindingDao(System2 system2, UuidFactory uuidFactory) { - this.system2 = system2; - this.uuidFactory = uuidFactory; - } - - public Optional selectByOrganization(DbSession dbSession, OrganizationDto organization) { - return selectByOrganizationUuid(dbSession, organization.getUuid()); - } - - public Optional selectByOrganizationUuid(DbSession dbSession, String organizationUuid) { - return ofNullable(getMapper(dbSession).selectByOrganizationUuid(organizationUuid)); - } - - public List selectByOrganizations(DbSession dbSession, Collection organizations) { - return selectByOrganizationUuids(dbSession, organizations.stream().map(OrganizationDto::getUuid).collect(toSet())); - } - - public List selectByOrganizationUuids(DbSession dbSession, Collection organizationUuids) { - return executeLargeInputs(organizationUuids, uuids -> getMapper(dbSession).selectByOrganizationUuids(uuids)); - } - - public Optional selectByAlmAppInstall(DbSession dbSession, AlmAppInstallDto almAppInstall) { - return ofNullable(getMapper(dbSession).selectByInstallationUuid(almAppInstall.getUuid())); - } - - public List selectByOrganizationAlmIds(DbSession dbSession, ALM alm, Collection organizationAlmIds) { - return executeLargeInputs(organizationAlmIds, o -> getMapper(dbSession).selectByOrganizationAlmIds(alm.getId(), o)); - } - - public void insert(DbSession dbSession, OrganizationDto organization, AlmAppInstallDto almAppInstall, String url, String userUuid, boolean membersSync) { - long now = system2.now(); - getMapper(dbSession).insert(new OrganizationAlmBindingDto() - .setUuid(uuidFactory.create()) - .setOrganizationUuid(organization.getUuid()) - .setAlmAppInstallUuid(almAppInstall.getUuid()) - .setAlmId(almAppInstall.getAlm()) - .setUrl(url) - .setUserUuid(userUuid) - .setMembersSyncEnabled(membersSync) - .setCreatedAt(now)); - } - - public void deleteByOrganization(DbSession dbSession, OrganizationDto organization) { - getMapper(dbSession).deleteByOrganizationUuid(organization.getUuid()); - } - - public void deleteByAlmAppInstall(DbSession dbSession, AlmAppInstallDto almAppInstall) { - getMapper(dbSession).deleteByAlmAppInstallUuid(almAppInstall.getUuid()); - } - - public void updateMembersSync(DbSession dbSession, OrganizationAlmBindingDto orgAlmBinding, boolean enabled) { - getMapper(dbSession).updateMembersSync(orgAlmBinding.getUuid(), enabled); - } - - private static OrganizationAlmBindingMapper getMapper(DbSession dbSession) { - return dbSession.getMapper(OrganizationAlmBindingMapper.class); - } -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDto.java deleted file mode 100644 index 7f851286934..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDto.java +++ /dev/null @@ -1,138 +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.db.alm; - -import java.util.Arrays; - -/** - * This DTO is used to link an {@link org.sonar.db.organization.OrganizationDto} to a {@link AlmAppInstallDto} - */ -public class OrganizationAlmBindingDto { - - /** - * Not empty. Max size is 40. Obviously it is unique. - */ - private String uuid; - /** - * The UUID of the organization. Can't be null. Max size is 40. - * It's unique, as an organization is only linked to one installation (at least for the moment). - */ - private String organizationUuid; - /** - * The UUID of ALM installation. Can't be null. Max size is 40. - * It's unique, as an installation is related to only one organization. - */ - private String almAppInstallUuid; - /** - * The id of the ALM. Can't be null. Max size is 40. - */ - private String rawAlmId; - /** - * The url of the ALM organization. Can't be null. Max size is 2000. - */ - private String url; - /** - * The UUID of the user who has created the link between the organization and the ALM installation. Can't be null. Max size is 255. - */ - private String userUuid; - /** - * If the members of the org are automatically sync with the ALM org - */ - private boolean membersSyncEnabled; - /** - * Technical creation date - */ - private long createdAt; - - public String getUuid() { - return uuid; - } - - OrganizationAlmBindingDto setUuid(String uuid) { - this.uuid = uuid; - return this; - } - - public String getOrganizationUuid() { - return organizationUuid; - } - - public OrganizationAlmBindingDto setOrganizationUuid(String organizationUuid) { - this.organizationUuid = organizationUuid; - return this; - } - - public String getAlmAppInstallUuid() { - return almAppInstallUuid; - } - - public OrganizationAlmBindingDto setAlmAppInstallUuid(String almAppInstallUuid) { - this.almAppInstallUuid = almAppInstallUuid; - return this; - } - - public ALM getAlm() { - return Arrays.stream(ALM.values()) - .filter(a -> a.getId().equals(rawAlmId)) - .findAny() - .orElseThrow(() -> new IllegalStateException("ALM id " + rawAlmId + " is invalid")); - } - - public OrganizationAlmBindingDto setAlmId(ALM alm) { - this.rawAlmId = alm.getId(); - return this; - } - - public String getUrl() { - return url; - } - - public OrganizationAlmBindingDto setUrl(String url) { - this.url = url; - return this; - } - - public String getUserUuid() { - return userUuid; - } - - public OrganizationAlmBindingDto setUserUuid(String userUuid) { - this.userUuid = userUuid; - return this; - } - - public boolean isMembersSyncEnable() { - return membersSyncEnabled; - } - - public OrganizationAlmBindingDto setMembersSyncEnabled(boolean membersSyncEnabled) { - this.membersSyncEnabled = membersSyncEnabled; - return this; - } - - public long getCreatedAt() { - return createdAt; - } - - OrganizationAlmBindingDto setCreatedAt(long createdAt) { - this.createdAt = createdAt; - return this; - } -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingMapper.java deleted file mode 100644 index 1ef4b91850a..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingMapper.java +++ /dev/null @@ -1,46 +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.db.alm; - -import java.util.Collection; -import java.util.List; -import javax.annotation.CheckForNull; -import org.apache.ibatis.annotations.Param; - -public interface OrganizationAlmBindingMapper { - - @CheckForNull - OrganizationAlmBindingDto selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid); - - List selectByOrganizationUuids(@Param("organizationUuids") Collection organizationUuids); - - @CheckForNull - OrganizationAlmBindingDto selectByInstallationUuid(@Param("installationUuid") String installationUuid); - - List selectByOrganizationAlmIds(@Param("alm") String alm, @Param("organizationAlmIds") List organizationAlmId); - - void insert(@Param("dto") OrganizationAlmBindingDto dto); - - void deleteByOrganizationUuid(@Param("organizationUuid") String organizationUuid); - - void deleteByAlmAppInstallUuid(@Param("almAppInstallUuid") String almAppInstallUuid); - - void updateMembersSync(@Param("uuid") String uuid, @Param("membersSyncEnabled") boolean membersSyncEnabled); -} 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 8a71d78a42e..af5e2bed102 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 @@ -27,7 +27,6 @@ import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; 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; @@ -97,10 +96,6 @@ public class OrganizationDao implements Dao { return getMapper(dbSession).selectByPermission(userUuid, permission); } - public Optional selectByOrganizationAlmId(DbSession dbSession, ALM alm, String organizationAlmId) { - return Optional.ofNullable(getMapper(dbSession).selectByOrganizationAlmId(alm.getId(), organizationAlmId)); - } - public List selectAllUuids(DbSession dbSession) { return getMapper(dbSession).selectAllUuids(); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java index defe27ba197..24708e10d2d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java @@ -40,9 +40,6 @@ public interface OrganizationMapper { @CheckForNull OrganizationDto selectByUuid(@Param("uuid") String uuid); - @CheckForNull - OrganizationDto selectByOrganizationAlmId(@Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId); - List selectByUuids(@Param("uuids") List uuids); List selectByPermission(@Param("userUuid") String userUuid, @Param("permission") String permission); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml deleted file mode 100644 index b7a8fcd42b3..00000000000 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - aai.uuid, - aai.alm_id as rawAlm, - aai.owner_id as organizationAlmId, - aai.is_owner_user as isOwnerUser, - aai.install_id as installId, - aai.user_external_id as userExternalId, - aai.created_at as createdAt, - aai.updated_at as updatedAt - - - - - - - - - - - - - - INSERT INTO alm_app_installs - ( - uuid, - alm_id, - owner_id, - is_owner_user, - install_id, - user_external_id, - created_at, - updated_at - ) - VALUES ( - #{uuid, jdbcType=VARCHAR}, - #{alm, jdbcType=VARCHAR}, - #{organizationAlmId, jdbcType=VARCHAR}, - #{isOwnerUser, jdbcType=BOOLEAN}, - #{installId, jdbcType=VARCHAR}, - #{userExternalId, jdbcType=VARCHAR}, - #{now, jdbcType=BIGINT}, - #{now, jdbcType=BIGINT} - ) - - - - update alm_app_installs set - install_id = #{installId, jdbcType=VARCHAR}, - is_owner_user = #{isOwnerUser, jdbcType=BOOLEAN}, - user_external_id = #{userExternalId, jdbcType=VARCHAR}, - updated_at = #{now, jdbcType=BIGINT} - where - alm_id = #{alm, jdbcType=VARCHAR} - and owner_id = #{organizationAlmId, jdbcType=VARCHAR} - - - - delete from alm_app_installs - where - alm_id = #{alm, jdbcType=VARCHAR} - and owner_id = #{organizationAlmId, jdbcType=VARCHAR} - - - - diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/OrganizationAlmBindingMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/OrganizationAlmBindingMapper.xml deleted file mode 100644 index 38af308113a..00000000000 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/OrganizationAlmBindingMapper.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - oab.uuid, - oab.organization_uuid as organizationUuid, - oab.alm_app_install_uuid as almAppInstallUuid, - oab.alm_id as rawAlmId, - oab.url, - oab.user_uuid as userUuid, - oab.members_sync_enabled as membersSyncEnabled, - oab.created_at as createdAt - - - - - - - - - - - - INSERT INTO organization_alm_bindings - ( - uuid, - organization_uuid, - alm_app_install_uuid, - alm_id, - url, - user_uuid, - members_sync_enabled, - created_at - ) - VALUES ( - #{dto.uuid, jdbcType=VARCHAR}, - #{dto.organizationUuid, jdbcType=VARCHAR}, - #{dto.almAppInstallUuid, jdbcType=VARCHAR}, - #{dto.rawAlmId, jdbcType=VARCHAR}, - #{dto.url, jdbcType=VARCHAR}, - #{dto.userUuid, jdbcType=VARCHAR}, - #{dto.membersSyncEnabled, jdbcType=BOOLEAN}, - #{dto.createdAt, jdbcType=BIGINT} - ) - - - - DELETE FROM organization_alm_bindings WHERE organization_uuid = #{organizationUuid, jdbcType=VARCHAR} - - - - DELETE FROM organization_alm_bindings WHERE alm_app_install_uuid = #{almAppInstallUuid, jdbcType=VARCHAR} - - - - update organization_alm_bindings set - members_sync_enabled = #{membersSyncEnabled, jdbcType=BOOLEAN} - where - uuid = #{uuid, jdbcType=VARCHAR} - - diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml index 884e30b9891..9a396e50ab9 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml @@ -57,17 +57,6 @@ - -