public class AccountConfig extends VersionedMetaData implements ValidationError.Sink
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:
AccountProperties
.
Preferences
.
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).
VersionedMetaData.BatchMetaDataUpdate, VersionedMetaData.PathInfo
inserter, newTree, projectName, reader, revision, rw
Constructor and Description |
---|
AccountConfig(Account.Id accountId,
AllUsersName allUsersName,
org.eclipse.jgit.lib.Repository allUsersRepo) |
Modifier and Type | Method and Description |
---|---|
org.eclipse.jgit.revwalk.RevCommit |
commit(MetaDataUpdate update)
Update this metadata branch, recording a new commit on its reference.
|
void |
error(ValidationError error) |
DiffPreferencesInfo |
getDiffPreferences()
Get the diff preferences of the loaded account.
|
EditPreferencesInfo |
getEditPreferences()
Get the edit preferences of the loaded account.
|
java.util.Optional<org.eclipse.jgit.lib.ObjectId> |
getExternalIdsRev()
Returns the revision of the
refs/meta/external-ids branch. |
GeneralPreferencesInfo |
getGeneralPreferences()
Get the general preferences of the loaded account.
|
java.util.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<ProjectWatches.NotifyType>> |
getProjectWatches()
Get the project watches of the loaded account.
|
protected java.lang.String |
getRefName() |
java.util.List<ValidationError> |
getValidationErrors()
Get the validation errors, if any were discovered during parsing the account data.
|
AccountConfig |
load() |
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 |
setAccountUpdate(InternalAccountUpdate accountUpdate) |
commitToNewRef, getObjectId, getPathInfos, getRevision, load, load, load, load, load, openUpdate, readConfig, readConfig, readFile, readTree, readUTF8, saveConfig, saveFile, saveUTF8, set, set, set
public AccountConfig(Account.Id accountId, AllUsersName allUsersName, org.eclipse.jgit.lib.Repository allUsersRepo)
protected java.lang.String getRefName()
getRefName
in class VersionedMetaData
public AccountConfig load() throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
java.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public java.util.Optional<Account> getLoadedAccount()
Optional.empty()
if load didn't find the account because it
doesn't existjava.lang.IllegalStateException
- if the account was not loaded yetpublic java.util.Optional<org.eclipse.jgit.lib.ObjectId> getExternalIdsRev()
refs/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.reviewdb.client.Account.Id, ObjectId)
.
refs/meta/external-ids
branch, Optional.empty()
if no
refs/meta/external-ids
branch existspublic com.google.common.collect.ImmutableMap<ProjectWatches.ProjectWatchKey,com.google.common.collect.ImmutableSet<ProjectWatches.NotifyType>> getProjectWatches()
public GeneralPreferencesInfo getGeneralPreferences()
public DiffPreferencesInfo getDiffPreferences()
public EditPreferencesInfo getEditPreferences()
public AccountConfig setAccount(Account account)
Changing the registration date of an account is not supported.
account
- account that should be setjava.lang.IllegalStateException
- if the account was not loaded yetpublic Account getNewAccount() throws com.google.gerrit.exceptions.DuplicateKeyException
com.google.gerrit.exceptions.DuplicateKeyException
- if the user branch already existspublic AccountConfig setAccountUpdate(InternalAccountUpdate accountUpdate)
protected void onLoad() throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
VersionedMetaData
onLoad
in class VersionedMetaData
java.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public org.eclipse.jgit.revwalk.RevCommit commit(MetaDataUpdate update) throws java.io.IOException
VersionedMetaData
commit
in class VersionedMetaData
update
- helper information to define the update that will occur.java.io.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 referenceprotected boolean onSave(org.eclipse.jgit.lib.CommitBuilder commit) throws java.io.IOException, org.eclipse.jgit.errors.ConfigInvalidException
VersionedMetaData
onSave
in class VersionedMetaData
java.io.IOException
org.eclipse.jgit.errors.ConfigInvalidException
public java.util.List<ValidationError> getValidationErrors()
public void error(ValidationError error)
error
in interface ValidationError.Sink