com.wallee.sdk.service.WebAppService 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.WebAppConfirmationRequest;
import com.wallee.sdk.model.WebAppConfirmationResponse;
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 WebAppService {
private ApiClient apiClient;
public WebAppService(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* Check Installation
* This operation returns true when the app is installed in given space. The web app is implied by the client ID resp. user ID that is been used to invoke this operation.
* 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 spaceId This parameter identifies the space which should be checked if the web app is installed.
* @return Boolean
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Check Installation Documentation
**/
public Boolean checkInstallation(Long spaceId) throws IOException {
HttpResponse response = checkInstallationForHttpResponse(spaceId);
String returnType = "Boolean";
if(returnType.equals("String")){
return (Boolean) (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 (Boolean)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
/**
* Check Installation
* This operation returns true when the app is installed in given space. The web app is implied by the client ID resp. user ID that is been used to invoke this operation.
* 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 spaceId This parameter identifies the space which should be checked if the web app is installed.
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return Boolean
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Check Installation Documentation
**/
public Boolean checkInstallation(Long spaceId, Map params) throws IOException {
HttpResponse response = checkInstallationForHttpResponse(spaceId, params);
String returnType = "Boolean";
if(returnType.equals("String")){
return (Boolean) (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 (Boolean)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
public HttpResponse checkInstallationForHttpResponse(Long spaceId) throws IOException {
// verify the required parameter 'spaceId' is set
if (spaceId == null) {
throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling checkInstallation");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/web-app/check-installation");
if (spaceId != null) {
String key = "spaceId";
Object value = spaceId;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = null;
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse checkInstallationForHttpResponse(Long spaceId, Map params) throws IOException {
// verify the required parameter 'spaceId' is set
if (spaceId == null) {
throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling checkInstallation");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/web-app/check-installation");
// 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 '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 = null;
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
/**
* Confirm
* This operation confirms the app installation. This method has to be invoked after the user returns to the web app. The request of the user will contain the code as a request parameter. The web app is implied by the client ID resp. user ID that is been used to invoke this operation.
* 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 request
* @return WebAppConfirmationResponse
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Confirm Documentation
**/
public WebAppConfirmationResponse confirm(WebAppConfirmationRequest request) throws IOException {
HttpResponse response = confirmForHttpResponse(request);
String returnType = "WebAppConfirmationResponse";
if(returnType.equals("String")){
return (WebAppConfirmationResponse) (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 (WebAppConfirmationResponse)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
/**
* Confirm
* This operation confirms the app installation. This method has to be invoked after the user returns to the web app. The request of the user will contain the code as a request parameter. The web app is implied by the client ID resp. user ID that is been used to invoke this operation.
* 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 request
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return WebAppConfirmationResponse
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Confirm Documentation
**/
public WebAppConfirmationResponse confirm(WebAppConfirmationRequest request, Map params) throws IOException {
HttpResponse response = confirmForHttpResponse(request, params);
String returnType = "WebAppConfirmationResponse";
if(returnType.equals("String")){
return (WebAppConfirmationResponse) (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 (WebAppConfirmationResponse)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
public HttpResponse confirmForHttpResponse(WebAppConfirmationRequest request) throws IOException {
// verify the required parameter 'request' is set
if (request == null) {
throw new IllegalArgumentException("Missing the required parameter 'request' when calling confirm");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/web-app/confirm");
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = apiClient.new JacksonJsonHttpContent(request);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse confirmForHttpResponse(java.io.InputStream request, String mediaType) throws IOException {
// verify the required parameter 'request' is set
if (request == null) {
throw new IllegalArgumentException("Missing the required parameter 'request' when calling confirm");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/web-app/confirm");
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = request == null ?
apiClient.new JacksonJsonHttpContent(null) :
new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, request);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse confirmForHttpResponse(WebAppConfirmationRequest request, Map params) throws IOException {
// verify the required parameter 'request' is set
if (request == null) {
throw new IllegalArgumentException("Missing the required parameter 'request' when calling confirm");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/web-app/confirm");
// Copy the params argument if present, to allow passing in immutable maps
Map allParams = params == null ? new HashMap() : new HashMap(params);
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(request);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
/**
* Uninstall
* This operation uninstalls the web app from the provided space. The web app is implied by the client ID resp. user ID that is been used to invoke this operation.
* 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 spaceId This parameter identifies the space within which the web app should be uninstalled.
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Uninstall Documentation
**/
public void uninstall(Long spaceId) throws IOException {
uninstallForHttpResponse(spaceId);
}
/**
* Uninstall
* This operation uninstalls the web app from the provided space. The web app is implied by the client ID resp. user ID that is been used to invoke this operation.
*
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 spaceId This parameter identifies the space within which the web app should be uninstalled.
* @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 Uninstall Documentation
**/
public void uninstall(Long spaceId, Map params) throws IOException {
uninstallForHttpResponse(spaceId, params);
}
public HttpResponse uninstallForHttpResponse(Long spaceId) throws IOException {
// verify the required parameter 'spaceId' is set
if (spaceId == null) {
throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling uninstall");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/web-app/uninstall");
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 uninstallForHttpResponse(Long spaceId, Map params) throws IOException {
// verify the required parameter 'spaceId' is set
if (spaceId == null) {
throw new IllegalArgumentException("Missing the required parameter 'spaceId' when calling uninstall");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/web-app/uninstall");
// 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 '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();
}
private boolean isNoBodyResponse(HttpResponse response) throws IOException {
java.io.InputStream content = response.getContent();
return content.available() == 0;
}
}