Class 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 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 repository
        externalIds - class to access external IDs
        accountConfig - 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 repository
        externalIds - class to access external IDs
        accountConfig - the account config, must already be loaded
        extIdNotes - external ID notes, must already be loaded, may be null
        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 repository
        account - 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 repository
        account - the account
        extIds - the external IDs
        Returns:
        the account state
      • getAllUsersNameForIndexing

        public AllUsersName getAllUsersNameForIndexing()
      • getAccount

        public Account getAccount()
        Get the cached account metadata.
      • checkPassword

        public boolean checkPassword​(String password,
                                     String username)
      • 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.
      • 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; or null to clear the value.