From: Julien Lancelot Date: Fri, 27 Jun 2014 15:33:26 +0000 (+0200) Subject: Add pagination to ruby rules search query X-Git-Tag: 4.4-RC1~117 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=07d0694cf654cf68d361ceb2ba729a6c08e2a0d5;p=sonarqube.git Add pagination to ruby rules search query --- diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java b/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java index ea792ca1eee..5ea09af178c 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java @@ -32,6 +32,7 @@ import org.sonar.server.rule.index.RuleDoc; import org.sonar.server.rule.index.RuleNormalizer; import org.sonar.server.rule.index.RuleQuery; import org.sonar.server.search.QueryOptions; +import org.sonar.server.search.Result; import org.sonar.server.user.UserSession; import org.sonar.server.util.RubyUtils; @@ -59,7 +60,7 @@ public class RubyRuleService implements ServerComponent, Startable { } /** - * Used in issues_controller.rb and in manual_rules_controller.rb + * Used in issues_controller.rb and in manual_rules_controller.rb and in SQALE */ @CheckForNull public Rule findByKey(String ruleKey) { @@ -82,9 +83,14 @@ public class RubyRuleService implements ServerComponent, Startable { query.setHasDebtCharacteristic(RubyUtils.toBoolean(params.get("hasDebtCharacteristic"))); query.setSortField(RuleNormalizer.RuleField.NAME); - QueryOptions options = new QueryOptions().setScroll(true); - List rules = newArrayList(service.search(query, options).scroll()); - return new PagedResult(rules, PagingResult.create(Integer.MAX_VALUE, 1, rules.size())); + QueryOptions options = new QueryOptions(); + Integer page = RubyUtils.toInteger(params.get("p")); + int pageIndex = page != null ? page : 1; + Integer pageSize = RubyUtils.toInteger(params.get("pageSize")); + options.setPage(pageIndex, pageSize != null ? pageSize : 50); + + Result result = service.search(query, options); + return new PagedResult(result.getHits(), PagingResult.create(options.getLimit(), pageIndex, result.getTotal())); } /**