diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-16 11:12:36 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-17 12:33:20 +0100 |
commit | 0d3be9943570cf5bfb7fbb72fdfe5a6fcb2798c0 (patch) | |
tree | 7daef363e47a7efeddb2ad1c219758390ae966f1 /sonar-ws | |
parent | 3d8248cb69680296d02a4c3141beccc2517fac87 (diff) | |
download | sonarqube-0d3be9943570cf5bfb7fbb72fdfe5a6fcb2798c0.tar.gz sonarqube-0d3be9943570cf5bfb7fbb72fdfe5a6fcb2798c0.zip |
SONAR-8224 SONAR-8225 Sort by name and metric
Diffstat (limited to 'sonar-ws')
4 files changed, 61 insertions, 5 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java index 5b5efb1028d..fd382d321a6 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java @@ -110,6 +110,8 @@ public class ComponentsService extends BaseService { .setParam(PARAM_ORGANIZATION, request.getOrganization()) .setParam(PARAM_FILTER, request.getFilter()) .setParam(Param.FACETS, request.getFacets()) + .setParam(Param.SORT, request.getSort()) + .setParam(Param.ASCENDING, request.getAsc()) .setParam(Param.PAGE, request.getPage()) .setParam(Param.PAGE_SIZE, request.getPageSize()); return call(get, SearchProjectsWsResponse.parser()); diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java index 05c3604ea27..f6d9e359645 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java @@ -28,6 +28,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; public class SearchProjectsRequest { + public static final int MAX_PAGE_SIZE = 500; public static final int DEFAULT_PAGE_SIZE = 100; @@ -36,6 +37,8 @@ public class SearchProjectsRequest { private final String organization; private final String filter; private final List<String> facets; + private final String sort; + private final Boolean asc; private SearchProjectsRequest(Builder builder) { this.page = builder.page; @@ -43,6 +46,8 @@ public class SearchProjectsRequest { this.organization = builder.organization; this.filter = builder.filter; this.facets = builder.facets; + this.sort = builder.sort; + this.asc = builder.asc; } @CheckForNull @@ -59,6 +64,11 @@ public class SearchProjectsRequest { return facets; } + @CheckForNull + public String getSort() { + return sort; + } + public int getPageSize() { return pageSize; } @@ -67,6 +77,11 @@ public class SearchProjectsRequest { return page; } + @CheckForNull + public Boolean getAsc() { + return asc; + } + public static Builder builder() { return new Builder(); } @@ -77,6 +92,8 @@ public class SearchProjectsRequest { private Integer pageSize; private String filter; private List<String> facets = new ArrayList<>(); + private String sort; + private Boolean asc; private Builder() { // enforce static factory method @@ -107,6 +124,16 @@ public class SearchProjectsRequest { return this; } + public Builder setSort(@Nullable String sort) { + this.sort = sort; + return this; + } + + public Builder setAsc(boolean asc) { + this.asc = asc; + return this; + } + public SearchProjectsRequest build() { if (page == null) { page = 1; diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchWsRequest.java index 1dbed44fe92..7d7dcc05323 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchWsRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchWsRequest.java @@ -33,11 +33,12 @@ public class SearchWsRequest { private String query; private String language; + @CheckForNull public String getOrganization() { return organization; } - public SearchWsRequest setOrganization(String organization) { + public SearchWsRequest setOrganization(@Nullable String organization) { this.organization = organization; return this; } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java index a2a71f91459..2989b4f883a 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/ComponentsServiceTest.java @@ -21,12 +21,16 @@ package org.sonarqube.ws.client.component; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.server.ws.WebService.Param; import org.sonarqube.ws.client.ServiceTester; import org.sonarqube.ws.client.WsConnector; import static java.util.Collections.singletonList; import static org.mockito.Mockito.mock; +import static org.sonar.api.server.ws.WebService.Param.ASCENDING; +import static org.sonar.api.server.ws.WebService.Param.FACETS; +import static org.sonar.api.server.ws.WebService.Param.PAGE; +import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; +import static org.sonar.api.server.ws.WebService.Param.SORT; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER; public class ComponentsServiceTest { @@ -41,6 +45,8 @@ public class ComponentsServiceTest { underTest.searchProjects(SearchProjectsRequest.builder() .setFilter("ncloc > 10") .setFacets(singletonList("ncloc")) + .setSort("coverage") + .setAsc(true) .setPage(3) .setPageSize(10) .build()); @@ -48,9 +54,29 @@ public class ComponentsServiceTest { serviceTester.assertThat(serviceTester.getGetRequest()) .hasPath("search_projects") .hasParam(PARAM_FILTER, "ncloc > 10") - .hasParam(Param.FACETS, singletonList("ncloc")) - .hasParam(Param.PAGE, 3) - .hasParam(Param.PAGE_SIZE, 10) + .hasParam(FACETS, singletonList("ncloc")) + .hasParam(SORT, "coverage") + .hasParam(ASCENDING, true) + .hasParam(PAGE, 3) + .hasParam(PAGE_SIZE, 10) + .andNoOtherParam(); + } + + @Test + public void search_projects_without_sort() { + underTest.searchProjects(SearchProjectsRequest.builder() + .setFilter("ncloc > 10") + .setFacets(singletonList("ncloc")) + .setPage(3) + .setPageSize(10) + .build()); + + serviceTester.assertThat(serviceTester.getGetRequest()) + .hasPath("search_projects") + .hasParam(PARAM_FILTER, "ncloc > 10") + .hasParam(FACETS, singletonList("ncloc")) + .hasParam(PAGE, 3) + .hasParam(PAGE_SIZE, 10) .andNoOtherParam(); } |