]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10762 Drop usage of 'user_managed' column
authorJacek <jacek.poreda@sonarsource.com>
Fri, 2 Jul 2021 14:26:35 +0000 (16:26 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 7 Jul 2021 20:03:25 +0000 (20:03 +0000)
23 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java
server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java
server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java
server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java
server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoToWsMetric.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultMetricsRepositoryLoader.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultMetricsRepositoryLoaderTest.java

index 566c0e4939341c67d8878383679ae502ad0da889..dfd167a24d8b4f26c6b13395bcf83635b1a7d5e0 100644 (file)
  */
 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;
   }
 
index 3e5093e67df063b8cadb681721b6a32fab9cc278..351fae53f8582545590780c7c6834f97afd28898 100644 (file)
@@ -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;
index a3537c1d5b04d27184953164e7687982cf3686db..00028bc49fc5ae3b714f87d533b828612186ddfd 100644 (file)
@@ -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);
 }
index 37527aebe9b4413724e6bd164c9cb60ad8ad0d99..604645fac12d99105e8ac7c9e9dd20540ee0f970 100644 (file)
@@ -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,
     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>
     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}
     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}
index 6aff35852bc575f798705f474c736371813579c6..71d680a4d72146d14b4af4d36b9cf03f116b9a37 100644 (file)
@@ -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,27 +217,15 @@ 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"));
@@ -258,30 +238,18 @@ public class MetricDaoTest {
       .extracting("key").containsOnly("first-key", "second-key", "third-key");
   }
 
-  @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());
   }
 }
index e79433240ecddca68a80e4ad783b4c414d7df708..4bee8934a127bf441344b790b4f30050e8f44d9a 100644 (file)
@@ -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();
index e602773cfd98f39640e068a721e630bb9878dae0..30f2daeb7431ad08bda44357b2e0c49d2e29d8ad 100644 (file)
@@ -44,7 +44,6 @@ public class MetricTesting {
       .setEnabled(true)
       .setOptimizedBestValue(RandomUtils.nextBoolean())
       .setQualitative(RandomUtils.nextBoolean())
-      .setUserManaged(RandomUtils.nextBoolean())
       .setWorstValue(RandomUtils.nextDouble());
   }
 }
index 58237289bae6688e4a226a2e8b3e63c1e701e829..e592a7ba361d1118cd64437c3a87f01880a01a6f 100644 (file)
@@ -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;
     }
index 08ee4a296a22f5bd744dd00cb6cef05bc913538e..76eedf0c253b663d4c54dd48161b15d20828fbe2 100644 (file)
@@ -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());
index 8de1a450bddd2389ea1f8fb3712a27c32a8df6f7..6757058ef218976bb161b525e877f81eb99bb83d 100644 (file)
@@ -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());
       }
     }
index e6262adff14ad68c14d7ecd6c29cce43452a0be4..69682a5d27ee250ef1150f28b731d77a53a16962 100644 (file)
@@ -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()));
@@ -161,21 +136,6 @@ public class RegisterMetricsTest {
       .containsOnly(true, true);
   }
 
-  @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);
@@ -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());
   }
 }
index 5c2fb55f44f87a08622237cefa2607755a07137b..5a30daa6926da97ac69a30aafbdbb78ecf6744f5 100644 (file)
@@ -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)));
index d34bfe2449e283b3ece13d9334fbea3d15bb470c..f049d7bb6a86acebe00a603ea558196fdd2613d8 100644 (file)
@@ -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);
-  }
 }
index fabfaed61342614e148df140823ffc4b2550f400..60299412502c75864e3e835b41899a980bad350e 100644 (file)
@@ -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": {
index 5344fd97e81b4c3c65c780f3cf8e15249e9f4078..7ba459d51c6c27f8d0284f5b6c385d5fb59998c0 100644 (file)
       "type": "INT",
       "higherValuesAreBetter": false,
       "qualitative": false,
-      "hidden": false,
-      "custom": false
+      "hidden": false
     },
     {
       "key": "ncloc",
       "type": "INT",
       "higherValuesAreBetter": false,
       "qualitative": false,
-      "hidden": false,
-      "custom": false
+      "hidden": false
     },
     {
       "key": "new_violations",
       "type": "INT",
       "higherValuesAreBetter": false,
       "qualitative": true,
-      "hidden": false,
-      "custom": false,
+      "hidden": false
       "bestValue": "0"
     }
   ],
index 95b01f6383c8947ee218829b1814a0a3ea6effc8..f51e1d3eb7d18aaa27e9dd52ed2653d5441cecbb 100644 (file)
@@ -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)
index 26e4c6f547929d77138e5b3b6850b1f4a92f0d3f..68280c9bbea1af850c79bee90f73ecfe24ab1466 100644 (file)
@@ -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;
   }
index 2548ecd1b83a849490c07a9ae06c50178f35d9e5..e3e9a8a791c67bd35cf0fc90531b849bd08b536e 100644 (file)
@@ -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;
   }
index 4307b47e9cc491d2c0d30f1fefdd697575f8cfee..bd743cf87fc4f8a384b675d6d75770003e48bade 100644 (file)
@@ -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();
   }
index 4aa3478cb2771205908cc441bea1e2f07e16a56a..19c8bc2a5ea0f9ac5b122d1959e0cfd631b87f44 100644 (file)
@@ -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);
index 76fe5ba492c6743bb532144a237c42dfdfd7b95d..762da232cb5d5723eda3c493bda6930791c48729 100644 (file)
@@ -327,6 +327,7 @@ public class Metric<G extends Serializable> implements Serializable, org.sonar.a
   /**
    * @return whether the metric is a managed by the users ("manual metric")
    */
+  @Deprecated
   public Boolean getUserManaged() {
     return userManaged;
   }
@@ -697,6 +698,7 @@ public class Metric<G extends Serializable> implements Serializable, org.sonar.a
      * @return the builder
      * @since 2.10
      */
+    @Deprecated
     public Builder setUserManaged(boolean b) {
       this.userManaged = b;
       return this;
index ab2f66462eaa90fde5a17d101646c6be2a02b1df..02ce013acaf990f6824addd44dc308e8a1bb5314 100644 (file)
@@ -31,7 +31,7 @@ import org.sonarqube.ws.client.GetRequest;
 
 public class DefaultMetricsRepositoryLoader implements MetricsRepositoryLoader {
 
-  private static final String METRICS_SEARCH_URL = "/api/metrics/search?f=name,description,direction,qualitative,custom&ps=500&p=";
+  private static final String METRICS_SEARCH_URL = "/api/metrics/search?ps=500&p=";
   private DefaultScannerWsClient wsClient;
 
   public DefaultMetricsRepositoryLoader(DefaultScannerWsClient wsClient) {
@@ -61,7 +61,7 @@ public class DefaultMetricsRepositoryLoader implements MetricsRepositoryLoader {
             .create()
             .setDirection(metric.getDirection())
             .setQualitative(metric.isQualitative())
-            .setUserManaged(metric.isCustom())
+            .setUserManaged(false)
             .setDescription(metric.getDescription())
             .setUuid(metric.getUuid()));
         }
@@ -78,7 +78,6 @@ public class DefaultMetricsRepositoryLoader implements MetricsRepositoryLoader {
     private String description;
     private int direction;
     private boolean qualitative;
-    private boolean custom;
 
     public String getUuid() {
       return uuid;
@@ -108,9 +107,6 @@ public class DefaultMetricsRepositoryLoader implements MetricsRepositoryLoader {
       return qualitative;
     }
 
-    public boolean isCustom() {
-      return custom;
-    }
   }
 
   private static class WsMetricsResponse {
index c1669b025b3e4e49ef412ddc0c5b4be8cd5e4ea9..90bc8c6bc8e15584288b8e66a6a21244a0627502 100644 (file)
@@ -24,13 +24,12 @@ import java.io.Reader;
 import java.io.StringReader;
 import org.apache.commons.io.IOUtils;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.sonar.scanner.WsTestUtil;
 import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Mockito.doThrow;
@@ -39,13 +38,10 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
 public class DefaultMetricsRepositoryLoaderTest {
-  private static final String WS_URL = "/api/metrics/search?f=name,description,direction,qualitative,custom&ps=500&p=";
+  private static final String WS_URL = "/api/metrics/search?ps=500&p=";
   private DefaultScannerWsClient wsClient;
   private DefaultMetricsRepositoryLoader metricsRepositoryLoader;
 
-  @Rule
-  public ExpectedException exception = ExpectedException.none();
-
   @Before
   public void setUp() throws IOException {
     wsClient = mock(DefaultScannerWsClient.class);
@@ -68,8 +64,8 @@ public class DefaultMetricsRepositoryLoaderTest {
     Reader reader = mock(Reader.class);
     when(reader.read(any(char[].class), anyInt(), anyInt())).thenThrow(new IOException());
     WsTestUtil.mockReader(wsClient, reader);
-    exception.expect(IllegalStateException.class);
-    metricsRepositoryLoader.load();
+    assertThatThrownBy(() -> metricsRepositoryLoader.load())
+      .isInstanceOf(IllegalStateException.class);
   }
 
   @Test
@@ -78,7 +74,7 @@ public class DefaultMetricsRepositoryLoaderTest {
     when(reader.read(any(char[].class), anyInt(), anyInt())).thenReturn(-1);
     doThrow(new IOException()).when(reader).close();
     WsTestUtil.mockReader(wsClient, reader);
-    exception.expect(IllegalStateException.class);
-    metricsRepositoryLoader.load();
+    assertThatThrownBy(() -> metricsRepositoryLoader.load())
+      .isInstanceOf(IllegalStateException.class);
   }
 }