Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
localhost.controllers.AdminController Maven / Gradle / Ivy
/*
* RESTAPISDKLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
package localhost.controllers;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import localhost.ApiHelper;
import localhost.AuthManager;
import localhost.Configuration;
import localhost.exceptions.ApiException;
import localhost.exceptions.ErrorResponseException;
import localhost.http.Headers;
import localhost.http.client.HttpCallback;
import localhost.http.client.HttpClient;
import localhost.http.client.HttpContext;
import localhost.http.request.HttpRequest;
import localhost.http.response.HttpResponse;
import localhost.http.response.HttpStringResponse;
import localhost.models.AdminsyncPrincipalResponse;
import localhost.models.TspublicRestV2AdminChangeownerRequest;
import localhost.models.TspublicRestV2AdminConfigurationUpdateRequest;
import localhost.models.TspublicRestV2AdminResetpasswordRequest;
import localhost.models.TspublicRestV2AdminSyncprincipalRequest;
/**
* This class lists all the endpoints of the groups.
*/
public final class AdminController extends BaseController {
/**
* Initializes the controller.
* @param config Configurations added in client.
* @param httpClient Send HTTP requests and read the responses.
* @param authManagers Apply authorization to requests.
*/
public AdminController(Configuration config, HttpClient httpClient,
Map authManagers) {
super(config, httpClient, authManagers);
}
/**
* Initializes the controller with HTTPCallback.
* @param config Configurations added in client.
* @param httpClient Send HTTP requests and read the responses.
* @param authManagers Apply authorization to requests.
* @param httpCallback Callback to be called before and after the HTTP call.
*/
public AdminController(Configuration config, HttpClient httpClient,
Map authManagers, HttpCallback httpCallback) {
super(config, httpClient, authManagers, httpCallback);
}
/**
* To get details of the current configuration of a Thoughtspot cluster, use this endpoint.
* @return Returns the Object response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public Object getClusterConfig() throws ApiException, IOException {
HttpRequest request = buildGetClusterConfigRequest();
authManagers.get("global").apply(request);
HttpResponse response = getClientInstance().execute(request, false);
HttpContext context = new HttpContext(request, response);
return handleGetClusterConfigResponse(context);
}
/**
* To get details of the current configuration of a Thoughtspot cluster, use this endpoint.
* @return Returns the Object response from the API call
*/
public CompletableFuture getClusterConfigAsync() {
return makeHttpCallAsync(() -> buildGetClusterConfigRequest(),
req -> authManagers.get("global").applyAsync(req)
.thenCompose(request -> getClientInstance()
.executeAsync(request, false)),
context -> handleGetClusterConfigResponse(context));
}
/**
* Builds the HttpRequest object for getClusterConfig.
*/
private HttpRequest buildGetClusterConfigRequest() {
//the base uri for api requests
String baseUri = config.getBaseUri();
//prepare query string for API call
final StringBuilder queryBuilder = new StringBuilder(baseUri
+ "/tspublic/rest/v2/admin/configuration");
//load all headers for the outgoing API request
Headers headers = new Headers();
headers.add("X-Requested-By", config.getXRequestedBy());
headers.add("Accept-Language", config.getAcceptLanguage());
headers.add("Content-Type", config.getContentType());
headers.add("user-agent", BaseController.userAgent);
//prepare and invoke the API call request to fetch the response
HttpRequest request = getClientInstance().get(queryBuilder, headers, null, null);
// Invoke the callback before request if its not null
if (getHttpCallback() != null) {
getHttpCallback().onBeforeRequest(request);
}
return request;
}
/**
* Processes the response for getClusterConfig.
* @return An object of type Object
*/
private Object handleGetClusterConfigResponse(
HttpContext context) throws ApiException, IOException {
HttpResponse response = context.getResponse();
//invoke the callback after response if its not null
if (getHttpCallback() != null) {
getHttpCallback().onAfterResponse(context);
}
//Error handling using HTTP status codes
int responseCode = response.getStatusCode();
if (responseCode == 500) {
throw new ErrorResponseException("Operation failed or unauthorized request", context);
}
//handle errors defined at the API level
validateResponse(response, context);
//extract result from the http response
String responseBody = ((HttpStringResponse) response).getBody();
Object result = responseBody;
return result;
}
/**
* To get the details of overrides to the Thoughtspot cluster configuration, use this endpoint.
* @return Returns the Object response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public Object getClusterConfigOverrides() throws ApiException, IOException {
HttpRequest request = buildGetClusterConfigOverridesRequest();
authManagers.get("global").apply(request);
HttpResponse response = getClientInstance().execute(request, false);
HttpContext context = new HttpContext(request, response);
return handleGetClusterConfigOverridesResponse(context);
}
/**
* To get the details of overrides to the Thoughtspot cluster configuration, use this endpoint.
* @return Returns the Object response from the API call
*/
public CompletableFuture getClusterConfigOverridesAsync() {
return makeHttpCallAsync(() -> buildGetClusterConfigOverridesRequest(),
req -> authManagers.get("global").applyAsync(req)
.thenCompose(request -> getClientInstance()
.executeAsync(request, false)),
context -> handleGetClusterConfigOverridesResponse(context));
}
/**
* Builds the HttpRequest object for getClusterConfigOverrides.
*/
private HttpRequest buildGetClusterConfigOverridesRequest() {
//the base uri for api requests
String baseUri = config.getBaseUri();
//prepare query string for API call
final StringBuilder queryBuilder = new StringBuilder(baseUri
+ "/tspublic/rest/v2/admin/configuration/overrides");
//load all headers for the outgoing API request
Headers headers = new Headers();
headers.add("X-Requested-By", config.getXRequestedBy());
headers.add("Accept-Language", config.getAcceptLanguage());
headers.add("Content-Type", config.getContentType());
headers.add("user-agent", BaseController.userAgent);
//prepare and invoke the API call request to fetch the response
HttpRequest request = getClientInstance().get(queryBuilder, headers, null, null);
// Invoke the callback before request if its not null
if (getHttpCallback() != null) {
getHttpCallback().onBeforeRequest(request);
}
return request;
}
/**
* Processes the response for getClusterConfigOverrides.
* @return An object of type Object
*/
private Object handleGetClusterConfigOverridesResponse(
HttpContext context) throws ApiException, IOException {
HttpResponse response = context.getResponse();
//invoke the callback after response if its not null
if (getHttpCallback() != null) {
getHttpCallback().onAfterResponse(context);
}
//Error handling using HTTP status codes
int responseCode = response.getStatusCode();
if (responseCode == 500) {
throw new ErrorResponseException("Operation failed or unauthorized request", context);
}
//handle errors defined at the API level
validateResponse(response, context);
//extract result from the http response
String responseBody = ((HttpStringResponse) response).getBody();
Object result = responseBody;
return result;
}
/**
* To update the Thoughtspot cluster configuration, use this endpoint.
* @param body Required parameter: Example:
* @return Returns the Boolean response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public Boolean updateClusterConfig(
final TspublicRestV2AdminConfigurationUpdateRequest body) throws ApiException, IOException {
HttpRequest request = buildUpdateClusterConfigRequest(body);
authManagers.get("global").apply(request);
HttpResponse response = getClientInstance().execute(request, false);
HttpContext context = new HttpContext(request, response);
return handleUpdateClusterConfigResponse(context);
}
/**
* To update the Thoughtspot cluster configuration, use this endpoint.
* @param body Required parameter: Example:
* @return Returns the Boolean response from the API call
*/
public CompletableFuture updateClusterConfigAsync(
final TspublicRestV2AdminConfigurationUpdateRequest body) {
return makeHttpCallAsync(() -> buildUpdateClusterConfigRequest(body),
req -> authManagers.get("global").applyAsync(req)
.thenCompose(request -> getClientInstance()
.executeAsync(request, false)),
context -> handleUpdateClusterConfigResponse(context));
}
/**
* Builds the HttpRequest object for updateClusterConfig.
*/
private HttpRequest buildUpdateClusterConfigRequest(
final TspublicRestV2AdminConfigurationUpdateRequest body) throws JsonProcessingException {
//validating required parameters
if (null == body) {
throw new NullPointerException("The parameter \"body\" is a required parameter and cannot be null.");
}
//the base uri for api requests
String baseUri = config.getBaseUri();
//prepare query string for API call
final StringBuilder queryBuilder = new StringBuilder(baseUri
+ "/tspublic/rest/v2/admin/configuration/update");
//load all headers for the outgoing API request
Headers headers = new Headers();
headers.add("Content-Type", "application/json");
headers.add("X-Requested-By", config.getXRequestedBy());
headers.add("Accept-Language", config.getAcceptLanguage());
headers.add("user-agent", BaseController.userAgent);
//prepare and invoke the API call request to fetch the response
String bodyJson = ApiHelper.serialize(body);
HttpRequest request = getClientInstance().putBody(queryBuilder, headers, null, bodyJson);
// Invoke the callback before request if its not null
if (getHttpCallback() != null) {
getHttpCallback().onBeforeRequest(request);
}
return request;
}
/**
* Processes the response for updateClusterConfig.
* @return An object of type boolean
*/
private Boolean handleUpdateClusterConfigResponse(
HttpContext context) throws ApiException, IOException {
HttpResponse response = context.getResponse();
//invoke the callback after response if its not null
if (getHttpCallback() != null) {
getHttpCallback().onAfterResponse(context);
}
//Error handling using HTTP status codes
int responseCode = response.getStatusCode();
if (responseCode == 500) {
throw new ErrorResponseException("Operation failed or unauthorized request", context);
}
//handle errors defined at the API level
validateResponse(response, context);
//extract result from the http response
String responseBody = ((HttpStringResponse) response).getBody();
boolean result = Boolean.parseBoolean(responseBody);
return result;
}
/**
* To reset the password of a ThoughtSpot user account, use this endpoint. It is mandatory to
* use Authorization header with token of a user with admin access to successfully run this
* endpoint. At least one of User Id or username is mandatory. When both are given, then user id
* will be considered.
* @param body Required parameter: Example:
* @return Returns the Boolean response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public Boolean resetUserPassword(
final TspublicRestV2AdminResetpasswordRequest body) throws ApiException, IOException {
HttpRequest request = buildResetUserPasswordRequest(body);
authManagers.get("global").apply(request);
HttpResponse response = getClientInstance().execute(request, false);
HttpContext context = new HttpContext(request, response);
return handleResetUserPasswordResponse(context);
}
/**
* To reset the password of a ThoughtSpot user account, use this endpoint. It is mandatory to
* use Authorization header with token of a user with admin access to successfully run this
* endpoint. At least one of User Id or username is mandatory. When both are given, then user id
* will be considered.
* @param body Required parameter: Example:
* @return Returns the Boolean response from the API call
*/
public CompletableFuture resetUserPasswordAsync(
final TspublicRestV2AdminResetpasswordRequest body) {
return makeHttpCallAsync(() -> buildResetUserPasswordRequest(body),
req -> authManagers.get("global").applyAsync(req)
.thenCompose(request -> getClientInstance()
.executeAsync(request, false)),
context -> handleResetUserPasswordResponse(context));
}
/**
* Builds the HttpRequest object for resetUserPassword.
*/
private HttpRequest buildResetUserPasswordRequest(
final TspublicRestV2AdminResetpasswordRequest body) throws JsonProcessingException {
//validating required parameters
if (null == body) {
throw new NullPointerException("The parameter \"body\" is a required parameter and cannot be null.");
}
//the base uri for api requests
String baseUri = config.getBaseUri();
//prepare query string for API call
final StringBuilder queryBuilder = new StringBuilder(baseUri
+ "/tspublic/rest/v2/admin/resetpassword");
//load all headers for the outgoing API request
Headers headers = new Headers();
headers.add("Content-Type", "application/json");
headers.add("X-Requested-By", config.getXRequestedBy());
headers.add("Accept-Language", config.getAcceptLanguage());
headers.add("user-agent", BaseController.userAgent);
//prepare and invoke the API call request to fetch the response
String bodyJson = ApiHelper.serialize(body);
HttpRequest request = getClientInstance().putBody(queryBuilder, headers, null, bodyJson);
// Invoke the callback before request if its not null
if (getHttpCallback() != null) {
getHttpCallback().onBeforeRequest(request);
}
return request;
}
/**
* Processes the response for resetUserPassword.
* @return An object of type boolean
*/
private Boolean handleResetUserPasswordResponse(
HttpContext context) throws ApiException, IOException {
HttpResponse response = context.getResponse();
//invoke the callback after response if its not null
if (getHttpCallback() != null) {
getHttpCallback().onAfterResponse(context);
}
//Error handling using HTTP status codes
int responseCode = response.getStatusCode();
if (responseCode == 500) {
throw new ErrorResponseException("Operation failed or unauthorized request", context);
}
//handle errors defined at the API level
validateResponse(response, context);
//extract result from the http response
String responseBody = ((HttpStringResponse) response).getBody();
boolean result = Boolean.parseBoolean(responseBody);
return result;
}
/**
* To programmatically synchronize user accounts and user groups from external system with
* ThoughtSpot, use this endpoint. The payload takes principals containing all users and groups
* present in the external system. The users and user groups in Thoughtspot get updated for any
* matching inputs. Any user and user group present in the input, but not present in the
* cluster, gets created in cluster. n You can optionally choose to delete the user and groups
* from the cluster, that are not present in the input.
* @param body Required parameter: Example:
* @return Returns the AdminsyncPrincipalResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public AdminsyncPrincipalResponse syncPrincipal(
final TspublicRestV2AdminSyncprincipalRequest body) throws ApiException, IOException {
HttpRequest request = buildSyncPrincipalRequest(body);
authManagers.get("global").apply(request);
HttpResponse response = getClientInstance().execute(request, false);
HttpContext context = new HttpContext(request, response);
return handleSyncPrincipalResponse(context);
}
/**
* To programmatically synchronize user accounts and user groups from external system with
* ThoughtSpot, use this endpoint. The payload takes principals containing all users and groups
* present in the external system. The users and user groups in Thoughtspot get updated for any
* matching inputs. Any user and user group present in the input, but not present in the
* cluster, gets created in cluster. n You can optionally choose to delete the user and groups
* from the cluster, that are not present in the input.
* @param body Required parameter: Example:
* @return Returns the AdminsyncPrincipalResponse response from the API call
*/
public CompletableFuture syncPrincipalAsync(
final TspublicRestV2AdminSyncprincipalRequest body) {
return makeHttpCallAsync(() -> buildSyncPrincipalRequest(body),
req -> authManagers.get("global").applyAsync(req)
.thenCompose(request -> getClientInstance()
.executeAsync(request, false)),
context -> handleSyncPrincipalResponse(context));
}
/**
* Builds the HttpRequest object for syncPrincipal.
*/
private HttpRequest buildSyncPrincipalRequest(
final TspublicRestV2AdminSyncprincipalRequest body) throws JsonProcessingException {
//validating required parameters
if (null == body) {
throw new NullPointerException("The parameter \"body\" is a required parameter and cannot be null.");
}
//the base uri for api requests
String baseUri = config.getBaseUri();
//prepare query string for API call
final StringBuilder queryBuilder = new StringBuilder(baseUri
+ "/tspublic/rest/v2/admin/syncprincipal");
//load all headers for the outgoing API request
Headers headers = new Headers();
headers.add("Content-Type", "application/json");
headers.add("X-Requested-By", config.getXRequestedBy());
headers.add("Accept-Language", config.getAcceptLanguage());
headers.add("user-agent", BaseController.userAgent);
headers.add("accept", "application/json");
//prepare and invoke the API call request to fetch the response
String bodyJson = ApiHelper.serialize(body);
HttpRequest request = getClientInstance().putBody(queryBuilder, headers, null, bodyJson);
// Invoke the callback before request if its not null
if (getHttpCallback() != null) {
getHttpCallback().onBeforeRequest(request);
}
return request;
}
/**
* Processes the response for syncPrincipal.
* @return An object of type AdminsyncPrincipalResponse
*/
private AdminsyncPrincipalResponse handleSyncPrincipalResponse(
HttpContext context) throws ApiException, IOException {
HttpResponse response = context.getResponse();
//invoke the callback after response if its not null
if (getHttpCallback() != null) {
getHttpCallback().onAfterResponse(context);
}
//Error handling using HTTP status codes
int responseCode = response.getStatusCode();
if (responseCode == 500) {
throw new ErrorResponseException("Operation failed or unauthorized request", context);
}
//handle errors defined at the API level
validateResponse(response, context);
//extract result from the http response
String responseBody = ((HttpStringResponse) response).getBody();
AdminsyncPrincipalResponse result = ApiHelper.deserialize(responseBody,
AdminsyncPrincipalResponse.class);
return result;
}
/**
* To programmatically change the owner of one or several objects from one user account to
* another, use this endpoint. You might want to transfer ownership of objects owned by a user
* to another active user, when the account is removed from the ThoughtSpot application.
* @param body Required parameter: Example:
* @return Returns the Boolean response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public Boolean changeOwnerOfObjects(
final TspublicRestV2AdminChangeownerRequest body) throws ApiException, IOException {
HttpRequest request = buildChangeOwnerOfObjectsRequest(body);
authManagers.get("global").apply(request);
HttpResponse response = getClientInstance().execute(request, false);
HttpContext context = new HttpContext(request, response);
return handleChangeOwnerOfObjectsResponse(context);
}
/**
* To programmatically change the owner of one or several objects from one user account to
* another, use this endpoint. You might want to transfer ownership of objects owned by a user
* to another active user, when the account is removed from the ThoughtSpot application.
* @param body Required parameter: Example:
* @return Returns the Boolean response from the API call
*/
public CompletableFuture changeOwnerOfObjectsAsync(
final TspublicRestV2AdminChangeownerRequest body) {
return makeHttpCallAsync(() -> buildChangeOwnerOfObjectsRequest(body),
req -> authManagers.get("global").applyAsync(req)
.thenCompose(request -> getClientInstance()
.executeAsync(request, false)),
context -> handleChangeOwnerOfObjectsResponse(context));
}
/**
* Builds the HttpRequest object for changeOwnerOfObjects.
*/
private HttpRequest buildChangeOwnerOfObjectsRequest(
final TspublicRestV2AdminChangeownerRequest body) throws JsonProcessingException {
//validating required parameters
if (null == body) {
throw new NullPointerException("The parameter \"body\" is a required parameter and cannot be null.");
}
//the base uri for api requests
String baseUri = config.getBaseUri();
//prepare query string for API call
final StringBuilder queryBuilder = new StringBuilder(baseUri
+ "/tspublic/rest/v2/admin/changeowner");
//load all headers for the outgoing API request
Headers headers = new Headers();
headers.add("Content-Type", "application/json");
headers.add("X-Requested-By", config.getXRequestedBy());
headers.add("Accept-Language", config.getAcceptLanguage());
headers.add("user-agent", BaseController.userAgent);
//prepare and invoke the API call request to fetch the response
String bodyJson = ApiHelper.serialize(body);
HttpRequest request = getClientInstance().putBody(queryBuilder, headers, null, bodyJson);
// Invoke the callback before request if its not null
if (getHttpCallback() != null) {
getHttpCallback().onBeforeRequest(request);
}
return request;
}
/**
* Processes the response for changeOwnerOfObjects.
* @return An object of type boolean
*/
private Boolean handleChangeOwnerOfObjectsResponse(
HttpContext context) throws ApiException, IOException {
HttpResponse response = context.getResponse();
//invoke the callback after response if its not null
if (getHttpCallback() != null) {
getHttpCallback().onAfterResponse(context);
}
//Error handling using HTTP status codes
int responseCode = response.getStatusCode();
if (responseCode == 500) {
throw new ErrorResponseException("Operation failed or unauthorized request", context);
}
//handle errors defined at the API level
validateResponse(response, context);
//extract result from the http response
String responseBody = ((HttpStringResponse) response).getBody();
boolean result = Boolean.parseBoolean(responseBody);
return result;
}
}