diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-12 11:15:00 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-17 13:40:59 +0100 |
commit | 614a6496873c9b8f2149c4ee17a3e738cea1f470 (patch) | |
tree | 0f6062ec14dcc731eb5ea1cc29a9893ceb48c0b6 /sonar-ws | |
parent | a5426fe36e91f6647c0dda681962299d5d6fb950 (diff) | |
download | sonarqube-614a6496873c9b8f2149c4ee17a3e738cea1f470.tar.gz sonarqube-614a6496873c9b8f2149c4ee17a3e738cea1f470.zip |
SONAR-6947 Create and use AddUserWsRequest
Diffstat (limited to 'sonar-ws')
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddUserWsRequest.java | 71 | ||||
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsClient.java | 9 |
2 files changed, 80 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddUserWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddUserWsRequest.java new file mode 100644 index 00000000000..d56d4dd063b --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddUserWsRequest.java @@ -0,0 +1,71 @@ +/* + * 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 AddUserWsRequest { + private String login; + private String permission; + private String projectId; + private String projectKey; + + public String getLogin() { + return login; + } + + public AddUserWsRequest setLogin(String login) { + this.login = requireNonNull(login, "login must not be null"); + return this; + } + + public String getPermission() { + return permission; + } + + public AddUserWsRequest setPermission(String permission) { + this.permission = requireNonNull(permission, "permission must not be null"); + return this; + } + + @CheckForNull + public String getProjectId() { + return projectId; + } + + public AddUserWsRequest setProjectId(@Nullable String projectId) { + this.projectId = projectId; + return this; + } + + @CheckForNull + public String getProjectKey() { + return projectKey; + } + + public AddUserWsRequest setProjectKey(@Nullable String projectKey) { + this.projectKey = projectKey; + 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 ba152378b6b..ba153a26e3d 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 @@ -32,6 +32,7 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_P import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME; import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_UUID; +import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_USER_LOGIN; public class PermissionsWsClient { private final WsClient wsClient; @@ -70,6 +71,14 @@ public class PermissionsWsClient { .setParam(PARAM_TEMPLATE_NAME, request.getTemplateName())); } + public void addUser(AddUserWsRequest request) { + wsClient.execute(newPostRequest(action("add_user")) + .setParam(PARAM_USER_LOGIN, request.getLogin()) + .setParam(PARAM_PERMISSION, request.getPermission()) + .setParam(PARAM_PROJECT_ID, request.getProjectId()) + .setParam(PARAM_PROJECT_KEY, request.getProjectKey())); + } + private static String action(String action) { return PermissionsWsParameters.ENDPOINT + "/" + action; } |