com.wallee.sdk.service.UserSpaceRoleService Maven / Gradle / Ivy
Show all versions of wallee-java-sdk Show documentation
package com.wallee.sdk.service;
import com.wallee.sdk.ApiClient;
import com.wallee.sdk.ErrorCode;
import com.wallee.sdk.WalleeSdkException;
import com.wallee.sdk.URIBuilderUtil;
import com.wallee.sdk.model.ClientError;
import com.wallee.sdk.model.ServerError;
import com.wallee.sdk.model.UserSpaceRole;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.http.*;
import com.google.api.client.json.Json;
import org.apache.http.client.utils.URIBuilder;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
public class UserSpaceRoleService {
private ApiClient apiClient;
public UserSpaceRoleService(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* Add Role
* This operation grants the given role to the user in the given space.
* 200 - This status code indicates that a client request was successfully received, understood, and accepted.
*
442 - This status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error.
*
542 - This status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the client request.
* @param userId The id of the user to whom the role is assigned.
* @param spaceId The space to which the role is mapped.
* @param roleId The role which is mapped to the user and space.
* @return UserSpaceRole
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Add Role Documentation
**/
public UserSpaceRole addRole(Long userId, Long spaceId, Long roleId) throws IOException {
HttpResponse response = addRoleForHttpResponse(userId, spaceId, roleId);
String returnType = "UserSpaceRole";
if(returnType.equals("String")){
return (UserSpaceRole) (Object) response.parseAsString();
}
TypeReference typeRef = new TypeReference() {};
if (isNoBodyResponse(response)) {
throw new WalleeSdkException(ErrorCode.ENTITY_NOT_FOUND, "Entity was not found for: " + typeRef.getType().getTypeName());
}
return (UserSpaceRole)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
/**
* Add Role
* This operation grants the given role to the user in the given space.
* 200 - This status code indicates that a client request was successfully received, understood, and accepted.
*
442 - This status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error.
*
542 - This status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the client request.
* @param userId The id of the user to whom the role is assigned.
* @param spaceId The space to which the role is mapped.
* @param roleId The role which is mapped to the user and space.
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return UserSpaceRole
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Add Role Documentation
**/
public UserSpaceRole addRole(Long userId, Long spaceId, Long roleId, Map params) throws IOException {
HttpResponse response = addRoleForHttpResponse(userId, spaceId, roleId, params);
String returnType = "UserSpaceRole";
if(returnType.equals("String")){
return (UserSpaceRole) (Object) response.parseAsString();
}
TypeReference typeRef = new TypeReference() {};
if (isNoBodyResponse(response)) {
throw new WalleeSdkException(ErrorCode.ENTITY_NOT_FOUND, "Entity was not found for: " + typeRef.getType().getTypeName());
}
return (UserSpaceRole)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
public HttpResponse addRoleForHttpResponse(Long userId, Long spaceId, Long roleId) throws IOException {
// verify the required parameter 'userId' is set
if (userId == null) {
throw new IllegalArgumentException("Missing the required parameter 'userId' when calling addRole");
}
// verify the required parameter 'spaceId' is set
if (spaceId == null) {
throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling addRole");
}
// verify the required parameter 'roleId' is set
if (roleId == null) {
throw new IllegalArgumentException("Missing the required parameter 'roleId' when calling addRole");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/user-space-role/addRole");
if (userId != null) {
String key = "userId";
Object value = userId;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
if (spaceId != null) {
String key = "spaceId";
Object value = spaceId;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
if (roleId != null) {
String key = "roleId";
Object value = roleId;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse addRoleForHttpResponse(Long userId, Long spaceId, Long roleId, Map params) throws IOException {
// verify the required parameter 'userId' is set
if (userId == null) {
throw new IllegalArgumentException("Missing the required parameter 'userId' when calling addRole");
}
// verify the required parameter 'spaceId' is set
if (spaceId == null) {
throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling addRole");
}
// verify the required parameter 'roleId' is set
if (roleId == null) {
throw new IllegalArgumentException("Missing the required parameter 'roleId' when calling addRole");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/user-space-role/addRole");
// Copy the params argument if present, to allow passing in immutable maps
Map allParams = params == null ? new HashMap() : new HashMap(params);
// Add the required query param 'userId' to the map of query params
allParams.put("userId", userId);
// Add the required query param 'spaceId' to the map of query params
allParams.put("spaceId", spaceId);
// Add the required query param 'roleId' to the map of query params
allParams.put("roleId", roleId);
for (Map.Entry entryMap: allParams.entrySet()) {
String key = entryMap.getKey();
Object value = entryMap.getValue();
if (key != null && value != null) {
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
}
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
/**
* List Roles
* List all the roles that are assigned to the given user in the given space.
* 200 - This status code indicates that a client request was successfully received, understood, and accepted.
*
409 - This status code indicates that there was a conflict with the current version of the data in the database and the provided data in the request.
*
442 - This status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error.
*
542 - This status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the client request.
* @param userId The id of the user to whom the role is assigned.
* @param spaceId The space to which the role is mapped.
* @return List<UserSpaceRole>
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see List Roles Documentation
**/
public List list(Long userId, Long spaceId) throws IOException {
HttpResponse response = listForHttpResponse(userId, spaceId);
String returnType = "List<UserSpaceRole>";
if(returnType.equals("String")){
return (List) (Object) response.parseAsString();
}
TypeReference typeRef = new TypeReference>() {};
if (isNoBodyResponse(response)) {
throw new WalleeSdkException(ErrorCode.ENTITY_NOT_FOUND, "Entity was not found for: " + typeRef.getType().getTypeName());
}
return (List)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
/**
* List Roles
* List all the roles that are assigned to the given user in the given space.
* 200 - This status code indicates that a client request was successfully received, understood, and accepted.
*
409 - This status code indicates that there was a conflict with the current version of the data in the database and the provided data in the request.
*
442 - This status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error.
*
542 - This status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the client request.
* @param userId The id of the user to whom the role is assigned.
* @param spaceId The space to which the role is mapped.
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return List<UserSpaceRole>
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see List Roles Documentation
**/
public List list(Long userId, Long spaceId, Map params) throws IOException {
HttpResponse response = listForHttpResponse(userId, spaceId, params);
String returnType = "List<UserSpaceRole>";
if(returnType.equals("String")){
return (List) (Object) response.parseAsString();
}
TypeReference typeRef = new TypeReference>() {};
if (isNoBodyResponse(response)) {
throw new WalleeSdkException(ErrorCode.ENTITY_NOT_FOUND, "Entity was not found for: " + typeRef.getType().getTypeName());
}
return (List)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
public HttpResponse listForHttpResponse(Long userId, Long spaceId) throws IOException {
// verify the required parameter 'userId' is set
if (userId == null) {
throw new IllegalArgumentException("Missing the required parameter 'userId' when calling list");
}
// verify the required parameter 'spaceId' is set
if (spaceId == null) {
throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling list");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/user-space-role/list");
if (userId != null) {
String key = "userId";
Object value = userId;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
if (spaceId != null) {
String key = "spaceId";
Object value = spaceId;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse listForHttpResponse(Long userId, Long spaceId, Map params) throws IOException {
// verify the required parameter 'userId' is set
if (userId == null) {
throw new IllegalArgumentException("Missing the required parameter 'userId' when calling list");
}
// verify the required parameter 'spaceId' is set
if (spaceId == null) {
throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling list");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/user-space-role/list");
// Copy the params argument if present, to allow passing in immutable maps
Map allParams = params == null ? new HashMap() : new HashMap(params);
// Add the required query param 'userId' to the map of query params
allParams.put("userId", userId);
// Add the required query param 'spaceId' to the map of query params
allParams.put("spaceId", spaceId);
for (Map.Entry entryMap: allParams.entrySet()) {
String key = entryMap.getKey();
Object value = entryMap.getValue();
if (key != null && value != null) {
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
}
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
/**
* Remove Role
* This operation removes the specified user space role.
* 442 - This status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error.
*
542 - This status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the client request.
* @param id The id of user space role which should be removed
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Remove Role Documentation
**/
public void removeRole(Long id) throws IOException {
removeRoleForHttpResponse(id);
}
/**
* Remove Role
* This operation removes the specified user space role.
*
442 - This status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error.
*
542 - This status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the client request.
* @param id The id of user space role which should be removed
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Remove Role Documentation
**/
public void removeRole(Long id, Map params) throws IOException {
removeRoleForHttpResponse(id, params);
}
public HttpResponse removeRoleForHttpResponse(Long id) throws IOException {
// verify the required parameter 'id' is set
if (id == null) {
throw new IllegalArgumentException("Missing the required parameter 'id' when calling removeRole");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/user-space-role/removeRole");
if (id != null) {
String key = "id";
Object value = id;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse removeRoleForHttpResponse(Long id, Map params) throws IOException {
// verify the required parameter 'id' is set
if (id == null) {
throw new IllegalArgumentException("Missing the required parameter 'id' when calling removeRole");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/user-space-role/removeRole");
// Copy the params argument if present, to allow passing in immutable maps
Map allParams = params == null ? new HashMap() : new HashMap(params);
// Add the required query param 'id' to the map of query params
allParams.put("id", id);
for (Map.Entry entryMap: allParams.entrySet()) {
String key = entryMap.getKey();
Object value = entryMap.getValue();
if (key != null && value != null) {
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
}
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = apiClient.new JacksonJsonHttpContent(null);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
private boolean isNoBodyResponse(HttpResponse response) throws IOException {
java.io.InputStream content = response.getContent();
return content.available() == 0;
}
}