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.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 Optional<AccountState>
fromAccountConfig(ExternalIds externalIds, AccountConfig accountConfig)
Creates an AccountState from the given account config.static Optional<AccountState>
fromAccountConfig(ExternalIds externalIds, AccountConfig accountConfig, ExternalIdNotes extIdNotes)
Creates an AccountState from the given account config.GeneralPreferencesInfo
generalPreferences()
The general preferences of the account.protected abstract Preferences.Diff
immutableDiffPreferences()
protected abstract Preferences.Edit
immutableEditPreferences()
protected abstract Preferences.General
immutableGeneralPreferences()
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.
-
-
-
Method Detail
-
fromAccountConfig
public static Optional<AccountState> fromAccountConfig(ExternalIds externalIds, AccountConfig accountConfig) throws IOException
Creates an AccountState from the given account config.- Parameters:
externalIds
- 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(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:
externalIds
- 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(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
-
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.
-
immutableGeneralPreferences
protected abstract Preferences.General immutableGeneralPreferences()
-
immutableDiffPreferences
protected abstract Preferences.Diff immutableDiffPreferences()
-
immutableEditPreferences
protected abstract Preferences.Edit immutableEditPreferences()
-
-