Commit cf908b5b authored by Sonia Zorba's avatar Sonia Zorba
Browse files

GMS client bugfix

parent 640aca6c
base_url=http://localhost:8081
base_url=http://localhost:8081/gms
client_id=test
client_secret=test
......@@ -69,28 +69,28 @@ public class CLI implements CommandLineRunner {
if (args.length < 3) {
displayUsage();
}
client.addMember(getNames(args, args.length - 2), args[args.length - 1]);
client.addMember(getNames(args, 1, args.length - 2), args[args.length - 1]);
System.out.println("Member added");
break;
case "remove-member":
if (args.length < 3) {
displayUsage();
}
client.removeMember(getNames(args, args.length - 2), args[args.length - 1]);
client.removeMember(getNames(args, 1, args.length - 2), args[args.length - 1]);
System.out.println("Member removed");
break;
case "add-permission":
if (args.length < 4) {
displayUsage();
}
client.addPermission(getNames(args, args.length - 3), args[args.length - 2], args[args.length - 1]);
client.addPermission(getNames(args, 1, args.length - 3), args[args.length - 2], args[args.length - 1]);
System.out.println("Permission added");
break;
case "delete-permission":
if (args.length < 4) {
displayUsage();
}
client.removePermission(getNames(args, args.length - 2), args[args.length - 1]);
client.removePermission(getNames(args, 1, args.length - 2), args[args.length - 1]);
System.out.println("Permission removed");
break;
case "prepare-join":
......@@ -108,12 +108,12 @@ public class CLI implements CommandLineRunner {
private void displayUsage() {
System.out.println("java -jar gms-client.jar\n"
+ " add-group <name1 name2 name3>\n"
+ " remove-group <name1 name2 name3>\n"
+ " create-group <name1 name2 name3>\n"
+ " delete-group <name1 name2 name3>\n"
+ " add-member <name1 name2 name3> <user_id>\n"
+ " remove-member <name1 name2 name3> <user_id>\n"
+ " add-permission <name1 name2 name3> <user_id> <permission>\n"
+ " remove-permission <name1 name2 name3> <user_id>\n"
+ " delete-permission <name1 name2 name3> <user_id>\n"
+ " prepare-join <from_user_id> <to_user_id>");
System.exit(0);
}
......
......@@ -16,13 +16,17 @@ import org.springframework.web.util.UriComponentsBuilder;
public class GmsClient {
private static final String WS = "ws";
private final String baseUrl;
private final String authHeader;
private RestTemplate restTemplate;
public GmsClient(String baseUrl, String clientId, String clientSecret) {
if (!baseUrl.endsWith("/")) {
baseUrl += "/";
}
baseUrl += "ws/basic";
this.baseUrl = baseUrl;
String auth = clientId + ":" + clientSecret;
......@@ -43,7 +47,7 @@ public class GmsClient {
public Group addGroup(List<String> names) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "group")
.pathSegment("group")
.toUriString();
HttpEntity<List<String>> httpEntity = getEntity(names);
......@@ -54,7 +58,7 @@ public class GmsClient {
public void removeGroup(List<String> names) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "group")
.pathSegment("group")
.queryParam("names", names.toArray())
.toUriString();
......@@ -64,7 +68,7 @@ public class GmsClient {
public Member addMember(List<String> names, String userId) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "member")
.pathSegment("member")
.toUriString();
Map<String, Object> params = new HashMap<>();
......@@ -78,7 +82,7 @@ public class GmsClient {
public void removeMember(List<String> names, String userId) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "member")
.pathSegment("member")
.queryParam("names", names.toArray())
.queryParam("userId", userId)
.toUriString();
......@@ -89,7 +93,7 @@ public class GmsClient {
public Permission addPermission(List<String> names, String userId, String permission) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "permission")
.pathSegment("permission")
.toUriString();
Map<String, Object> params = new HashMap<>();
......@@ -104,7 +108,7 @@ public class GmsClient {
public void removePermission(List<String> names, String userId) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "permission")
.pathSegment("permission")
.queryParam("names", names.toArray())
.queryParam("userId", userId)
.toUriString();
......@@ -115,7 +119,7 @@ public class GmsClient {
public void prepareToJoin(String fromUserId, String toUserId) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "prepare-join")
.pathSegment("prepare-join")
.toUriString();
Map<String, Object> params = new HashMap<>();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment