diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-12 16:16:25 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-17 13:41:00 +0100 |
commit | f4d255703d5440c118ee8ab9e9b3f77b23771619 (patch) | |
tree | 311e41f4a03bd26ad7cccc9bb1fe4f36efedb8a0 /sonar-ws | |
parent | 31f6f53074997281db532ebc75bf5006929e9c6a (diff) | |
download | sonarqube-f4d255703d5440c118ee8ab9e9b3f77b23771619.tar.gz sonarqube-f4d255703d5440c118ee8ab9e9b3f77b23771619.zip |
SONAR-6947 Create and use CreateTemplateWsRequest
Diffstat (limited to 'sonar-ws')
5 files changed, 98 insertions, 2 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/CreateTemplateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/CreateTemplateWsRequest.java new file mode 100644 index 00000000000..08196d43254 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/CreateTemplateWsRequest.java @@ -0,0 +1,61 @@ +/* + * 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.permission; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +import static java.util.Objects.requireNonNull; + +public class CreateTemplateWsRequest { + private String description; + private String name; + private String projectKeyPattern; + + @CheckForNull + public String getDescription() { + return description; + } + + public CreateTemplateWsRequest setDescription(@Nullable String description) { + this.description = description; + return this; + } + + public String getName() { + return name; + } + + public CreateTemplateWsRequest setName(String name) { + this.name = requireNonNull(name); + return this; + } + + @CheckForNull + public String getProjectKeyPattern() { + return projectKeyPattern; + } + + public CreateTemplateWsRequest setProjectKeyPattern(@Nullable String projectKeyPattern) { + this.projectKeyPattern = projectKeyPattern; + return this; + } +} 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 40da04c5800..8f48106fe8e 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 @@ -21,15 +21,19 @@ package org.sonarqube.ws.client.permission; import org.sonarqube.ws.WsPermissions; +import org.sonarqube.ws.WsPermissions.CreateTemplateWsResponse; import org.sonarqube.ws.client.WsClient; import static org.sonarqube.ws.client.WsRequest.newGetRequest; import static org.sonarqube.ws.client.WsRequest.newPostRequest; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_DESCRIPTION; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_NAME; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY_PATTERN; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_USER_LOGIN; @@ -95,6 +99,15 @@ public class PermissionsWsClient { .setParam(PARAM_TEMPLATE_NAME, request.getTemplateName())); } + public CreateTemplateWsResponse createTemplate(CreateTemplateWsRequest request) { + return wsClient.execute(newPostRequest( + action("create_template")) + .setParam(PARAM_NAME, request.getName()) + .setParam(PARAM_DESCRIPTION, request.getDescription()) + .setParam(PARAM_PROJECT_KEY_PATTERN, request.getProjectKeyPattern()), + CreateTemplateWsResponse.parser()); + } + private static String action(String action) { return PermissionsWsParameters.ENDPOINT + "/" + action; } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsParameters.java index 8c9079f674f..c2821a26970 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsParameters.java @@ -34,6 +34,6 @@ public class PermissionsWsParameters { public static final String PARAM_ID = "id"; public static final String PARAM_NAME = "name"; public static final String PARAM_DESCRIPTION = "description"; - public static final String PARAM_PATTERN = "projectKeyPattern"; + public static final String PARAM_PROJECT_KEY_PATTERN = "projectKeyPattern"; public static final String PARAM_QUALIFIER = "qualifier"; } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/package-info.java new file mode 100644 index 00000000000..d35aaa82415 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonarqube.ws.client.permission; diff --git a/sonar-ws/src/main/protobuf/ws-permissions.proto b/sonar-ws/src/main/protobuf/ws-permissions.proto index 043fe71a19b..7ca6e7417ce 100644 --- a/sonar-ws/src/main/protobuf/ws-permissions.proto +++ b/sonar-ws/src/main/protobuf/ws-permissions.proto @@ -58,7 +58,7 @@ message WsSearchProjectPermissionsResponse { repeated Permission permissions = 3; } -message WsCreatePermissionTemplateResponse { +message CreateTemplateWsResponse { optional PermissionTemplate permissionTemplate = 1; } |