]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8890 Refactor restriction of ps parameter for WS api/project_tags/search
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 3 Jul 2017 10:08:02 +0000 (12:08 +0200)
committerTeryk Bellahsene <teryk@users.noreply.github.com>
Fri, 28 Jul 2017 15:05:09 +0000 (17:05 +0200)
server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java

index 551a1f742f3fedf21aff57d8531058788ecf6a67..ecc3da783778f12bfb02e38f54e7067d515e1c9d 100644 (file)
@@ -112,7 +112,7 @@ public class ProjectMeasuresIndex {
   private static final Double[] LINES_THRESHOLDS = new Double[] {1_000d, 10_000d, 100_000d, 500_000d};
   private static final Double[] COVERAGE_THRESHOLDS = new Double[] {30d, 50d, 70d, 80d};
   private static final Double[] DUPLICATIONS_THRESHOLDS = new Double[] {3d, 5d, 10d, 20d};
-
+  
   private static final String FIELD_MEASURES_KEY = FIELD_MEASURES + "." + ProjectMeasuresIndexDefinition.FIELD_MEASURES_KEY;
   private static final String FIELD_MEASURES_VALUE = FIELD_MEASURES + "." + ProjectMeasuresIndexDefinition.FIELD_MEASURES_VALUE;
 
@@ -348,15 +348,16 @@ public class ProjectMeasuresIndex {
     }
   }
 
-  public List<String> searchTags(@Nullable String textQuery, int pageSize) {
-    checkArgument(pageSize <= 100, "Page size must be lower than or equals to " + 100);
-    if (pageSize == 0) {
+  public List<String> searchTags(@Nullable String textQuery, int size) {
+    int maxPageSize = 500;
+    checkArgument(size <= maxPageSize, "Page size must be lower than or equals to " + maxPageSize);
+    if (size <= 0) {
       return emptyList();
     }
 
     TermsBuilder tagFacet = AggregationBuilders.terms(FIELD_TAGS)
       .field(FIELD_TAGS)
-      .size(pageSize)
+      .size(size)
       .minDocCount(1)
       .order(Terms.Order.term(true));
     if (textQuery != null) {
index e078cfe193e1c660e3d2c04d11679a9ce1568e97..ea43ada08c648f2060a737311ff22287dbcebaa2 100644 (file)
@@ -1269,7 +1269,7 @@ public class ProjectMeasuresIndexTest {
   }
 
   @Test
-  public void facet_tags_size_limited_to_10() {
+  public void facet_tags_returns_10_elements_by_default() {
     index(
       newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")),
       newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")),
@@ -1371,11 +1371,11 @@ public class ProjectMeasuresIndexTest {
   }
 
   @Test
-  public void fail_if_page_size_greater_than_100() {
+  public void fail_if_page_size_greater_than_500() {
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("Page size must be lower than or equals to 100");
+    expectedException.expectMessage("Page size must be lower than or equals to 500");
 
-    underTest.searchTags("whatever", 101);
+    underTest.searchTags("whatever", 501);
   }
 
   private void index(ProjectMeasuresDoc... docs) {