diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-21 16:01:54 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-22 15:25:13 +0100 |
commit | a3935607ecae26f8ede68d587fc4eec95c84a9c9 (patch) | |
tree | 3d6df53e8c505f5a904cec598b0af26f53795210 /sonar-ws | |
parent | 93372f657343da87415b1625cb15b4e90c6febe3 (diff) | |
download | sonarqube-a3935607ecae26f8ede68d587fc4eec95c84a9c9.tar.gz sonarqube-a3935607ecae26f8ede68d587fc4eec95c84a9c9.zip |
SONAR-8790 Add last analysis date on api/components/search_projects WS
Diffstat (limited to 'sonar-ws')
3 files changed, 19 insertions, 1 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 fd382d321a6..5a4817ddc1d 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 @@ -20,6 +20,7 @@ package org.sonarqube.ws.client.component; import com.google.common.base.Joiner; +import java.util.List; import org.sonarqube.ws.WsComponents.BulkUpdateKeyWsResponse; import org.sonarqube.ws.WsComponents.SearchProjectsWsResponse; import org.sonarqube.ws.WsComponents.SearchWsResponse; @@ -106,6 +107,7 @@ public class ComponentsService extends BaseService { } public SearchProjectsWsResponse searchProjects(SearchProjectsRequest request) { + List<String> additionalFields = request.getAdditionalFields(); GetRequest get = new GetRequest(path(ACTION_SEARCH_PROJECTS)) .setParam(PARAM_ORGANIZATION, request.getOrganization()) .setParam(PARAM_FILTER, request.getFilter()) @@ -113,7 +115,8 @@ public class ComponentsService extends BaseService { .setParam(Param.SORT, request.getSort()) .setParam(Param.ASCENDING, request.getAsc()) .setParam(Param.PAGE, request.getPage()) - .setParam(Param.PAGE_SIZE, request.getPageSize()); + .setParam(Param.PAGE_SIZE, request.getPageSize()) + .setParam(Param.FIELDS, !additionalFields.isEmpty() ? inlineMultipleParamValue(additionalFields) : null); 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 f6d9e359645..a2e249a866b 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 @@ -39,6 +39,7 @@ public class SearchProjectsRequest { private final List<String> facets; private final String sort; private final Boolean asc; + private final List<String> additionalFields; private SearchProjectsRequest(Builder builder) { this.page = builder.page; @@ -48,6 +49,7 @@ public class SearchProjectsRequest { this.facets = builder.facets; this.sort = builder.sort; this.asc = builder.asc; + this.additionalFields = builder.additionalFields; } @CheckForNull @@ -82,6 +84,10 @@ public class SearchProjectsRequest { return asc; } + public List<String> getAdditionalFields() { + return additionalFields; + } + public static Builder builder() { return new Builder(); } @@ -94,6 +100,7 @@ public class SearchProjectsRequest { private List<String> facets = new ArrayList<>(); private String sort; private Boolean asc; + private List<String> additionalFields = new ArrayList<>(); private Builder() { // enforce static factory method @@ -134,6 +141,11 @@ public class SearchProjectsRequest { return this; } + public Builder setAdditionalFields(List<String> additionalFields) { + this.additionalFields = requireNonNull(additionalFields, "additional fields cannot be null"); + return this; + } + public SearchProjectsRequest build() { if (page == null) { page = 1; 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 2989b4f883a..1096ae43486 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 @@ -28,6 +28,7 @@ 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.FIELDS; 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; @@ -49,6 +50,7 @@ public class ComponentsServiceTest { .setAsc(true) .setPage(3) .setPageSize(10) + .setAdditionalFields(singletonList("analysisDate")) .build()); serviceTester.assertThat(serviceTester.getGetRequest()) @@ -59,6 +61,7 @@ public class ComponentsServiceTest { .hasParam(ASCENDING, true) .hasParam(PAGE, 3) .hasParam(PAGE_SIZE, 10) + .hasParam(FIELDS, "analysisDate") .andNoOtherParam(); } |