diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-13 15:28:02 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-17 13:41:25 +0100 |
commit | 1de32aa4798f3246861214ec7f52bfc5f76fd0bb (patch) | |
tree | 514fa7bb8d40a072fdbd3457c97050e129ded59e /sonar-ws | |
parent | 47b324c49f2c7af5bee4fc9378214aa531a2b4c5 (diff) | |
download | sonarqube-1de32aa4798f3246861214ec7f52bfc5f76fd0bb.tar.gz sonarqube-1de32aa4798f3246861214ec7f52bfc5f76fd0bb.zip |
SONAR-6947 api/components/search use SearchWsRequest
Diffstat (limited to 'sonar-ws')
7 files changed, 162 insertions, 11 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsClient.java new file mode 100644 index 00000000000..1b081fe6ebe --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsClient.java @@ -0,0 +1,49 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonarqube.ws.client.component; + +import org.sonarqube.ws.WsComponents.SearchWsResponse; +import org.sonarqube.ws.client.WsClient; + +import static org.sonarqube.ws.client.WsRequest.newGetRequest; + +public class ComponentsWsClient { + private static final String ENDPOINT = "api/components/"; + private final WsClient wsClient; + + public ComponentsWsClient(WsClient wsClient) { + this.wsClient = wsClient; + } + + public SearchWsResponse search(SearchWsRequest request) { + return wsClient.execute( + newGetRequest(action("search")) + .setParam("qualifiers", request.getQualifiers()) + .setParam("p", request.getPage()) + .setParam("ps", request.getPageSize()) + .setParam("q", request.getQuery()), + SearchWsResponse.parser()); + } + + private static String action(String action) { + return ENDPOINT + action; + } +} 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 new file mode 100644 index 00000000000..f537c1d22ac --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchWsRequest.java @@ -0,0 +1,73 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonarqube.ws.client.component; + +import java.util.List; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +import static java.util.Objects.requireNonNull; + +public class SearchWsRequest { + private List<String> qualifiers; + private Integer page; + private Integer pageSize; + private String query; + + public List<String> getQualifiers() { + return qualifiers; + } + + public SearchWsRequest setQualifiers(List<String> qualifiers) { + this.qualifiers = requireNonNull(qualifiers); + return this; + } + + @CheckForNull + public Integer getPage() { + return page; + } + + public SearchWsRequest setPage(int page) { + this.page = page; + return this; + } + + @CheckForNull + public Integer getPageSize() { + return pageSize; + } + + public SearchWsRequest setPageSize(int pageSize) { + this.pageSize = pageSize; + return this; + } + + @CheckForNull + public String getQuery() { + return query; + } + + public SearchWsRequest setQuery(@Nullable String query) { + this.query = query; + return this; + } +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/package-info.java new file mode 100644 index 00000000000..aa64612df56 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/package-info.java @@ -0,0 +1,25 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +@ParametersAreNonnullByDefault +package org.sonarqube.ws.client.component; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsClient.java index 5eb82edcf1c..61a8dcd28c5 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsClient.java @@ -163,7 +163,7 @@ public class PermissionsWsClient { public SearchProjectPermissionsWsResponse searchProjectPermissions(SearchProjectPermissionsWsRequest request) { return wsClient.execute( - newGetRequest("search_project_permissions") + newGetRequest(action("search_project_permissions")) .setParam(PARAM_PROJECT_ID, request.getProjectId()) .setParam(PARAM_PROJECT_KEY, request.getProjectKey()) .setParam("p", request.getPage()) @@ -174,14 +174,14 @@ public class PermissionsWsClient { public SearchTemplatesWsResponse searchTemplates(SearchTemplatesWsRequest request) { return wsClient.execute( - newGetRequest("search_templates") + newGetRequest(action("search_templates")) .setParam("q", request.getQuery()), SearchTemplatesWsResponse.parser()); } public void setDefaultTemplate(SetDefaultTemplateWsRequest request) { wsClient.execute( - newPostRequest("set_default_template") + newPostRequest(action("set_default_template")) .setParam(PARAM_QUALIFIER, request.getQualifier()) .setParam(PARAM_TEMPLATE_ID, request.getTemplateId()) .setParam(PARAM_TEMPLATE_NAME, request.getTemplateName())); @@ -189,7 +189,7 @@ public class PermissionsWsClient { public UpdateTemplateWsResponse updateTemplate(UpdateTemplateWsRequest request) { return wsClient.execute( - newPostRequest("update_template") + newPostRequest(action("update_template")) .setParam(PARAM_DESCRIPTION, request.getDescription()) .setParam(PARAM_ID, request.getId()) .setParam(PARAM_NAME, request.getName()) @@ -199,7 +199,7 @@ public class PermissionsWsClient { public UsersWsResponse users(UsersWsRequest request) { return wsClient.execute( - newGetRequest("users") + newGetRequest(action("users")) .setParam(PARAM_PERMISSION, request.getPermission()) .setParam(PARAM_PROJECT_ID, request.getProjectId()) .setParam(PARAM_PROJECT_KEY, request.getProjectKey()) diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesWsClient.java index 2adb7528af2..dcbdec4951c 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesWsClient.java @@ -34,11 +34,15 @@ public class QualityProfilesWsClient { public SearchWsResponse search(SearchWsRequest request) { return wsClient.execute( - newGetRequest("search") + newGetRequest(action("search")) .setParam("defaults", request.getDefaults()) .setParam("language", request.getLanguage()) .setParam("profileName", request.getProfileName()) .setParam("projectKey", request.getProjectKey()), SearchWsResponse.parser()); } + + private static String action(String action) { + return "api/qualityprofiles/" + action; + } } diff --git a/sonar-ws/src/main/protobuf/ws-components.proto b/sonar-ws/src/main/protobuf/ws-components.proto index 5b7d68bb8ae..2f94e41f670 100644 --- a/sonar-ws/src/main/protobuf/ws-components.proto +++ b/sonar-ws/src/main/protobuf/ws-components.proto @@ -27,7 +27,7 @@ option java_outer_classname = "WsComponents"; option optimize_for = SPEED; // WS api/components/search -message WsSearchResponse { +message SearchWsResponse { message Component { optional string id = 1; optional string key = 2; diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/WsClientTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/WsClientTest.java index 3f2beff0d2c..a3bdf4967f6 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/WsClientTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/WsClientTest.java @@ -65,18 +65,18 @@ public class WsClientTest { @Test public void return_protobuf_response() throws Exception { server.doReturnBody( - WsComponents.WsSearchResponse + WsComponents.SearchWsResponse .newBuilder() - .addComponents(WsComponents.WsSearchResponse.Component.getDefaultInstance()) + .addComponents(WsComponents.SearchWsResponse.Component.getDefaultInstance()) .build() .toByteArray()); server.doReturnStatus(HTTP_OK); server.doReturnContentType(MediaTypes.PROTOBUF); - WsComponents.WsSearchResponse response = underTest.execute( + WsComponents.SearchWsResponse response = underTest.execute( newGetRequest("api/components/search") .setMediaType(WsRequest.MediaType.PROTOBUF), - WsComponents.WsSearchResponse.parser()); + WsComponents.SearchWsResponse.parser()); assertThat(response.getComponentsCount()).isEqualTo(1); assertThat(server.requestHeaders().get(HttpHeaders.ACCEPT)) |