aboutsummaryrefslogtreecommitdiffstats
path: root/server
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
parenta5fc8a2122a569dc2305b10594d672df2a25a548 (diff)
downloadsonarqube-130b050813c91466815252a929fe2e29879da9f3.tar.gz
sonarqube-130b050813c91466815252a929fe2e29879da9f3.zip
SONAR-10762 Drop usage of 'user_managed' column
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java41
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java11
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml39
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java69
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java2
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java1
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java1
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java1
-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
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoToWsMetric.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/SearchAction.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json9
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json9
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java9
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java13
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java12
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java11
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java2
20 files changed, 65 insertions, 257 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java
index 566c0e49393..dfd167a24d8 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java
@@ -19,26 +19,18 @@
*/
package org.sonar.db.metric;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.apache.ibatis.session.RowBounds;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.RowNotFoundException;
-import static com.google.common.collect.Lists.newArrayList;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
-import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput;
public class MetricDao implements Dao {
@@ -67,19 +59,12 @@ public class MetricDao implements Dao {
return mapper(session).selectAllEnabled();
}
- public List<MetricDto> selectEnabled(DbSession session, @Nullable Boolean isCustom, int offset, int limit) {
- Map<String, Object> properties;
- if (isCustom != null) {
- properties = Collections.singletonMap("isCustom", isCustom);
- } else {
- properties = Collections.emptyMap();
- }
-
- return mapper(session).selectAllEnabled(properties, new RowBounds(offset, limit));
+ public List<MetricDto> selectEnabled(DbSession session, int offset, int limit) {
+ return mapper(session).selectAllEnabled(new RowBounds(offset, limit));
}
- public int countEnabled(DbSession session, @Nullable Boolean isCustom) {
- return mapper(session).countEnabled(isCustom);
+ public int countEnabled(DbSession session) {
+ return mapper(session).countEnabled();
}
public MetricDto insert(DbSession session, MetricDto dto) {
@@ -98,35 +83,19 @@ public class MetricDao implements Dao {
insert(session, Lists.asList(item, others));
}
- public List<String> selectEnabledDomains(DbSession session) {
- return newArrayList(Collections2.filter(mapper(session).selectDomains(), new NotEmptyPredicate()));
- }
-
public List<MetricDto> selectByUuids(DbSession session, Set<String> uuidsSet) {
return executeLargeInputs(new ArrayList<>(uuidsSet), mapper(session)::selectByUuids);
}
- private static class NotEmptyPredicate implements Predicate<String> {
-
- @Override
- public boolean apply(@Nonnull String input) {
- return !input.isEmpty();
- }
- }
-
private static MetricMapper mapper(DbSession session) {
return session.getMapper(MetricMapper.class);
}
- public void disableCustomByUuids(final DbSession session, List<String> uuids) {
- executeLargeInputsWithoutOutput(uuids, input -> mapper(session).disableByUuids(input));
- }
-
/**
* Disable a metric and return {@code false} if the metric does not exist
* or is already disabled.
*/
- public boolean disableCustomByKey(DbSession session, String key) {
+ public boolean disableByKey(DbSession session, String key) {
return mapper(session).disableByKey(key) == 1;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java
index 3e5093e67df..351fae53f85 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java
@@ -45,8 +45,6 @@ public class MetricDto {
private boolean qualitative;
- private boolean userManaged;
-
private Double worstValue;
private Double bestValue;
@@ -138,15 +136,6 @@ public class MetricDto {
return this;
}
- public boolean isUserManaged() {
- return userManaged;
- }
-
- public MetricDto setUserManaged(boolean userManaged) {
- this.userManaged = userManaged;
- return this;
- }
-
@CheckForNull
public Double getWorstValue() {
return worstValue;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java
index a3537c1d5b0..00028bc49fc 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java
@@ -20,8 +20,6 @@
package org.sonar.db.metric;
import java.util.List;
-import java.util.Map;
-import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
@@ -39,17 +37,13 @@ public interface MetricMapper {
List<MetricDto> selectAllEnabled();
- List<MetricDto> selectAllEnabled(Map<String, Object> properties, RowBounds rowBounds);
+ List<MetricDto> selectAllEnabled(RowBounds rowBounds);
void insert(MetricDto dto);
- List<String> selectDomains();
-
- void disableByUuids(@Param("uuids") List<String> uuids);
-
int disableByKey(@Param("key") String key);
- int countEnabled(@Param("isCustom") @Nullable Boolean isCustom);
+ int countEnabled();
void update(MetricDto metric);
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
index 37527aebe9b..604645fac12 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
@@ -12,7 +12,6 @@
m.short_name as shortName,
m.qualitative,
m.val_type as valueType,
- m.user_managed as userManaged,
m.enabled,
m.worst_value as worstValue,
m.best_value as bestValue,
@@ -44,14 +43,6 @@
FROM metrics m
<where>
m.enabled=${_true}
- <if test="isCustom!=null">
- <if test="isCustom.equals(true)">
- AND m.user_managed=${_true}
- </if>
- <if test="isCustom.equals(false)">
- AND m.user_managed=${_false}
- </if>
- </if>
</where>
ORDER BY UPPER(m.short_name), m.short_name
</select>
@@ -61,25 +52,17 @@
FROM metrics m
<where>
m.enabled=${_true}
- <if test="isCustom!=null">
- <if test="isCustom.equals(true)">
- AND m.user_managed=${_true}
- </if>
- <if test="isCustom.equals(false)">
- AND m.user_managed=${_false}
- </if>
- </if>
</where>
</select>
<insert id="insert" parameterType="org.sonar.db.metric.MetricDto" useGeneratedKeys="false">
INSERT INTO metrics (
- uuid, name, description, direction, domain, short_name, qualitative, val_type, user_managed, enabled, worst_value,
+ uuid, name, description, direction, domain, short_name, qualitative, val_type, enabled, worst_value,
best_value, optimized_best_value, hidden, delete_historical_data, decimal_scale)
VALUES (
#{uuid, jdbcType=VARCHAR}, #{kee, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{direction, jdbcType=INTEGER},
#{domain, jdbcType=VARCHAR}, #{shortName, jdbcType=VARCHAR}, #{qualitative, jdbcType=BOOLEAN},
- #{valueType, jdbcType=VARCHAR}, #{userManaged, jdbcType=BOOLEAN}, #{enabled, jdbcType=BOOLEAN},
+ #{valueType, jdbcType=VARCHAR}, #{enabled, jdbcType=BOOLEAN},
#{worstValue, jdbcType=DOUBLE}, #{bestValue, jdbcType=DOUBLE},
#{optimizedBestValue, jdbcType=BOOLEAN}, #{hidden, jdbcType=BOOLEAN}, #{deleteHistoricalData, jdbcType=BOOLEAN},
#{decimalScale, jdbcType=INTEGER}
@@ -102,24 +85,6 @@
where uuid=#{uuid}
</update>
- <select id="selectDomains" resultType="String">
- select distinct domain
- from metrics m
- where m.domain is not null and m.enabled=${_true}
- </select>
-
- <update id="disableByUuids">
- update metrics
- set enabled=${_false}
- <where>
- AND user_managed=${_true}
- AND uuid in
- <foreach item="uuid" collection="uuids" open="(" separator="," close=")">
- #{uuid}
- </foreach>
- </where>
- </update>
-
<update id="disableByKey" parameterType="string">
update metrics
set enabled=${_false}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
index 6aff35852bc..71d680a4d72 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
@@ -52,21 +52,14 @@ public class MetricDaoTest {
@Test
public void select_by_key_enabled_metric() {
- MetricDto expected = db.measures().insertMetric(t -> t.setEnabled(true).setUserManaged(false));
+ MetricDto expected = db.measures().insertMetric(t -> t.setEnabled(true));
assertEquals(expected, underTest.selectByKey(dbSession, expected.getKey()));
}
@Test
public void select_by_key_disabled_metric() {
- MetricDto expected = db.measures().insertMetric(t -> t.setEnabled(false).setUserManaged(false));
-
- assertEquals(expected, underTest.selectByKey(dbSession, expected.getKey()));
- }
-
- @Test
- public void select_by_key_manual_metric() {
- MetricDto expected = db.measures().insertMetric(t -> t.setUserManaged(true));
+ MetricDto expected = db.measures().insertMetric(t -> t.setEnabled(false));
assertEquals(expected, underTest.selectByKey(dbSession, expected.getKey()));
}
@@ -128,7 +121,7 @@ public class MetricDaoTest {
.setDomain("Tests")
.setValueType("PERCENT")
.setQualitative(true)
- .setUserManaged(true)
+
.setWorstValue(0d)
.setBestValue(100d)
.setOptimizedBestValue(true)
@@ -146,7 +139,6 @@ public class MetricDaoTest {
assertThat(result.getValueType()).isEqualTo("PERCENT");
assertThat(result.getDirection()).isEqualTo(1);
assertThat(result.isQualitative()).isTrue();
- assertThat(result.isUserManaged()).isTrue();
assertThat(result.getWorstValue()).isEqualTo(0d);
assertThat(result.getBestValue()).isEqualTo(100d);
assertThat(result.isOptimizedBestValue()).isTrue();
@@ -165,7 +157,7 @@ public class MetricDaoTest {
.setDomain("Tests")
.setValueType("PERCENT")
.setQualitative(true)
- .setUserManaged(true)
+
.setWorstValue(0d)
.setBestValue(100d)
.setOptimizedBestValue(true)
@@ -181,7 +173,7 @@ public class MetricDaoTest {
.setDomain("Tests")
.setValueType("INT")
.setQualitative(true)
- .setUserManaged(true)
+
.setWorstValue(0d)
.setBestValue(100d)
.setOptimizedBestValue(true)
@@ -225,28 +217,16 @@ public class MetricDaoTest {
@Test
public void countEnabled() {
- underTest.insert(dbSession, newMetricDto().setEnabled(true).setUserManaged(true));
- underTest.insert(dbSession, newMetricDto().setEnabled(true).setUserManaged(true));
+ underTest.insert(dbSession, newMetricDto().setEnabled(true));
+ underTest.insert(dbSession, newMetricDto().setEnabled(true));
underTest.insert(dbSession, newMetricDto().setEnabled(false));
- int result = underTest.countEnabled(dbSession, true);
+ int result = underTest.countEnabled(dbSession);
assertThat(result).isEqualTo(2);
}
@Test
- public void selectDomains() {
- underTest.insert(dbSession, newMetricDto().setDomain("first-domain").setEnabled(true));
- underTest.insert(dbSession, newMetricDto().setDomain("second-domain").setEnabled(true));
- underTest.insert(dbSession, newMetricDto().setDomain("second-domain").setEnabled(true));
- underTest.insert(dbSession, newMetricDto().setDomain("third-domain").setEnabled(true));
-
- List<String> domains = underTest.selectEnabledDomains(dbSession);
-
- assertThat(domains).hasSize(3).containsOnly("first-domain", "second-domain", "third-domain");
- }
-
- @Test
public void selectByKeys() {
underTest.insert(dbSession, newMetricDto().setKey("first-key"));
underTest.insert(dbSession, newMetricDto().setKey("second-key"));
@@ -259,29 +239,17 @@ public class MetricDaoTest {
}
@Test
- public void disableByUuids() {
- MetricDto metric1 = underTest.insert(dbSession, newMetricDto().setEnabled(true).setUserManaged(true));
- MetricDto metric2 = underTest.insert(dbSession, newMetricDto().setEnabled(true).setUserManaged(true));
-
- underTest.disableCustomByUuids(dbSession, Arrays.asList(metric1.getUuid(), metric2.getUuid()));
-
- List<MetricDto> result = underTest.selectByUuids(dbSession, newHashSet(metric1.getUuid(), metric2.getUuid()));
- assertThat(result).hasSize(2);
- assertThat(result).extracting("enabled").containsOnly(false);
- }
-
- @Test
public void disableByKey() {
- underTest.insert(dbSession, newMetricDto().setKey("metric-key").setEnabled(true).setUserManaged(true));
+ underTest.insert(dbSession, newMetricDto().setKey("metric-key").setEnabled(true));
- boolean updated = underTest.disableCustomByKey(dbSession, "metric-key");
+ boolean updated = underTest.disableByKey(dbSession, "metric-key");
assertThat(updated).isTrue();
MetricDto result = underTest.selectByKey(dbSession, "metric-key");
assertThat(result.isEnabled()).isFalse();
// disable again -> zero rows are touched
- updated = underTest.disableCustomByKey(dbSession, "metric-key");
+ updated = underTest.disableByKey(dbSession, "metric-key");
assertThat(updated).isFalse();
}
@@ -296,14 +264,13 @@ public class MetricDaoTest {
}
@Test
- public void selectEnabled_with_paging_and_custom() {
- underTest.insert(dbSession, newMetricDto().setUserManaged(true).setEnabled(true));
- underTest.insert(dbSession, newMetricDto().setUserManaged(true).setEnabled(true));
- underTest.insert(dbSession, newMetricDto().setUserManaged(true).setEnabled(true));
- underTest.insert(dbSession, newMetricDto().setUserManaged(false).setEnabled(true));
- underTest.insert(dbSession, newMetricDto().setUserManaged(true).setEnabled(false));
+ public void selectEnabled_with_paging() {
+ underTest.insert(dbSession, newMetricDto().setEnabled(true));
+ underTest.insert(dbSession, newMetricDto().setEnabled(true));
+ underTest.insert(dbSession, newMetricDto().setEnabled(true));
+ underTest.insert(dbSession, newMetricDto().setEnabled(false));
- List<MetricDto> result = underTest.selectEnabled(dbSession, true, 0, 100);
+ List<MetricDto> result = underTest.selectEnabled(dbSession, 0, 100);
assertThat(result).hasSize(3);
}
@@ -316,7 +283,6 @@ public class MetricDaoTest {
assertThat(result.getValueType()).isEqualTo(expected.getValueType());
assertThat(result.getDirection()).isEqualTo(expected.getDirection());
assertThat(result.isQualitative()).isEqualTo(expected.isQualitative());
- assertThat(result.isUserManaged()).isEqualTo(expected.isUserManaged());
assertThat(result.getWorstValue()).isCloseTo(expected.getWorstValue(), within(0.001d));
assertThat(result.getBestValue()).isCloseTo(expected.getBestValue(), within(0.001d));
assertThat(result.isOptimizedBestValue()).isEqualTo(expected.isOptimizedBestValue());
@@ -324,6 +290,5 @@ public class MetricDaoTest {
assertThat(result.isHidden()).isEqualTo(expected.isHidden());
assertThat(result.isEnabled()).isEqualTo(expected.isEnabled());
assertThat(result.getDecimalScale()).isEqualTo(expected.getDecimalScale());
- assertThat(result.isUserManaged()).isEqualTo(expected.isUserManaged());
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java
index e79433240ec..4bee8934a12 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java
@@ -42,7 +42,6 @@ public class MetricDtoTest {
.setDomain("Tests")
.setValueType("PERCENT")
.setQualitative(true)
- .setUserManaged(false)
.setWorstValue(0d)
.setBestValue(100d)
.setOptimizedBestValue(true)
@@ -58,7 +57,6 @@ public class MetricDtoTest {
assertThat(metricDto.getDomain()).isEqualTo("Tests");
assertThat(metricDto.getValueType()).isEqualTo("PERCENT");
assertThat(metricDto.isQualitative()).isTrue();
- assertThat(metricDto.isUserManaged()).isFalse();
assertThat(metricDto.getWorstValue()).isEqualTo(0d);
assertThat(metricDto.getBestValue()).isEqualTo(100d);
assertThat(metricDto.isOptimizedBestValue()).isTrue();
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java
index e602773cfd9..30f2daeb743 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java
@@ -44,7 +44,6 @@ public class MetricTesting {
.setEnabled(true)
.setOptimizedBestValue(RandomUtils.nextBoolean())
.setQualitative(RandomUtils.nextBoolean())
- .setUserManaged(RandomUtils.nextBoolean())
.setWorstValue(RandomUtils.nextDouble());
}
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java b/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java
index 58237289bae..e592a7ba361 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java
@@ -100,7 +100,6 @@ public class MetricFinder {
metric.setQualitative(dto.isQualitative());
metric.setType(Metric.ValueType.valueOf(dto.getValueType()));
metric.setOptimizedBestValue(dto.isOptimizedBestValue());
- metric.setUserManaged(dto.isUserManaged());
metric.setWorstValue(dto.getWorstValue());
return metric;
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java b/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java
index 08ee4a296a2..76eedf0c253 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java
@@ -43,7 +43,6 @@ public enum MetricToDto implements Function<Metric, MetricDto> {
dto.setQualitative(metric.getQualitative());
dto.setValueType(metric.getType().name());
dto.setOptimizedBestValue(Optional.ofNullable(metric.isOptimizedBestValue()).orElse(false));
- dto.setUserManaged(metric.getUserManaged());
dto.setWorstValue(metric.getWorstValue());
dto.setDeleteHistoricalData(metric.getDeleteHistoricalData());
dto.setDecimalScale(metric.getDecimalScale());
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());
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoToWsMetric.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoToWsMetric.java
index 5c2fb55f44f..5a30daa6926 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoToWsMetric.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoToWsMetric.java
@@ -42,7 +42,6 @@ class MetricDtoToWsMetric {
}
metric.setQualitative(metricDto.isQualitative());
metric.setHidden(metricDto.isHidden());
- metric.setCustom(metricDto.isUserManaged());
ofNullable(metricDto.getDecimalScale()).ifPresent(metric::setDecimalScale);
ofNullable(metricDto.getBestValue()).ifPresent(bv -> metric.setBestValue(formatNumericalValue(bv, metricDto)));
ofNullable(metricDto.getWorstValue()).ifPresent(wv -> metric.setWorstValue(formatNumericalValue(wv, metricDto)));
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/SearchAction.java
index d34bfe2449e..f049d7bb6a8 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/SearchAction.java
@@ -61,18 +61,14 @@ public class SearchAction implements MetricsWsAction {
.setPage(request.mandatoryParamAsInt(Param.PAGE),
request.mandatoryParamAsInt(Param.PAGE_SIZE));
try (DbSession dbSession = dbClient.openSession(false)) {
- List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, false, searchOptions.getOffset(), searchOptions.getLimit());
- int nbMetrics = dbClient.metricDao().countEnabled(dbSession, false);
+ List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, searchOptions.getOffset(), searchOptions.getLimit());
+ int nbMetrics = dbClient.metricDao().countEnabled(dbSession);
try (JsonWriter json = response.newJsonWriter()) {
json.beginObject();
- writeMetrics(json, metrics);
+ MetricJsonWriter.write(json, metrics);
searchOptions.writeJson(json, nbMetrics);
json.endObject();
}
}
}
-
- public static void writeMetrics(JsonWriter json, List<MetricDto> metrics) {
- MetricJsonWriter.write(json, metrics);
- }
}
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json
index fabfaed6134..60299412502 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json
@@ -40,8 +40,7 @@
"type": "INT",
"higherValuesAreBetter": false,
"qualitative": false,
- "hidden": false,
- "custom": false
+ "hidden": false
},
{
"key": "ncloc",
@@ -51,8 +50,7 @@
"type": "INT",
"higherValuesAreBetter": false,
"qualitative": false,
- "hidden": false,
- "custom": false
+ "hidden": false
},
{
"key": "new_violations",
@@ -62,8 +60,7 @@
"type": "INT",
"higherValuesAreBetter": false,
"qualitative": true,
- "hidden": false,
- "custom": false
+ "hidden": false
}
],
"period": {
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json
index 5344fd97e81..7ba459d51c6 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json
@@ -102,8 +102,7 @@
"type": "INT",
"higherValuesAreBetter": false,
"qualitative": false,
- "hidden": false,
- "custom": false
+ "hidden": false
},
{
"key": "ncloc",
@@ -113,8 +112,7 @@
"type": "INT",
"higherValuesAreBetter": false,
"qualitative": false,
- "hidden": false,
- "custom": false
+ "hidden": false
},
{
"key": "new_violations",
@@ -124,8 +122,7 @@
"type": "INT",
"higherValuesAreBetter": false,
"qualitative": true,
- "hidden": false,
- "custom": false,
+ "hidden": false
"bestValue": "0"
}
],
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
index 95b01f6383c..f51e1d3eb7d 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
@@ -417,8 +417,7 @@ public class ComponentActionTest {
.setValueType("INT")
.setDirection(-1)
.setQualitative(false)
- .setHidden(false)
- .setUserManaged(false));
+ .setHidden(false));
db.measures().insertLiveMeasure(file, complexity,
m -> m.setValue(12.0d)
.setVariation(2.0d)
@@ -431,8 +430,7 @@ public class ComponentActionTest {
.setValueType("INT")
.setDirection(-1)
.setQualitative(false)
- .setHidden(false)
- .setUserManaged(false));
+ .setHidden(false));
db.measures().insertLiveMeasure(file, ncloc,
m -> m.setValue(114.0d)
.setVariation(3.0d)
@@ -445,8 +443,7 @@ public class ComponentActionTest {
.setValueType("INT")
.setDirection(-1)
.setQualitative(true)
- .setHidden(false)
- .setUserManaged(false));
+ .setHidden(false));
db.measures().insertLiveMeasure(file, newViolations,
m -> m.setVariation(25.0d)
.setValue(null)
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
index 26e4c6f5479..68280c9bbea 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
@@ -986,8 +986,7 @@ public class ComponentTreeActionTest {
return MetricTesting.newMetricDto()
.setWorstValue(null)
.setBestValue(null)
- .setOptimizedBestValue(false)
- .setUserManaged(false);
+ .setOptimizedBestValue(false);
}
private MetricDto insertNewViolationsMetric() {
@@ -1000,7 +999,6 @@ public class ComponentTreeActionTest {
.setDirection(-1)
.setQualitative(true)
.setHidden(false)
- .setUserManaged(false)
.setOptimizedBestValue(true)
.setBestValue(0.0d));
db.commit();
@@ -1016,8 +1014,7 @@ public class ComponentTreeActionTest {
.setValueType(INT.name())
.setDirection(-1)
.setQualitative(false)
- .setHidden(false)
- .setUserManaged(false));
+ .setHidden(false));
db.commit();
return metric;
}
@@ -1031,8 +1028,7 @@ public class ComponentTreeActionTest {
.setValueType(INT.name())
.setDirection(-1)
.setQualitative(false)
- .setHidden(false)
- .setUserManaged(false));
+ .setHidden(false));
db.commit();
return metric;
}
@@ -1046,8 +1042,7 @@ public class ComponentTreeActionTest {
.setValueType(FLOAT.name())
.setDirection(1)
.setQualitative(false)
- .setHidden(false)
- .setUserManaged(false));
+ .setHidden(false));
db.commit();
return metric;
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java
index 2548ecd1b83..e3e9a8a791c 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java
@@ -498,8 +498,7 @@ public class SearchHistoryActionTest {
return newMetricDto()
.setWorstValue(null)
.setOptimizedBestValue(false)
- .setBestValue(null)
- .setUserManaged(false);
+ .setBestValue(null);
}
private MetricDto insertNclocMetric() {
@@ -511,8 +510,7 @@ public class SearchHistoryActionTest {
.setValueType("INT")
.setDirection(-1)
.setQualitative(false)
- .setHidden(false)
- .setUserManaged(false));
+ .setHidden(false));
db.commit();
return metric;
}
@@ -526,8 +524,7 @@ public class SearchHistoryActionTest {
.setValueType("INT")
.setDirection(-1)
.setQualitative(false)
- .setHidden(false)
- .setUserManaged(false));
+ .setHidden(false));
db.commit();
return metric;
}
@@ -541,8 +538,7 @@ public class SearchHistoryActionTest {
.setValueType("INT")
.setDirection(-1)
.setQualitative(true)
- .setHidden(false)
- .setUserManaged(false));
+ .setHidden(false));
db.commit();
return metric;
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java
index 4307b47e9cc..bd743cf87fc 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java
@@ -69,8 +69,7 @@ public class SearchActionTest {
.setDirection(0)
.setQualitative(true)
.setHidden(false)
- .setEnabled(true)
- .setUserManaged(false));
+ .setEnabled(true));
db.measures().insertMetric(metricDto -> metricDto
.setKey("custom-key-2")
.setShortName("custom-name-2")
@@ -80,8 +79,7 @@ public class SearchActionTest {
.setDirection(0)
.setQualitative(true)
.setHidden(false)
- .setEnabled(true)
- .setUserManaged(false));
+ .setEnabled(true));
db.measures().insertMetric(metricDto -> metricDto
.setKey("custom-key-3")
.setShortName("custom-name-3")
@@ -91,8 +89,7 @@ public class SearchActionTest {
.setDirection(0)
.setQualitative(true)
.setHidden(false)
- .setEnabled(true)
- .setUserManaged(false));
+ .setEnabled(true));
TestResponse result = ws.newRequest().execute();
@@ -126,7 +123,7 @@ public class SearchActionTest {
private void insertMetrics(String... ids) {
for (String id : ids) {
- db.measures().insertMetric(metricDto -> metricDto.setUuid(id).setShortName("name-" + id).setEnabled(true).setUserManaged(false));
+ db.measures().insertMetric(metricDto -> metricDto.setUuid(id).setShortName("name-" + id).setEnabled(true));
}
dbSession.commit();
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
index 4aa3478cb27..19c8bc2a5ea 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
@@ -228,7 +228,7 @@ public class ShowActionTest {
db.qualityGates().setDefaultQualityGate(qualityGate);
MetricDto metric = db.measures().insertMetric();
db.qualityGates().addCondition(qualityGate, metric);
- db.getDbClient().metricDao().disableCustomByKey(db.getSession(), metric.getKey());
+ db.getDbClient().metricDao().disableByKey(db.getSession(), metric.getKey());
db.commit();
expectedException.expect(IllegalStateException.class);