All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dominodatalab.api.rest.QuotaApi Maven / Gradle / Ivy

/*
 * Domino Data Lab API v4
 * This API is going to provide access to all the Domino functions available in the user interface. To authenticate your requests, include your API Key (which you can find on your account page) with the header X-Domino-Api-Key. 
 *
 * The version of the OpenAPI document: 4.0.0
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

package com.dominodatalab.api.rest;

import com.dominodatalab.api.invoker.ApiClient;
import com.dominodatalab.api.invoker.ApiException;
import com.dominodatalab.api.invoker.ApiResponse;
import com.dominodatalab.api.invoker.Pair;

import com.dominodatalab.api.model.DominoApiErrorResponse;
import com.dominodatalab.api.model.DominoQuotaApiQuotaActionDto;
import com.dominodatalab.api.model.DominoQuotaApiQuotaDto;
import com.dominodatalab.api.model.DominoQuotaWebCreateQuotaOverridesRequest;
import com.dominodatalab.api.model.DominoQuotaWebRecordQuotaActionRequest;
import com.dominodatalab.api.model.DominoQuotaWebUpdateQuotaRequest;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;

import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.http.HttpRequest;
import java.nio.channels.Channels;
import java.nio.channels.Pipe;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

import java.util.ArrayList;
import java.util.StringJoiner;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-10-17T15:20:46.682098100-04:00[America/New_York]")
public class QuotaApi {
  private final HttpClient memberVarHttpClient;
  private final ObjectMapper memberVarObjectMapper;
  private final String memberVarBaseUri;
  private final Consumer memberVarInterceptor;
  private final Duration memberVarReadTimeout;
  private final Consumer> memberVarResponseInterceptor;
  private final Consumer> memberVarAsyncResponseInterceptor;

  public QuotaApi() {
    this(new ApiClient());
  }

  public QuotaApi(ApiClient apiClient) {
    memberVarHttpClient = apiClient.getHttpClient();
    memberVarObjectMapper = apiClient.getObjectMapper();
    memberVarBaseUri = apiClient.getBaseUri();
    memberVarInterceptor = apiClient.getRequestInterceptor();
    memberVarReadTimeout = apiClient.getReadTimeout();
    memberVarResponseInterceptor = apiClient.getResponseInterceptor();
    memberVarAsyncResponseInterceptor = apiClient.getAsyncResponseInterceptor();
  }

  protected ApiException getApiException(String operationId, HttpResponse response) throws IOException {
    String body = response.body() == null ? null : new String(response.body().readAllBytes());
    String message = formatExceptionMessage(operationId, response.statusCode(), body);
    return new ApiException(response.statusCode(), message, response.headers(), body);
  }

  private String formatExceptionMessage(String operationId, int statusCode, String body) {
    if (body == null || body.isEmpty()) {
      body = "[no body]";
    }
    return operationId + " call failed with: " + statusCode + " - " + body;
  }

  /**
   * create quota overrides
   * 
   * @param dominoQuotaWebCreateQuotaOverridesRequest quota overrides to create (required)
   * @return List<DominoQuotaApiQuotaDto>
   * @throws ApiException if fails to make API call
   */
  public List createQuotaOverrides(DominoQuotaWebCreateQuotaOverridesRequest dominoQuotaWebCreateQuotaOverridesRequest) throws ApiException {
    ApiResponse> localVarResponse = createQuotaOverridesWithHttpInfo(dominoQuotaWebCreateQuotaOverridesRequest);
    return localVarResponse.getData();
  }

  /**
   * create quota overrides
   * 
   * @param dominoQuotaWebCreateQuotaOverridesRequest quota overrides to create (required)
   * @return ApiResponse<List<DominoQuotaApiQuotaDto>>
   * @throws ApiException if fails to make API call
   */
  public ApiResponse> createQuotaOverridesWithHttpInfo(DominoQuotaWebCreateQuotaOverridesRequest dominoQuotaWebCreateQuotaOverridesRequest) throws ApiException {
    HttpRequest.Builder localVarRequestBuilder = createQuotaOverridesRequestBuilder(dominoQuotaWebCreateQuotaOverridesRequest);
    try {
      HttpResponse localVarResponse = memberVarHttpClient.send(
          localVarRequestBuilder.build(),
          HttpResponse.BodyHandlers.ofInputStream());
      if (memberVarResponseInterceptor != null) {
        memberVarResponseInterceptor.accept(localVarResponse);
      }
      try {
        if (localVarResponse.statusCode()/ 100 != 2) {
          throw getApiException("createQuotaOverrides", localVarResponse);
        }
        return new ApiResponse>(
          localVarResponse.statusCode(),
          localVarResponse.headers().map(),
          localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference>() {}) // closes the InputStream
        );
      } finally {
      }
    } catch (IOException e) {
      throw new ApiException(e);
    }
    catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new ApiException(e);
    }
  }

  private HttpRequest.Builder createQuotaOverridesRequestBuilder(DominoQuotaWebCreateQuotaOverridesRequest dominoQuotaWebCreateQuotaOverridesRequest) throws ApiException {
    // verify the required parameter 'dominoQuotaWebCreateQuotaOverridesRequest' is set
    if (dominoQuotaWebCreateQuotaOverridesRequest == null) {
      throw new ApiException(400, "Missing the required parameter 'dominoQuotaWebCreateQuotaOverridesRequest' when calling createQuotaOverrides");
    }

    HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();

    String localVarPath = "/quota/quota-overrides";

    localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));

    localVarRequestBuilder.header("Content-Type", "application/json");
    localVarRequestBuilder.header("Accept", "application/json");

    try {
      byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(dominoQuotaWebCreateQuotaOverridesRequest);
      localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
    } catch (IOException e) {
      throw new ApiException(e);
    }
    if (memberVarReadTimeout != null) {
      localVarRequestBuilder.timeout(memberVarReadTimeout);
    }
    if (memberVarInterceptor != null) {
      memberVarInterceptor.accept(localVarRequestBuilder);
    }
    return localVarRequestBuilder;
  }
  /**
   * delete a quota
   * 
   * @param targetId id of user in quota override (optional)
   * @throws ApiException if fails to make API call
   */
  public void deleteQuota(String targetId) throws ApiException {
    deleteQuotaWithHttpInfo(targetId);
  }

  /**
   * delete a quota
   * 
   * @param targetId id of user in quota override (optional)
   * @return ApiResponse<Void>
   * @throws ApiException if fails to make API call
   */
  public ApiResponse deleteQuotaWithHttpInfo(String targetId) throws ApiException {
    HttpRequest.Builder localVarRequestBuilder = deleteQuotaRequestBuilder(targetId);
    try {
      HttpResponse localVarResponse = memberVarHttpClient.send(
          localVarRequestBuilder.build(),
          HttpResponse.BodyHandlers.ofInputStream());
      if (memberVarResponseInterceptor != null) {
        memberVarResponseInterceptor.accept(localVarResponse);
      }
      try {
        if (localVarResponse.statusCode()/ 100 != 2) {
          throw getApiException("deleteQuota", localVarResponse);
        }
        return new ApiResponse(
          localVarResponse.statusCode(),
          localVarResponse.headers().map(),
          null
        );
      } finally {
        // Drain the InputStream
        while (localVarResponse.body().read() != -1) {
            // Ignore
        }
        localVarResponse.body().close();
      }
    } catch (IOException e) {
      throw new ApiException(e);
    }
    catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new ApiException(e);
    }
  }

  private HttpRequest.Builder deleteQuotaRequestBuilder(String targetId) throws ApiException {

    HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();

    String localVarPath = "/quota/quota";

    List localVarQueryParams = new ArrayList<>();
    StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
    String localVarQueryParameterBaseName;
    localVarQueryParameterBaseName = "targetId";
    localVarQueryParams.addAll(ApiClient.parameterToPairs("targetId", targetId));

    if (!localVarQueryParams.isEmpty() || localVarQueryStringJoiner.length() != 0) {
      StringJoiner queryJoiner = new StringJoiner("&");
      localVarQueryParams.forEach(p -> queryJoiner.add(p.getName() + '=' + p.getValue()));
      if (localVarQueryStringJoiner.length() != 0) {
        queryJoiner.add(localVarQueryStringJoiner.toString());
      }
      localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath + '?' + queryJoiner.toString()));
    } else {
      localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
    }

    localVarRequestBuilder.header("Accept", "application/json");

    localVarRequestBuilder.method("DELETE", HttpRequest.BodyPublishers.noBody());
    if (memberVarReadTimeout != null) {
      localVarRequestBuilder.timeout(memberVarReadTimeout);
    }
    if (memberVarInterceptor != null) {
      memberVarInterceptor.accept(localVarRequestBuilder);
    }
    return localVarRequestBuilder;
  }
  /**
   * get quota
   * 
   * @param targetId id of user the quota applies to (optional)
   * @return DominoQuotaApiQuotaDto
   * @throws ApiException if fails to make API call
   */
  public DominoQuotaApiQuotaDto getQuota(String targetId) throws ApiException {
    ApiResponse localVarResponse = getQuotaWithHttpInfo(targetId);
    return localVarResponse.getData();
  }

  /**
   * get quota
   * 
   * @param targetId id of user the quota applies to (optional)
   * @return ApiResponse<DominoQuotaApiQuotaDto>
   * @throws ApiException if fails to make API call
   */
  public ApiResponse getQuotaWithHttpInfo(String targetId) throws ApiException {
    HttpRequest.Builder localVarRequestBuilder = getQuotaRequestBuilder(targetId);
    try {
      HttpResponse localVarResponse = memberVarHttpClient.send(
          localVarRequestBuilder.build(),
          HttpResponse.BodyHandlers.ofInputStream());
      if (memberVarResponseInterceptor != null) {
        memberVarResponseInterceptor.accept(localVarResponse);
      }
      try {
        if (localVarResponse.statusCode()/ 100 != 2) {
          throw getApiException("getQuota", localVarResponse);
        }
        return new ApiResponse(
          localVarResponse.statusCode(),
          localVarResponse.headers().map(),
          localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream
        );
      } finally {
      }
    } catch (IOException e) {
      throw new ApiException(e);
    }
    catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new ApiException(e);
    }
  }

  private HttpRequest.Builder getQuotaRequestBuilder(String targetId) throws ApiException {

    HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();

    String localVarPath = "/quota/quota";

    List localVarQueryParams = new ArrayList<>();
    StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
    String localVarQueryParameterBaseName;
    localVarQueryParameterBaseName = "targetId";
    localVarQueryParams.addAll(ApiClient.parameterToPairs("targetId", targetId));

    if (!localVarQueryParams.isEmpty() || localVarQueryStringJoiner.length() != 0) {
      StringJoiner queryJoiner = new StringJoiner("&");
      localVarQueryParams.forEach(p -> queryJoiner.add(p.getName() + '=' + p.getValue()));
      if (localVarQueryStringJoiner.length() != 0) {
        queryJoiner.add(localVarQueryStringJoiner.toString());
      }
      localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath + '?' + queryJoiner.toString()));
    } else {
      localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
    }

    localVarRequestBuilder.header("Accept", "application/json");

    localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
    if (memberVarReadTimeout != null) {
      localVarRequestBuilder.timeout(memberVarReadTimeout);
    }
    if (memberVarInterceptor != null) {
      memberVarInterceptor.accept(localVarRequestBuilder);
    }
    return localVarRequestBuilder;
  }
  /**
   * get quota overrides
   * 
   * @return List<DominoQuotaApiQuotaDto>
   * @throws ApiException if fails to make API call
   */
  public List getQuotaOverrides() throws ApiException {
    ApiResponse> localVarResponse = getQuotaOverridesWithHttpInfo();
    return localVarResponse.getData();
  }

  /**
   * get quota overrides
   * 
   * @return ApiResponse<List<DominoQuotaApiQuotaDto>>
   * @throws ApiException if fails to make API call
   */
  public ApiResponse> getQuotaOverridesWithHttpInfo() throws ApiException {
    HttpRequest.Builder localVarRequestBuilder = getQuotaOverridesRequestBuilder();
    try {
      HttpResponse localVarResponse = memberVarHttpClient.send(
          localVarRequestBuilder.build(),
          HttpResponse.BodyHandlers.ofInputStream());
      if (memberVarResponseInterceptor != null) {
        memberVarResponseInterceptor.accept(localVarResponse);
      }
      try {
        if (localVarResponse.statusCode()/ 100 != 2) {
          throw getApiException("getQuotaOverrides", localVarResponse);
        }
        return new ApiResponse>(
          localVarResponse.statusCode(),
          localVarResponse.headers().map(),
          localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference>() {}) // closes the InputStream
        );
      } finally {
      }
    } catch (IOException e) {
      throw new ApiException(e);
    }
    catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new ApiException(e);
    }
  }

  private HttpRequest.Builder getQuotaOverridesRequestBuilder() throws ApiException {

    HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();

    String localVarPath = "/quota/quotas";

    localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));

    localVarRequestBuilder.header("Accept", "application/json");

    localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
    if (memberVarReadTimeout != null) {
      localVarRequestBuilder.timeout(memberVarReadTimeout);
    }
    if (memberVarInterceptor != null) {
      memberVarInterceptor.accept(localVarRequestBuilder);
    }
    return localVarRequestBuilder;
  }
  /**
   * record when a quotaAction is taken
   * 
   * @param dominoQuotaWebRecordQuotaActionRequest fields for quotaAction (required)
   * @return DominoQuotaApiQuotaActionDto
   * @throws ApiException if fails to make API call
   */
  public DominoQuotaApiQuotaActionDto recordQuotaAction(DominoQuotaWebRecordQuotaActionRequest dominoQuotaWebRecordQuotaActionRequest) throws ApiException {
    ApiResponse localVarResponse = recordQuotaActionWithHttpInfo(dominoQuotaWebRecordQuotaActionRequest);
    return localVarResponse.getData();
  }

  /**
   * record when a quotaAction is taken
   * 
   * @param dominoQuotaWebRecordQuotaActionRequest fields for quotaAction (required)
   * @return ApiResponse<DominoQuotaApiQuotaActionDto>
   * @throws ApiException if fails to make API call
   */
  public ApiResponse recordQuotaActionWithHttpInfo(DominoQuotaWebRecordQuotaActionRequest dominoQuotaWebRecordQuotaActionRequest) throws ApiException {
    HttpRequest.Builder localVarRequestBuilder = recordQuotaActionRequestBuilder(dominoQuotaWebRecordQuotaActionRequest);
    try {
      HttpResponse localVarResponse = memberVarHttpClient.send(
          localVarRequestBuilder.build(),
          HttpResponse.BodyHandlers.ofInputStream());
      if (memberVarResponseInterceptor != null) {
        memberVarResponseInterceptor.accept(localVarResponse);
      }
      try {
        if (localVarResponse.statusCode()/ 100 != 2) {
          throw getApiException("recordQuotaAction", localVarResponse);
        }
        return new ApiResponse(
          localVarResponse.statusCode(),
          localVarResponse.headers().map(),
          localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream
        );
      } finally {
      }
    } catch (IOException e) {
      throw new ApiException(e);
    }
    catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new ApiException(e);
    }
  }

  private HttpRequest.Builder recordQuotaActionRequestBuilder(DominoQuotaWebRecordQuotaActionRequest dominoQuotaWebRecordQuotaActionRequest) throws ApiException {
    // verify the required parameter 'dominoQuotaWebRecordQuotaActionRequest' is set
    if (dominoQuotaWebRecordQuotaActionRequest == null) {
      throw new ApiException(400, "Missing the required parameter 'dominoQuotaWebRecordQuotaActionRequest' when calling recordQuotaAction");
    }

    HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();

    String localVarPath = "/quota/quota-action";

    localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));

    localVarRequestBuilder.header("Content-Type", "application/json");
    localVarRequestBuilder.header("Accept", "application/json");

    try {
      byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(dominoQuotaWebRecordQuotaActionRequest);
      localVarRequestBuilder.method("PUT", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
    } catch (IOException e) {
      throw new ApiException(e);
    }
    if (memberVarReadTimeout != null) {
      localVarRequestBuilder.timeout(memberVarReadTimeout);
    }
    if (memberVarInterceptor != null) {
      memberVarInterceptor.accept(localVarRequestBuilder);
    }
    return localVarRequestBuilder;
  }
  /**
   * update a quota
   * 
   * @param dominoQuotaWebUpdateQuotaRequest fields with which to update a quota (required)
   * @return DominoQuotaApiQuotaDto
   * @throws ApiException if fails to make API call
   */
  public DominoQuotaApiQuotaDto updateQuota(DominoQuotaWebUpdateQuotaRequest dominoQuotaWebUpdateQuotaRequest) throws ApiException {
    ApiResponse localVarResponse = updateQuotaWithHttpInfo(dominoQuotaWebUpdateQuotaRequest);
    return localVarResponse.getData();
  }

  /**
   * update a quota
   * 
   * @param dominoQuotaWebUpdateQuotaRequest fields with which to update a quota (required)
   * @return ApiResponse<DominoQuotaApiQuotaDto>
   * @throws ApiException if fails to make API call
   */
  public ApiResponse updateQuotaWithHttpInfo(DominoQuotaWebUpdateQuotaRequest dominoQuotaWebUpdateQuotaRequest) throws ApiException {
    HttpRequest.Builder localVarRequestBuilder = updateQuotaRequestBuilder(dominoQuotaWebUpdateQuotaRequest);
    try {
      HttpResponse localVarResponse = memberVarHttpClient.send(
          localVarRequestBuilder.build(),
          HttpResponse.BodyHandlers.ofInputStream());
      if (memberVarResponseInterceptor != null) {
        memberVarResponseInterceptor.accept(localVarResponse);
      }
      try {
        if (localVarResponse.statusCode()/ 100 != 2) {
          throw getApiException("updateQuota", localVarResponse);
        }
        return new ApiResponse(
          localVarResponse.statusCode(),
          localVarResponse.headers().map(),
          localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference() {}) // closes the InputStream
        );
      } finally {
      }
    } catch (IOException e) {
      throw new ApiException(e);
    }
    catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new ApiException(e);
    }
  }

  private HttpRequest.Builder updateQuotaRequestBuilder(DominoQuotaWebUpdateQuotaRequest dominoQuotaWebUpdateQuotaRequest) throws ApiException {
    // verify the required parameter 'dominoQuotaWebUpdateQuotaRequest' is set
    if (dominoQuotaWebUpdateQuotaRequest == null) {
      throw new ApiException(400, "Missing the required parameter 'dominoQuotaWebUpdateQuotaRequest' when calling updateQuota");
    }

    HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();

    String localVarPath = "/quota/quota";

    localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));

    localVarRequestBuilder.header("Content-Type", "application/json");
    localVarRequestBuilder.header("Accept", "application/json");

    try {
      byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(dominoQuotaWebUpdateQuotaRequest);
      localVarRequestBuilder.method("PUT", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
    } catch (IOException e) {
      throw new ApiException(e);
    }
    if (memberVarReadTimeout != null) {
      localVarRequestBuilder.timeout(memberVarReadTimeout);
    }
    if (memberVarInterceptor != null) {
      memberVarInterceptor.accept(localVarRequestBuilder);
    }
    return localVarRequestBuilder;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy