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

      • AccountConfig

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

      • load

        public AccountConfig load​(org.eclipse.jgit.lib.ObjectId rev)
                           throws IOException,
                                  org.eclipse.jgit.errors.ConfigInvalidException
        Throws:
        IOException
        org.eclipse.jgit.errors.ConfigInvalidException
      • 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()
                              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
      • 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

        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.