Search in sources :

Example 1 with AccountConfig

use of com.google.gerrit.server.account.AccountConfig in project gerrit by GerritCodeReview.

the class AccountValidator method loadAccount.

private Optional<Account> loadAccount(Account.Id accountId, Repository allUsersRepo, RevWalk rw, ObjectId commit, @Nullable ImmutableList.Builder<String> messages) throws IOException, ConfigInvalidException {
    rw.reset();
    AccountConfig accountConfig = new AccountConfig(accountId, allUsersName, allUsersRepo);
    accountConfig.load(allUsersName, rw, commit);
    if (messages != null) {
        messages.addAll(accountConfig.getValidationErrors().stream().map(ValidationError::getMessage).collect(toSet()));
    }
    return accountConfig.getLoadedAccount();
}
Also used : ValidationError(com.google.gerrit.server.git.ValidationError) AccountConfig(com.google.gerrit.server.account.AccountConfig)

Example 2 with AccountConfig

use of com.google.gerrit.server.account.AccountConfig in project gerrit by GerritCodeReview.

the class AccountIndexerIT method updateAccountWithoutCacheOrIndex.

private void updateAccountWithoutCacheOrIndex(Account.Id accountId, AccountDelta accountDelta) throws IOException, ConfigInvalidException {
    try (Repository allUsersRepo = repoManager.openRepository(allUsersName);
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, allUsersRepo)) {
        PersonIdent ident = serverIdent.get();
        md.getCommitBuilder().setAuthor(ident);
        md.getCommitBuilder().setCommitter(ident);
        AccountConfig accountConfig = new AccountConfig(accountId, allUsersName, allUsersRepo).load();
        accountConfig.setAccountDelta(accountDelta);
        accountConfig.commit(md);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) AccountConfig(com.google.gerrit.server.account.AccountConfig)

Example 3 with AccountConfig

use of com.google.gerrit.server.account.AccountConfig in project gerrit by GerritCodeReview.

the class AbstractQueryAccountsTest method reindex.

// reindex permissions are tested by {@link AccountIT#reindexPermissions}
@Test
public void reindex() throws Exception {
    AccountInfo user1 = newAccountWithFullName("tester", "Test Usre");
    // update account without reindex so that account index is stale
    Account.Id accountId = Account.id(user1._accountId);
    String newName = "Test User";
    try (Repository repo = repoManager.openRepository(allUsers)) {
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsers, repo);
        PersonIdent ident = serverIdent.get();
        md.getCommitBuilder().setAuthor(ident);
        md.getCommitBuilder().setCommitter(ident);
        new AccountConfig(accountId, allUsers, repo).load().setAccountDelta(AccountDelta.builder().setFullName(newName).build()).commit(md);
    }
    // Querying for the account here will not result in a stale document because
    // we load AccountStates from the cache after reading documents from the index
    // which means we always read fresh data when matching.
    // 
    // Reindex document
    gApi.accounts().id(user1.username).index();
    assertQuery("name:" + quote(user1.name));
    assertQuery("name:" + quote(newName), user1);
}
Also used : Account(com.google.gerrit.entities.Account) Repository(org.eclipse.jgit.lib.Repository) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) AccountConfig(com.google.gerrit.server.account.AccountConfig) Test(org.junit.Test)

Aggregations

AccountConfig (com.google.gerrit.server.account.AccountConfig)3 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)2 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)2 PersonIdent (org.eclipse.jgit.lib.PersonIdent)2 Repository (org.eclipse.jgit.lib.Repository)2 Account (com.google.gerrit.entities.Account)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1 ValidationError (com.google.gerrit.server.git.ValidationError)1 Test (org.junit.Test)1