summaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-23 18:07:59 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-23 18:08:15 +0200
commit78f2909b5ef26d889c16423a05e1e3371244861c (patch)
treead8919a57f1ba58cda26b95a846dc3273c1c44a6 /sonar-server/src/main
parentb1c27d7b983062e4236d43371bc14596819bc050 (diff)
downloadsonarqube-78f2909b5ef26d889c16423a05e1e3371244861c.tar.gz
sonarqube-78f2909b5ef26d889c16423a05e1e3371244861c.zip
SONAR-5329 Add pagination on changelog
Diffstat (limited to 'sonar-server/src/main')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/activity/RubyQProfileActivityService.java (renamed from sonar-server/src/main/java/org/sonar/server/activity/RubyActivityService.java)37
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileService.java9
-rw-r--r--sonar-server/src/main/java/org/sonar/server/search/Result.java19
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb6
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb77
6 files changed, 97 insertions, 55 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/activity/RubyActivityService.java b/sonar-server/src/main/java/org/sonar/server/activity/RubyQProfileActivityService.java
index 43b98eabf3b..d5715a20a62 100644
--- a/sonar-server/src/main/java/org/sonar/server/activity/RubyActivityService.java
+++ b/sonar-server/src/main/java/org/sonar/server/activity/RubyQProfileActivityService.java
@@ -22,10 +22,12 @@ package org.sonar.server.activity;
import org.picocontainer.Startable;
import org.sonar.api.ServerComponent;
+import org.sonar.api.utils.Paging;
import org.sonar.server.qualityprofile.QProfileActivity;
import org.sonar.server.qualityprofile.QProfileActivityQuery;
import org.sonar.server.qualityprofile.QProfileService;
import org.sonar.server.search.QueryOptions;
+import org.sonar.server.search.Result;
import org.sonar.server.util.RubyUtils;
import java.util.Date;
@@ -36,19 +38,20 @@ import java.util.Map;
* @deprecated in 4.4 because Ruby on Rails is deprecated too !
*/
@Deprecated
-public class RubyActivityService implements ServerComponent, Startable {
+public class RubyQProfileActivityService implements ServerComponent, Startable {
private final QProfileService service;
- public RubyActivityService(QProfileService service) {
+ public RubyQProfileActivityService(QProfileService service) {
this.service = service;
}
/**
* Used in profiles_controller.rb
*/
- public List<QProfileActivity> search(Map<String, Object> params) {
+ public QProfileActivityResult search(Map<String, Object> params) {
QProfileActivityQuery query = new QProfileActivityQuery();
+ QueryOptions queryOptions = new QueryOptions().setMaxLimit();
List<String> profileKeys = RubyUtils.toStrings(params.get("profileKeys"));
if (profileKeys != null) {
query.setQprofileKeys(profileKeys);
@@ -61,7 +64,12 @@ public class RubyActivityService implements ServerComponent, Startable {
if (to != null) {
query.setTo(to);
}
- return service.findActivities(query, new QueryOptions().setMaxLimit());
+ Integer page = RubyUtils.toInteger(params.get("p"));
+ int pageIndex = page != null ? page : 1;
+ queryOptions.setPage(pageIndex, 50);
+
+ Result<QProfileActivity> result = service.searchActivities(query, queryOptions);
+ return new QProfileActivityResult(result.getHits(), Paging.create(queryOptions.getLimit(), pageIndex, Long.valueOf(result.getTotal()).intValue()));
}
@Override
@@ -73,4 +81,25 @@ public class RubyActivityService implements ServerComponent, Startable {
public void stop() {
// implement startable
}
+
+ public static class QProfileActivityResult {
+
+ private final List<QProfileActivity> activities;
+
+ private final Paging paging;
+
+ public QProfileActivityResult(List<QProfileActivity> activities, Paging paging) {
+ this.activities = activities;
+ this.paging = paging;
+ }
+
+ public List<QProfileActivity> activities() {
+ return activities;
+ }
+
+ public Paging paging() {
+ return paging;
+ }
+
+ }
}
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
index 40685bd9646..1bb53f1316c 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
@@ -72,7 +72,7 @@ import org.sonar.jpa.session.DatabaseSessionProvider;
import org.sonar.jpa.session.DefaultDatabaseConnector;
import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
import org.sonar.server.activity.ActivityService;
-import org.sonar.server.activity.RubyActivityService;
+import org.sonar.server.activity.RubyQProfileActivityService;
import org.sonar.server.activity.db.ActivityDao;
import org.sonar.server.activity.index.ActivityIndex;
import org.sonar.server.activity.index.ActivityNormalizer;
@@ -320,7 +320,7 @@ class ServerComponents {
pico.addSingleton(QProfileCopier.class);
pico.addSingleton(QProfileBackuper.class);
pico.addSingleton(QProfileReset.class);
- pico.addSingleton(RubyActivityService.class);
+ pico.addSingleton(RubyQProfileActivityService.class);
// rule
pico.addSingleton(AnnotationRuleParser.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileService.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileService.java
index 91a4e342fbe..9ab2e196ba8 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileService.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileService.java
@@ -43,6 +43,7 @@ import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.search.FacetValue;
import org.sonar.server.search.IndexClient;
import org.sonar.server.search.QueryOptions;
+import org.sonar.server.search.Result;
import org.sonar.server.user.UserSession;
import javax.annotation.CheckForNull;
@@ -279,8 +280,7 @@ public class QProfileService implements ServerComponent {
new QueryOptions().setLimit(0)).getTotal();
}
- public List<QProfileActivity> findActivities(QProfileActivityQuery query, QueryOptions options) {
- List<QProfileActivity> results = Lists.newArrayList();
+ public Result<QProfileActivity> searchActivities(QProfileActivityQuery query, QueryOptions options) {
DbSession session = db.openSession(false);
try {
OrFilterBuilder activityFilter = FilterBuilders.orFilter();
@@ -290,6 +290,7 @@ public class QProfileService implements ServerComponent {
}
SearchResponse response = index.get(ActivityIndex.class).search(query, options, activityFilter);
+ Result<QProfileActivity> result = new Result<QProfileActivity>(response);
for (SearchHit hit : response.getHits().getHits()) {
QProfileActivity profileActivity = new QProfileActivity(hit.getSource());
RuleDto ruleDto = db.ruleDao().getNullableByKey(session, profileActivity.ruleKey());
@@ -297,9 +298,9 @@ public class QProfileService implements ServerComponent {
UserDto user = db.userDao().selectActiveUserByLogin(profileActivity.login(), session);
profileActivity.authorName(user != null ? user.getName() : null);
- results.add(profileActivity);
+ result.getHits().add(profileActivity);
}
- return results;
+ return result;
} finally {
session.close();
}
diff --git a/sonar-server/src/main/java/org/sonar/server/search/Result.java b/sonar-server/src/main/java/org/sonar/server/search/Result.java
index 491fdfc088d..85a32c26cf4 100644
--- a/sonar-server/src/main/java/org/sonar/server/search/Result.java
+++ b/sonar-server/src/main/java/org/sonar/server/search/Result.java
@@ -29,12 +29,9 @@ import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class Result<K> {
@@ -45,15 +42,21 @@ public class Result<K> {
private final String scrollId;
private final BaseIndex<K, ?, ?> index;
- public Result(BaseIndex<K, ?, ?> index, SearchResponse response) {
+ public Result(SearchResponse response) {
+ this(null, response);
+ }
+
+ public Result(@Nullable BaseIndex<K, ?, ?> index, SearchResponse response) {
this.index = index;
this.scrollId = response.getScrollId();
this.facets = LinkedListMultimap.create();
this.total = (int) response.getHits().totalHits();
this.timeInMillis = response.getTookInMillis();
this.hits = new ArrayList<K>();
- for (SearchHit hit : response.getHits()) {
- this.hits.add(index.toDoc(hit.getSource()));
+ if (index != null) {
+ for (SearchHit hit : response.getHits()) {
+ this.hits.add(index.toDoc(hit.getSource()));
+ }
}
if (response.getAggregations() != null) {
for (Map.Entry<String, Aggregation> facet : response.getAggregations().asMap().entrySet()) {
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
index 04f4cd80389..9c9d485beb8 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
@@ -246,8 +246,10 @@ class ProfilesController < ApplicationController
require_parameters 'key'
@profile = Internal.component(Java::OrgSonarServerQualityprofile::QProfileService.java_class).getByKey(params[:key])
- search = {'profileKeys' => @profile.key().to_s, 'since' => params[:since], 'to' => params[:to]}
- @changes = Internal.component(Java::OrgSonarServerActivity::RubyActivityService.java_class).search(search)
+ search = {'profileKeys' => @profile.key().to_s, 'since' => params[:since], 'to' => params[:to], 'p' => params[:p]}
+ result = Internal.component(Java::OrgSonarServerActivity::RubyQProfileActivityService.java_class).search(search)
+ @changes = result.activities
+ @paging = result.paging
set_profile_breadcrumbs
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb
index 77d8b728da8..ce962dbc83f 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb
@@ -2,17 +2,18 @@
<%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'changelog'} %>
<div class="tabs-panel marginbottom10">
+ <form class="marginbottom10" method="get" action="<%= ApplicationController.root_context %>/profiles/changelog">
+ <input name="key" type="hidden" value="<%= @profile.key() %>"/>
+ <%= message('quality_profiles.changelog_from') -%>
+ <input name="since" type="text" value="<%= params['since'] %>" placeholder="1970-01-31"/>
+ <%= message('to').downcase -%>
+ <input name="to" type="text" value="<%= params['to'] %>" placeholder="1970-01-31"/>
+ <input type="submit" value="<%= h message('search_verb') -%>" id="submit"/>
+ </form>
+
<% if @changes.empty? %>
<%= message('quality_profiles.changelog.empty') -%>
<% else %>
- <form class="marginbottom10" method="get" action="<%= ApplicationController.root_context %>/profiles/changelog">
- <input name="key" type="hidden" value="<%= @profile.key() %>"/>
- <%= message('quality_profiles.changelog_from') -%>
- <input name="since" type="text" value="<%= params['since'] %>" placeholder="1970-01-31"/>
- <%= message('to').downcase -%>
- <input name="to" type="text" value="<%= params['to'] %>" placeholder="1970-01-31"/>
- <input type="submit" value="<%= h message('load_verb') -%>" id="submit"/>
- </form>
<table id="profile-changelog" class="data width100">
<thead>
@@ -24,36 +25,42 @@
<th><%= message('parameters') -%></th>
</tr>
</thead>
- <%
- @changes.each do |change|
- %>
- <tr class="<%= cycle('even', 'odd') -%>">
+ <tbody>
<%
- action = change.action()
- action_message = message('quality_profiles.changelog.' + action.downcase) if action
- author = change.authorName() ? change.authorName() : change.login() ? !change.login().emtpy? : 'System'
- rule = change.ruleName() ? change.ruleName() : change.ruleKey()
+ @changes.each do |change|
%>
- <td valign="top" width="1%" nowrap><%= Internal.i18n.formatDateTime(change.time()) -%></td>
- <td valign="top" width="1%" nowrap><%= author %></td>
- <td valign="top" width="1%" nowrap><%= action_message %></td>
- <td valign="top"><%= rule %></td>
- <td valign="top">
- <% if change.severity() %>
- <%= message('quality_profiles.severity_set_to_x', :params => ["<i class=\"icon-severity-#{change.severity().downcase}\"></i>", change.severity()]) -%>
- <br/>
- <% end %>
- <% change.parameters().each do |param_key, param_value| %>
- <% unless param_value.empty? %>
- <%= message('quality_profiles.parameter_set_to_x', :params => [param_key, param_value]) -%>
- <% else %>
- <%= message('quality_profiles.changelog.parameter_reset_to_default_value_x', :params => [param_key]) -%>
+ <tr class="<%= cycle('even', 'odd') -%>">
+ <%
+ action = change.action()
+ action_message = message('quality_profiles.changelog.' + action.downcase) if action
+ author = change.authorName() ? change.authorName() : change.login() ? !change.login().emtpy? : 'System'
+ rule = change.ruleName() ? change.ruleName() : change.ruleKey()
+ %>
+ <td valign="top" width="1%" nowrap><%= Internal.i18n.formatDateTime(change.time()) -%></td>
+ <td valign="top" width="1%" nowrap><%= author %></td>
+ <td valign="top" width="1%" nowrap><%= action_message %></td>
+ <td valign="top"><%= rule %></td>
+ <td valign="top">
+ <% if change.severity() %>
+ <%= message('quality_profiles.severity_set_to_x', :params => ["<i class=\"icon-severity-#{change.severity().downcase}\"></i>", change.severity()]) -%>
+ <br/>
+ <% end %>
+ <% change.parameters().each do |param_key, param_value| %>
+ <% unless param_value.empty? %>
+ <%= message('quality_profiles.parameter_set_to_x', :params => [param_key, param_value]) -%>
+ <% else %>
+ <%= message('quality_profiles.changelog.parameter_reset_to_default_value_x', :params => [param_key]) -%>
+ <% end %>
+ <br/>
<% end %>
- <br/>
- <% end %>
- </td>
- </tr>
- <% end %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+ <%= paginate_java(@paging, :colspan => 5, :include_loading_icon => true) { |label, page_id|
+ link_to(label, params.merge({:p => page_id}), :style => 'text-decoration:underline')
+ }
+ %>
</table>
<% end %>