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
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).
-
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
ConstructorsConstructorDescriptionAccountConfig
(Account.Id accountId, AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo) -
Method Summary
Modifier and TypeMethodDescriptionReturns the content of thepreferences.config
file wrapped asCachedPreferences
.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>
Returns the revision of therefs/meta/external-ids
branch.Get the loaded account.getNewAccount
(Instant registeredOn) Creates a new account.com.google.common.collect.ImmutableMap<ProjectWatches.ProjectWatchKey,
com.google.common.collect.ImmutableSet<NotifyConfig.NotifyType>> Get the project watches of the loaded account.Returns name of the reference storing this configuration.Get the validation errors, if any were discovered during parsing the account data.load()
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.setAccount
(Account account) Sets the account.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 Details
-
AccountConfig
public AccountConfig(Account.Id accountId, AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo)
-
-
Method Details
-
getRefName
Description copied from class:VersionedMetaData
Returns name of the reference storing this configuration.- Specified by:
getRefName
in classVersionedMetaData
-
load
- 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
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
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
ExternalIdsNoteDbImpl.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
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
-
asCachedPreferences
Returns the content of thepreferences.config
file wrapped asCachedPreferences
. -
onLoad
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
@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 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
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
- Specified by:
error
in interfaceValidationError.Sink
-