aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDejan Milisavljevic <dejan.milisavljevic@sonarsource.com>2024-09-20 17:45:02 +0200
committersonartech <sonartech@sonarsource.com>2024-09-20 20:02:37 +0000
commitd5450363bddc9a66114cb8675484f38032a2fc4a (patch)
tree12f5033dbfe77f35723f21d65d603e0ae3bf9513
parentb99c9cc72ff8889936251795275f6326c597e79a (diff)
downloadsonarqube-d5450363bddc9a66114cb8675484f38032a2fc4a.tar.gz
sonarqube-d5450363bddc9a66114cb8675484f38032a2fc4a.zip
SONAR-23100 Confidential header can be removed from the Portfolio report
Co-authored-by: OrlovAlexander <alexander.orlov@sonarsource.com>
-rw-r--r--server/sonar-webserver/build.gradle1
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java2
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java66
-rw-r--r--server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProviderTest.java71
4 files changed, 140 insertions, 0 deletions
diff --git a/server/sonar-webserver/build.gradle b/server/sonar-webserver/build.gradle
index 6b055e5d06a..9a0e7599971 100644
--- a/server/sonar-webserver/build.gradle
+++ b/server/sonar-webserver/build.gradle
@@ -33,6 +33,7 @@ dependencies {
testImplementation 'com.github.spotbugs:spotbugs-annotations'
testImplementation 'com.tngtech.java:junit-dataprovider'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
+ testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.eclipse.jetty:jetty-server'
testImplementation 'org.eclipse.jetty:jetty-servlet'
diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
index a839d435b17..57b213a119a 100644
--- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
+++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
@@ -190,6 +190,7 @@ import org.sonar.server.platform.db.CheckAnyonePermissionsAtStartup;
import org.sonar.server.platform.telemetry.ProjectCppAutoconfigTelemetryProvider;
import org.sonar.server.platform.telemetry.TelemetryFipsEnabledProvider;
import org.sonar.server.platform.telemetry.TelemetryNclocProvider;
+import org.sonar.server.platform.telemetry.TelemetryPortfolioConfidentialFlagProvider;
import org.sonar.server.platform.telemetry.TelemetryUserEnabledProvider;
import org.sonar.server.platform.telemetry.TelemetryVersionProvider;
import org.sonar.server.platform.web.ActionDeprecationLoggerInterceptor;
@@ -672,6 +673,7 @@ public class PlatformLevel4 extends PlatformLevel {
TelemetryNclocProvider.class,
TelemetryUserEnabledProvider.class,
TelemetryFipsEnabledProvider.class,
+ TelemetryPortfolioConfidentialFlagProvider.class,
// telemetry
TelemetryMetricsLoader.class,
diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java
new file mode 100644
index 00000000000..14e9bcf8049
--- /dev/null
+++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.telemetry;
+
+import java.util.Optional;
+import org.sonar.db.DbClient;
+import org.sonar.db.property.PropertyDto;
+import org.sonar.telemetry.core.Dimension;
+import org.sonar.telemetry.core.Granularity;
+import org.sonar.telemetry.core.TelemetryDataProvider;
+import org.sonar.telemetry.core.TelemetryDataType;
+
+import static org.sonar.telemetry.core.Dimension.INSTALLATION;
+import static org.sonar.telemetry.core.Granularity.WEEKLY;
+import static org.sonar.telemetry.core.TelemetryDataType.BOOLEAN;
+
+public class TelemetryPortfolioConfidentialFlagProvider implements TelemetryDataProvider<Boolean> {
+ private final DbClient dbClient;
+
+ public TelemetryPortfolioConfidentialFlagProvider(DbClient dbClient) {
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public String getMetricKey() {
+ return "portfolio_reports_confidential_flag";
+ }
+
+ @Override
+ public Dimension getDimension() {
+ return INSTALLATION;
+ }
+
+ @Override
+ public Granularity getGranularity() {
+ return WEEKLY;
+ }
+
+ @Override
+ public TelemetryDataType getType() {
+ return BOOLEAN;
+ }
+
+ @Override
+ public Optional<Boolean> getValue() {
+ PropertyDto property = dbClient.propertiesDao().selectGlobalProperty("sonar.portfolios.confidential.header");
+ return property == null ? Optional.of(true) : Optional.of(Boolean.valueOf(property.getValue()));
+ }
+}
diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProviderTest.java
new file mode 100644
index 00000000000..4ce562740b5
--- /dev/null
+++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProviderTest.java
@@ -0,0 +1,71 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.telemetry;
+
+import java.util.Optional;
+import java.util.stream.Stream;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.Mockito;
+import org.sonar.db.DbClient;
+import org.sonar.db.property.PropertiesDao;
+import org.sonar.db.property.PropertyDto;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.telemetry.core.Dimension.INSTALLATION;
+import static org.sonar.telemetry.core.Granularity.WEEKLY;
+import static org.sonar.telemetry.core.TelemetryDataType.BOOLEAN;
+
+class TelemetryPortfolioConfidentialFlagProviderTest {
+
+ private final DbClient dbClient = Mockito.mock();
+ private final PropertiesDao propertiesDao = mock();
+ private final TelemetryPortfolioConfidentialFlagProvider underTest = new TelemetryPortfolioConfidentialFlagProvider(dbClient);
+
+ @ParameterizedTest
+ @MethodSource("getValues")
+ void getter_should_return_correct_values(Boolean value, Boolean expected) {
+ when(dbClient.propertiesDao()).thenReturn(propertiesDao);
+ if (value == null) {
+ when(dbClient.propertiesDao().selectGlobalProperty("sonar.portfolios.confidential.header"))
+ .thenReturn(null);
+ } else {
+ when(dbClient.propertiesDao().selectGlobalProperty("sonar.portfolios.confidential.header"))
+ .thenReturn(new PropertyDto().setValue(value.toString()));
+ }
+
+ assertEquals("portfolio_reports_confidential_flag", underTest.getMetricKey());
+ assertEquals(INSTALLATION, underTest.getDimension());
+ assertEquals(WEEKLY, underTest.getGranularity());
+ assertEquals(BOOLEAN, underTest.getType());
+ assertEquals(Optional.of(expected), underTest.getValue());
+ }
+
+ public static Stream<Arguments> getValues() {
+ return Stream.of(
+ Arguments.of(true, true),
+ Arguments.of(false, false),
+ Arguments.of(null, true)
+ );
+ }
+}