Package com.google.gerrit.server.account
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 theAll-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).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.gerrit.server.git.meta.VersionedMetaData
VersionedMetaData.BatchMetaDataUpdate, VersionedMetaData.PathInfo
-
-
Field Summary
-
Fields inherited from class com.google.gerrit.server.git.meta.VersionedMetaData
inserter, newTree, projectName, reader, revision, rw
-
-
Constructor Summary
Constructors Constructor Description AccountConfig(Account.Id accountId, AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.eclipse.jgit.revwalk.RevCommit
commit(MetaDataUpdate update)
Update this metadata branch, recording a new commit on its reference.void
error(ValidationError error)
Optional<org.eclipse.jgit.lib.ObjectId>
getExternalIdsRev()
Returns the revision of therefs/meta/external-ids
branch.Optional<Account>
getLoadedAccount()
Get the loaded account.Account
getNewAccount()
Creates a new account.com.google.common.collect.ImmutableMap<ProjectWatches.ProjectWatchKey,com.google.common.collect.ImmutableSet<NotifyConfig.NotifyType>>
getProjectWatches()
Get the project watches of the loaded account.protected String
getRefName()
Returns name of the reference storing this configuration.List<ValidationError>
getValidationErrors()
Get the validation errors, if any were discovered during parsing the account data.AccountConfig
load()
AccountConfig
load(org.eclipse.jgit.lib.ObjectId rev)
protected void
onLoad()
Set up the metadata, parsing any state from the loaded revision.protected boolean
onSave(org.eclipse.jgit.lib.CommitBuilder commit)
Save any changes to the metadata in a commit.AccountConfig
setAccount(Account account)
Sets the account.AccountConfig
setAccountDelta(AccountDelta accountDelta)
-
Methods inherited from class com.google.gerrit.server.git.meta.VersionedMetaData
commit, commitToNewRef, getObjectId, getPathInfos, getRevision, load, load, load, load, load, openUpdate, openUpdate, readConfig, readConfig, readFile, readTree, readUTF8, saveConfig, saveFile, saveUTF8, set, set, set
-
-
-
-
Constructor Detail
-
AccountConfig
public AccountConfig(Account.Id accountId, AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo)
-
-
Method Detail
-
getRefName
protected String getRefName()
Description copied from class:VersionedMetaData
Returns name of the reference storing this configuration.- Specified by:
getRefName
in classVersionedMetaData
-
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 therefs/meta/external-ids
branch.This revision can be used to load the external IDs of the loaded account lazily via
ExternalIds.byAccount(com.google.gerrit.entities.Account.Id, ObjectId)
.- Returns:
- revision of the
refs/meta/external-ids
branch,Optional.empty()
if norefs/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() 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
public AccountConfig setAccountDelta(AccountDelta accountDelta)
-
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 classVersionedMetaData
- 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 classVersionedMetaData
- 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 classVersionedMetaData
- 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 interfaceValidationError.Sink
-
-