aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-12 11:20:43 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-17 13:40:59 +0100
commit3c3d60d4e50ce70d7038bf1d2a71e98effc3d458 (patch)
treed8d9359140407fbeb553dd3c658c64c4fe12c92d
parent614a6496873c9b8f2149c4ee17a3e738cea1f470 (diff)
downloadsonarqube-3c3d60d4e50ce70d7038bf1d2a71e98effc3d458.tar.gz
sonarqube-3c3d60d4e50ce70d7038bf1d2a71e98effc3d458.zip
SONAR-6947 Improve XXXWsRequest contracts
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java15
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupToTemplateWsRequest.java4
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupWsRequest.java10
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java8
4 files changed, 22 insertions, 15 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java
index 6642c58839e..bdd8563b258 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java
@@ -29,17 +29,17 @@ import org.sonar.server.permission.PermissionChange;
import org.sonar.server.permission.PermissionUpdater;
import org.sonarqube.ws.client.permission.AddGroupWsRequest;
-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_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.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupIdParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupNameParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameter;
import static org.sonar.server.permission.ws.WsProjectRef.newOptionalWsProjectRef;
import static org.sonar.server.usergroups.ws.WsGroupRef.newWsGroupRef;
+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_PERMISSION;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
public class AddGroupAction implements PermissionsWsAction {
@@ -83,11 +83,12 @@ public class AddGroupAction implements PermissionsWsAction {
private void doHandle(AddGroupWsRequest request) throws Exception {
DbSession dbSession = dbClient.openSession(false);
try {
+ Long groupId = request.getGroupId() == null ? null : Long.valueOf(request.getGroupId());
PermissionChange permissionChange = permissionChangeBuilder.buildGroupPermissionChange(
dbSession,
request.getPermission(),
newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey()),
- newWsGroupRef(request.getGroupId(), request.getGroupName()));
+ newWsGroupRef(groupId, request.getGroupName()));
permissionUpdater.addPermission(permissionChange);
} finally {
dbClient.closeSession(dbSession);
@@ -97,7 +98,7 @@ public class AddGroupAction implements PermissionsWsAction {
private static AddGroupWsRequest toAddGroupWsRequest(Request request) {
return new AddGroupWsRequest()
.setPermission(request.mandatoryParam(PARAM_PERMISSION))
- .setGroupId(request.paramAsLong(PARAM_GROUP_ID))
+ .setGroupId(request.param(PARAM_GROUP_ID))
.setGroupName(request.param(PARAM_GROUP_NAME))
.setProjectId(request.param(PARAM_PROJECT_ID))
.setProjectKey(request.param(PARAM_PROJECT_KEY));
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupToTemplateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupToTemplateWsRequest.java
index 2fff2a6928f..3cd273d0903 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupToTemplateWsRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupToTemplateWsRequest.java
@@ -23,6 +23,8 @@ package org.sonarqube.ws.client.permission;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import static java.util.Objects.requireNonNull;
+
public class AddGroupToTemplateWsRequest {
private String groupId;
private String groupName;
@@ -55,7 +57,7 @@ public class AddGroupToTemplateWsRequest {
}
public AddGroupToTemplateWsRequest setPermission(String permission) {
- this.permission = permission;
+ this.permission = requireNonNull(permission, "permission must not be null");
return this;
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupWsRequest.java
index 975580862fb..8a7ddbd00e2 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupWsRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddGroupWsRequest.java
@@ -23,9 +23,11 @@ package org.sonarqube.ws.client.permission;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import static java.util.Objects.requireNonNull;
+
public class AddGroupWsRequest {
private String permission;
- private Long groupId;
+ private String groupId;
private String groupName;
private String projectId;
private String projectKey;
@@ -35,16 +37,16 @@ public class AddGroupWsRequest {
}
public AddGroupWsRequest setPermission(String permission) {
- this.permission = permission;
+ this.permission = requireNonNull(permission, "permission must not be null");
return this;
}
@CheckForNull
- public Long getGroupId() {
+ public String getGroupId() {
return groupId;
}
- public AddGroupWsRequest setGroupId(@Nullable Long groupId) {
+ public AddGroupWsRequest setGroupId(@Nullable String groupId) {
this.groupId = groupId;
return this;
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java
index 535ed11ce37..35690aaf80e 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java
@@ -22,6 +22,8 @@ package org.sonarqube.ws.client.permission;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import static java.util.Objects.requireNonNull;
+
public class GroupsWsRequest {
private String permission;
private String projectId;
@@ -36,7 +38,7 @@ public class GroupsWsRequest {
}
public GroupsWsRequest setPermission(String permission) {
- this.permission = permission;
+ this.permission = requireNonNull(permission, "permission must not be null");
return this;
}
@@ -45,7 +47,7 @@ public class GroupsWsRequest {
return projectId;
}
- public GroupsWsRequest setProjectId(String projectId) {
+ public GroupsWsRequest setProjectId(@Nullable String projectId) {
this.projectId = projectId;
return this;
}
@@ -93,7 +95,7 @@ public class GroupsWsRequest {
}
public GroupsWsRequest setSelected(String selected) {
- this.selected = selected;
+ this.selected = requireNonNull(selected, "selected must not be null");
return this;
}
}