Class AccountState
- java.lang.Object
-
- com.google.gerrit.server.account.AccountState
-
public class AccountState extends Object
Superset of all information related to an Account. This includes external IDs, project watches, and properties from the account config file. AccountState maps one-to-one to Account.Most callers should not construct AccountStates directly but rather lookup accounts via the account cache (see
AccountCache.get(Account.Id)
).
-
-
Field Summary
Fields Modifier and Type Field Description static com.google.common.base.Function<AccountState,Account.Id>
ACCOUNT_ID_FUNCTION
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkPassword(String password, String username)
static AccountState
forAccount(AllUsersName allUsersName, Account account)
Creates an AccountState for a given account with no external IDs, no project watches and default preferences.static AccountState
forAccount(AllUsersName allUsersName, Account account, Collection<ExternalId> extIds)
Creates an AccountState for a given account with no project watches and default preferences.static Optional<AccountState>
fromAccountConfig(AllUsersName allUsersName, ExternalIds externalIds, AccountConfig accountConfig)
Creates an AccountState from the given account config.static Optional<AccountState>
fromAccountConfig(AllUsersName allUsersName, ExternalIds externalIds, AccountConfig accountConfig, ExternalIdNotes extIdNotes)
Creates an AccountState from the given account config.<T> T
get(CurrentUser.PropertyKey<T> key)
Lookup a previously stored property.Account
getAccount()
Get the cached account metadata.AllUsersName
getAllUsersNameForIndexing()
DiffPreferencesInfo
getDiffPreferences()
The diff preferences of the account.EditPreferencesInfo
getEditPreferences()
The edit preferences of the account.com.google.common.collect.ImmutableSet<ExternalId>
getExternalIds()
The external identities that identify the account holder.com.google.common.collect.ImmutableSet<ExternalId>
getExternalIds(String scheme)
The external identities that identify the account holder that match the given scheme.GeneralPreferencesInfo
getGeneralPreferences()
The general preferences of the account.com.google.common.collect.ImmutableMap<ProjectWatches.ProjectWatchKey,com.google.common.collect.ImmutableSet<ProjectWatches.NotifyType>>
getProjectWatches()
The project watches of the account.Optional<String>
getUserName()
Get the username, if one has been declared for this user.<T> void
put(CurrentUser.PropertyKey<T> key, T value)
Store a property for later retrieval.String
toString()
-
-
-
Field Detail
-
ACCOUNT_ID_FUNCTION
public static final com.google.common.base.Function<AccountState,Account.Id> ACCOUNT_ID_FUNCTION
-
-
Method Detail
-
fromAccountConfig
public static Optional<AccountState> fromAccountConfig(AllUsersName allUsersName, ExternalIds externalIds, AccountConfig accountConfig) throws IOException
Creates an AccountState from the given account config.- Parameters:
allUsersName
- the name of the All-Users repositoryexternalIds
- class to access external IDsaccountConfig
- the account config, must already be loaded- Returns:
- the account state,
Optional.empty()
if the account doesn't exist - Throws:
IOException
- if accessing the external IDs fails
-
fromAccountConfig
public static Optional<AccountState> fromAccountConfig(AllUsersName allUsersName, ExternalIds externalIds, AccountConfig accountConfig, ExternalIdNotes extIdNotes) throws IOException
Creates an AccountState from the given account config.If external ID notes are provided the revision of the external IDs branch from which the external IDs for the account should be loaded is taken from the external ID notes. If external ID notes are not given the revision of the external IDs branch is taken from the account config. Updating external IDs is done via
ExternalIdNotes
and if external IDs were updated the revision of the external IDs branch in account config is outdated. Hence after updating external IDs the external ID notes must be provided.- Parameters:
allUsersName
- the name of the All-Users repositoryexternalIds
- class to access external IDsaccountConfig
- the account config, must already be loadedextIdNotes
- external ID notes, must already be loaded, may benull
- Returns:
- the account state,
Optional.empty()
if the account doesn't exist - Throws:
IOException
- if accessing the external IDs fails
-
forAccount
public static AccountState forAccount(AllUsersName allUsersName, Account account)
Creates an AccountState for a given account with no external IDs, no project watches and default preferences.- Parameters:
allUsersName
- the name of the All-Users repositoryaccount
- the account- Returns:
- the account state
-
forAccount
public static AccountState forAccount(AllUsersName allUsersName, Account account, Collection<ExternalId> extIds)
Creates an AccountState for a given account with no project watches and default preferences.- Parameters:
allUsersName
- the name of the All-Users repositoryaccount
- the accountextIds
- the external IDs- Returns:
- the account state
-
getAllUsersNameForIndexing
public AllUsersName getAllUsersNameForIndexing()
-
getAccount
public Account getAccount()
Get the cached account metadata.
-
getUserName
public Optional<String> getUserName()
Get the username, if one has been declared for this user.The username is the
ExternalId
using the schemeExternalId.SCHEME_USERNAME
.- Returns:
- the username,
Optional.empty()
if the user has no username, or if the username is empty
-
getExternalIds
public com.google.common.collect.ImmutableSet<ExternalId> getExternalIds()
The external identities that identify the account holder.
-
getExternalIds
public com.google.common.collect.ImmutableSet<ExternalId> getExternalIds(String scheme)
The external identities that identify the account holder that match the given scheme.
-
getProjectWatches
public com.google.common.collect.ImmutableMap<ProjectWatches.ProjectWatchKey,com.google.common.collect.ImmutableSet<ProjectWatches.NotifyType>> getProjectWatches()
The project watches of the account.
-
getGeneralPreferences
public GeneralPreferencesInfo getGeneralPreferences()
The general preferences of the account.
-
getDiffPreferences
public DiffPreferencesInfo getDiffPreferences()
The diff preferences of the account.
-
getEditPreferences
public EditPreferencesInfo getEditPreferences()
The edit preferences of the account.
-
get
public <T> T get(CurrentUser.PropertyKey<T> key)
Lookup a previously stored property.All properties are automatically cleared when the account cache invalidates the
AccountState
. This method is thread-safe.- Parameters:
key
- unique property key.- Returns:
- previously stored value, or
null
.
-
put
public <T> void put(CurrentUser.PropertyKey<T> key, T value)
Store a property for later retrieval.This method is thread-safe.
- Parameters:
key
- unique property key.value
- value to store; ornull
to clear the value.
-
-