edu.ucsb.nceas.metacat.dataone.quota

## Class BookKeeperClient

- java.lang.Object
- - edu.ucsb.nceas.metacat.dataone.quota.BookKeeperClient

-     public class BookKeeperClient
      extends java.lang.Object

  A client class to access the BookKeeper service
  Author:
    tao

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_REMOTE_USAGE_ID`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `BookKeeperClient()` A private constructor

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `createUsage(org.dataone.bookkeeper.api.Usage usage)` Create a usage record for a given quota identifier in the book keeper service.
    `int` | `deleteUsage(int quotaId, java.lang.String instanceId)` Delete the usage with the given quota type and instance id in the remote book keeper service
    `static BookKeeperClient` | `getInstance()` Get the singleton instance of the BookKeeplerClient class
    `java.util.List<org.dataone.bookkeeper.api.Quota>` | `listQuotas(java.lang.String quotaSubject, java.lang.String requestor, java.lang.String quotaType)` List the quotas associated with the given subject
    `int` | `updateUsage(int quotaId, java.lang.String instanceId, org.dataone.bookkeeper.api.Usage usage)` Update an existing usage with the given quota id and instance id

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_REMOTE_USAGE_ID

          public static final int DEFAULT_REMOTE_USAGE_ID

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### BookKeeperClient

          protected BookKeeperClient()
                              throws org.dataone.service.exceptions.ServiceFailure

      A private constructor
      Throws:
        `java.io.IOException`
        `org.dataone.service.exceptions.ServiceFailure`

  - ### Method Detail

    - #### getInstance

          public static BookKeeperClient getInstance()
                                              throws org.dataone.service.exceptions.ServiceFailure

      Get the singleton instance of the BookKeeplerClient class
      Returns:
        the instance of the class
      Throws:
        `java.io.IOException`
        `org.dataone.service.exceptions.ServiceFailure`

    - #### listQuotas

          public java.util.List<org.dataone.bookkeeper.api.Quota> listQuotas(java.lang.String quotaSubject,
                                                                             java.lang.String requestor,
                                                                             java.lang.String quotaType)
                                                                      throws org.dataone.service.exceptions.ServiceFailure,
                                                                             org.dataone.service.exceptions.NotFound,
                                                                             org.dataone.service.exceptions.InvalidRequest,
                                                                             java.io.UnsupportedEncodingException

      List the quotas associated with the given subject
      Parameters:
        `quotaSubject` - the subject who owns the quotas
        `requestor` - the subject of user who will request a usage
        `quotaType` - the type of the quotas (storage or portal)
      Returns:
        the list of quotas associated with the subject.
      Throws:
        `java.io.IOException`
        `org.apache.http.client.ClientProtocolException`
        `org.dataone.service.exceptions.NotFound`
        `org.dataone.service.exceptions.ServiceFailure`
        `org.dataone.service.exceptions.InvalidRequest`
        `java.io.UnsupportedEncodingException`

    - #### createUsage

          public int createUsage(org.dataone.bookkeeper.api.Usage usage)
                          throws org.apache.http.client.ClientProtocolException,
                                 java.io.IOException,
                                 org.dataone.service.exceptions.ServiceFailure

      Create a usage record for a given quota identifier in the book keeper service. If it fails, an exception will be thrown
      Parameters:
        `usage` - the object of the usage will be created
      Returns:
        the usage id from the remote book keeper server
      Throws:
        `org.apache.http.client.ClientProtocolException`
        `java.io.IOException`
        `org.dataone.service.exceptions.ServiceFailure`

    - #### deleteUsage

          public int deleteUsage(int quotaId,
                                 java.lang.String instanceId)
                          throws org.dataone.service.exceptions.InvalidRequest,
                                 org.apache.http.client.ClientProtocolException,
                                 org.dataone.service.exceptions.ServiceFailure,
                                 java.io.IOException

      Delete the usage with the given quota type and instance id in the remote book keeper service
      Parameters:
        `quotaType` - the quota type associated with the usage
        `instanceId` - the instance id associated with the usage
      Returns:
        the remote usage id which was deleted. If it returns the default value -1, it means there is no remote usage matching the quota id and instance id and Metacat did nothing.
      Throws:
        `org.dataone.service.exceptions.InvalidRequest`
        `org.apache.http.client.ClientProtocolException`
        `org.dataone.service.exceptions.ServiceFailure`
        `java.io.IOException`

    - #### updateUsage

          public int updateUsage(int quotaId,
                                 java.lang.String instanceId,
                                 org.dataone.bookkeeper.api.Usage usage)
                          throws org.dataone.service.exceptions.InvalidRequest,
                                 org.apache.http.client.ClientProtocolException,
                                 org.dataone.service.exceptions.ServiceFailure,
                                 java.io.IOException

      Update an existing usage with the given quota id and instance id
      Parameters:
        `quotaId` - the quota id which the existing usage matches
        `instanceId` - the instance id which the existing usage matches
        `usage` - the new usage value will be used
      Returns:
        the remote usage id which was updated. If it returns the default value -1, it means there is no remote usage matching the quota id and instance id and Metacat did nothing.
      Throws:
        `org.dataone.service.exceptions.InvalidRequest`
        `org.apache.http.client.ClientProtocolException`
        `org.dataone.service.exceptions.ServiceFailure`
        `java.io.IOException`

Copyright © 2023 Regents of the University of California. All Rights Reserved.