public class AccountState
extends java.lang.Object
Most callers should not construct AccountStates directly but rather lookup accounts via the
account cache (see AccountCache.get(Account.Id)
).
Modifier and Type | Field and Description |
---|---|
static com.google.common.base.Function<AccountState,Account.Id> |
ACCOUNT_ID_FUNCTION |
Modifier and Type | Method and Description |
---|---|
boolean |
checkPassword(java.lang.String password,
java.lang.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,
java.util.Collection<ExternalId> extIds)
Creates an AccountState for a given account with no project watches and default preferences.
|
static java.util.Optional<AccountState> |
fromAccountConfig(AllUsersName allUsersName,
ExternalIds externalIds,
AccountConfig accountConfig)
Creates an AccountState from the given account config.
|
static java.util.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(java.lang.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.
|
java.util.Optional<java.lang.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.
|
java.lang.String |
toString() |
public static final com.google.common.base.Function<AccountState,Account.Id> ACCOUNT_ID_FUNCTION
public static java.util.Optional<AccountState> fromAccountConfig(AllUsersName allUsersName, ExternalIds externalIds, AccountConfig accountConfig) throws java.io.IOException
allUsersName
- the name of the All-Users repositoryexternalIds
- class to access external IDsaccountConfig
- the account config, must already be loadedOptional.empty()
if the account doesn't existjava.io.IOException
- if accessing the external IDs failspublic static java.util.Optional<AccountState> fromAccountConfig(AllUsersName allUsersName, ExternalIds externalIds, AccountConfig accountConfig, ExternalIdNotes extIdNotes) throws java.io.IOException
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.
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 be null
Optional.empty()
if the account doesn't existjava.io.IOException
- if accessing the external IDs failspublic static AccountState forAccount(AllUsersName allUsersName, Account account)
allUsersName
- the name of the All-Users repositoryaccount
- the accountpublic static AccountState forAccount(AllUsersName allUsersName, Account account, java.util.Collection<ExternalId> extIds)
allUsersName
- the name of the All-Users repositoryaccount
- the accountextIds
- the external IDspublic AllUsersName getAllUsersNameForIndexing()
public Account getAccount()
public java.util.Optional<java.lang.String> getUserName()
The username is the ExternalId
using the scheme ExternalId.SCHEME_USERNAME
.
Optional.empty()
if the user has no username, or if the username
is emptypublic boolean checkPassword(java.lang.String password, java.lang.String username)
public com.google.common.collect.ImmutableSet<ExternalId> getExternalIds()
public com.google.common.collect.ImmutableSet<ExternalId> getExternalIds(java.lang.String scheme)
public com.google.common.collect.ImmutableMap<ProjectWatches.ProjectWatchKey,com.google.common.collect.ImmutableSet<ProjectWatches.NotifyType>> getProjectWatches()
public GeneralPreferencesInfo getGeneralPreferences()
public DiffPreferencesInfo getDiffPreferences()
public EditPreferencesInfo getEditPreferences()
public <T> T get(CurrentUser.PropertyKey<T> key)
All properties are automatically cleared when the account cache invalidates the AccountState
. This method is thread-safe.
key
- unique property key.null
.public <T> void put(CurrentUser.PropertyKey<T> key, T value)
This method is thread-safe.
key
- unique property key.value
- value to store; or null
to clear the value.public java.lang.String toString()
toString
in class java.lang.Object