diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2023-05-17 19:07:41 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-06-01 20:02:59 +0000 |
commit | ed9e9fe01378bf17277ed300689b1304ee4497f6 (patch) | |
tree | 767faf1e829e92a55c46ee7d2a3e028f98895cfe /server/sonar-db-dao/src/main/java/org | |
parent | aa08b062fe0ad882f7da840e8a6eb01bcc87b4e1 (diff) | |
download | sonarqube-ed9e9fe01378bf17277ed300689b1304ee4497f6.tar.gz sonarqube-ed9e9fe01378bf17277ed300689b1304ee4497f6.zip |
SONAR-18856 Extract governance reports data from properties table
Diffstat (limited to 'server/sonar-db-dao/src/main/java/org')
12 files changed, 389 insertions, 0 deletions
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 44a996e4b41..aeb4c6ed446 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 @@ -78,6 +78,8 @@ import org.sonar.db.qualityprofile.QProfileEditUsersDao; import org.sonar.db.qualityprofile.QualityProfileDao; import org.sonar.db.qualityprofile.QualityProfileExportDao; import org.sonar.db.report.RegulatoryReportDao; +import org.sonar.db.report.ReportScheduleDao; +import org.sonar.db.report.ReportSubscriptionDao; import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleRepositoryDao; import org.sonar.db.scannercache.ScannerAnalysisCacheDao; @@ -162,6 +164,8 @@ public class DaoModule extends Module { QualityProfileDao.class, QualityProfileExportDao.class, RegulatoryReportDao.class, + ReportSubscriptionDao.class, + ReportScheduleDao.class, RoleDao.class, RuleDao.class, RuleRepositoryDao.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 80add385af8..7acf9c8ad5b 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 @@ -78,6 +78,8 @@ import org.sonar.db.qualityprofile.QProfileEditUsersDao; import org.sonar.db.qualityprofile.QualityProfileDao; import org.sonar.db.qualityprofile.QualityProfileExportDao; import org.sonar.db.report.RegulatoryReportDao; +import org.sonar.db.report.ReportScheduleDao; +import org.sonar.db.report.ReportSubscriptionDao; import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleRepositoryDao; import org.sonar.db.scannercache.ScannerAnalysisCacheDao; @@ -181,6 +183,9 @@ public class DbClient { private final ScimGroupDao scimGroupDao; private final EntityDao entityDao; + private final ReportScheduleDao reportScheduleDao; + private final ReportSubscriptionDao reportSubscriptionDao; + public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) { this.database = database; this.myBatis = myBatis; @@ -266,6 +271,8 @@ public class DbClient { scimUserDao = getDao(map, ScimUserDao.class); scimGroupDao = getDao(map, ScimGroupDao.class); entityDao = getDao(map, EntityDao.class); + reportScheduleDao = getDao(map, ReportScheduleDao.class); + reportSubscriptionDao = getDao(map, ReportSubscriptionDao.class); } public DbSession openSession(boolean batch) { @@ -589,5 +596,13 @@ public class DbClient { public EntityDao entityDao() { return entityDao; } + + public ReportScheduleDao reportScheduleDao(){ + return reportScheduleDao; + } + + public ReportSubscriptionDao reportSubscriptionDao() { + return reportSubscriptionDao; + } } 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 f2aeefdcc27..88c2322862a 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 @@ -138,6 +138,8 @@ import org.sonar.db.qualityprofile.QProfileEditUsersMapper; import org.sonar.db.qualityprofile.QualityProfileExportMapper; import org.sonar.db.qualityprofile.QualityProfileMapper; import org.sonar.db.report.RegulatoryReportMapper; +import org.sonar.db.report.ReportScheduleMapper; +import org.sonar.db.report.ReportSubscriptionMapper; import org.sonar.db.rule.RuleMapper; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleRepositoryMapper; @@ -314,6 +316,8 @@ public class MyBatis { QualityProfileMapper.class, QualityProfileExportMapper.class, RegulatoryReportMapper.class, + ReportScheduleMapper.class, + ReportSubscriptionMapper.class, RoleMapper.class, RuleMapper.class, RuleRepositoryMapper.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java index 614043369e4..632bf5ad99f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java @@ -234,6 +234,16 @@ class PurgeCommands { uuidsPartitions.forEach(purgeMapper::deletePropertiesByComponentUuids); session.commit(); profiler.stop(); + + profiler.start("deleteByRootAndSubviews (report_schedules)"); + uuidsPartitions.forEach(purgeMapper::deleteReportSchedulesByPortfolioUuids); + session.commit(); + profiler.stop(); + + profiler.start("deleteByRootAndSubviews (report_subscriptions)"); + uuidsPartitions.forEach(purgeMapper::deleteReportSubscriptionsByPortfolioUuids); + session.commit(); + profiler.stop(); } void deleteDisabledComponentsWithoutIssues(List<String> disabledComponentsWithoutIssue) { @@ -492,4 +502,20 @@ class PurgeCommands { profiler.stop(); } + public void deleteReportSchedules(String rootUuid) { + profiler.start("deleteReportSchedules (report_schedules)"); + purgeMapper.deleteReportSchedulesByBranchUuid(rootUuid); + session.commit(); + profiler.stop(); + } + + + public void deleteReportSubscriptions(String rootUuid){ + profiler.start("deleteReportSubscriptions (report_subscriptions)"); + purgeMapper.deleteReportSubscriptionsByBranchUuid(rootUuid); + session.commit(); + profiler.stop(); + } + + } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java index c8ae626baa0..b8524112225 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -256,6 +256,8 @@ public class PurgeDao implements Dao { commands.deleteProject(rootUuid); commands.deleteUserDismissedMessages(rootUuid); commands.deleteOutdatedProperties(rootUuid); + commands.deleteReportSchedules(rootUuid); + commands.deleteReportSubscriptions(rootUuid); } /** diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java index 66d60bdd6f7..15d05650cf6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -178,4 +178,12 @@ public interface PurgeMapper { void deleteUserDismissedMessagesByProjectUuid(@Param("projectUuid") String projectUuid); void deleteScannerAnalysisCacheByBranchUuid(@Param("branchUuid") String branchUuid); + + void deleteReportSchedulesByBranchUuid(@Param("branchUuid") String branchUuid); + + void deleteReportSubscriptionsByBranchUuid(@Param("branchUuid") String branchUuid); + + void deleteReportSchedulesByPortfolioUuids(@Param("portfolioUuids") List<String> portfolioUuids); + + void deleteReportSubscriptionsByPortfolioUuids(@Param("portfolioUuids") List<String> portfolioUuids); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleDao.java new file mode 100644 index 00000000000..13b5b674b11 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleDao.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.report; + +import java.util.List; +import java.util.Optional; +import org.sonar.db.Dao; +import org.sonar.db.DbSession; + +public class ReportScheduleDao implements Dao { + public Optional<ReportScheduleDto> selectByBranch(DbSession dbSession, String branchUuid) { + return mapper(dbSession).selectByBranch(branchUuid); + } + + public Optional<ReportScheduleDto> selectByPortfolio(DbSession dbSession, String portfolioUuid) { + return mapper(dbSession).selectByPortfolio(portfolioUuid); + } + + public void upsert(DbSession dbSession, ReportScheduleDto reportScheduleDto) { + if (!mapper(dbSession).update(reportScheduleDto)) { + mapper(dbSession).insert(reportScheduleDto); + } + } + + private static ReportScheduleMapper mapper(DbSession dbSession) { + return dbSession.getMapper(ReportScheduleMapper.class); + } + + public List<ReportScheduleDto> selectAll(DbSession dbSession) { + return mapper(dbSession).selectAll(); + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleDto.java new file mode 100644 index 00000000000..4b1c1ff0d90 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleDto.java @@ -0,0 +1,69 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.report; + +public class ReportScheduleDto { + + private String uuid; + private String portfolioUuid; + private String branchUuid; + private long lastSendTimeInMs; + + public ReportScheduleDto() { + //Default constructor + } + + public String getUuid() { + return uuid; + } + + public ReportScheduleDto setUuid(String uuid) { + this.uuid = uuid; + return this; + } + + public String getPortfolioUuid() { + return portfolioUuid; + } + + public ReportScheduleDto setPortfolioUuid(String portfolioUuid) { + this.portfolioUuid = portfolioUuid; + return this; + } + + public String getBranchUuid() { + return branchUuid; + } + + public ReportScheduleDto setBranchUuid(String branchUuid) { + this.branchUuid = branchUuid; + return this; + + } + + public long getLastSendTimeInMs() { + return lastSendTimeInMs; + } + + public ReportScheduleDto setLastSendTimeInMs(long lastSendTimeInMs) { + this.lastSendTimeInMs = lastSendTimeInMs; + return this; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleMapper.java new file mode 100644 index 00000000000..b156420d237 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportScheduleMapper.java @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.report; + +import java.util.List; +import java.util.Optional; +import javax.annotation.Nullable; +import org.apache.ibatis.annotations.Param; + +public interface ReportScheduleMapper { + Optional<ReportScheduleDto> selectByBranch(@Param("branchUuid") String branchUuid); + + Optional<ReportScheduleDto> selectByPortfolio(@Nullable @Param("portfolioUuid") String portfolioUuid); + + List<ReportScheduleDto> selectAll(); + + boolean insert(ReportScheduleDto reportScheduleDto); + + boolean update(ReportScheduleDto reportScheduleDto); +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionDao.java new file mode 100644 index 00000000000..a7cbc694306 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionDao.java @@ -0,0 +1,64 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.report; + +import java.util.List; +import java.util.Optional; +import java.util.Set; +import org.apache.ibatis.annotations.Param; +import org.sonar.db.Dao; +import org.sonar.db.DbSession; + +public class ReportSubscriptionDao implements Dao { + + public Optional<ReportSubscriptionDto> selectByUserAndPortfolio(DbSession dbSession, String portfolioUuid, String userUuid) { + return mapper(dbSession).selectByUserAndPortfolio(portfolioUuid, userUuid); + + } + + public Optional<ReportSubscriptionDto> selectByUserAndBranch(DbSession dbSession, @Param("branchUuid") String branchUuid, @Param("userUuid") String userUuid) { + return mapper(dbSession).selectByUserAndBranch(branchUuid, userUuid); + + } + + public List<ReportSubscriptionDto> selectByPortfolio(DbSession dbSession, String portfolioUuid) { + return mapper(dbSession).selectByPortfolio(portfolioUuid); + } + + public List<ReportSubscriptionDto> selectByProjectBranch(DbSession dbSession, String branchUuid) { + return mapper(dbSession).selectByBranch(branchUuid); + } + + public Set<ReportSubscriptionDto> selectAll(DbSession dbSession) { + return mapper(dbSession).selectAll(); + } + + public void delete(DbSession dbSession, ReportSubscriptionDto subscriptionDto) { + mapper(dbSession).delete(subscriptionDto); + } + + public void insert(DbSession dbSession, ReportSubscriptionDto subscriptionDto) { + mapper(dbSession).insert(subscriptionDto); + } + + private static ReportSubscriptionMapper mapper(DbSession dbSession) { + return dbSession.getMapper(ReportSubscriptionMapper.class); + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionDto.java new file mode 100644 index 00000000000..8c7f16d1fd2 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionDto.java @@ -0,0 +1,70 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.report; + +import javax.annotation.Nullable; + +public class ReportSubscriptionDto { + + private String uuid; + private String portfolioUuid; + private String branchUuid; + private String userUuid; + + public ReportSubscriptionDto() { + //Default constructor + } + + public String getUuid() { + return uuid; + } + + public ReportSubscriptionDto setUuid(String uuid) { + this.uuid = uuid; + return this; + } + + public String getPortfolioUuid() { + return portfolioUuid; + } + + public ReportSubscriptionDto setPortfolioUuid(@Nullable String portfolioUuid) { + this.portfolioUuid = portfolioUuid; + return this; + } + + public String getBranchUuid() { + return branchUuid; + } + + public ReportSubscriptionDto setBranchUuid(@Nullable String branchUuid) { + this.branchUuid = branchUuid; + return this; + } + + public String getUserUuid() { + return userUuid; + } + + public ReportSubscriptionDto setUserUuid(String userUuid) { + this.userUuid = userUuid; + return this; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionMapper.java new file mode 100644 index 00000000000..ae58736c3dd --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/report/ReportSubscriptionMapper.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.report; + +import java.util.List; +import java.util.Optional; +import java.util.Set; +import org.apache.ibatis.annotations.Param; + +public interface ReportSubscriptionMapper { + Optional<ReportSubscriptionDto> selectByUserAndPortfolio(@Param("portfolioUuid") String portfolioUuid, @Param("userUuid") String userUuid); + + Optional<ReportSubscriptionDto> selectByUserAndBranch(@Param("branchUuid") String branchUuid, @Param("userUuid") String userUuid); + + List<ReportSubscriptionDto> selectByPortfolio(String portfolioUuid); + + List<ReportSubscriptionDto> selectByBranch(String projectBranchUuid); + + Set<ReportSubscriptionDto> selectAll(); + + void insert(ReportSubscriptionDto subscriptionDto); + + void delete(ReportSubscriptionDto subscriptionDto); +} |