aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-core/src
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2021-07-02 16:26:35 +0200
committersonartech <sonartech@sonarsource.com>2021-07-07 20:03:25 +0000
commit130b050813c91466815252a929fe2e29879da9f3 (patch)
tree94d73c226f32d14355b6f5a69938d731b6671dc0 /server/sonar-webserver-core/src
parenta5fc8a2122a569dc2305b10594d672df2a25a548 (diff)
downloadsonarqube-130b050813c91466815252a929fe2e29879da9f3.tar.gz
sonarqube-130b050813c91466815252a929fe2e29879da9f3.zip
SONAR-10762 Drop usage of 'user_managed' column
Diffstat (limited to 'server/sonar-webserver-core/src')
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java15
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java56
2 files changed, 14 insertions, 57 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java
index 8de1a450bdd..6757058ef21 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java
@@ -19,6 +19,9 @@
*/
package org.sonar.server.startup;
+import static com.google.common.collect.FluentIterable.concat;
+import static com.google.common.collect.Lists.newArrayList;
+
import com.google.common.annotations.VisibleForTesting;
import java.util.HashMap;
import java.util.List;
@@ -36,10 +39,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.metric.MetricToDto;
-import static com.google.common.collect.FluentIterable.from;
-import static com.google.common.collect.Iterables.concat;
-import static com.google.common.collect.Lists.newArrayList;
-
public class RegisterMetrics implements Startable {
private static final Logger LOG = Loggers.get(RegisterMetrics.class);
@@ -87,7 +86,8 @@ public class RegisterMetrics implements Startable {
private void save(DbSession session, Iterable<Metric> metrics) {
Map<String, MetricDto> basesByKey = new HashMap<>();
- for (MetricDto base : from(dbClient.metricDao().selectAll(session)).toList()) {
+ var allMetrics = dbClient.metricDao().selectAll(session);
+ for (MetricDto base : allMetrics) {
basesByKey.put(base.getKey(), base);
}
@@ -98,8 +98,7 @@ public class RegisterMetrics implements Startable {
// new metric, never installed
dto.setUuid(uuidFactory.create());
dbClient.metricDao().insert(session, dto);
- } else if (!base.isUserManaged()) {
- // existing metric, update changes. Existing custom metrics are kept without applying changes.
+ } else {
dto.setUuid(base.getUuid());
dbClient.metricDao().update(session, dto);
}
@@ -107,7 +106,7 @@ public class RegisterMetrics implements Startable {
}
for (MetricDto nonUpdatedBase : basesByKey.values()) {
- if (!nonUpdatedBase.isUserManaged() && dbClient.metricDao().disableCustomByKey(session, nonUpdatedBase.getKey())) {
+ if (dbClient.metricDao().disableByKey(session, nonUpdatedBase.getKey())) {
LOG.info("Disable metric {} [{}]", nonUpdatedBase.getShortName(), nonUpdatedBase.getKey());
}
}
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
index e6262adff14..69682a5d27e 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
@@ -38,7 +38,6 @@ import org.sonar.db.metric.MetricDto;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
public class RegisterMetricsTest {
@@ -76,10 +75,10 @@ public class RegisterMetricsTest {
}
/**
- * Update existing metrics, except if custom metric
+ * Update existing metrics
*/
@Test
- public void update_non_custom_metrics() {
+ public void update_metrics() {
dbTester.measures().insertMetric(t -> t.setKey("m1")
.setShortName("name")
.setValueType(Metric.ValueType.INT.name())
@@ -87,22 +86,10 @@ public class RegisterMetricsTest {
.setDomain("old domain")
.setShortName("old short name")
.setQualitative(false)
- .setUserManaged(false)
.setEnabled(true)
.setOptimizedBestValue(false)
.setDirection(1)
.setHidden(false));
- MetricDto customMetric = dbTester.measures().insertMetric(t -> t.setKey("custom")
- .setValueType(Metric.ValueType.FLOAT.name())
- .setDescription("old desc")
- .setShortName("Custom")
- .setQualitative(false)
- .setUserManaged(true)
- .setEnabled(true)
- .setOptimizedBestValue(false)
- .setDirection(0)
- .setHidden(false)
- .setDecimalScale(1));
RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
Metric m1 = new Metric.Builder("m1", "New name", Metric.ValueType.FLOAT)
@@ -114,23 +101,11 @@ public class RegisterMetricsTest {
.setDecimalScale(3)
.setHidden(true)
.create();
- Metric custom = new Metric.Builder("custom", "New custom", Metric.ValueType.FLOAT)
- .setDescription("New description of custom metric")
- .setUserManaged(true)
- .create();
- register.register(asList(m1, custom));
+ register.register(asList(m1));
Map<String, MetricDto> metricsByKey = selectAllMetrics();
- assertThat(metricsByKey).hasSize(2);
+ assertThat(metricsByKey).hasSize(1);
assertEquals(m1, metricsByKey.get("m1"));
- MetricDto actual = metricsByKey.get("custom");
- assertThat(actual.getKey()).isEqualTo(custom.getKey());
- assertThat(actual.getShortName()).isEqualTo(customMetric.getShortName());
- assertThat(actual.getValueType()).isEqualTo(customMetric.getValueType());
- assertThat(actual.getDescription()).isEqualTo(customMetric.getDescription());
- assertThat(actual.getDirection()).isEqualTo(customMetric.getDirection());
- assertThat(actual.isQualitative()).isEqualTo(customMetric.isQualitative());
- assertThat(actual.isUserManaged()).isEqualTo(customMetric.isUserManaged());
}
@Test
@@ -138,7 +113,7 @@ public class RegisterMetricsTest {
Random random = new Random();
int count = 1 + random.nextInt(10);
IntStream.range(0, count)
- .forEach(t -> dbTester.measures().insertMetric(m -> m.setEnabled(random.nextBoolean()).setUserManaged(false)));
+ .forEach(t -> dbTester.measures().insertMetric(m -> m.setEnabled(random.nextBoolean())));
RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
register.register(Collections.emptyList());
@@ -150,8 +125,8 @@ public class RegisterMetricsTest {
@Test
public void enable_disabled_metrics() {
- MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true).setUserManaged(false));
- MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false).setUserManaged(false));
+ MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true));
+ MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false));
RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
register.register(asList(builderOf(enabledMetric).create(), builderOf(disabledMetric).create()));
@@ -162,21 +137,6 @@ public class RegisterMetricsTest {
}
@Test
- public void does_not_enable_disabled_custom_metrics() {
- MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true).setUserManaged(true));
- MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false).setUserManaged(true));
-
- RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
- register.register(asList(builderOf(enabledMetric).create(), builderOf(disabledMetric).create()));
-
- assertThat(selectAllMetrics().values())
- .extracting(MetricDto::getKey, MetricDto::isEnabled)
- .containsOnly(
- tuple(enabledMetric.getKey(), true),
- tuple(disabledMetric.getKey(), false));
- }
-
- @Test
public void insert_core_metrics() {
RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
register.start();
@@ -225,7 +185,6 @@ public class RegisterMetricsTest {
assertThat(actual.getDescription()).isEqualTo(expected.getDescription());
assertThat(actual.getDirection()).isEqualTo(expected.getDirection());
assertThat(actual.isQualitative()).isEqualTo(expected.getQualitative());
- assertThat(actual.isUserManaged()).isEqualTo(expected.getUserManaged());
}
private static Metric.Builder builderOf(MetricDto enabledMetric) {
@@ -235,7 +194,6 @@ public class RegisterMetricsTest {
.setQualitative(enabledMetric.isQualitative())
.setQualitative(enabledMetric.isQualitative())
.setDomain(enabledMetric.getDomain())
- .setUserManaged(enabledMetric.isUserManaged())
.setHidden(enabledMetric.isHidden());
}
}