Class Account


  • public class Account
    extends java.lang.Object

    A representation of an Ambry user. A user is an entity (an application or an individual user) who uses ambry as a service. This Account class contains general information of a user, which can be used for user-based operations such as authentication, get a Container under this account, and access control.

    Account name is provided by an Ambry user as an external reference. Account id is an internal identifier of the user, and is one-to-one mapped to an account name. Account name and id are generated through user registration process.

    Account is serialized into JSONObject in the currentJsonVersion, which is version 1 for now. Below lists all the json versions and their formats:

    
     Version 1:
     {
       "accountId": 101,
       "accountName": "MyAccount",
       "containers": [
         {
           "containerName": "MyPrivateContainer",
           "description": "This is my private container",
           "isPrivate": "true",
           "containerId": 0,
           "version": 1,
           "status": "ACTIVE",
           "parentAccountId": "101"
         },
         {
           "containerName": "MyPublicContainer",
           "description": "This is my public container",
           "isPrivate": "false",
           "containerId": 1,
           "version": 1,
           "status": "ACTIVE",
           "parentAccountId": "101"
         }
       ],
       "version": 1,
       "status": "ACTIVE"
     }
     

    An account object is immutable. To update an account, refer to AccountBuilder for how to build a new account object with updated field(s).

    • Field Detail

      • UNKNOWN_ACCOUNT_ID

        public static final short UNKNOWN_ACCOUNT_ID
        The id of unknown account.
        See Also:
        Constant Field Values
      • UNKNOWN_ACCOUNT_NAME

        public static final java.lang.String UNKNOWN_ACCOUNT_NAME
        The name of the unknown account.
        See Also:
        Constant Field Values
      • HELIX_ACCOUNT_SERVICE_ACCOUNT_ID

        public static final short HELIX_ACCOUNT_SERVICE_ACCOUNT_ID
        The id for to save account metadata in ambry.
        See Also:
        Constant Field Values
      • HELIX_ACCOUNT_SERVICE_ACCOUNT_NAME

        public static final java.lang.String HELIX_ACCOUNT_SERVICE_ACCOUNT_NAME
        The name of the HELIX_ACCOUNT_SERVICE_ACCOUNT_ID.
        See Also:
        Constant Field Values
    • Method Detail

      • toJson

        public org.json.JSONObject toJson​(boolean incrementSnapshotVersion)
                                   throws org.json.JSONException
        Gets the metadata of the account in JSONObject. This will increment the snapshot version by one if incrementSnapshotVersion is true.
        Parameters:
        incrementSnapshotVersion - true to increment the snapshot version by one.
        Returns:
        The metadata of the account in JSONObject.
        Throws:
        org.json.JSONException - If fails to compose the metadata in JSONObject.
      • fromJson

        public static Account fromJson​(org.json.JSONObject json)
                                throws org.json.JSONException
        Deserializes a JSONObject to an account object.
        Parameters:
        json - The JSONObject to deserialize.
        Returns:
        An account object deserialized from the JSONObject.
        Throws:
        org.json.JSONException - If parsing the JSONObject fails.
      • getId

        public short getId()
        Returns:
        The id of the account.
      • getName

        public java.lang.String getName()
        Returns:
        The name of the account.
      • getSnapshotVersion

        public int getSnapshotVersion()
        The snapshot version is generally the number of modifications to the account that were expected to have occurred before the current time. This is used to validate that there were no unexpected account modifications that could be inadvertently overwritten by an account update.
        Returns:
        the expected version for the account record.
      • getLastModifiedTime

        public long getLastModifiedTime()
        Get the created/modified time of this Account
        Returns:
        epoch time in milliseconds
      • getContainerById

        public Container getContainerById​(short containerId)
        Gets the Container of this account with the specified container id.
        Parameters:
        containerId - The id of the container to get.
        Returns:
        The Container of this account with the specified id, or null if such a container does not exist.
      • getContainerByName

        public Container getContainerByName​(java.lang.String containerName)
        Gets the Container of this account with the specified container name.
        Parameters:
        containerName - The name of the container to get.
        Returns:
        The Container of this account with the specified name, or null if such a container does not exist.
      • getAllContainers

        public java.util.Collection<Container> getAllContainers()
        Gets all the containers of this account in a Collection.
        Returns:
        All the containers of this account.
      • toString

        public java.lang.String toString()
        Generates a String representation that uniquely identifies this account. The string is in the format of Account[id].
        Overrides:
        toString in class java.lang.Object
        Returns:
        The String representation of this account.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • updateContainerMap

        public void updateContainerMap​(java.util.Collection<Container> containers)
        Adds a collection of Container(s) to this account and updates internal maps accordingly.
        Parameters:
        containers - The containers to update this account.