Class 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 Detail

      • AccountState

        public AccountState()
    • 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 IDs
        accountConfig - the account config, must already be loaded
        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
      • 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 IDs
        accountConfig - the account config, must already be loaded
        extIdNotes - external ID notes, must already be loaded, may be null
        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
      • 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 account
        extIds - 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.
      • 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 in preferences.config.
      • userPreferences

        protected abstract Optional<CachedPreferences> userPreferences()
        User preferences as stored in preferences.config.