Class Account
- java.lang.Object
-
- com.github.ambry.account.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 aContainer
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 thecurrentJsonVersion
, 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).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Account.AccountStatus
The status of the account.
-
Field Summary
Fields Modifier and Type Field Description static short
HELIX_ACCOUNT_SERVICE_ACCOUNT_ID
The id for to save account metadata in ambry.static java.lang.String
HELIX_ACCOUNT_SERVICE_ACCOUNT_NAME
The name of theHELIX_ACCOUNT_SERVICE_ACCOUNT_ID
.static short
UNKNOWN_ACCOUNT_ID
The id of unknown account.static java.lang.String
UNKNOWN_ACCOUNT_NAME
The name of the unknown account.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
static Account
fromJson(org.json.JSONObject json)
Deserializes aJSONObject
to an account object.java.util.Collection<Container>
getAllContainers()
Gets all the containers of this account in a Collection.Container
getContainerById(short containerId)
Gets theContainer
of this account with the specified container id.Container
getContainerByName(java.lang.String containerName)
Gets theContainer
of this account with the specified container name.short
getId()
long
getLastModifiedTime()
Get the created/modified time of this Accountjava.lang.String
getName()
int
getSnapshotVersion()
The snapshot version is generally the number of modifications to the account that were expected to have occurred before the current time.Account.AccountStatus
getStatus()
int
hashCode()
org.json.JSONObject
toJson(boolean incrementSnapshotVersion)
Gets the metadata of the account inJSONObject
.java.lang.String
toString()
Generates a String representation that uniquely identifies this account.void
updateContainerMap(java.util.Collection<Container> containers)
Adds a collection ofContainer
(s) to this account and updates internal maps accordingly.
-
-
-
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 theHELIX_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 inJSONObject
. This will increment the snapshot version by one ifincrementSnapshotVersion
istrue
.- 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 inJSONObject
.
-
fromJson
public static Account fromJson(org.json.JSONObject json) throws org.json.JSONException
Deserializes aJSONObject
to an account object.- Parameters:
json
- TheJSONObject
to deserialize.- Returns:
- An account object deserialized from the
JSONObject
. - Throws:
org.json.JSONException
- If parsing theJSONObject
fails.
-
getId
public short getId()
- Returns:
- The id of the account.
-
getName
public java.lang.String getName()
- Returns:
- The name of the account.
-
getStatus
public Account.AccountStatus getStatus()
- Returns:
- The status 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 theContainer
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, ornull
if such a container does not exist.
-
getContainerByName
public Container getContainerByName(java.lang.String containerName)
Gets theContainer
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, ornull
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 ofAccount[id]
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The String representation of this account.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-