]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3392 Disable paging when searching for components to which a permission templat...
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Wed, 24 Jul 2013 08:09:48 +0000 (10:09 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Wed, 24 Jul 2013 08:09:48 +0000 (10:09 +0200)
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-server/src/main/java/org/sonar/server/component/ComponentQuery.java
sonar-server/src/main/java/org/sonar/server/component/DefaultComponentFinder.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/roles/_apply_template_form.html.erb
sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java
sonar-server/src/test/java/org/sonar/server/component/DefaultComponentFinderTest.java

index 6c511ff2322e844e8df02e837d1d153303e356da..38febb529309841b6dbac4af4760afb1aa753933 100644 (file)
@@ -2263,7 +2263,6 @@ projects_role.bulk_change=Bulk Change
 projects_role.apply_template=Apply Permission Template
 projects_role.apply_template_to_xxx=Apply Permission Template To "{0}"
 projects_role.no_projects=There are currently no results to apply the permission template to.
-projects_role.exceeds_projects_limit_xxx=The current selection exceeds the limit of {0} projects that can be updated in a row. Please narrow your search before applying the permission template.
 
 
 
index 32bcb356557ba46328961f1c6e6c81904fbf7c69..387963227e7f8f55f8fe1f57544d8e54994ad7e9 100644 (file)
@@ -37,6 +37,7 @@ public class ComponentQuery {
 
   public static final int DEFAULT_PAGE_INDEX = 1;
   public static final int DEFAULT_PAGE_SIZE = 100;
+  public static final int NO_PAGINATION = -1;
 
   public static final String SORT_BY_NAME = "NAME";
   public static final Set<String> SORTS = ImmutableSet.of(SORT_BY_NAME);
index 6bd4e9291de0f731bc5f464f17cce6f931b19e4f..ac199cbb23bfc5b693c598833ae3277fea7a0a81 100644 (file)
@@ -57,11 +57,16 @@ public class DefaultComponentFinder {
       // 2. Sort components
       Collection<? extends Component> sortedComponents = new ComponentsFinderSort(foundComponents, query).sort();
 
-      // 3. Apply pagination
-      Paging paging = Paging.create(query.pageSize(), query.pageIndex(), foundComponents.size());
-      Collection<? extends Component> pagedComponents = pagedComponents(sortedComponents, paging);
+      if(ComponentQuery.NO_PAGINATION == query.pageSize()) {
+        return new DefaultComponentQueryResult(sortedComponents).setQuery(query);
+      } else {
+        // 3. Apply pagination
+        Paging paging = Paging.create(query.pageSize(), query.pageIndex(), foundComponents.size());
+        Collection<? extends Component> pagedComponents = pagedComponents(sortedComponents, paging);
+
+        return new DefaultComponentQueryResult(pagedComponents).setPaging(paging).setQuery(query);
+      }
 
-      return new DefaultComponentQueryResult(pagedComponents).setPaging(paging).setQuery(query);
     } finally {
       LOG.debug("ComponentQuery execution time : {} ms", System.currentTimeMillis() - start);
     }
index d49b116980f57103a31e13b5f47b26936df73d51..3b68aac03b50dd05da4d713a0228f33c973feced 100644 (file)
@@ -21,7 +21,6 @@ class RolesController < ApplicationController
   helper RolesHelper
 
   SECTION=Navigation::SECTION_CONFIGURATION
-  BULK_LIMIT=500
 
   before_filter :admin_required
   verify :method => :post, :only => [:set_users, :set_groups], :redirect_to => {:action => 'global'}
@@ -84,19 +83,17 @@ class RolesController < ApplicationController
     @permission_templates = Internal.permission_templates.selectAllPermissionTemplates().sort_by {|t| t.name.downcase}.collect {|pt| [pt.name, pt.key]}
 
     params['qualifiers'] ||= 'TRK'
-    params['pageSize'] = 500
+    params['pageSize'] = -1
 
     query_result = Internal.component_api.find(params)
     components = query_result.components().to_a
-    total_results_count = query_result.paging.total.to_i
 
     @projects_ids = components.collect{|component| component.getId()}
     @qualifier = params[:qualifiers]
 
     render :partial => 'apply_template_form',
            :locals => {:project_name => components.size == 1 ? components[0].name : nil,
-                       :empty => @projects_ids.nil? || @projects_ids.size == 0,
-                       :overflow => total_results_count > BULK_LIMIT}
+                       :empty => @projects_ids.nil? || @projects_ids.size == 0}
   end
 
   # POST /roles/apply_template?criteria
index c8796ae10eb90da99058f42081291edf0aec2199..58e2a63cbb6eb20f6fef1cefde2ef69c76de41ee 100644 (file)
@@ -1,5 +1,5 @@
 <form id="apply-template-form" method="post" action="<%= ApplicationController.root_context -%>/roles/apply_template">
-  <% unless @projects_ids.nil? %>
+  <% unless empty %>
     <input type="hidden" name="components" id="apply-template-components" value="<%= @projects_ids.join(',') %>"/>
   <% end %>
   <fieldset>
           <img src="<%= ApplicationController.root_context -%>/images/information.png" style="vertical-align: text-bottom"/>
           <%= message 'projects_role.no_projects' -%>
         </div>
-      <% elsif overflow %>
-        <div class="info">
-          <img src="<%= ApplicationController.root_context -%>/images/information.png" style="vertical-align: text-bottom"/>
-          <%= message 'projects_role.exceeds_projects_limit_xxx', :params => RolesController::BULK_LIMIT -%>
-        </div>
       <% else %>
         <div class="modal-field">
           <%= label_tag 'template_key', 'Permission Template' %>
@@ -33,7 +28,7 @@
       <% end %>
     </div>
     <div class="modal-foot">
-      <% unless empty || overflow %>
+      <% unless empty %>
         <span id="apply-template-loading-image" class="loading-image hidden"><%= image_tag 'loading.gif' %></span>
         <input type="submit" value="<%= message('apply') -%>" id="apply-template-submit" class="apply-template" onclick="return displayLoadingImage()" />
       <% end %>
index f3dfdd8164a8dc3f2b4f24d7a6b1eb89d498252f..44953b04d4a55db66eb3fdd37623b4fa5783fd79 100644 (file)
@@ -78,4 +78,10 @@ public class ComponentQueryTest {
     assertThat(query.pageIndex()).isEqualTo(ComponentQuery.DEFAULT_PAGE_INDEX);
   }
 
+  @Test
+  public void should_build_non_paginated_query() throws Exception {
+    ComponentQuery query = ComponentQuery.builder().pageSize(ComponentQuery.NO_PAGINATION).build();
+    assertThat(query.pageSize()).isEqualTo(ComponentQuery.NO_PAGINATION);
+    assertThat(query.pageIndex()).isEqualTo(ComponentQuery.DEFAULT_PAGE_INDEX);
+  }
 }
index 9aa014331a56e0e24c90f9660e03d269cfdf2949..d94bb819c0125b9a7864c648c7a22b1aedf15698 100644 (file)
@@ -115,6 +115,22 @@ public class DefaultComponentFinderTest {
     assertThat(results.paging().total()).isEqualTo(3);
   }
 
+  @Test
+  public void should_skip_pagination() throws Exception {
+    ComponentQuery query = ComponentQuery.builder().pageSize(ComponentQuery.NO_PAGINATION)
+      .pageIndex(ComponentQuery.DEFAULT_PAGE_INDEX).build();
+
+    when(dao.selectComponentsByQualifiers(anyCollection())).thenReturn(newArrayList(
+      createProject("org.codehaus.sonar", "Sonar"),
+      createProject("org.apache.tika:tika", "Apache Tika"),
+      createProject("org.picocontainer:picocontainer-parent", "PicoContainer Parent")
+    ));
+
+    DefaultComponentQueryResult results = finder.find(query);
+    assertThat(results.paging()).isNull();
+    assertThat(results.components().size()).isEqualTo(3);
+  }
+
   private Component createProject(String key, String name){
     return new Project(key, null, name);
   }