Commit 7009ee4d authored by zonia3000's avatar zonia3000
Browse files

Started gms client lib

parent 0479a621
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>it.inaf.ia2</groupId>
    <artifactId>gms-client-lib</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <spring.version>5.1.8.RELEASE</spring.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>
</project>
 No newline at end of file
+112 −0
Original line number Diff line number Diff line
package it.inaf.ia2.gms.client;

import it.inaf.ia2.gms.client.model.Group;
import it.inaf.ia2.gms.client.model.Member;
import it.inaf.ia2.gms.client.model.Permission;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

public class GmsClient {

    private static final String WS = "ws";

    private final String baseUrl;
    private final RestTemplate restTemplate;

    public GmsClient(String baseUrl, String clientId, String clientSecret) {
        this.baseUrl = baseUrl;
        restTemplate = new RestTemplate();
    }

    public Group createGroup(List<String> names) {

        String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
                .pathSegment(WS, "group")
                .toUriString();

        HttpEntity<List<String>> httpEntity = new HttpEntity<>(names);

        return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Group.class).getBody();
    }

    public void deleteGroupByPath(List<String> names) {

        String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
                .pathSegment(WS, "group")
                .queryParam("names", names)
                .toUriString();

        restTemplate.delete(url);
    }

    public Member addMember(List<String> names, String userId) {

        String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
                .pathSegment(WS, "member")
                .toUriString();

        Map<String, Object> params = new HashMap<>();
        params.put("names", names);
        params.put("userId", userId);
        HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(params);

        return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Member.class).getBody();
    }

    public void removeMember(List<String> names, String userId) {

        String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
                .pathSegment(WS, "member")
                .queryParam("names", names)
                .queryParam("userId", userId)
                .toUriString();

        restTemplate.delete(url);
    }

    public Permission addPermission(List<String> names, String userId, String permission) {

        String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
                .pathSegment(WS, "permission")
                .toUriString();

        Map<String, Object> params = new HashMap<>();
        params.put("names", names);
        params.put("userId", userId);
        params.put("permission", permission);
        HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(params);

        return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Permission.class).getBody();
    }

    public void deletePermission(List<String> names, String userId, String permission) {

        String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
                .pathSegment(WS, "permission")
                .queryParam("names", names)
                .queryParam("userId", userId)
                .queryParam("permission", permission)
                .toUriString();

        restTemplate.delete(url);
    }

    public void prepareToJoin(String fromUserId, String toUserId) {

        String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
                .pathSegment(WS, "prepare-join")
                .toUriString();

        Map<String, Object> params = new HashMap<>();
        params.put("fromUserId", fromUserId);
        params.put("toUserId", toUserId);
        HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(params);

        restTemplate.exchange(url, HttpMethod.POST, httpEntity, Void.class);
    }
}
+41 −0
Original line number Diff line number Diff line
package it.inaf.ia2.gms.client.model;

public class Group {

    private String id;
    private String name;
    private String path;
    private String parentPath;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getParentPath() {
        return parentPath;
    }

    public void setParentPath(String parentPath) {
        this.parentPath = parentPath;
    }
}
+23 −0
Original line number Diff line number Diff line
package it.inaf.ia2.gms.client.model;

public class Member {

    private String groupId;
    private String userId;

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }
}
+32 −0
Original line number Diff line number Diff line
package it.inaf.ia2.gms.client.model;

public class Permission {

    private String groupId;
    private String userId;
    private String permission;

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }
}
Loading