Class AccountConfig

java.lang.Object
com.google.gerrit.server.git.meta.VersionedMetaData
com.google.gerrit.server.account.AccountConfig
All Implemented Interfaces:
ValidationError.Sink

public class AccountConfig extends VersionedMetaData implements ValidationError.Sink
Reads/writes account data from/to a user branch in the All-Users repository.

This is the low-level API for account creation and account updates. Most callers should use AccountsUpdate for creating and updating accounts.

This class can read/write account properties, preferences (general, diff and edit preferences) and project watches.

The following files are read/written:

  • 'account.config': Contains the account properties. Parsing and writing it is delegated to AccountProperties.
  • 'preferences.config': Contains the preferences. Parsing and writing it is delegated to StoredPreferences.
  • 'account.config': Contains the project watches. Parsing and writing it is delegated to ProjectWatches.

The commit date of the first commit on the user branch is used as registration date of the account. The first commit may be an empty commit (since all config files are optional).

  • Constructor Details

    • AccountConfig

      public AccountConfig(Account.Id accountId, AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo)
  • Method Details

    • getRefName

      public String getRefName()
      Description copied from class: VersionedMetaData
      Returns name of the reference storing this configuration.
      Specified by:
      getRefName in class VersionedMetaData
    • load

      public AccountConfig load() throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
      Throws:
      IOException
      org.eclipse.jgit.errors.ConfigInvalidException
    • load

      public AccountConfig load(org.eclipse.jgit.lib.ObjectId rev) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
      Throws:
      IOException
      org.eclipse.jgit.errors.ConfigInvalidException
    • getLoadedAccount

      public Optional<Account> getLoadedAccount()
      Get the loaded account.
      Returns:
      the loaded account, Optional.empty() if load didn't find the account because it doesn't exist
      Throws:
      IllegalStateException - if the account was not loaded yet
    • getExternalIdsRev

      public Optional<org.eclipse.jgit.lib.ObjectId> getExternalIdsRev()
      Returns the revision of the refs/meta/external-ids branch.

      This revision can be used to load the external IDs of the loaded account lazily via ExternalIdsNoteDbImpl.byAccount(com.google.gerrit.entities.Account.Id, ObjectId).

      Returns:
      revision of the refs/meta/external-ids branch, Optional.empty() if no refs/meta/external-ids branch exists
    • getProjectWatches

      public com.google.common.collect.ImmutableMap<ProjectWatches.ProjectWatchKey,com.google.common.collect.ImmutableSet<NotifyConfig.NotifyType>> getProjectWatches()
      Get the project watches of the loaded account.
      Returns:
      the project watches of the loaded account
    • setAccount

      public AccountConfig setAccount(Account account)
      Sets the account. This means the loaded account will be overwritten with the given account.

      Changing the registration date of an account is not supported.

      Parameters:
      account - account that should be set
      Throws:
      IllegalStateException - if the account was not loaded yet
    • getNewAccount

      public Account getNewAccount(Instant registeredOn) throws com.google.gerrit.exceptions.DuplicateKeyException
      Creates a new account.
      Returns:
      the new account
      Throws:
      com.google.gerrit.exceptions.DuplicateKeyException - if the user branch already exists
    • setAccountDelta

      @CanIgnoreReturnValue public AccountConfig setAccountDelta(AccountDelta accountDelta)
    • asCachedPreferences

      public CachedPreferences asCachedPreferences()
      Returns the content of the preferences.config file wrapped as CachedPreferences.
    • onLoad

      protected void onLoad() throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
      Description copied from class: VersionedMetaData
      Set up the metadata, parsing any state from the loaded revision.
      Specified by:
      onLoad in class VersionedMetaData
      Throws:
      IOException
      org.eclipse.jgit.errors.ConfigInvalidException
    • commit

      @CanIgnoreReturnValue public org.eclipse.jgit.revwalk.RevCommit commit(MetaDataUpdate update) throws IOException
      Description copied from class: VersionedMetaData
      Update this metadata branch, recording a new commit on its reference. This method mutates its receiver.
      Overrides:
      commit in class VersionedMetaData
      Parameters:
      update - helper information to define the update that will occur.
      Returns:
      the commit that was created
      Throws:
      IOException - if there is a storage problem and the update cannot be executed as requested or if it failed because of a concurrent update to the same reference
    • onSave

      protected boolean onSave(org.eclipse.jgit.lib.CommitBuilder commit) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
      Description copied from class: VersionedMetaData
      Save any changes to the metadata in a commit.
      Specified by:
      onSave in class VersionedMetaData
      Returns:
      true if the commit should proceed, false to abort.
      Throws:
      IOException
      org.eclipse.jgit.errors.ConfigInvalidException
    • getValidationErrors

      public List<ValidationError> getValidationErrors()
      Get the validation errors, if any were discovered during parsing the account data.
      Returns:
      list of errors; empty list if there are no errors.
    • error

      public void error(ValidationError error)
      Specified by:
      error in interface ValidationError.Sink