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.
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);
// 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);
}
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'}
@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
<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' %>
<% 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 %>
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);
+ }
}
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);
}