Package com.google.gerrit.server.account
Class AccountState
- java.lang.Object
-
- com.google.gerrit.server.account.AccountState
-
public abstract 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)
).
-
-
Constructor Summary
Constructors Constructor Description AccountState()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Account
account()
Get the cached account metadata.protected abstract Optional<CachedPreferences>
defaultPreferences()
Gerrit's default preferences as stored inpreferences.config
.DiffPreferencesInfo
diffPreferences()
The diff preferences of the account.EditPreferencesInfo
editPreferences()
The edit preferences of the account.abstract com.google.common.collect.ImmutableSet<ExternalId>
externalIds()
The external identities that identify the account holder.static AccountState
forAccount(Account account)
Creates an AccountState for a given account with no external IDs, no project watches and default preferences.static AccountState
forAccount(Account account, Collection<ExternalId> extIds)
Creates an AccountState for a given account with no project watches and default preferences.static AccountState
forCachedAccount(CachedAccountDetails account, CachedPreferences defaultConfig, ExternalIds externalIds)
Creates an AccountState for a given account and external IDs.static Optional<AccountState>
fromAccountConfig(ExternalIds externalIds, AccountConfig accountConfig, ExternalIdNotes extIdNotes, CachedPreferences defaultPreferences)
Creates an AccountState from the given account config.static Optional<AccountState>
fromAccountConfig(ExternalIds externalIds, AccountConfig accountConfig, CachedPreferences defaultPreferences)
Creates an AccountState from the given account config.GeneralPreferencesInfo
generalPreferences()
The general preferences of the account.abstract com.google.common.collect.ImmutableMap<ProjectWatches.ProjectWatchKey,com.google.common.collect.ImmutableSet<ProjectWatches.NotifyType>>
projectWatches()
The project watches of the account.String
toString()
abstract Optional<String>
userName()
Get the username, if one has been declared for this user.protected abstract Optional<CachedPreferences>
userPreferences()
User preferences as stored inpreferences.config
.
-
-
-
Method Detail
-
fromAccountConfig
public static Optional<AccountState> fromAccountConfig(ExternalIds externalIds, AccountConfig accountConfig, CachedPreferences defaultPreferences) throws IOException
Creates an AccountState from the given account config.- Parameters:
externalIds
- class to access external IDsaccountConfig
- the account config, must already be loadeddefaultPreferences
- the default preferences for this Gerrit installation- 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(ExternalIds externalIds, AccountConfig accountConfig, ExternalIdNotes extIdNotes, CachedPreferences defaultPreferences) 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:
externalIds
- class to access external IDsaccountConfig
- the account config, must already be loadedextIdNotes
- external ID notes, must already be loaded, may benull
defaultPreferences
- the default preferences for this Gerrit installation- 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(Account account)
Creates an AccountState for a given account with no external IDs, no project watches and default preferences.- Parameters:
account
- the account- Returns:
- the account state
-
forCachedAccount
public static AccountState forCachedAccount(CachedAccountDetails account, CachedPreferences defaultConfig, ExternalIds externalIds) throws IOException
Creates an AccountState for a given account and external IDs.- Parameters:
account
- the account- Returns:
- the account state
- Throws:
IOException
-
forAccount
public static AccountState forAccount(Account account, Collection<ExternalId> extIds)
Creates an AccountState for a given account with no project watches and default preferences.- Parameters:
account
- the accountextIds
- the external IDs- Returns:
- the account state
-
account
public abstract Account account()
Get the cached account metadata.
-
externalIds
public abstract com.google.common.collect.ImmutableSet<ExternalId> externalIds()
The external identities that identify the account holder.
-
userName
public abstract Optional<String> userName()
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
-
projectWatches
public abstract com.google.common.collect.ImmutableMap<ProjectWatches.ProjectWatchKey,com.google.common.collect.ImmutableSet<ProjectWatches.NotifyType>> projectWatches()
The project watches of the account.
-
generalPreferences
public GeneralPreferencesInfo generalPreferences()
The general preferences of the account.
-
diffPreferences
public DiffPreferencesInfo diffPreferences()
The diff preferences of the account.
-
editPreferences
public EditPreferencesInfo editPreferences()
The edit preferences of the account.
-
defaultPreferences
protected abstract Optional<CachedPreferences> defaultPreferences()
Gerrit's default preferences as stored inpreferences.config
.
-
userPreferences
protected abstract Optional<CachedPreferences> userPreferences()
User preferences as stored inpreferences.config
.
-
-