com.wallee.sdk.service.AnalyticsQueryService Maven / Gradle / Ivy
Show all versions of wallee-java-sdk Show documentation
package com.wallee.sdk.service;
import static com.wallee.sdk.ErrorCode.*;
import com.wallee.sdk.ApiClient;
import com.wallee.sdk.ErrorCode;
import com.wallee.sdk.exception.WalleeSdkException;
import com.wallee.sdk.util.URIBuilderUtil;
import com.wallee.sdk.StringUtil;
import com.wallee.sdk.model.AnalyticsQuery;
import com.wallee.sdk.model.AnalyticsQueryExecution;
import com.wallee.sdk.model.AnalyticsQueryResultBatch;
import com.wallee.sdk.model.AnalyticsSchemaTable;
import com.wallee.sdk.model.ClientError;
import com.wallee.sdk.model.ServerError;
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;
import java.util.Objects;
public class AnalyticsQueryService {
private ApiClient apiClient;
public AnalyticsQueryService(ApiClient apiClient) {
this.apiClient = Objects.requireNonNull(apiClient, "ApiClient must be non null");
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = Objects.requireNonNull(apiClient, "ApiClient must be non null");
}
/**
* Cancel Execution
* Cancels the specified query execution.
* 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 the query execution to cancel.
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Cancel Execution Documentation
**/
public void cancelExecution(Long id) throws IOException {
cancelExecutionForHttpResponse(id);
}
/**
* Cancel Execution
* Cancels the specified query execution.
*
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 the query execution to cancel.
* @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 Cancel Execution Documentation
**/
public void cancelExecution(Long id, Map params) throws IOException {
cancelExecutionForHttpResponse(id, params);
}
public HttpResponse cancelExecutionForHttpResponse(Long id) throws IOException {
// verify the required parameter 'id' is set
if (id == null) {
throw new IllegalArgumentException("Missing the required parameter 'id' when calling cancelExecution");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/cancel-execution");
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 cancelExecutionForHttpResponse(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 cancelExecution");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/cancel-execution");
// 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();
}
/**
* Fetch Result
* Fetches one batch of the result of a query execution.
* 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 id The ID of the query execution for which to fetch the result.
* @param timeout The maximal time in seconds to wait for the result if it is not yet available. Use 0 (the default) to return immediately without waiting.
* @param maxRows The maximum number of rows to return per batch. (Between 1 and 999. The default is 999.)
* @param nextToken The next-token of the preceding batch to get the next result batch or null to get the first result batch.
* @return AnalyticsQueryResultBatch
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Fetch Result Documentation
**/
public AnalyticsQueryResultBatch fetchResult(Long id, Integer timeout, Integer maxRows, String nextToken) throws IOException {
HttpResponse response = fetchResultForHttpResponse(id, timeout, maxRows, nextToken);
String returnType = "AnalyticsQueryResultBatch";
if(returnType.equals("String")){
return (AnalyticsQueryResultBatch) (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 (AnalyticsQueryResultBatch)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
/**
* Fetch Result
* Fetches one batch of the result of a query execution.
* 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 id The ID of the query execution for which to fetch the result.
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return AnalyticsQueryResultBatch
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Fetch Result Documentation
**/
public AnalyticsQueryResultBatch fetchResult(Long id, Map params) throws IOException {
HttpResponse response = fetchResultForHttpResponse(id, params);
String returnType = "AnalyticsQueryResultBatch";
if(returnType.equals("String")){
return (AnalyticsQueryResultBatch) (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 (AnalyticsQueryResultBatch)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
public HttpResponse fetchResultForHttpResponse(Long id, Integer timeout, Integer maxRows, String nextToken) throws IOException {
// verify the required parameter 'id' is set
if (id == null) {
throw new IllegalArgumentException("Missing the required parameter 'id' when calling fetchResult");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/fetch-result");
if (id != null) {
String key = "id";
Object value = id;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
if (timeout != null) {
String key = "timeout";
Object value = timeout;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
if (maxRows != null) {
String key = "maxRows";
Object value = maxRows;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
if (nextToken != null) {
String key = "nextToken";
Object value = nextToken;
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);
httpRequest.getHeaders().setContentType("*/*");
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse fetchResultForHttpResponse(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 fetchResult");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/fetch-result");
// 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 = null;
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content);
httpRequest.getHeaders().setContentType("*/*");
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
/**
* Generate Download URL
* Generate a URL from which the results of a query execution can be downloaded in CSV format.
* 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 id The ID of the query execution for which to generate the download URL.
* @param timeout The maximal time in seconds to wait for the result if it is not yet available. Use 0 (the default) to return immediately without waiting.
* @return String
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Generate Download URL Documentation
**/
public String generateDownloadUrl(Long id, Integer timeout) throws IOException {
HttpResponse response = generateDownloadUrlForHttpResponse(id, timeout);
String returnType = "String";
if(returnType.equals("String")){
return (String) (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 (String)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
/**
* Generate Download URL
* Generate a URL from which the results of a query execution can be downloaded in CSV format.
* 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 id The ID of the query execution for which to generate the download URL.
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return String
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Generate Download URL Documentation
**/
public String generateDownloadUrl(Long id, Map params) throws IOException {
HttpResponse response = generateDownloadUrlForHttpResponse(id, params);
String returnType = "String";
if(returnType.equals("String")){
return (String) (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 (String)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
public HttpResponse generateDownloadUrlForHttpResponse(Long id, Integer timeout) throws IOException {
// verify the required parameter 'id' is set
if (id == null) {
throw new IllegalArgumentException("Missing the required parameter 'id' when calling generateDownloadUrl");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/generate-download-url");
if (id != null) {
String key = "id";
Object value = id;
uriBuilder = URIBuilderUtil.applyQueryParam(uriBuilder, key, value);
}
if (timeout != null) {
String key = "timeout";
Object value = timeout;
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);
httpRequest.getHeaders().setContentType("*/*");
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse generateDownloadUrlForHttpResponse(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 generateDownloadUrl");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/generate-download-url");
// 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 = null;
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content);
httpRequest.getHeaders().setContentType("*/*");
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
/**
* Get Schemas
* Get the schemas describing the available tables and their columns.
* 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.
* @return List<AnalyticsSchemaTable>
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Get Schemas Documentation
**/
public List schema() throws IOException {
HttpResponse response = schemaForHttpResponse();
String returnType = "List<AnalyticsSchemaTable>";
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);
}
/**
* Get Schemas
* Get the schemas describing the available tables and their columns.
* 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 params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return List<AnalyticsSchemaTable>
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Get Schemas Documentation
**/
public List schema(Map params) throws IOException {
HttpResponse response = schemaForHttpResponse(params);
String returnType = "List<AnalyticsSchemaTable>";
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 schemaForHttpResponse() throws IOException {
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/schema");
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = null;
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content);
httpRequest.getHeaders().setContentType("*/*");
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse schemaForHttpResponse(Map params) throws IOException {
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/schema");
// 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 = null;
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content);
httpRequest.getHeaders().setContentType("*/*");
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
/**
* Execution Status
* Returns the current status of a query execution.
* 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 id The ID of the query execution for which to get the status.
* @return AnalyticsQueryExecution
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Execution Status Documentation
**/
public AnalyticsQueryExecution status(Long id) throws IOException {
HttpResponse response = statusForHttpResponse(id);
String returnType = "AnalyticsQueryExecution";
if(returnType.equals("String")){
return (AnalyticsQueryExecution) (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 (AnalyticsQueryExecution)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
/**
* Execution Status
* Returns the current status of a query execution.
* 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 id The ID of the query execution for which to get the status.
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return AnalyticsQueryExecution
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Execution Status Documentation
**/
public AnalyticsQueryExecution status(Long id, Map params) throws IOException {
HttpResponse response = statusForHttpResponse(id, params);
String returnType = "AnalyticsQueryExecution";
if(returnType.equals("String")){
return (AnalyticsQueryExecution) (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 (AnalyticsQueryExecution)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
public HttpResponse statusForHttpResponse(Long id) throws IOException {
// verify the required parameter 'id' is set
if (id == null) {
throw new IllegalArgumentException("Missing the required parameter 'id' when calling status");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/status");
if (id != null) {
String key = "id";
Object value = id;
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);
httpRequest.getHeaders().setContentType("*/*");
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse statusForHttpResponse(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 status");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/status");
// 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 = null;
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content);
httpRequest.getHeaders().setContentType("*/*");
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
/**
* Submit Query
* Submits a query for execution.
* 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 query The query to submit.
* @return AnalyticsQueryExecution
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Submit Query Documentation
**/
public AnalyticsQueryExecution submitQuery(AnalyticsQuery query) throws IOException {
HttpResponse response = submitQueryForHttpResponse(query);
String returnType = "AnalyticsQueryExecution";
if(returnType.equals("String")){
return (AnalyticsQueryExecution) (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 (AnalyticsQueryExecution)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
/**
* Submit Query
* Submits a query for execution.
* 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 query The query to submit.
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return AnalyticsQueryExecution
* @throws IOException if an error occurs while attempting to invoke the API
* For more information visit this link.
* @see Submit Query Documentation
**/
public AnalyticsQueryExecution submitQuery(AnalyticsQuery query, Map params) throws IOException {
HttpResponse response = submitQueryForHttpResponse(query, params);
String returnType = "AnalyticsQueryExecution";
if(returnType.equals("String")){
return (AnalyticsQueryExecution) (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 (AnalyticsQueryExecution)apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}
public HttpResponse submitQueryForHttpResponse(AnalyticsQuery query) throws IOException {
// verify the required parameter 'query' is set
if (query == null) {
throw new IllegalArgumentException("Missing the required parameter 'query' when calling submitQuery");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/submit-query");
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = apiClient.new JacksonJsonHttpContent(query);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse submitQueryForHttpResponse(java.io.InputStream query, String mediaType) throws IOException {
// verify the required parameter 'query' is set
if (query == null) {
throw new IllegalArgumentException("Missing the required parameter 'query' when calling submitQuery");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/submit-query");
GenericUrl genericUrl = new GenericUrl(URIBuilderUtil.build(uriBuilder));
HttpContent content = query == null ?
apiClient.new JacksonJsonHttpContent(null) :
new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, query);
HttpRequest httpRequest = apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content);
int readTimeOut = apiClient.getReadTimeOut() * 1000;
httpRequest.setReadTimeout(readTimeOut);
return httpRequest.execute();
}
public HttpResponse submitQueryForHttpResponse(AnalyticsQuery query, Map params) throws IOException {
// verify the required parameter 'query' is set
if (query == null) {
throw new IllegalArgumentException("Missing the required parameter 'query' when calling submitQuery");
}
URIBuilder uriBuilder = URIBuilderUtil.create(apiClient.getBasePath() + "/analytics-query/submit-query");
// 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(query);
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;
}
}