edu.ucsb.nceas.metacat.dataone.quota

## Class QuotaServiceManager

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

-     public class QuotaServiceManager
      extends java.lang.Object

  A class manages the quota service for users
  Author:
    tao

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `ACTIVE`
    `static java.lang.String` | `ARCHIVEMETHOD`
    `static java.lang.String` | `CREATEMETHOD`
    `static java.lang.String` | `DELETED`
    `static java.lang.String` | `DELETEMETHOD`
    `static java.lang.String` | `INACTIVE`
    `static java.lang.String` | `PROPERTYNAMEOFPORTALNAMESPACE`
    `static java.lang.String` | `QUOTASUBJECTHEADER`
    `static java.lang.String` | `UPDATEMETHOD`
    `static java.lang.String` | `USAGE`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `enforce(java.lang.String quotaSubject, org.dataone.service.types.v1.Subject requestor, org.dataone.service.types.v2.SystemMetadata sysmeta, java.lang.String method)` Enforce quota service
    `static QuotaServiceManager` | `getInstance()` Get the singleton instance of the service
    `boolean` | `isEnabled()` Check if the quota service is enabled.
    `void` | `startDailyCheck()` Start a timer to check failed usage reporting and report them again in daily base.

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

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

- - ### Field Detail

    - #### USAGE

          public static final java.lang.String USAGE

      See Also:
        Constant Field Values

    - #### ACTIVE

          public static final java.lang.String ACTIVE

      See Also:
        Constant Field Values

    - #### INACTIVE

          public static final java.lang.String INACTIVE

      See Also:
        Constant Field Values

    - #### DELETED

          public static final java.lang.String DELETED

      See Also:
        Constant Field Values

    - #### CREATEMETHOD

          public static final java.lang.String CREATEMETHOD

      See Also:
        Constant Field Values

    - #### UPDATEMETHOD

          public static final java.lang.String UPDATEMETHOD

      See Also:
        Constant Field Values

    - #### ARCHIVEMETHOD

          public static final java.lang.String ARCHIVEMETHOD

      See Also:
        Constant Field Values

    - #### DELETEMETHOD

          public static final java.lang.String DELETEMETHOD

      See Also:
        Constant Field Values

    - #### PROPERTYNAMEOFPORTALNAMESPACE

          public static final java.lang.String PROPERTYNAMEOFPORTALNAMESPACE

      See Also:
        Constant Field Values

    - #### QUOTASUBJECTHEADER

          public static final java.lang.String QUOTASUBJECTHEADER

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### getInstance

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

      Get the singleton instance of the service
      Returns:
        the quota service instance. The instance will have a bookeeperClient if the quota service is enabled.
      Throws:
        `java.io.IOException`
        `org.dataone.service.exceptions.ServiceFailure`

    - #### isEnabled

          public boolean isEnabled()

      Check if the quota service is enabled.
      Returns:
        true if it is enabled; otherwise false.

    - #### startDailyCheck

          public void startDailyCheck()

      Start a timer to check failed usage reporting and report them again in daily base. Metacat only needs one timer, but this method will be called on four different servlet init methods. So the method has a indicator of already starting a timer and is synchronized to make sure only one timer will be started.

    - #### enforce

          public void enforce(java.lang.String quotaSubject,
                              org.dataone.service.types.v1.Subject requestor,
                              org.dataone.service.types.v2.SystemMetadata sysmeta,
                              java.lang.String method)
                       throws org.dataone.service.exceptions.InsufficientResources,
                              org.dataone.service.exceptions.InvalidRequest,
                              org.dataone.service.exceptions.ServiceFailure,
                              org.dataone.service.exceptions.NotImplemented,
                              org.dataone.service.exceptions.NotFound

      Enforce quota service
      Parameters:
        `quotaSubject` - the subject of the quota which will be used
        `requestor` - the subject of the user who requests the usage
        `sysmeta` - the system metadata of the object which will use the quota
        `method` - the method name which will call the createUsage method (create or update
      Throws:
        `org.dataone.service.exceptions.InsufficientResources`
        `org.dataone.service.exceptions.InvalidRequest`
        `org.dataone.service.exceptions.ServiceFailure`
        `org.dataone.service.exceptions.NotFound`
        `org.dataone.service.exceptions.NotImplemented`

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