aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-04-24 14:41:05 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-04-24 14:54:08 +0200
commit27679449745382c2f1ec39aa84975d7eb19ae9f9 (patch)
tree92ebbdf27768c5a8ee591c4f19cc9de289859b3c /sonar-plugin-api
parent9d6221dde611b7ba5a09b0e90185cfc034db0b1f (diff)
downloadsonarqube-27679449745382c2f1ec39aa84975d7eb19ae9f9.tar.gz
sonarqube-27679449745382c2f1ec39aa84975d7eb19ae9f9.zip
SONAR-3755 Add pagination on Issues WS
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java42
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/Paging.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/issue/Pagination.java)41
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java8
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/PagingTest.java (renamed from sonar-plugin-api/src/test/java/org/sonar/api/issue/PaginationTest.java)21
5 files changed, 56 insertions, 58 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java
index d40120f32db..59257860eaf 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java
@@ -48,7 +48,7 @@ public interface IssueFinder extends ServerComponent {
Collection<Component> components();
- Pagination pagination();
+ Paging paging();
}
Results find(IssueQuery query, @Nullable Integer currentUserId, String role);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
index b481db42961..bde2cab4488 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
@@ -46,11 +46,11 @@ public class IssueQuery {
private final Date createdAfter;
private final Date createdBefore;
- // max results
- private final int limit;
+ // max results per page
+ private final int pageSize;
// index of selected page. Start with 1.
- private final int page;
+ private final int pageIndex;
private IssueQuery(Builder builder) {
this.keys = builder.keys;
@@ -64,8 +64,8 @@ public class IssueQuery {
this.assignees = builder.assignees;
this.createdAfter = builder.createdAfter;
this.createdBefore = builder.createdBefore;
- this.limit = builder.limit;
- this.page = builder.page;
+ this.pageSize = builder.pageSize;
+ this.pageIndex = builder.pageIndex;
}
public Collection<String> keys() {
@@ -112,12 +112,12 @@ public class IssueQuery {
return createdBefore;
}
- public int limit() {
- return limit;
+ public int pageSize() {
+ return pageSize;
}
- public int page() {
- return page;
+ public int pageIndex() {
+ return pageIndex;
}
@Override
@@ -134,9 +134,9 @@ public class IssueQuery {
* @since 3.6
*/
public static class Builder {
- private static final int DEFAULT_LIMIT = 100;
- private static final int MAX_LIMIT = 1000;
- private static final int DEFAULT_PAGE = 1;
+ private static final int DEFAULT_PAGE_SIZE = 100;
+ private static final int MAX_PAGE_SIZE = 1000;
+ private static final int DEFAULT_PAGE_INDEX = 1;
private Collection<String> keys;
private Collection<String> severities;
@@ -149,8 +149,8 @@ public class IssueQuery {
private Collection<String> assignees;
private Date createdAfter;
private Date createdBefore;
- private int limit = DEFAULT_LIMIT;
- private int page = DEFAULT_PAGE;
+ private int pageSize = DEFAULT_PAGE_SIZE;
+ private int pageIndex = DEFAULT_PAGE_INDEX;
private Builder() {
}
@@ -210,16 +210,16 @@ public class IssueQuery {
return this;
}
- public Builder limit(Integer i) {
- Preconditions.checkArgument(i == null || i.intValue() > 0, "Limit must be greater than 0 (got " + i + ")");
- Preconditions.checkArgument(i == null || i.intValue() < MAX_LIMIT, "Limit must be less than " + MAX_LIMIT + " (got " + i + ")");
- this.limit = (i == null ? DEFAULT_LIMIT : i.intValue());
+ public Builder pageSize(Integer i) {
+ Preconditions.checkArgument(i == null || i.intValue() > 0, "Page size must be greater than 0 (got " + i + ")");
+ Preconditions.checkArgument(i == null || i.intValue() < MAX_PAGE_SIZE, "Page size must be less than " + MAX_PAGE_SIZE + " (got " + i + ")");
+ this.pageSize = (i == null ? DEFAULT_PAGE_SIZE : i.intValue());
return this;
}
- public Builder page(Integer i) {
- Preconditions.checkArgument(i == null || i.intValue() > 0, "Page must be greater than 0 (got " + i + ")");
- this.page = (i == null ? DEFAULT_PAGE : i.intValue());
+ public Builder pageIndex(Integer i) {
+ Preconditions.checkArgument(i == null || i.intValue() > 0, "Page index must be greater than 0 (got " + i + ")");
+ this.pageIndex = (i == null ? DEFAULT_PAGE_INDEX : i.intValue());
return this;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Pagination.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Paging.java
index b519145ab0a..95f610948f0 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Pagination.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Paging.java
@@ -20,43 +20,42 @@
package org.sonar.api.issue;
-public class Pagination {
+/**
+ * @since 3.6
+ */
+public class Paging {
- private int limit;
- private int page;
- private int size;
+ private int pageSize;
+ private int pageIndex;
+ private int total;
- public Pagination(int limit, int page, int size) {
- this.limit = limit;
- this.page = page;
- this.size = size;
+ public Paging(int pageSize, int pageIndex, int total) {
+ this.pageSize = pageSize;
+ this.pageIndex = pageIndex;
+ this.total = total;
}
- public int page() {
- return page;
+ public int pageIndex() {
+ return pageIndex;
}
- public int limit() {
- return limit;
+ public int pageSize() {
+ return pageSize;
}
- public int size() {
- return size;
+ public int total() {
+ return total;
}
public int offset(){
- return (page - 1) * limit;
+ return (pageIndex - 1) * pageSize;
}
public int pages() {
- int p = (size / limit);
- if ((size % limit) > 0) {
+ int p = (total / pageSize);
+ if ((total % pageSize) > 0) {
p++;
}
return p;
}
-
- public boolean empty() {
- return size == 0;
- }
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java
index 8f46066a642..cb47aec4e18 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java
@@ -44,8 +44,8 @@ public class IssueQueryTest {
.assignees(Lists.newArrayList("gargantua"))
.createdAfter(new Date())
.createdBefore(new Date())
- .limit(10)
- .page(2)
+ .pageSize(10)
+ .pageIndex(2)
.build();
assertThat(query.keys()).containsOnly("ABCDE");
assertThat(query.severities()).containsOnly(Severity.BLOCKER);
@@ -58,7 +58,7 @@ public class IssueQueryTest {
assertThat(query.rules()).containsOnly(RuleKey.of("squid", "AvoidCycle"));
assertThat(query.createdAfter()).isNotNull();
assertThat(query.createdBefore()).isNotNull();
- assertThat(query.limit()).isEqualTo(10);
- assertThat(query.page()).isEqualTo(2);
+ assertThat(query.pageSize()).isEqualTo(10);
+ assertThat(query.pageIndex()).isEqualTo(2);
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/PaginationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/PagingTest.java
index 0801bd0e61d..5229fdad344 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/PaginationTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/PagingTest.java
@@ -24,27 +24,26 @@ import org.junit.Test;
import static org.fest.assertions.Assertions.assertThat;
-public class PaginationTest {
+public class PagingTest {
@Test
public void test_pagination(){
- Pagination pagination = new Pagination(5, 1, 20);
+ Paging paging = new Paging(5, 1, 20);
- assertThat(pagination.limit()).isEqualTo(5);
- assertThat(pagination.page()).isEqualTo(1);
- assertThat(pagination.size()).isEqualTo(20);
- assertThat(pagination.empty()).isFalse();
+ assertThat(paging.pageSize()).isEqualTo(5);
+ assertThat(paging.pageIndex()).isEqualTo(1);
+ assertThat(paging.total()).isEqualTo(20);
- assertThat(pagination.offset()).isEqualTo(0);
- assertThat(pagination.pages()).isEqualTo(4);
+ assertThat(paging.offset()).isEqualTo(0);
+ assertThat(paging.pages()).isEqualTo(4);
}
@Test
public void test_pagination_on_second_page(){
- Pagination pagination = new Pagination(5, 2, 20);
+ Paging paging = new Paging(5, 2, 20);
- assertThat(pagination.offset()).isEqualTo(5);
- assertThat(pagination.pages()).isEqualTo(4);
+ assertThat(paging.offset()).isEqualTo(5);
+ assertThat(paging.pages()).isEqualTo(4);
}
}