aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-webapi-v2
diff options
context:
space:
mode:
authorAurelien Poscia <aurelien.poscia@sonarsource.com>2023-08-18 12:11:47 +0200
committersonartech <sonartech@sonarsource.com>2023-08-21 20:02:47 +0000
commit30b058eb8ee9921e5bc2f0409ee529c8f3a639a6 (patch)
tree8b16850311d12d6ab962e17b74d1a32b2121030c /server/sonar-webserver-webapi-v2
parentbe5f38aad4af03268722e3f4fff85d1127406095 (diff)
downloadsonarqube-30b058eb8ee9921e5bc2f0409ee529c8f3a639a6.tar.gz
sonarqube-30b058eb8ee9921e5bc2f0409ee529c8f3a639a6.zip
SONAR-20181 Support pageSize=0
Diffstat (limited to 'server/sonar-webserver-webapi-v2')
-rw-r--r--server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/model/RestPage.java4
-rw-r--r--server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/controller/DefaultUserController.java6
-rw-r--r--server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGenerator.java6
-rw-r--r--server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGeneratorTest.java19
4 files changed, 18 insertions, 17 deletions
diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/model/RestPage.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/model/RestPage.java
index 49572e66038..d7b667480c8 100644
--- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/model/RestPage.java
+++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/model/RestPage.java
@@ -27,9 +27,9 @@ import javax.validation.constraints.Positive;
import org.jetbrains.annotations.Nullable;
public record RestPage(
- @Min(1)
+ @Min(0)
@Max(500)
- @Schema(defaultValue = DEFAULT_PAGE_SIZE, description = "Number of results per page")
+ @Schema(defaultValue = DEFAULT_PAGE_SIZE, description = "Number of results per page. A value of 0 will only return the pagination information.")
Integer pageSize,
@Positive
diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/controller/DefaultUserController.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/controller/DefaultUserController.java
index 113b7b00608..7a100dfdb77 100644
--- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/controller/DefaultUserController.java
+++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/controller/DefaultUserController.java
@@ -21,7 +21,7 @@ package org.sonar.server.v2.api.user.controller;
import java.util.Optional;
import javax.annotation.Nullable;
-import org.sonar.api.utils.Paging;
+import org.sonar.server.common.PaginationInformation;
import org.sonar.server.common.SearchResults;
import org.sonar.server.common.user.service.UserCreateRequest;
import org.sonar.server.common.user.service.UserSearchResult;
@@ -37,7 +37,7 @@ import org.sonar.server.v2.api.user.request.UserCreateRestRequest;
import org.sonar.server.v2.api.user.request.UsersSearchRestRequest;
import org.sonar.server.v2.api.user.response.UsersSearchRestResponse;
-import static org.sonar.api.utils.Paging.forPageIndex;
+import static org.sonar.server.common.PaginationInformation.forPageIndex;
import static org.sonar.server.exceptions.BadRequestException.checkRequest;
public class DefaultUserController implements UserController {
@@ -60,7 +60,7 @@ public class DefaultUserController implements UserController {
checkRequest(!RestSortOrder.DESC.equals(order), "order parameter is present for doc-demo purpose, it will be removed.");
SearchResults<UserSearchResult> userSearchResults = userService.findUsers(toUserSearchRequest(usersSearchRestRequest, page));
- Paging paging = forPageIndex(page.pageIndex()).withPageSize(page.pageSize()).andTotal(userSearchResults.total());
+ PaginationInformation paging = forPageIndex(page.pageIndex()).withPageSize(page.pageSize()).andTotal(userSearchResults.total());
return usersSearchResponseGenerator.toUsersForResponse(userSearchResults.searchResults(), paging);
}
diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGenerator.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGenerator.java
index ee4ba94f2aa..f92c3e3784d 100644
--- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGenerator.java
+++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGenerator.java
@@ -24,8 +24,8 @@ import java.util.Objects;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import org.sonar.api.utils.DateUtils;
-import org.sonar.api.utils.Paging;
import org.sonar.db.user.UserDto;
+import org.sonar.server.common.PaginationInformation;
import org.sonar.server.common.user.UsersSearchResponseGenerator;
import org.sonar.server.common.user.service.UserSearchResult;
import org.sonar.server.user.UserSession;
@@ -45,9 +45,9 @@ public class UsersSearchRestResponseGenerator implements UsersSearchResponseGene
}
@Override
- public UsersSearchRestResponse toUsersForResponse(List<UserSearchResult> userSearchResults, Paging paging) {
+ public UsersSearchRestResponse toUsersForResponse(List<UserSearchResult> userSearchResults, PaginationInformation paginationInformation) {
List<RestUser> usersForResponse = toUsersForResponse(userSearchResults);
- PageRestResponse pageRestResponse = new PageRestResponse(paging.pageIndex(), paging.pageSize(), paging.total());
+ PageRestResponse pageRestResponse = new PageRestResponse(paginationInformation.pageIndex(), paginationInformation.pageSize(), paginationInformation.total());
return new UsersSearchRestResponse(usersForResponse, pageRestResponse);
}
diff --git a/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGeneratorTest.java b/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGeneratorTest.java
index 741201135c9..665e80a2761 100644
--- a/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGeneratorTest.java
+++ b/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/user/converter/UsersSearchRestResponseGeneratorTest.java
@@ -28,8 +28,8 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.sonar.api.utils.DateUtils;
-import org.sonar.api.utils.Paging;
import org.sonar.db.user.UserDto;
+import org.sonar.server.common.PaginationInformation;
import org.sonar.server.common.user.service.UserSearchResult;
import org.sonar.server.user.UserSession;
import org.sonar.server.v2.api.response.PageRestResponse;
@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.server.common.PaginationInformation.forPageIndex;
@RunWith(MockitoJUnitRunner.class)
public class UsersSearchRestResponseGeneratorTest {
@@ -54,7 +55,7 @@ public class UsersSearchRestResponseGeneratorTest {
@Test
public void toUsersForResponse_whenNoResults_mapsCorrectly() {
- Paging paging = Paging.forPageIndex(1).withPageSize(2).andTotal(3);
+ PaginationInformation paging = forPageIndex(1).withPageSize(2).andTotal(3);
UsersSearchRestResponse usersForResponse = usersSearchRestResponseGenerator.toUsersForResponse(List.of(), paging);
@@ -67,7 +68,7 @@ public class UsersSearchRestResponseGeneratorTest {
when(userSession.isLoggedIn()).thenReturn(true);
when(userSession.isSystemAdministrator()).thenReturn(true);
- Paging paging = Paging.forPageIndex(1).withPageSize(2).andTotal(3);
+ PaginationInformation paging = forPageIndex(1).withPageSize(2).andTotal(3);
UserSearchResult userSearchResult1 = mockSearchResult(1, true);
UserSearchResult userSearchResult2 = mockSearchResult(2, false);
@@ -105,7 +106,7 @@ public class UsersSearchRestResponseGeneratorTest {
public void toUsersForResponse_whenNonAdmin_mapsNonAdminFields() {
when(userSession.isLoggedIn()).thenReturn(true);
- Paging paging = Paging.forPageIndex(1).withPageSize(2).andTotal(3);
+ PaginationInformation paging = forPageIndex(1).withPageSize(2).andTotal(3);
UserSearchResult userSearchResult1 = mockSearchResult(1, true);
UserSearchResult userSearchResult2 = mockSearchResult(2, false);
@@ -134,7 +135,7 @@ public class UsersSearchRestResponseGeneratorTest {
@Test
public void toUsersForResponse_whenAnonymous_returnsOnlyNameAndLogin() {
- Paging paging = Paging.forPageIndex(1).withPageSize(2).andTotal(3);
+ PaginationInformation paging = forPageIndex(1).withPageSize(2).andTotal(3);
UserSearchResult userSearchResult1 = mockSearchResult(1, true);
UserSearchResult userSearchResult2 = mockSearchResult(2, false);
@@ -182,10 +183,10 @@ public class UsersSearchRestResponseGeneratorTest {
return userSearchResult;
}
- private static void assertPaginationInformationAreCorrect(Paging paging, PageRestResponse pageRestResponse) {
- assertThat(pageRestResponse.pageIndex()).isEqualTo(paging.pageIndex());
- assertThat(pageRestResponse.pageSize()).isEqualTo(paging.pageSize());
- assertThat(pageRestResponse.total()).isEqualTo(paging.total());
+ private static void assertPaginationInformationAreCorrect(PaginationInformation paginationInformation, PageRestResponse pageRestResponse) {
+ assertThat(pageRestResponse.pageIndex()).isEqualTo(paginationInformation.pageIndex());
+ assertThat(pageRestResponse.pageSize()).isEqualTo(paginationInformation.pageSize());
+ assertThat(pageRestResponse.total()).isEqualTo(paginationInformation.total());
}
}