From cd01dd4e2a883177d515b4f71554ee90e449b742 Mon Sep 17 00:00:00 2001 From: alain <108417558+alain-kermis-sonarsource@users.noreply.github.com> Date: Tue, 30 Aug 2022 17:00:34 +0200 Subject: SONAR-17195 Add new telemetry fields --- .../src/main/java/org/sonar/db/MyBatis.java | 16 +- .../db/alm/setting/ProjectAlmKeyAndProject.java | 58 +++++++ .../sonar/db/alm/setting/ProjectAlmSettingDao.java | 4 + .../db/alm/setting/ProjectAlmSettingMapper.java | 2 + .../sonar/db/component/AnalysisPropertiesDao.java | 4 +- .../db/component/AnalysisPropertiesMapper.java | 2 +- .../component/AnalysisPropertyValuePerProject.java | 45 +++++ .../java/org/sonar/db/component/BranchDao.java | 4 + .../java/org/sonar/db/component/BranchMapper.java | 2 + .../db/component/PrAndBranchCountByProjectDto.java | 51 ++++++ .../ProjectCountPerAnalysisPropertyValue.java | 45 ----- .../main/java/org/sonar/db/measure/MeasureDao.java | 5 + .../java/org/sonar/db/measure/MeasureMapper.java | 2 + .../org/sonar/db/measure/ProjectMeasureDto.java | 65 ++++++++ .../main/java/org/sonar/db/project/ProjectDao.java | 3 + .../java/org/sonar/db/project/ProjectMapper.java | 2 + .../src/main/java/org/sonar/db/user/UserDao.java | 4 + .../main/java/org/sonar/db/user/UserMapper.java | 2 + .../java/org/sonar/db/user/UserTelemetryDto.java | 70 ++++++++ .../db/alm/setting/ProjectAlmSettingMapper.xml | 11 ++ .../db/component/AnalysisPropertiesMapper.xml | 7 +- .../org/sonar/db/component/BranchMapper.xml | 8 + .../org/sonar/db/measure/MeasureMapper.xml | 41 +++++ .../org/sonar/db/project/ProjectMapper.xml | 6 + .../resources/org/sonar/db/user/UserMapper.xml | 10 ++ .../db/alm/setting/ProjectAlmSettingDaoTest.java | 12 ++ .../db/component/AnalysisPropertiesDaoTest.java | 16 +- .../java/org/sonar/db/component/BranchDaoTest.java | 26 +++ .../test/java/org/sonar/db/user/UserDaoTest.java | 36 +++- .../org/sonar/server/telemetry/TelemetryData.java | 144 ++++++++++++---- .../server/telemetry/TelemetryDataJsonWriter.java | 113 +++++++++---- .../telemetry/TelemetryDataJsonWriterTest.java | 184 ++++++++++++++------- .../sonar/server/telemetry/TelemetryDaemon.java | 3 - .../server/telemetry/TelemetryDataLoaderImpl.java | 103 ++++++++---- .../server/telemetry/TelemetryDaemonTest.java | 3 - .../telemetry/TelemetryDataLoaderImplTest.java | 167 +++++++++++++++---- 36 files changed, 1005 insertions(+), 271 deletions(-) create mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmKeyAndProject.java create mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyValuePerProject.java create mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/component/PrAndBranchCountByProjectDto.java delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectCountPerAnalysisPropertyValue.java create mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasureDto.java create mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java 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 4327429abc8..02a2576417d 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 @@ -35,6 +35,7 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.apache.ibatis.session.TransactionIsolationLevel; import org.sonar.db.alm.pat.AlmPatMapper; import org.sonar.db.alm.setting.AlmSettingMapper; +import org.sonar.db.alm.setting.ProjectAlmKeyAndProject; import org.sonar.db.alm.setting.ProjectAlmSettingMapper; import org.sonar.db.audit.AuditMapper; import org.sonar.db.ce.CeActivityMapper; @@ -45,6 +46,7 @@ import org.sonar.db.ce.CeTaskCharacteristicMapper; import org.sonar.db.ce.CeTaskInputMapper; import org.sonar.db.ce.CeTaskMessageMapper; import org.sonar.db.component.AnalysisPropertiesMapper; +import org.sonar.db.component.AnalysisPropertyValuePerProject; import org.sonar.db.component.ApplicationProjectsMapper; import org.sonar.db.component.BranchMapper; import org.sonar.db.component.ComponentDto; @@ -54,7 +56,7 @@ import org.sonar.db.component.ComponentMapper; import org.sonar.db.component.ComponentWithModuleUuidDto; import org.sonar.db.component.FilePathWithHashDto; import org.sonar.db.component.KeyWithUuidDto; -import org.sonar.db.component.ProjectCountPerAnalysisPropertyValue; +import org.sonar.db.component.PrAndBranchCountByProjectDto; import org.sonar.db.component.ProjectLinkMapper; import org.sonar.db.component.ResourceDto; import org.sonar.db.component.ScrapAnalysisPropertyDto; @@ -80,6 +82,7 @@ import org.sonar.db.measure.LargestBranchNclocDto; import org.sonar.db.measure.LiveMeasureMapper; import org.sonar.db.measure.MeasureDto; import org.sonar.db.measure.MeasureMapper; +import org.sonar.db.measure.ProjectMeasureDto; import org.sonar.db.metric.MetricMapper; import org.sonar.db.newcodeperiod.NewCodePeriodMapper; import org.sonar.db.notification.NotificationQueueDto; @@ -154,6 +157,7 @@ import org.sonar.db.user.UserDto; import org.sonar.db.user.UserGroupDto; import org.sonar.db.user.UserGroupMapper; import org.sonar.db.user.UserMapper; +import org.sonar.db.user.UserTelemetryDto; import org.sonar.db.user.UserTokenCount; import org.sonar.db.user.UserTokenDto; import org.sonar.db.user.UserTokenMapper; @@ -218,8 +222,11 @@ public class MyBatis { confBuilder.loadAlias("ProjectQgateAssociation", ProjectQgateAssociationDto.class); confBuilder.loadAlias("Project", ProjectDto.class); confBuilder.loadAlias("ProjectBadgeToken", ProjectBadgeTokenDto.class); - confBuilder.loadAlias("ProjectCountPerAnalysisPropertyValue", ProjectCountPerAnalysisPropertyValue.class); + confBuilder.loadAlias("AnalysisPropertyValuePerProject", AnalysisPropertyValuePerProject.class); + confBuilder.loadAlias("ProjectAlmKeyAndProject", ProjectAlmKeyAndProject.class); + confBuilder.loadAlias("PrAndBranchCountByProjectDto", PrAndBranchCountByProjectDto.class); confBuilder.loadAlias("ProjectMapping", ProjectMappingDto.class); + confBuilder.loadAlias("ProjectMeasure", ProjectMeasureDto.class); confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class); confBuilder.loadAlias("PushEvent", PushEventDto.class); confBuilder.loadAlias("QualityGateCondition", QualityGateConditionDto.class); @@ -230,11 +237,12 @@ public class MyBatis { confBuilder.loadAlias("ScrapProperty", ScrapPropertyDto.class); confBuilder.loadAlias("ScrapAnalysisProperty", ScrapAnalysisPropertyDto.class); confBuilder.loadAlias("Snapshot", SnapshotDto.class); + confBuilder.loadAlias("User", UserDto.class); confBuilder.loadAlias("UserGroup", UserGroupDto.class); confBuilder.loadAlias("UserPermission", UserPermissionDto.class); - confBuilder.loadAlias("UserTokenCount", UserTokenCount.class); + confBuilder.loadAlias("UserTelemetry", UserTelemetryDto.class); confBuilder.loadAlias("UserToken", UserTokenDto.class); - confBuilder.loadAlias("User", UserDto.class); + confBuilder.loadAlias("UserTokenCount", UserTokenCount.class); confBuilder.loadAlias("UuidWithProjectUuid", UuidWithProjectUuidDto.class); confBuilder.loadAlias("ViewsSnapshot", ViewsSnapshotDto.class); confExtensions.forEach(ext -> ext.loadAliases(confBuilder::loadAlias)); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmKeyAndProject.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmKeyAndProject.java new file mode 100644 index 00000000000..be435294c7e --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmKeyAndProject.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.setting; + +public class ProjectAlmKeyAndProject { + + private String projectUuid; + private String almId; + private String url; + + public ProjectAlmKeyAndProject() { + // keep empty + } + + public String getProjectUuid() { + return projectUuid; + } + + public ProjectAlmKeyAndProject setProjectUuid(String projectUuid) { + this.projectUuid = projectUuid; + return this; + } + + public String getAlmId() { + return almId; + } + + public ProjectAlmKeyAndProject setAlmId(String almId) { + this.almId = almId; + return this; + } + + public String getUrl() { + return url; + } + + public ProjectAlmKeyAndProject setUrl(String url) { + this.url = url; + return this; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java index c8c44cf9dac..f6c7867e7fb 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java @@ -101,4 +101,8 @@ public class ProjectAlmSettingDao implements Dao { public List selectByAlmSettingAndRepos(DbSession dbSession, AlmSettingDto almSettingDto, Set almRepos) { return executeLargeInputs(almRepos, repos -> getMapper(dbSession).selectByAlmSettingAndRepos(almSettingDto.getUuid(), repos)); } + + public List selectAlmTypeAndUrlByProject(DbSession dbSession) { + return getMapper(dbSession).selectAlmTypeAndUrlByProject(); + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.java index 98c7478d6e7..6e8425501b0 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.java @@ -40,4 +40,6 @@ public interface ProjectAlmSettingMapper { List selectByAlmSettingAndSlugs(@Param("almSettingUuid") String almSettingUuid, @Param("slugs") List slugs); List selectByAlmSettingAndRepos(@Param("almSettingUuid") String almSettingUuid, @Param("repos") List repos); + + List selectAlmTypeAndUrlByProject(); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesDao.java index 72dde4807dd..8227d65b1c6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesDao.java @@ -71,8 +71,8 @@ public class AnalysisPropertiesDao implements Dao { } } - public List selectProjectCountPerAnalysisPropertyValueInLastAnalysis(DbSession session, String analysisPropertyKey) { - return getMapper(session).selectProjectCountPerAnalysisPropertyValueInLastAnalysis(analysisPropertyKey); + public List selectAnalysisPropertyValueInLastAnalysisPerProject(DbSession session, String analysisPropertyKey) { + return getMapper(session).selectAnalysisPropertyValueInLastAnalysisPerProject(analysisPropertyKey); } private static boolean mustBeStoredInClob(String value) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesMapper.java index 34839273c96..e83046d8306 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesMapper.java @@ -33,7 +33,7 @@ public interface AnalysisPropertiesMapper { void insertAsText(@Param("analysisPropertyDto") AnalysisPropertyDto analysisPropertyDto, @Param("createdAt") long createdAt); - List selectProjectCountPerAnalysisPropertyValueInLastAnalysis(@Param("analysisPropertyKey") String analysisPropertyKey); + List selectAnalysisPropertyValueInLastAnalysisPerProject(@Param("analysisPropertyKey") String analysisPropertyKey); List selectByKeyAnAnalysisUuids(@Param("analysisUuids") Collection analysisUuids, @Param("analysisPropertyKey") String analysisPropertyKey); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyValuePerProject.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyValuePerProject.java new file mode 100644 index 00000000000..ca6d73a64aa --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyValuePerProject.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.component; + +public class AnalysisPropertyValuePerProject { + private String projectUuid; + private String propertyValue; + + public AnalysisPropertyValuePerProject() { + //nothing to do here + } + + public String getPropertyValue() { + return propertyValue; + } + + public void setPropertyValue(String propertyValue) { + this.propertyValue = propertyValue; + } + + public String getProjectUuid() { + return projectUuid; + } + + public void setProjectUuid(String projectUuid) { + this.projectUuid = projectUuid; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java index f03eea0479c..9d6cc0f6d29 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java @@ -101,6 +101,10 @@ public class BranchDao implements Dao { return mapper(dbSession).selectByProjectUuid(project.getUuid()); } + public List countPrAndBranchByProjectUuid(DbSession dbSession){ + return mapper(dbSession).countPrAndBranchByProjectUuid(); + } + public List selectByUuids(DbSession session, Collection uuids) { if (uuids.isEmpty()) { return emptyList(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java index 166765d4994..a1793e1d7dd 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java @@ -47,6 +47,8 @@ public interface BranchMapper { Collection selectByProjectUuid(@Param("projectUuid") String projectUuid); + List countPrAndBranchByProjectUuid(); + List selectByBranchKeys(@Param("branchKeyByProjectUuid") Map branchKeyByProjectUuid); List selectByUuids(@Param("uuids") Collection uuids); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/PrAndBranchCountByProjectDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/PrAndBranchCountByProjectDto.java new file mode 100644 index 00000000000..ef9149bfb8c --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/PrAndBranchCountByProjectDto.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.component; + +public class PrAndBranchCountByProjectDto { + + private String projectUuid = null; + private Long pullRequest = null; + private Long branch = null; + + public String getProjectUuid() { + return projectUuid; + } + + public void setProjectUuid(String projectUuid) { + this.projectUuid = projectUuid; + } + + public Long getPullRequest() { + return pullRequest; + } + + public void setPullRequest(Long pullRequest) { + this.pullRequest = pullRequest; + } + + public Long getBranch() { + return branch; + } + + public void setBranch(Long branch) { + this.branch = branch; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectCountPerAnalysisPropertyValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectCountPerAnalysisPropertyValue.java deleted file mode 100644 index 21f4de3758c..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectCountPerAnalysisPropertyValue.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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.component; - -public class ProjectCountPerAnalysisPropertyValue { - private String propertyValue; - private Long count; - - public ProjectCountPerAnalysisPropertyValue() { - //nothing to do here - } - - public String getPropertyValue() { - return propertyValue; - } - - public void setPropertyValue(String propertyValue) { - this.propertyValue = propertyValue; - } - - public Long getCount() { - return count; - } - - public void setCount(Long count) { - this.count = count; - } -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java index ddac96633da..d6b8adb6a02 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java @@ -75,4 +75,9 @@ public class MeasureDao implements Dao { private static MeasureMapper mapper(DbSession session) { return session.getMapper(MeasureMapper.class); } + + public List selectLastMeasureForAllProjects(DbSession session, String metricKey) { + return mapper(session).selectLastMeasureForAllProjects(metricKey); + + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java index 68829023849..9f80836c15b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java @@ -41,4 +41,6 @@ public interface MeasureMapper { List selectPastMeasuresOnSeveralAnalyses(@Param("query") PastMeasureQuery query); void insert(MeasureDto measureDto); + + List selectLastMeasureForAllProjects(@Param("metricKey") String metricKey); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasureDto.java new file mode 100644 index 00000000000..8d9bb72cf8e --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasureDto.java @@ -0,0 +1,65 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.measure; + +public class ProjectMeasureDto { + + private String projectUuid; + private Long lastAnalysis; + private long loc; + private String textValue; + + public String getProjectUuid() { + return projectUuid; + } + + public ProjectMeasureDto setProjectUuid(String projectUuid) { + this.projectUuid = projectUuid; + return this; + } + + public String getTextValue() { + return textValue; + } + + public ProjectMeasureDto setTextValue(String textValue) { + this.textValue = textValue; + return this; + } + + public long getLoc() { + return loc; + } + + public ProjectMeasureDto setLoc(long loc) { + this.loc = loc; + return this; + } + + public Long getLastAnalysis() { + return lastAnalysis; + } + + public ProjectMeasureDto setLastAnalysis(Long lastAnalysis) { + this.lastAnalysis = lastAnalysis; + return this; + } + +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java index 64dbe688486..ca78366e668 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java @@ -118,4 +118,7 @@ public class ProjectDao implements Dao { return session.getMapper(ProjectMapper.class); } + public List selectAllProjectUuids(DbSession session) { + return mapper(session).selectAllProjectUuids(); + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java index 4d8d94bc6d4..e2715aafa4f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java @@ -59,4 +59,6 @@ public interface ProjectMapper { List selectAllApplications(); List selectApplicationsByKeys(@Param("kees") Collection kees); + + List selectAllProjectUuids(); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java index c43e3b1dce3..082c34a4509 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java @@ -102,6 +102,10 @@ public class UserDao implements Dao { return mapper(dbSession).selectUsers(query); } + public List selectUsersForTelemetry(DbSession dbSession) { + return mapper(dbSession).selectUsersForTelemetry(); + } + public UserDto insert(DbSession session, UserDto dto) { long now = system2.now(); mapper(session).insert(dto.setUuid(uuidFactory.create()).setCreatedAt(now).setUpdatedAt(now)); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java index 5e59ef4958f..353b1dc5785 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java @@ -48,6 +48,8 @@ public interface UserMapper { List selectUsers(UserQuery query); + List selectUsersForTelemetry(); + List selectByLogins(List logins); List selectByUuids(List uuids); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java new file mode 100644 index 00000000000..0c0a0c35539 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java @@ -0,0 +1,70 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.user; + +import javax.annotation.Nullable; + +public class UserTelemetryDto { + + private String uuid; + private boolean active = true; + @Nullable + private Long lastConnectionDate; + @Nullable + private Long lastSonarlintConnectionDate; + + public String getUuid() { + return uuid; + } + + public UserTelemetryDto setUuid(String uuid) { + this.uuid = uuid; + return this; + } + + public boolean isActive() { + return active; + } + + public UserTelemetryDto setActive(boolean active) { + this.active = active; + return this; + } + + @Nullable + public Long getLastConnectionDate() { + return lastConnectionDate; + } + + public UserTelemetryDto setLastConnectionDate(@Nullable Long lastConnectionDate) { + this.lastConnectionDate = lastConnectionDate; + return this; + } + + @Nullable + public Long getLastSonarlintConnectionDate() { + return lastSonarlintConnectionDate; + } + + public UserTelemetryDto setLastSonarlintConnectionDate(@Nullable Long lastSonarlintConnectionDate) { + this.lastSonarlintConnectionDate = lastSonarlintConnectionDate; + return this; + } +} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml index 1b689a3c475..00bc5cc5668 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml @@ -15,6 +15,17 @@ p.updated_at as updatedAt + + - select - ap.text_value as "propertyValue", - count(ap.text_value) as "count" + cp.uuid as "projectUuid", ap.text_value as "propertyValue" from components cp inner join snapshots s on s.component_uuid = cp.uuid inner join analysis_properties ap on ap.analysis_uuid = s.uuid where cp.main_branch_project_uuid is null and s.islast = ${_true} and ap.kee = #{analysisPropertyKey, jdbcType=VARCHAR} - group by ap.text_value + order by cp.uuid asc diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml index 3cecf8644f9..1a4f660db53 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml @@ -111,6 +111,14 @@ pb.project_uuid = #{projectUuid, jdbcType=VARCHAR} + + + + + + SELECT + p.uuid as uuid + FROM projects p + + + +