]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6570 WS metrics/search count take into account the isCustom property
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 8 Jun 2015 12:50:02 +0000 (14:50 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 8 Jun 2015 13:11:41 +0000 (15:11 +0200)
server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java
server/sonar-server/src/main/java/org/sonar/server/metric/ws/SearchAction.java
sonar-core/src/main/java/org/sonar/core/metric/db/MetricMapper.java
sonar-core/src/main/resources/org/sonar/core/metric/db/MetricMapper.xml

index 63611986243a220d0fba852c5bcdf26df1ec05e5..a9f669dda25438a633fdf7bbea2f0f35538db73b 100644 (file)
@@ -79,6 +79,10 @@ public class MetricDao implements DaoComponent {
     return mapper(session).selectAllEnabled(properties, new RowBounds(searchOptions.getOffset(), searchOptions.getLimit()));
   }
 
+  public int countEnabled(DbSession session, @Nullable Boolean isCustom) {
+    return mapper(session).countEnabled(isCustom);
+  }
+
   public void insert(DbSession session, MetricDto dto) {
     mapper(session).insert(dto);
   }
@@ -106,10 +110,6 @@ public class MetricDao implements DaoComponent {
     });
   }
 
-  public int countCustom(DbSession session) {
-    return mapper(session).countCustom();
-  }
-
   public void update(DbSession session, MetricDto metric) {
     mapper(session).update(metric);
   }
index a9d2c6c00da5cc14170fecfcff6ee37174c5844b..da138001d80c0ee80a95bf79d7c7059e7dfbfcd7 100644 (file)
@@ -89,7 +89,7 @@ public class SearchAction implements MetricsWsAction {
     DbSession dbSession = dbClient.openSession(false);
     try {
       List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions);
-      int nbMetrics = dbClient.metricDao().countCustom(dbSession);
+      int nbMetrics = dbClient.metricDao().countEnabled(dbSession, isCustom);
       JsonWriter json = response.newJsonWriter();
       json.beginObject();
       Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS));
index abf450248e8ce5b45c20083a90eb4f19d2950f73..619670bfab42180344cfe3a191009f93ca47ab16 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.core.metric.db;
 
 import java.util.List;
 import java.util.Map;
+import javax.annotation.Nullable;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.session.RowBounds;
 
@@ -41,7 +42,7 @@ public interface MetricMapper {
 
   void disable(@Param("ids") List<Integer> ids);
 
-  int countCustom();
+  int countEnabled(@Param("isCustom") @Nullable Boolean isCustom);
 
   void update(MetricDto metric);
 
index 94d8727cadad6513126946a3a867efea93fa28f6..9278b7252a59f3a9a4d621ce6c1747125233f676 100644 (file)
     </where>
     ORDER BY UPPER(m.short_name), m.short_name
   </select>
-  <select id="countCustom" resultType="Integer">
+  <select id="countEnabled" resultType="Integer">
     SELECT COUNT(*)
     FROM metrics m
     <where>
       AND m.enabled=${_true}
-      AND m.user_managed=${_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>