]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5084 Add total number of matching rules in the rules search WS result
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 7 Mar 2014 13:05:34 +0000 (14:05 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 7 Mar 2014 13:43:31 +0000 (14:43 +0100)
sonar-server/src/main/java/org/sonar/server/rule/ws/RuleSearchWsHandler.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RuleSearchWsHandlerTest.java

index ed76a8c16aecaa4827ca554cdb928c643aa0b3f1..f2b8314ac22f009330cdea7ff862067248ac356c 100644 (file)
@@ -52,6 +52,7 @@ public class RuleSearchWsHandler implements RequestHandler {
     final String ruleKeyParam = request.param("k");
     Collection<Rule> foundRules = Collections.emptyList();
     boolean hasMore = false;
+    long total = 0L;
     if (ruleKeyParam == null) {
       final String ruleSearchParam = request.param("s");
       final int pageSize = request.paramAsInt("ps", 25);
@@ -63,11 +64,13 @@ public class RuleSearchWsHandler implements RequestHandler {
           .build());
       foundRules = searchResult.results();
       hasMore = searchResult.paging().hasNextPage();
+      total = searchResult.paging().total();
     } else {
       RuleKey ruleKey = RuleKey.parse(ruleKeyParam);
       Rule rule = findRule(ruleKey);
       if (rule != null) {
         foundRules = Collections.singleton(rule);
+        total = 1L;
       }
       hasMore = false;
     }
@@ -79,7 +82,7 @@ public class RuleSearchWsHandler implements RequestHandler {
       writeRule(rule, json);
       json.endObject();
     }
-    json.endArray().prop("more", hasMore).endObject().close();
+    json.endArray().prop("more", hasMore).prop("total", total).endObject().close();
   }
 
   @CheckForNull
index af418c5f418af431d1e1252076c66ebd76de14f2..b100664f10c735da77c75f0592bb42f24232c1ed 100644 (file)
@@ -78,7 +78,7 @@ public class RuleSearchWsHandlerTest {
 
     MockUserSession.set();
     WsTester.TestRequest request = tester.newRequest("list").setParam("ps", "10").setParam("p", "2");
-    request.execute().assertJson("{'more':false,'results':["
+    request.execute().assertJson("{'more':false,'total':1,'results':["
       + "{'key':'squid:AvoidCycle','name':'Avoid cycle','language':'Java'}"
       + "]}");
   }
@@ -95,7 +95,7 @@ public class RuleSearchWsHandlerTest {
 
     MockUserSession.set();
     WsTester.TestRequest request = tester.newRequest("list").setParam("k", ruleKey);
-    request.execute().assertJson("{'more':false,'results':["
+    request.execute().assertJson("{'more':false,'total':1,'results':["
       + "{'key':'squid:AvoidCycle','name':'Avoid cycle','language':'Java'}"
       + "]}");
   }