Make Account an AutoValue
Change-Id: Iaf2fc09dee221cf25d05932ba8ccf30b047da014
This commit is contained in:
		@@ -61,9 +61,9 @@ public class AccountOperationsImpl implements AccountOperations {
 | 
			
		||||
  private Account.Id createAccount(TestAccountCreation accountCreation) throws Exception {
 | 
			
		||||
    AccountsUpdate.AccountUpdater accountUpdater =
 | 
			
		||||
        (account, updateBuilder) ->
 | 
			
		||||
            fillBuilder(updateBuilder, accountCreation, account.getAccount().getId());
 | 
			
		||||
            fillBuilder(updateBuilder, accountCreation, account.getAccount().id());
 | 
			
		||||
    AccountState createdAccount = createAccount(accountUpdater);
 | 
			
		||||
    return createdAccount.getAccount().getId();
 | 
			
		||||
    return createdAccount.getAccount().id();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private AccountState createAccount(AccountsUpdate.AccountUpdater accountUpdater)
 | 
			
		||||
@@ -131,9 +131,9 @@ public class AccountOperationsImpl implements AccountOperations {
 | 
			
		||||
    private TestAccount toTestAccount(AccountState accountState) {
 | 
			
		||||
      Account account = accountState.getAccount();
 | 
			
		||||
      return TestAccount.builder()
 | 
			
		||||
          .accountId(account.getId())
 | 
			
		||||
          .preferredEmail(Optional.ofNullable(account.getPreferredEmail()))
 | 
			
		||||
          .fullname(Optional.ofNullable(account.getFullName()))
 | 
			
		||||
          .accountId(account.id())
 | 
			
		||||
          .preferredEmail(Optional.ofNullable(account.preferredEmail()))
 | 
			
		||||
          .fullname(Optional.ofNullable(account.fullName()))
 | 
			
		||||
          .username(accountState.getUserName())
 | 
			
		||||
          .active(accountState.getAccount().isActive())
 | 
			
		||||
          .build();
 | 
			
		||||
 
 | 
			
		||||
@@ -85,7 +85,7 @@ public class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, Accoun
 | 
			
		||||
      throw new StorageException(
 | 
			
		||||
          String.format(
 | 
			
		||||
              "Failed to replace account %s in index %s: %s",
 | 
			
		||||
              as.getAccount().getId(), indexName, statusCode));
 | 
			
		||||
              as.getAccount().id(), indexName, statusCode));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -108,7 +108,7 @@ public class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, Accoun
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String getId(AccountState as) {
 | 
			
		||||
    return as.getAccount().getId().toString();
 | 
			
		||||
    return as.getAccount().id().toString();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -105,7 +105,7 @@ public class DeleteGpgKey implements RestModifyView<GpgKey, Input> {
 | 
			
		||||
          } catch (EmailException e) {
 | 
			
		||||
            logger.atSevere().withCause(e).log(
 | 
			
		||||
                "Cannot send GPG key deletion message to %s",
 | 
			
		||||
                rsrc.getUser().getAccount().getPreferredEmail());
 | 
			
		||||
                rsrc.getUser().getAccount().preferredEmail());
 | 
			
		||||
          }
 | 
			
		||||
          break;
 | 
			
		||||
        case FORCED:
 | 
			
		||||
 
 | 
			
		||||
@@ -137,7 +137,7 @@ public class PostGpgKeys implements RestModifyView<AccountResource, GpgKeysInput
 | 
			
		||||
        ExternalId.Key extIdKey = toExtIdKey(key.getFingerprint());
 | 
			
		||||
        Account account = getAccountByExternalId(extIdKey);
 | 
			
		||||
        if (account != null) {
 | 
			
		||||
          if (!account.getId().equals(rsrc.getUser().getAccountId())) {
 | 
			
		||||
          if (!account.id().equals(rsrc.getUser().getAccountId())) {
 | 
			
		||||
            throw new ResourceConflictException("GPG key already associated with another account");
 | 
			
		||||
          }
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -257,7 +257,7 @@ public class PostGpgKeys implements RestModifyView<AccountResource, GpgKeysInput
 | 
			
		||||
            } catch (EmailException e) {
 | 
			
		||||
              logger.atSevere().withCause(e).log(
 | 
			
		||||
                  "Cannot send GPG key added message to %s",
 | 
			
		||||
                  rsrc.getUser().getAccount().getPreferredEmail());
 | 
			
		||||
                  rsrc.getUser().getAccount().preferredEmail());
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          if (!toRemove.isEmpty()) {
 | 
			
		||||
@@ -267,8 +267,7 @@ public class PostGpgKeys implements RestModifyView<AccountResource, GpgKeysInput
 | 
			
		||||
                  .send();
 | 
			
		||||
            } catch (EmailException e) {
 | 
			
		||||
              logger.atSevere().withCause(e).log(
 | 
			
		||||
                  "Cannot send GPG key deleted message to %s",
 | 
			
		||||
                  user.getAccount().getPreferredEmail());
 | 
			
		||||
                  "Cannot send GPG key deleted message to %s", user.getAccount().preferredEmail());
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          break;
 | 
			
		||||
@@ -304,7 +303,7 @@ public class PostGpgKeys implements RestModifyView<AccountResource, GpgKeysInput
 | 
			
		||||
      String msg = "GPG key " + extIdKey.get() + " associated with multiple accounts: [";
 | 
			
		||||
      msg =
 | 
			
		||||
          accountStates.stream()
 | 
			
		||||
              .map(a -> a.getAccount().getId().toString())
 | 
			
		||||
              .map(a -> a.getAccount().id().toString())
 | 
			
		||||
              .collect(joining(", ", msg, "]"));
 | 
			
		||||
      throw new IllegalStateException(msg);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -118,7 +118,7 @@ class ContainerAuthFilter implements Filter {
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    WebSession ws = session.get();
 | 
			
		||||
    ws.setUserAccountId(who.get().getAccount().getId());
 | 
			
		||||
    ws.setUserAccountId(who.get().getAccount().id());
 | 
			
		||||
    ws.setAccessPathOk(AccessPath.GIT, true);
 | 
			
		||||
    ws.setAccessPathOk(AccessPath.REST_API, true);
 | 
			
		||||
    return true;
 | 
			
		||||
 
 | 
			
		||||
@@ -177,7 +177,7 @@ class ProjectBasicAuthFilter implements Filter {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private boolean succeedAuthentication(AccountState who) {
 | 
			
		||||
    setUserIdentified(who.getAccount().getId());
 | 
			
		||||
    setUserIdentified(who.getAccount().id());
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -163,8 +163,8 @@ class ProjectOAuthFilter implements Filter {
 | 
			
		||||
 | 
			
		||||
    Account account = who.get().getAccount();
 | 
			
		||||
    AuthRequest authRequest = AuthRequest.forExternalUser(authInfo.username);
 | 
			
		||||
    authRequest.setEmailAddress(account.getPreferredEmail());
 | 
			
		||||
    authRequest.setDisplayName(account.getFullName());
 | 
			
		||||
    authRequest.setEmailAddress(account.preferredEmail());
 | 
			
		||||
    authRequest.setDisplayName(account.fullName());
 | 
			
		||||
    authRequest.setPassword(authInfo.tokenOrSecret);
 | 
			
		||||
    authRequest.setAuthPlugin(authInfo.pluginName);
 | 
			
		||||
    authRequest.setAuthProvider(authInfo.exportName);
 | 
			
		||||
 
 | 
			
		||||
@@ -105,7 +105,7 @@ class RunAsFilter implements Filter {
 | 
			
		||||
 | 
			
		||||
      Account.Id target;
 | 
			
		||||
      try {
 | 
			
		||||
        target = accountResolver.resolve(runas).asUnique().getAccount().getId();
 | 
			
		||||
        target = accountResolver.resolve(runas).asUnique().getAccount().id();
 | 
			
		||||
      } catch (UnprocessableEntityException e) {
 | 
			
		||||
        replyError(req, res, SC_FORBIDDEN, "no account matches " + RUN_AS, null);
 | 
			
		||||
        return;
 | 
			
		||||
 
 | 
			
		||||
@@ -157,16 +157,16 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
 | 
			
		||||
      String displayName;
 | 
			
		||||
      if (accountState.get().getUserName().isPresent()) {
 | 
			
		||||
        displayName = accountState.get().getUserName().get();
 | 
			
		||||
      } else if (account.getFullName() != null && !account.getFullName().isEmpty()) {
 | 
			
		||||
        displayName = account.getFullName();
 | 
			
		||||
      } else if (account.getPreferredEmail() != null) {
 | 
			
		||||
        displayName = account.getPreferredEmail();
 | 
			
		||||
      } else if (account.fullName() != null && !account.fullName().isEmpty()) {
 | 
			
		||||
        displayName = account.fullName();
 | 
			
		||||
      } else if (account.preferredEmail() != null) {
 | 
			
		||||
        displayName = account.preferredEmail();
 | 
			
		||||
      } else {
 | 
			
		||||
        displayName = accountId.toString();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      Element linkElement = doc.createElement("a");
 | 
			
		||||
      linkElement.setAttribute("href", "?account_id=" + account.getId().toString());
 | 
			
		||||
      linkElement.setAttribute("href", "?account_id=" + account.id().toString());
 | 
			
		||||
      linkElement.setTextContent(displayName);
 | 
			
		||||
      userlistElement.appendChild(linkElement);
 | 
			
		||||
      userlistElement.appendChild(doc.createElement("br"));
 | 
			
		||||
@@ -176,7 +176,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private Optional<AuthResult> auth(Optional<AccountState> account) {
 | 
			
		||||
    return account.map(a -> new AuthResult(a.getAccount().getId(), null, false));
 | 
			
		||||
    return account.map(a -> new AuthResult(a.getAccount().id(), null, false));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private AuthResult auth(Account.Id account) {
 | 
			
		||||
@@ -196,7 +196,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
 | 
			
		||||
      getServletContext().log("Multiple accounts with username " + userName + " found");
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
    return auth(accountStates.get(0).getAccount().getId());
 | 
			
		||||
    return auth(accountStates.get(0).getAccount().id());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private Optional<AuthResult> byPreferredEmail(String email) {
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,7 @@ public class LuceneAccountIndex extends AbstractLuceneIndex<Account.Id, AccountS
 | 
			
		||||
  private static final String ID_SORT_FIELD = sortFieldName(ID);
 | 
			
		||||
 | 
			
		||||
  private static Term idTerm(AccountState as) {
 | 
			
		||||
    return idTerm(as.getAccount().getId());
 | 
			
		||||
    return idTerm(as.getAccount().id());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static Term idTerm(Account.Id id) {
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@
 | 
			
		||||
package com.google.gerrit.pgm.init;
 | 
			
		||||
 | 
			
		||||
import static com.google.common.base.Preconditions.checkArgument;
 | 
			
		||||
import static com.google.common.base.Preconditions.checkState;
 | 
			
		||||
import static java.nio.charset.StandardCharsets.UTF_8;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.pgm.init.api.AllUsersNameOnInitProvider;
 | 
			
		||||
@@ -60,63 +61,59 @@ public class AccountsOnInit {
 | 
			
		||||
    this.allUsers = allUsers.get();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void insert(Account account) throws IOException {
 | 
			
		||||
  public Account insert(Account.Builder account) throws IOException {
 | 
			
		||||
    File path = getPath();
 | 
			
		||||
    if (path != null) {
 | 
			
		||||
      try (Repository repo = new FileRepository(path);
 | 
			
		||||
          ObjectInserter oi = repo.newObjectInserter()) {
 | 
			
		||||
        PersonIdent ident =
 | 
			
		||||
            new PersonIdent(
 | 
			
		||||
                new GerritPersonIdentProvider(flags.cfg).get(), account.getRegisteredOn());
 | 
			
		||||
    try (Repository repo = new FileRepository(path);
 | 
			
		||||
        ObjectInserter oi = repo.newObjectInserter()) {
 | 
			
		||||
      PersonIdent ident =
 | 
			
		||||
          new PersonIdent(new GerritPersonIdentProvider(flags.cfg).get(), account.registeredOn());
 | 
			
		||||
 | 
			
		||||
        Config accountConfig = new Config();
 | 
			
		||||
        AccountProperties.writeToAccountConfig(
 | 
			
		||||
            InternalAccountUpdate.builder()
 | 
			
		||||
                .setActive(account.isActive())
 | 
			
		||||
                .setFullName(account.getFullName())
 | 
			
		||||
                .setPreferredEmail(account.getPreferredEmail())
 | 
			
		||||
                .setStatus(account.getStatus())
 | 
			
		||||
                .build(),
 | 
			
		||||
            accountConfig);
 | 
			
		||||
      Config accountConfig = new Config();
 | 
			
		||||
      AccountProperties.writeToAccountConfig(
 | 
			
		||||
          InternalAccountUpdate.builder()
 | 
			
		||||
              .setActive(!account.inactive())
 | 
			
		||||
              .setFullName(account.fullName())
 | 
			
		||||
              .setPreferredEmail(account.preferredEmail())
 | 
			
		||||
              .setStatus(account.status())
 | 
			
		||||
              .build(),
 | 
			
		||||
          accountConfig);
 | 
			
		||||
 | 
			
		||||
        DirCache newTree = DirCache.newInCore();
 | 
			
		||||
        DirCacheEditor editor = newTree.editor();
 | 
			
		||||
        final ObjectId blobId =
 | 
			
		||||
            oi.insert(Constants.OBJ_BLOB, accountConfig.toText().getBytes(UTF_8));
 | 
			
		||||
        editor.add(
 | 
			
		||||
            new PathEdit(AccountProperties.ACCOUNT_CONFIG) {
 | 
			
		||||
              @Override
 | 
			
		||||
              public void apply(DirCacheEntry ent) {
 | 
			
		||||
                ent.setFileMode(FileMode.REGULAR_FILE);
 | 
			
		||||
                ent.setObjectId(blobId);
 | 
			
		||||
              }
 | 
			
		||||
            });
 | 
			
		||||
        editor.finish();
 | 
			
		||||
      DirCache newTree = DirCache.newInCore();
 | 
			
		||||
      DirCacheEditor editor = newTree.editor();
 | 
			
		||||
      final ObjectId blobId = oi.insert(Constants.OBJ_BLOB, accountConfig.toText().getBytes(UTF_8));
 | 
			
		||||
      editor.add(
 | 
			
		||||
          new PathEdit(AccountProperties.ACCOUNT_CONFIG) {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void apply(DirCacheEntry ent) {
 | 
			
		||||
              ent.setFileMode(FileMode.REGULAR_FILE);
 | 
			
		||||
              ent.setObjectId(blobId);
 | 
			
		||||
            }
 | 
			
		||||
          });
 | 
			
		||||
      editor.finish();
 | 
			
		||||
 | 
			
		||||
        ObjectId treeId = newTree.writeTree(oi);
 | 
			
		||||
      ObjectId treeId = newTree.writeTree(oi);
 | 
			
		||||
 | 
			
		||||
        CommitBuilder cb = new CommitBuilder();
 | 
			
		||||
        cb.setTreeId(treeId);
 | 
			
		||||
        cb.setCommitter(ident);
 | 
			
		||||
        cb.setAuthor(ident);
 | 
			
		||||
        cb.setMessage("Create Account");
 | 
			
		||||
        ObjectId id = oi.insert(cb);
 | 
			
		||||
        oi.flush();
 | 
			
		||||
      CommitBuilder cb = new CommitBuilder();
 | 
			
		||||
      cb.setTreeId(treeId);
 | 
			
		||||
      cb.setCommitter(ident);
 | 
			
		||||
      cb.setAuthor(ident);
 | 
			
		||||
      cb.setMessage("Create Account");
 | 
			
		||||
      ObjectId id = oi.insert(cb);
 | 
			
		||||
      oi.flush();
 | 
			
		||||
 | 
			
		||||
        String refName = RefNames.refsUsers(account.getId());
 | 
			
		||||
        RefUpdate ru = repo.updateRef(refName);
 | 
			
		||||
        ru.setExpectedOldObjectId(ObjectId.zeroId());
 | 
			
		||||
        ru.setNewObjectId(id);
 | 
			
		||||
        ru.setRefLogIdent(ident);
 | 
			
		||||
        ru.setRefLogMessage("Create Account", false);
 | 
			
		||||
        Result result = ru.update();
 | 
			
		||||
        if (result != Result.NEW) {
 | 
			
		||||
          throw new IOException(
 | 
			
		||||
              String.format("Failed to update ref %s: %s", refName, result.name()));
 | 
			
		||||
        }
 | 
			
		||||
        account.setMetaId(id.name());
 | 
			
		||||
      String refName = RefNames.refsUsers(account.id());
 | 
			
		||||
      RefUpdate ru = repo.updateRef(refName);
 | 
			
		||||
      ru.setExpectedOldObjectId(ObjectId.zeroId());
 | 
			
		||||
      ru.setNewObjectId(id);
 | 
			
		||||
      ru.setRefLogIdent(ident);
 | 
			
		||||
      ru.setRefLogMessage("Create Account", false);
 | 
			
		||||
      Result result = ru.update();
 | 
			
		||||
      if (result != Result.NEW) {
 | 
			
		||||
        throw new IOException(String.format("Failed to update ref %s: %s", refName, result.name()));
 | 
			
		||||
      }
 | 
			
		||||
      account.setMetaId(id.name()).build();
 | 
			
		||||
    }
 | 
			
		||||
    return account.build();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public boolean hasAnyAccount() throws IOException {
 | 
			
		||||
@@ -133,6 +130,8 @@ public class AccountsOnInit {
 | 
			
		||||
  private File getPath() {
 | 
			
		||||
    Path basePath = site.resolve(flags.cfg.getString("gerrit", null, "basePath"));
 | 
			
		||||
    checkArgument(basePath != null, "gerrit.basePath must be configured");
 | 
			
		||||
    return FileKey.resolve(basePath.resolve(allUsers).toFile(), FS.DETECTED);
 | 
			
		||||
    File file = FileKey.resolve(basePath.resolve(allUsers).toFile(), FS.DETECTED);
 | 
			
		||||
    checkState(file != null, "%s does not exist", file.getAbsolutePath());
 | 
			
		||||
    return file;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -155,7 +155,7 @@ public class GroupsOnInit {
 | 
			
		||||
 | 
			
		||||
  private static InternalGroupUpdate getMemberAdditionUpdate(Account account) {
 | 
			
		||||
    return InternalGroupUpdate.builder()
 | 
			
		||||
        .setMemberModification(members -> Sets.union(members, ImmutableSet.of(account.getId())))
 | 
			
		||||
        .setMemberModification(members -> Sets.union(members, ImmutableSet.of(account.id())))
 | 
			
		||||
        .build();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -111,11 +111,9 @@ public class InitAdminUser implements InitStep {
 | 
			
		||||
        }
 | 
			
		||||
        externalIds.insert("Add external IDs for initial admin user", extIds);
 | 
			
		||||
 | 
			
		||||
        Account a = new Account(id, TimeUtil.nowTs());
 | 
			
		||||
        a.setFullName(name);
 | 
			
		||||
        a.setPreferredEmail(email);
 | 
			
		||||
        accounts.insert(a);
 | 
			
		||||
 | 
			
		||||
        Account persistedAccount =
 | 
			
		||||
            accounts.insert(
 | 
			
		||||
                Account.builder(id, TimeUtil.nowTs()).setFullName(name).setPreferredEmail(email));
 | 
			
		||||
        // Only two groups should exist at this point in time and hence iterating over all of them
 | 
			
		||||
        // is cheap.
 | 
			
		||||
        Optional<GroupReference> adminGroupReference =
 | 
			
		||||
@@ -127,7 +125,7 @@ public class InitAdminUser implements InitStep {
 | 
			
		||||
          throw new NoSuchGroupException("Administrators");
 | 
			
		||||
        }
 | 
			
		||||
        GroupReference adminGroup = adminGroupReference.get();
 | 
			
		||||
        groupsOnInit.addGroupMember(adminGroup.getUUID(), a);
 | 
			
		||||
        groupsOnInit.addGroupMember(adminGroup.getUUID(), persistedAccount);
 | 
			
		||||
 | 
			
		||||
        if (sshKey != null) {
 | 
			
		||||
          VersionedAuthorizedKeysOnInit authorizedKeys = authorizedKeysFactory.create(id).load();
 | 
			
		||||
@@ -135,7 +133,7 @@ public class InitAdminUser implements InitStep {
 | 
			
		||||
          authorizedKeys.save("Add SSH key for initial admin user\n");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        AccountState as = AccountState.forAccount(a, extIds);
 | 
			
		||||
        AccountState as = AccountState.forAccount(persistedAccount, extIds);
 | 
			
		||||
        for (AccountIndex accountIndex : accountIndexCollection.getWriteIndexes()) {
 | 
			
		||||
          accountIndex.replace(as);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,7 @@ import static com.google.gerrit.reviewdb.client.RefNames.REFS_USERS;
 | 
			
		||||
 | 
			
		||||
import com.google.auto.value.AutoValue;
 | 
			
		||||
import com.google.common.primitives.Ints;
 | 
			
		||||
import com.google.gerrit.common.Nullable;
 | 
			
		||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
 | 
			
		||||
import java.sql.Timestamp;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
@@ -43,7 +44,8 @@ import java.util.Optional;
 | 
			
		||||
 *   <li>{@link DiffPreferencesInfo}: user's preferences for rendering side-to-side and unified diff
 | 
			
		||||
 * </ul>
 | 
			
		||||
 */
 | 
			
		||||
public final class Account {
 | 
			
		||||
@AutoValue
 | 
			
		||||
public abstract class Account {
 | 
			
		||||
  public static Id id(int id) {
 | 
			
		||||
    return new AutoValue_Account_Id(id);
 | 
			
		||||
  }
 | 
			
		||||
@@ -118,30 +120,32 @@ public final class Account {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private Id accountId;
 | 
			
		||||
  public abstract Id id();
 | 
			
		||||
 | 
			
		||||
  /** Date and time the user registered with the review server. */
 | 
			
		||||
  private Timestamp registeredOn;
 | 
			
		||||
  public abstract Timestamp registeredOn();
 | 
			
		||||
 | 
			
		||||
  /** Full name of the user ("Given-name Surname" style). */
 | 
			
		||||
  private String fullName;
 | 
			
		||||
  @Nullable
 | 
			
		||||
  public abstract String fullName();
 | 
			
		||||
 | 
			
		||||
  /** Email address the user prefers to be contacted through. */
 | 
			
		||||
  private String preferredEmail;
 | 
			
		||||
  @Nullable
 | 
			
		||||
  public abstract String preferredEmail();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Is this user inactive? This is used to avoid showing some users (eg. former employees) in
 | 
			
		||||
   * auto-suggest.
 | 
			
		||||
   */
 | 
			
		||||
  private boolean inactive;
 | 
			
		||||
  public abstract boolean inactive();
 | 
			
		||||
 | 
			
		||||
  /** The user-settable status of this account (e.g. busy, OOO, available) */
 | 
			
		||||
  private String status;
 | 
			
		||||
  @Nullable
 | 
			
		||||
  public abstract String status();
 | 
			
		||||
 | 
			
		||||
  /** ID of the user branch from which the account was read. */
 | 
			
		||||
  private String metaId;
 | 
			
		||||
 | 
			
		||||
  protected Account() {}
 | 
			
		||||
  @Nullable
 | 
			
		||||
  public abstract String metaId();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Create a new account.
 | 
			
		||||
@@ -149,38 +153,11 @@ public final class Account {
 | 
			
		||||
   * @param newId unique id, see {@link com.google.gerrit.server.notedb.Sequences#nextAccountId()}.
 | 
			
		||||
   * @param registeredOn when the account was registered.
 | 
			
		||||
   */
 | 
			
		||||
  public Account(Account.Id newId, Timestamp registeredOn) {
 | 
			
		||||
    this.accountId = newId;
 | 
			
		||||
    this.registeredOn = registeredOn;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Get local id of this account, to link with in other entities */
 | 
			
		||||
  public Account.Id getId() {
 | 
			
		||||
    return accountId;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Get the full name of the user ("Given-name Surname" style). */
 | 
			
		||||
  public String getFullName() {
 | 
			
		||||
    return fullName;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Set the full name of the user ("Given-name Surname" style). */
 | 
			
		||||
  public void setFullName(String name) {
 | 
			
		||||
    if (name != null && !name.trim().isEmpty()) {
 | 
			
		||||
      fullName = name.trim();
 | 
			
		||||
    } else {
 | 
			
		||||
      fullName = null;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Email address the user prefers to be contacted through. */
 | 
			
		||||
  public String getPreferredEmail() {
 | 
			
		||||
    return preferredEmail;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Set the email address the user prefers to be contacted through. */
 | 
			
		||||
  public void setPreferredEmail(String addr) {
 | 
			
		||||
    preferredEmail = addr;
 | 
			
		||||
  public static Account.Builder builder(Account.Id newId, Timestamp registeredOn) {
 | 
			
		||||
    return new AutoValue_Account.Builder()
 | 
			
		||||
        .setInactive(false)
 | 
			
		||||
        .setId(newId)
 | 
			
		||||
        .setRegisteredOn(registeredOn);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -196,13 +173,13 @@ public final class Account {
 | 
			
		||||
   *     generic string containing the accountId.
 | 
			
		||||
   */
 | 
			
		||||
  public String getName() {
 | 
			
		||||
    if (fullName != null) {
 | 
			
		||||
      return fullName;
 | 
			
		||||
    if (fullName() != null) {
 | 
			
		||||
      return fullName();
 | 
			
		||||
    }
 | 
			
		||||
    if (preferredEmail != null) {
 | 
			
		||||
      return preferredEmail;
 | 
			
		||||
    if (preferredEmail() != null) {
 | 
			
		||||
      return preferredEmail();
 | 
			
		||||
    }
 | 
			
		||||
    return getName(accountId);
 | 
			
		||||
    return getName(id());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static String getName(Account.Id accountId) {
 | 
			
		||||
@@ -222,57 +199,65 @@ public final class Account {
 | 
			
		||||
   * </ul>
 | 
			
		||||
   */
 | 
			
		||||
  public String getNameEmail(String anonymousCowardName) {
 | 
			
		||||
    String name = fullName != null ? fullName : anonymousCowardName;
 | 
			
		||||
    String name = fullName() != null ? fullName() : anonymousCowardName;
 | 
			
		||||
    StringBuilder b = new StringBuilder();
 | 
			
		||||
    b.append(name);
 | 
			
		||||
    if (preferredEmail != null) {
 | 
			
		||||
    if (preferredEmail() != null) {
 | 
			
		||||
      b.append(" <");
 | 
			
		||||
      b.append(preferredEmail);
 | 
			
		||||
      b.append(preferredEmail());
 | 
			
		||||
      b.append(">");
 | 
			
		||||
    } else {
 | 
			
		||||
      b.append(" (");
 | 
			
		||||
      b.append(accountId.get());
 | 
			
		||||
      b.append(id().get());
 | 
			
		||||
      b.append(")");
 | 
			
		||||
    }
 | 
			
		||||
    return b.toString();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Get the date and time the user first registered. */
 | 
			
		||||
  public Timestamp getRegisteredOn() {
 | 
			
		||||
    return registeredOn;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getMetaId() {
 | 
			
		||||
    return metaId;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setMetaId(String metaId) {
 | 
			
		||||
    this.metaId = metaId;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public boolean isActive() {
 | 
			
		||||
    return !inactive;
 | 
			
		||||
    return !inactive();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setActive(boolean active) {
 | 
			
		||||
    inactive = !active;
 | 
			
		||||
  }
 | 
			
		||||
  public abstract Builder toBuilder();
 | 
			
		||||
 | 
			
		||||
  public String getStatus() {
 | 
			
		||||
    return status;
 | 
			
		||||
  }
 | 
			
		||||
  @AutoValue.Builder
 | 
			
		||||
  public abstract static class Builder {
 | 
			
		||||
    public abstract Id id();
 | 
			
		||||
 | 
			
		||||
  public void setStatus(String status) {
 | 
			
		||||
    this.status = status;
 | 
			
		||||
  }
 | 
			
		||||
    abstract Builder setId(Id id);
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean equals(Object o) {
 | 
			
		||||
    return o instanceof Account && ((Account) o).getId().equals(getId());
 | 
			
		||||
  }
 | 
			
		||||
    public abstract Timestamp registeredOn();
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int hashCode() {
 | 
			
		||||
    return getId().get();
 | 
			
		||||
    abstract Builder setRegisteredOn(Timestamp registeredOn);
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public abstract String fullName();
 | 
			
		||||
 | 
			
		||||
    public abstract Builder setFullName(String fullName);
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public abstract String preferredEmail();
 | 
			
		||||
 | 
			
		||||
    public abstract Builder setPreferredEmail(String preferredEmail);
 | 
			
		||||
 | 
			
		||||
    public abstract boolean inactive();
 | 
			
		||||
 | 
			
		||||
    public abstract Builder setInactive(boolean inactive);
 | 
			
		||||
 | 
			
		||||
    public Builder setActive(boolean active) {
 | 
			
		||||
      return setInactive(!active);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public abstract String status();
 | 
			
		||||
 | 
			
		||||
    public abstract Builder setStatus(String status);
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public abstract String metaId();
 | 
			
		||||
 | 
			
		||||
    public abstract Builder setMetaId(@Nullable String metaId);
 | 
			
		||||
 | 
			
		||||
    public abstract Account build();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -234,7 +234,7 @@ public class IdentifiedUser extends CurrentUser {
 | 
			
		||||
        groupBackend,
 | 
			
		||||
        enableReverseDnsLookup,
 | 
			
		||||
        remotePeerProvider,
 | 
			
		||||
        state.getAccount().getId(),
 | 
			
		||||
        state.getAccount().id(),
 | 
			
		||||
        realUser);
 | 
			
		||||
    this.state = state;
 | 
			
		||||
  }
 | 
			
		||||
@@ -330,8 +330,7 @@ public class IdentifiedUser extends CurrentUser {
 | 
			
		||||
  @Override
 | 
			
		||||
  public String getLoggableName() {
 | 
			
		||||
    return getUserName()
 | 
			
		||||
        .orElseGet(
 | 
			
		||||
            () -> firstNonNull(getAccount().getPreferredEmail(), "a/" + getAccountId().get()));
 | 
			
		||||
        .orElseGet(() -> firstNonNull(getAccount().preferredEmail(), "a/" + getAccountId().get()));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -403,29 +402,29 @@ public class IdentifiedUser extends CurrentUser {
 | 
			
		||||
  public PersonIdent newRefLogIdent(Date when, TimeZone tz) {
 | 
			
		||||
    final Account ua = getAccount();
 | 
			
		||||
 | 
			
		||||
    String name = ua.getFullName();
 | 
			
		||||
    String name = ua.fullName();
 | 
			
		||||
    if (name == null || name.isEmpty()) {
 | 
			
		||||
      name = ua.getPreferredEmail();
 | 
			
		||||
      name = ua.preferredEmail();
 | 
			
		||||
    }
 | 
			
		||||
    if (name == null || name.isEmpty()) {
 | 
			
		||||
      name = anonymousCowardName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    String user = getUserName().orElse("") + "|account-" + ua.getId().toString();
 | 
			
		||||
    String user = getUserName().orElse("") + "|account-" + ua.id().toString();
 | 
			
		||||
    return new PersonIdent(name, user + "@" + guessHost(), when, tz);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public PersonIdent newCommitterIdent(Date when, TimeZone tz) {
 | 
			
		||||
    final Account ua = getAccount();
 | 
			
		||||
    String name = ua.getFullName();
 | 
			
		||||
    String email = ua.getPreferredEmail();
 | 
			
		||||
    String name = ua.fullName();
 | 
			
		||||
    String email = ua.preferredEmail();
 | 
			
		||||
 | 
			
		||||
    if (email == null || email.isEmpty()) {
 | 
			
		||||
      // No preferred email is configured. Use a generic identity so we
 | 
			
		||||
      // don't leak an address the user may have given us, but doesn't
 | 
			
		||||
      // necessarily want to publish through Git records.
 | 
			
		||||
      //
 | 
			
		||||
      String user = getUserName().orElseGet(() -> "account-" + ua.getId().toString());
 | 
			
		||||
      String user = getUserName().orElseGet(() -> "account-" + ua.id().toString());
 | 
			
		||||
 | 
			
		||||
      String host;
 | 
			
		||||
      if (canonicalUrl.get() != null) {
 | 
			
		||||
 
 | 
			
		||||
@@ -129,7 +129,7 @@ public class AccountCacheImpl implements AccountCache {
 | 
			
		||||
    }
 | 
			
		||||
    for (Future<Optional<AccountState>> f : futures) {
 | 
			
		||||
      try {
 | 
			
		||||
        f.get().ifPresent(s -> accountStates.put(s.getAccount().getId(), s));
 | 
			
		||||
        f.get().ifPresent(s -> accountStates.put(s.getAccount().id(), s));
 | 
			
		||||
      } catch (InterruptedException | ExecutionException e) {
 | 
			
		||||
        logger.atSevere().withCause(e).log("Cannot load AccountState");
 | 
			
		||||
      }
 | 
			
		||||
@@ -165,9 +165,9 @@ public class AccountCacheImpl implements AccountCache {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private AccountState missing(Account.Id accountId) {
 | 
			
		||||
    Account account = new Account(accountId, TimeUtil.nowTs());
 | 
			
		||||
    Account.Builder account = Account.builder(accountId, TimeUtil.nowTs());
 | 
			
		||||
    account.setActive(false);
 | 
			
		||||
    return AccountState.forAccount(account);
 | 
			
		||||
    return AccountState.forAccount(account.build());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static class ByIdLoader extends CacheLoader<Account.Id, Optional<AccountState>> {
 | 
			
		||||
 
 | 
			
		||||
@@ -184,14 +184,14 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
 | 
			
		||||
    checkLoaded();
 | 
			
		||||
    this.loadedAccountProperties =
 | 
			
		||||
        Optional.of(
 | 
			
		||||
            new AccountProperties(account.getId(), account.getRegisteredOn(), new Config(), null));
 | 
			
		||||
            new AccountProperties(account.id(), account.registeredOn(), new Config(), null));
 | 
			
		||||
    this.accountUpdate =
 | 
			
		||||
        Optional.of(
 | 
			
		||||
            InternalAccountUpdate.builder()
 | 
			
		||||
                .setActive(account.isActive())
 | 
			
		||||
                .setFullName(account.getFullName())
 | 
			
		||||
                .setPreferredEmail(account.getPreferredEmail())
 | 
			
		||||
                .setStatus(account.getStatus())
 | 
			
		||||
                .setFullName(account.fullName())
 | 
			
		||||
                .setPreferredEmail(account.preferredEmail())
 | 
			
		||||
                .setStatus(account.status())
 | 
			
		||||
                .build());
 | 
			
		||||
    return this;
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -133,7 +133,7 @@ public class AccountControl {
 | 
			
		||||
        new OtherUser() {
 | 
			
		||||
          @Override
 | 
			
		||||
          Account.Id getId() {
 | 
			
		||||
            return otherUser.getAccount().getId();
 | 
			
		||||
            return otherUser.getAccount().id();
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -108,7 +108,7 @@ public class AccountDeactivator implements Runnable {
 | 
			
		||||
    logger.atFine().log("processing account %s", userName);
 | 
			
		||||
    try {
 | 
			
		||||
      if (realm.accountBelongsToRealm(accountState.getExternalIds()) && !realm.isActive(userName)) {
 | 
			
		||||
        sif.deactivate(accountState.getAccount().getId());
 | 
			
		||||
        sif.deactivate(accountState.getAccount().id());
 | 
			
		||||
        logger.atInfo().log("deactivated account %s", userName);
 | 
			
		||||
        return true;
 | 
			
		||||
      }
 | 
			
		||||
@@ -117,7 +117,7 @@ public class AccountDeactivator implements Runnable {
 | 
			
		||||
    } catch (Exception e) {
 | 
			
		||||
      logger.atSevere().withCause(e).log(
 | 
			
		||||
          "Error deactivating account: %s (%s) %s",
 | 
			
		||||
          userName, accountState.getAccount().getId(), e.getMessage());
 | 
			
		||||
          userName, accountState.getAccount().id(), e.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -195,18 +195,18 @@ public class AccountManager {
 | 
			
		||||
 | 
			
		||||
    if (authRequest.isActive()) {
 | 
			
		||||
      try {
 | 
			
		||||
        setInactiveFlag.activate(account.getId());
 | 
			
		||||
        setInactiveFlag.activate(account.id());
 | 
			
		||||
      } catch (Exception e) {
 | 
			
		||||
        throw new AccountException("Unable to activate account " + account.getId(), e);
 | 
			
		||||
        throw new AccountException("Unable to activate account " + account.id(), e);
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      try {
 | 
			
		||||
        setInactiveFlag.deactivate(account.getId());
 | 
			
		||||
        setInactiveFlag.deactivate(account.id());
 | 
			
		||||
      } catch (Exception e) {
 | 
			
		||||
        throw new AccountException("Unable to deactivate account " + account.getId(), e);
 | 
			
		||||
        throw new AccountException("Unable to deactivate account " + account.id(), e);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return byIdCache.get(account.getId()).map(AccountState::getAccount);
 | 
			
		||||
    return byIdCache.get(account.id()).map(AccountState::getAccount);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private boolean shouldUpdateActiveStatus(AuthRequest authRequest) {
 | 
			
		||||
@@ -229,20 +229,20 @@ public class AccountManager {
 | 
			
		||||
      checkEmailNotUsed(extIdWithNewEmail);
 | 
			
		||||
      accountUpdates.add(u -> u.replaceExternalId(extId, extIdWithNewEmail));
 | 
			
		||||
 | 
			
		||||
      if (oldEmail != null && oldEmail.equals(user.getAccount().getPreferredEmail())) {
 | 
			
		||||
      if (oldEmail != null && oldEmail.equals(user.getAccount().preferredEmail())) {
 | 
			
		||||
        accountUpdates.add(u -> u.setPreferredEmail(newEmail));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!Strings.isNullOrEmpty(who.getDisplayName())
 | 
			
		||||
        && !Objects.equals(user.getAccount().getFullName(), who.getDisplayName())) {
 | 
			
		||||
        && !Objects.equals(user.getAccount().fullName(), who.getDisplayName())) {
 | 
			
		||||
      accountUpdates.add(u -> u.setFullName(who.getDisplayName()));
 | 
			
		||||
      if (realm.allowsEdit(AccountFieldName.FULL_NAME)) {
 | 
			
		||||
        accountUpdates.add(a -> a.setFullName(who.getDisplayName()));
 | 
			
		||||
      } else {
 | 
			
		||||
        logger.atWarning().log(
 | 
			
		||||
            "Not changing already set display name '%s' to '%s'",
 | 
			
		||||
            user.getAccount().getFullName(), who.getDisplayName());
 | 
			
		||||
            user.getAccount().fullName(), who.getDisplayName());
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -420,7 +420,7 @@ public class AccountManager {
 | 
			
		||||
              to,
 | 
			
		||||
              (a, u) -> {
 | 
			
		||||
                u.addExternalId(newExtId);
 | 
			
		||||
                if (who.getEmailAddress() != null && a.getAccount().getPreferredEmail() == null) {
 | 
			
		||||
                if (who.getEmailAddress() != null && a.getAccount().preferredEmail() == null) {
 | 
			
		||||
                  u.setPreferredEmail(who.getEmailAddress());
 | 
			
		||||
                }
 | 
			
		||||
              });
 | 
			
		||||
@@ -511,9 +511,9 @@ public class AccountManager {
 | 
			
		||||
            from,
 | 
			
		||||
            (a, u) -> {
 | 
			
		||||
              u.deleteExternalIds(extIds);
 | 
			
		||||
              if (a.getAccount().getPreferredEmail() != null
 | 
			
		||||
              if (a.getAccount().preferredEmail() != null
 | 
			
		||||
                  && extIds.stream()
 | 
			
		||||
                      .anyMatch(e -> a.getAccount().getPreferredEmail().equals(e.email()))) {
 | 
			
		||||
                      .anyMatch(e -> a.getAccount().preferredEmail().equals(e.email()))) {
 | 
			
		||||
                u.setPreferredEmail(null);
 | 
			
		||||
              }
 | 
			
		||||
            });
 | 
			
		||||
 
 | 
			
		||||
@@ -88,15 +88,16 @@ public class AccountProperties {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void parse() {
 | 
			
		||||
    account = new Account(accountId, registeredOn);
 | 
			
		||||
    account.setActive(accountConfig.getBoolean(ACCOUNT, null, KEY_ACTIVE, true));
 | 
			
		||||
    account.setFullName(get(accountConfig, KEY_FULL_NAME));
 | 
			
		||||
    Account.Builder accountBuilder = Account.builder(accountId, registeredOn);
 | 
			
		||||
    accountBuilder.setActive(accountConfig.getBoolean(ACCOUNT, null, KEY_ACTIVE, true));
 | 
			
		||||
    accountBuilder.setFullName(get(accountConfig, KEY_FULL_NAME));
 | 
			
		||||
 | 
			
		||||
    String preferredEmail = get(accountConfig, KEY_PREFERRED_EMAIL);
 | 
			
		||||
    account.setPreferredEmail(preferredEmail);
 | 
			
		||||
    accountBuilder.setPreferredEmail(preferredEmail);
 | 
			
		||||
 | 
			
		||||
    account.setStatus(get(accountConfig, KEY_STATUS));
 | 
			
		||||
    account.setMetaId(metaId != null ? metaId.name() : null);
 | 
			
		||||
    accountBuilder.setStatus(get(accountConfig, KEY_STATUS));
 | 
			
		||||
    accountBuilder.setMetaId(metaId != null ? metaId.name() : null);
 | 
			
		||||
    account = accountBuilder.build();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Config save(InternalAccountUpdate accountUpdate) {
 | 
			
		||||
 
 | 
			
		||||
@@ -113,7 +113,7 @@ public class AccountResolver {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static String formatForException(Result result, AccountState state) {
 | 
			
		||||
    return state.getAccount().getId()
 | 
			
		||||
    return state.getAccount().id()
 | 
			
		||||
        + ": "
 | 
			
		||||
        + state.getAccount().getNameEmail(result.accountResolver().anonymousCowardName);
 | 
			
		||||
  }
 | 
			
		||||
@@ -135,7 +135,7 @@ public class AccountResolver {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private ImmutableList<AccountState> canonicalize(List<AccountState> list) {
 | 
			
		||||
      TreeSet<AccountState> set = new TreeSet<>(comparing(a -> a.getAccount().getId().get()));
 | 
			
		||||
      TreeSet<AccountState> set = new TreeSet<>(comparing(a -> a.getAccount().id().get()));
 | 
			
		||||
      set.addAll(requireNonNull(list));
 | 
			
		||||
      return ImmutableList.copyOf(set);
 | 
			
		||||
    }
 | 
			
		||||
@@ -160,7 +160,7 @@ public class AccountResolver {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ImmutableSet<Account.Id> asIdSet() {
 | 
			
		||||
      return list.stream().map(a -> a.getAccount().getId()).collect(toImmutableSet());
 | 
			
		||||
      return list.stream().map(a -> a.getAccount().id()).collect(toImmutableSet());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public AccountState asUnique() throws UnresolvableAccountException {
 | 
			
		||||
@@ -192,7 +192,7 @@ public class AccountResolver {
 | 
			
		||||
        return self.get().asIdentifiedUser();
 | 
			
		||||
      }
 | 
			
		||||
      return userFactory.runAs(
 | 
			
		||||
          null, list.get(0).getAccount().getId(), requireNonNull(caller).getRealUser());
 | 
			
		||||
          null, list.get(0).getAccount().id(), requireNonNull(caller).getRealUser());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @VisibleForTesting
 | 
			
		||||
@@ -349,7 +349,7 @@ public class AccountResolver {
 | 
			
		||||
      String name = nameOrEmail.substring(0, lt - 1);
 | 
			
		||||
      ImmutableList<AccountState> nameMatches =
 | 
			
		||||
          allMatches.stream()
 | 
			
		||||
              .filter(a -> name.equals(a.getAccount().getFullName()))
 | 
			
		||||
              .filter(a -> name.equals(a.getAccount().fullName()))
 | 
			
		||||
              .collect(toImmutableList());
 | 
			
		||||
      return !nameMatches.isEmpty() ? nameMatches.stream() : allMatches.stream();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -95,7 +95,7 @@ public class AccountState {
 | 
			
		||||
            : accountConfig.getExternalIdsRev();
 | 
			
		||||
    ImmutableSet<ExternalId> extIds =
 | 
			
		||||
        extIdsRev.isPresent()
 | 
			
		||||
            ? ImmutableSet.copyOf(externalIds.byAccount(account.getId(), extIdsRev.get()))
 | 
			
		||||
            ? ImmutableSet.copyOf(externalIds.byAccount(account.id(), extIdsRev.get()))
 | 
			
		||||
            : ImmutableSet.of();
 | 
			
		||||
 | 
			
		||||
    // Don't leak references to AccountConfig into the AccountState, since it holds a reference to
 | 
			
		||||
@@ -292,7 +292,7 @@ public class AccountState {
 | 
			
		||||
  @Override
 | 
			
		||||
  public String toString() {
 | 
			
		||||
    MoreObjects.ToStringHelper h = MoreObjects.toStringHelper(this);
 | 
			
		||||
    h.addValue(getAccount().getId());
 | 
			
		||||
    h.addValue(getAccount().id());
 | 
			
		||||
    return h.toString();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -36,13 +36,13 @@ public class AccountsConsistencyChecker {
 | 
			
		||||
 | 
			
		||||
    for (AccountState accountState : accounts.all()) {
 | 
			
		||||
      Account account = accountState.getAccount();
 | 
			
		||||
      if (account.getPreferredEmail() != null) {
 | 
			
		||||
      if (account.preferredEmail() != null) {
 | 
			
		||||
        if (!accountState.getExternalIds().stream()
 | 
			
		||||
            .anyMatch(e -> account.getPreferredEmail().equals(e.email()))) {
 | 
			
		||||
            .anyMatch(e -> account.preferredEmail().equals(e.email()))) {
 | 
			
		||||
          addError(
 | 
			
		||||
              String.format(
 | 
			
		||||
                  "Account '%s' has no external ID for its preferred email '%s'",
 | 
			
		||||
                  account.getId().get(), account.getPreferredEmail()),
 | 
			
		||||
                  account.id().get(), account.preferredEmail()),
 | 
			
		||||
              problems);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,7 @@ public class Emails {
 | 
			
		||||
    return Streams.concat(
 | 
			
		||||
            externalIds.byEmail(email).stream().map(ExternalId::accountId),
 | 
			
		||||
            executeIndexQuery(() -> queryProvider.get().byPreferredEmail(email).stream())
 | 
			
		||||
                .map(a -> a.getAccount().getId()))
 | 
			
		||||
                .map(a -> a.getAccount().id()))
 | 
			
		||||
        .collect(toImmutableSet());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -88,7 +88,7 @@ public class Emails {
 | 
			
		||||
    externalIds.byEmails(emails).entries().stream()
 | 
			
		||||
        .forEach(e -> builder.put(e.getKey(), e.getValue().accountId()));
 | 
			
		||||
    executeIndexQuery(() -> queryProvider.get().byPreferredEmail(emails).entries().stream())
 | 
			
		||||
        .forEach(e -> builder.put(e.getKey(), e.getValue().getAccount().getId()));
 | 
			
		||||
        .forEach(e -> builder.put(e.getKey(), e.getValue().getAccount().id()));
 | 
			
		||||
    return builder.build();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -105,7 +105,7 @@ public class InternalAccountDirectory extends AccountDirectory {
 | 
			
		||||
      AccountState state = accountStates.get(id);
 | 
			
		||||
      if (state != null) {
 | 
			
		||||
        if (!options.contains(FillOptions.SECONDARY_EMAILS)
 | 
			
		||||
            || Objects.equals(currentUserId, state.getAccount().getId())
 | 
			
		||||
            || Objects.equals(currentUserId, state.getAccount().id())
 | 
			
		||||
            || canModifyAccount) {
 | 
			
		||||
          fill(info, accountStates.get(id), options);
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -122,19 +122,19 @@ public class InternalAccountDirectory extends AccountDirectory {
 | 
			
		||||
  private void fill(AccountInfo info, AccountState accountState, Set<FillOptions> options) {
 | 
			
		||||
    Account account = accountState.getAccount();
 | 
			
		||||
    if (options.contains(FillOptions.ID)) {
 | 
			
		||||
      info._accountId = account.getId().get();
 | 
			
		||||
      info._accountId = account.id().get();
 | 
			
		||||
    } else {
 | 
			
		||||
      // Was previously set to look up account for filling.
 | 
			
		||||
      info._accountId = null;
 | 
			
		||||
    }
 | 
			
		||||
    if (options.contains(FillOptions.NAME)) {
 | 
			
		||||
      info.name = Strings.emptyToNull(account.getFullName());
 | 
			
		||||
      info.name = Strings.emptyToNull(account.fullName());
 | 
			
		||||
      if (info.name == null) {
 | 
			
		||||
        info.name = accountState.getUserName().orElse(null);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (options.contains(FillOptions.EMAIL)) {
 | 
			
		||||
      info.email = account.getPreferredEmail();
 | 
			
		||||
      info.email = account.preferredEmail();
 | 
			
		||||
    }
 | 
			
		||||
    if (options.contains(FillOptions.SECONDARY_EMAILS)) {
 | 
			
		||||
      info.secondaryEmails = getSecondaryEmails(account, accountState.getExternalIds());
 | 
			
		||||
@@ -144,14 +144,14 @@ public class InternalAccountDirectory extends AccountDirectory {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (options.contains(FillOptions.STATUS)) {
 | 
			
		||||
      info.status = account.getStatus();
 | 
			
		||||
      info.status = account.status();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (options.contains(FillOptions.AVATARS)) {
 | 
			
		||||
      AvatarProvider ap = avatar.get();
 | 
			
		||||
      if (ap != null) {
 | 
			
		||||
        info.avatars = new ArrayList<>();
 | 
			
		||||
        IdentifiedUser user = userFactory.create(account.getId());
 | 
			
		||||
        IdentifiedUser user = userFactory.create(account.id());
 | 
			
		||||
 | 
			
		||||
        // PolyGerrit UI uses the following sizes for avatars:
 | 
			
		||||
        // - 32px for avatars next to names e.g. on the dashboard. This is also Gerrit's default.
 | 
			
		||||
@@ -170,7 +170,7 @@ public class InternalAccountDirectory extends AccountDirectory {
 | 
			
		||||
 | 
			
		||||
  public List<String> getSecondaryEmails(Account account, Collection<ExternalId> externalIds) {
 | 
			
		||||
    return ExternalId.getEmails(externalIds)
 | 
			
		||||
        .filter(e -> !e.equals(account.getPreferredEmail()))
 | 
			
		||||
        .filter(e -> !e.equals(account.preferredEmail()))
 | 
			
		||||
        .sorted()
 | 
			
		||||
        .collect(toList());
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -141,7 +141,7 @@ class GroupsImpl implements Groups {
 | 
			
		||||
 | 
			
		||||
    if (req.getUser() != null) {
 | 
			
		||||
      try {
 | 
			
		||||
        list.setUser(accountResolver.resolve(req.getUser()).asUnique().getAccount().getId());
 | 
			
		||||
        list.setUser(accountResolver.resolve(req.getUser()).asUnique().getAccount().id());
 | 
			
		||||
      } catch (Exception e) {
 | 
			
		||||
        throw asRestApiException("Error looking up user " + req.getUser(), e);
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,7 @@ public class AccountIdHandler extends OptionHandler<Account.Id> {
 | 
			
		||||
    Account.Id accountId;
 | 
			
		||||
    try {
 | 
			
		||||
      try {
 | 
			
		||||
        accountId = accountResolver.resolve(token).asUnique().getAccount().getId();
 | 
			
		||||
        accountId = accountResolver.resolve(token).asUnique().getAccount().id();
 | 
			
		||||
      } catch (UnprocessableEntityException e) {
 | 
			
		||||
        switch (authType) {
 | 
			
		||||
          case HTTP_LDAP:
 | 
			
		||||
 
 | 
			
		||||
@@ -302,7 +302,7 @@ class LdapRealm extends AbstractRealm {
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void onCreateAccount(AuthRequest who, Account account) {
 | 
			
		||||
    usernameCache.put(who.getLocalUser(), Optional.of(account.getId()));
 | 
			
		||||
    usernameCache.put(who.getLocalUser(), Optional.of(account.id()));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -112,7 +112,7 @@ public class AbandonOp implements BatchUpdateOp {
 | 
			
		||||
    try {
 | 
			
		||||
      ReplyToChangeSender cm = abandonedSenderFactory.create(ctx.getProject(), change.getId());
 | 
			
		||||
      if (accountState != null) {
 | 
			
		||||
        cm.setFrom(accountState.getAccount().getId());
 | 
			
		||||
        cm.setFrom(accountState.getAccount().id());
 | 
			
		||||
      }
 | 
			
		||||
      cm.setChangeMessage(message.getMessage(), ctx.getWhen());
 | 
			
		||||
      cm.setNotify(notify);
 | 
			
		||||
 
 | 
			
		||||
@@ -211,9 +211,9 @@ public class ChangeResource implements RestResource, HasETag {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void hashAccount(Hasher h, AccountState accountState, byte[] buf) {
 | 
			
		||||
    h.putInt(accountState.getAccount().getId().get());
 | 
			
		||||
    h.putInt(accountState.getAccount().id().get());
 | 
			
		||||
    h.putString(
 | 
			
		||||
        MoreObjects.firstNonNull(accountState.getAccount().getMetaId(), ZERO_ID_STRING), UTF_8);
 | 
			
		||||
        MoreObjects.firstNonNull(accountState.getAccount().metaId(), ZERO_ID_STRING), UTF_8);
 | 
			
		||||
    accountState.getExternalIds().stream().forEach(e -> hashObjectId(h, e.blobId(), buf));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -108,7 +108,7 @@ public class DeleteReviewerOp implements BatchUpdateOp {
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean updateChange(ChangeContext ctx)
 | 
			
		||||
      throws AuthException, ResourceNotFoundException, PermissionBackendException, IOException {
 | 
			
		||||
    Account.Id reviewerId = reviewer.getAccount().getId();
 | 
			
		||||
    Account.Id reviewerId = reviewer.getAccount().id();
 | 
			
		||||
    // Check of removing this reviewer (even if there is no vote processed by the loop below) is OK
 | 
			
		||||
    removeReviewerControl.checkRemoveReviewer(ctx.getNotes(), ctx.getUser(), reviewerId);
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +125,7 @@ public class DeleteReviewerOp implements BatchUpdateOp {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    StringBuilder msg = new StringBuilder();
 | 
			
		||||
    msg.append("Removed reviewer " + reviewer.getAccount().getFullName());
 | 
			
		||||
    msg.append("Removed reviewer " + reviewer.getAccount().fullName());
 | 
			
		||||
    StringBuilder removedVotesMsg = new StringBuilder();
 | 
			
		||||
    removedVotesMsg.append(" with the following votes:\n\n");
 | 
			
		||||
    List<PatchSetApproval> del = new ArrayList<>();
 | 
			
		||||
@@ -212,13 +212,13 @@ public class DeleteReviewerOp implements BatchUpdateOp {
 | 
			
		||||
      NotifyResolver.Result notify)
 | 
			
		||||
      throws EmailException {
 | 
			
		||||
    Account.Id userId = user.get().getAccountId();
 | 
			
		||||
    if (userId.equals(reviewer.getAccount().getId())) {
 | 
			
		||||
    if (userId.equals(reviewer.getAccount().id())) {
 | 
			
		||||
      // The user knows they removed themselves, don't bother emailing them.
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    DeleteReviewerSender cm = deleteReviewerSenderFactory.create(projectName, change.getId());
 | 
			
		||||
    cm.setFrom(userId);
 | 
			
		||||
    cm.addReviewers(Collections.singleton(reviewer.getAccount().getId()));
 | 
			
		||||
    cm.addReviewers(Collections.singleton(reviewer.getAccount().id()));
 | 
			
		||||
    cm.setChangeMessage(changeMessage.getMessage(), changeMessage.getWrittenOn());
 | 
			
		||||
    cm.setNotify(notify);
 | 
			
		||||
    cm.send();
 | 
			
		||||
 
 | 
			
		||||
@@ -100,7 +100,7 @@ public class NotifyResolver {
 | 
			
		||||
    List<String> problems = new ArrayList<>(inputs.size());
 | 
			
		||||
    for (String nameOrEmail : inputs) {
 | 
			
		||||
      try {
 | 
			
		||||
        r.add(accountResolver.resolve(nameOrEmail).asUnique().getAccount().getId());
 | 
			
		||||
        r.add(accountResolver.resolve(nameOrEmail).asUnique().getAccount().id());
 | 
			
		||||
      } catch (UnprocessableEntityException e) {
 | 
			
		||||
        problems.add(e.getMessage());
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -340,7 +340,7 @@ public class ReviewerAdder {
 | 
			
		||||
 | 
			
		||||
    for (Account member : members) {
 | 
			
		||||
      if (isValidReviewer(notes.getChange().getDest(), member)) {
 | 
			
		||||
        reviewers.add(member.getId());
 | 
			
		||||
        reviewers.add(member.id());
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -375,7 +375,7 @@ public class ReviewerAdder {
 | 
			
		||||
      // Check ref permission instead of change permission, since change permissions take into
 | 
			
		||||
      // account the private bit, whereas adding a user as a reviewer is explicitly allowing them to
 | 
			
		||||
      // see private changes.
 | 
			
		||||
      permissionBackend.absentUser(member.getId()).ref(branch).check(RefPermission.READ);
 | 
			
		||||
      permissionBackend.absentUser(member.id()).ref(branch).check(RefPermission.READ);
 | 
			
		||||
      return true;
 | 
			
		||||
    } catch (AuthException e) {
 | 
			
		||||
      return false;
 | 
			
		||||
 
 | 
			
		||||
@@ -571,8 +571,8 @@ public class EventFactory {
 | 
			
		||||
   */
 | 
			
		||||
  public AccountAttribute asAccountAttribute(AccountState accountState) {
 | 
			
		||||
    AccountAttribute who = new AccountAttribute();
 | 
			
		||||
    who.name = accountState.getAccount().getFullName();
 | 
			
		||||
    who.email = accountState.getAccount().getPreferredEmail();
 | 
			
		||||
    who.name = accountState.getAccount().fullName();
 | 
			
		||||
    who.email = accountState.getAccount().preferredEmail();
 | 
			
		||||
    who.username = accountState.getUserName().orElse(null);
 | 
			
		||||
    return who;
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -89,13 +89,13 @@ public class EventUtil {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public AccountInfo accountInfo(AccountState accountState) {
 | 
			
		||||
    if (accountState == null || accountState.getAccount().getId() == null) {
 | 
			
		||||
    if (accountState == null || accountState.getAccount().id() == null) {
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
    Account account = accountState.getAccount();
 | 
			
		||||
    AccountInfo accountInfo = new AccountInfo(account.getId().get());
 | 
			
		||||
    accountInfo.email = account.getPreferredEmail();
 | 
			
		||||
    accountInfo.name = account.getFullName();
 | 
			
		||||
    AccountInfo accountInfo = new AccountInfo(account.id().get());
 | 
			
		||||
    accountInfo.email = account.preferredEmail();
 | 
			
		||||
    accountInfo.name = account.fullName();
 | 
			
		||||
    accountInfo.username = accountState.getUserName().orElse(null);
 | 
			
		||||
    return accountInfo;
 | 
			
		||||
  }
 | 
			
		||||
@@ -107,7 +107,7 @@ public class EventUtil {
 | 
			
		||||
      Integer value = e.getValue() != null ? Integer.valueOf(e.getValue()) : null;
 | 
			
		||||
      result.put(
 | 
			
		||||
          e.getKey(),
 | 
			
		||||
          new ApprovalInfo(accountState.getAccount().getId().get(), value, null, null, ts));
 | 
			
		||||
          new ApprovalInfo(accountState.getAccount().id().get(), value, null, null, ts));
 | 
			
		||||
    }
 | 
			
		||||
    return result;
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -539,21 +539,21 @@ public class MergeUtil {
 | 
			
		||||
 | 
			
		||||
      final Account acc = identifiedUserFactory.create(a.accountId()).getAccount();
 | 
			
		||||
      final StringBuilder identbuf = new StringBuilder();
 | 
			
		||||
      if (acc.getFullName() != null && acc.getFullName().length() > 0) {
 | 
			
		||||
      if (acc.fullName() != null && acc.fullName().length() > 0) {
 | 
			
		||||
        if (identbuf.length() > 0) {
 | 
			
		||||
          identbuf.append(' ');
 | 
			
		||||
        }
 | 
			
		||||
        identbuf.append(acc.getFullName());
 | 
			
		||||
        identbuf.append(acc.fullName());
 | 
			
		||||
      }
 | 
			
		||||
      if (acc.getPreferredEmail() != null && acc.getPreferredEmail().length() > 0) {
 | 
			
		||||
        if (isSignedOffBy(footers, acc.getPreferredEmail())) {
 | 
			
		||||
      if (acc.preferredEmail() != null && acc.preferredEmail().length() > 0) {
 | 
			
		||||
        if (isSignedOffBy(footers, acc.preferredEmail())) {
 | 
			
		||||
          continue;
 | 
			
		||||
        }
 | 
			
		||||
        if (identbuf.length() > 0) {
 | 
			
		||||
          identbuf.append(' ');
 | 
			
		||||
        }
 | 
			
		||||
        identbuf.append('<');
 | 
			
		||||
        identbuf.append(acc.getPreferredEmail());
 | 
			
		||||
        identbuf.append(acc.preferredEmail());
 | 
			
		||||
        identbuf.append('>');
 | 
			
		||||
      }
 | 
			
		||||
      if (identbuf.length() == 0) {
 | 
			
		||||
 
 | 
			
		||||
@@ -543,7 +543,7 @@ public class ReplaceOp implements BatchUpdateOp {
 | 
			
		||||
      try {
 | 
			
		||||
        ReplacePatchSetSender cm =
 | 
			
		||||
            replacePatchSetFactory.create(projectState.getNameKey(), notes.getChangeId());
 | 
			
		||||
        cm.setFrom(ctx.getAccount().getAccount().getId());
 | 
			
		||||
        cm.setFrom(ctx.getAccount().getAccount().id());
 | 
			
		||||
        cm.setPatchSet(newPatchSet, info);
 | 
			
		||||
        cm.setChangeMessage(msg.getMessage(), ctx.getWhen());
 | 
			
		||||
        cm.setNotify(ctx.getNotify(notes.getChangeId()));
 | 
			
		||||
 
 | 
			
		||||
@@ -87,10 +87,10 @@ public class AccountValidator {
 | 
			
		||||
      messages.add("cannot deactivate own account");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    String newPreferredEmail = newAccount.get().getPreferredEmail();
 | 
			
		||||
    String newPreferredEmail = newAccount.get().preferredEmail();
 | 
			
		||||
    if (newPreferredEmail != null
 | 
			
		||||
        && (!oldAccount.isPresent()
 | 
			
		||||
            || !newPreferredEmail.equals(oldAccount.get().getPreferredEmail()))) {
 | 
			
		||||
            || !newPreferredEmail.equals(oldAccount.get().preferredEmail()))) {
 | 
			
		||||
      if (!emailValidator.isValid(newPreferredEmail)) {
 | 
			
		||||
        messages.add(
 | 
			
		||||
            String.format(
 | 
			
		||||
 
 | 
			
		||||
@@ -72,7 +72,7 @@ public class AuditLogFormatter {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static Optional<Account> getAccount(ImmutableSet<Account> accounts, Account.Id id) {
 | 
			
		||||
    return accounts.stream().filter(account -> account.getId().equals(id)).findAny();
 | 
			
		||||
    return accounts.stream().filter(account -> account.id().equals(id)).findAny();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static AuditLogFormatter createPartiallyWorkingFallBack() {
 | 
			
		||||
@@ -119,7 +119,7 @@ public class AuditLogFormatter {
 | 
			
		||||
   * @return a {@code PersonIdent} which can be used for the author of a commit
 | 
			
		||||
   */
 | 
			
		||||
  public PersonIdent getParsableAuthorIdent(Account account, PersonIdent personIdent) {
 | 
			
		||||
    return getParsableAuthorIdent(account.getName(), account.getId(), personIdent);
 | 
			
		||||
    return getParsableAuthorIdent(account.getName(), account.id(), personIdent);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,7 @@ import org.eclipse.jgit.lib.ObjectId;
 | 
			
		||||
/** Secondary index schemas for accounts. */
 | 
			
		||||
public class AccountField {
 | 
			
		||||
  public static final FieldDef<AccountState, Integer> ID =
 | 
			
		||||
      integer("id").stored().build(a -> a.getAccount().getId().get());
 | 
			
		||||
      integer("id").stored().build(a -> a.getAccount().id().get());
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * External IDs.
 | 
			
		||||
@@ -77,10 +77,10 @@ public class AccountField {
 | 
			
		||||
   */
 | 
			
		||||
  public static final FieldDef<AccountState, Iterable<String>> NAME_PART_NO_SECONDARY_EMAIL =
 | 
			
		||||
      prefix("name2")
 | 
			
		||||
          .buildRepeatable(a -> getNameParts(a, Arrays.asList(a.getAccount().getPreferredEmail())));
 | 
			
		||||
          .buildRepeatable(a -> getNameParts(a, Arrays.asList(a.getAccount().preferredEmail())));
 | 
			
		||||
 | 
			
		||||
  public static final FieldDef<AccountState, String> FULL_NAME =
 | 
			
		||||
      exact("full_name").build(a -> a.getAccount().getFullName());
 | 
			
		||||
      exact("full_name").build(a -> a.getAccount().fullName());
 | 
			
		||||
 | 
			
		||||
  public static final FieldDef<AccountState, String> ACTIVE =
 | 
			
		||||
      exact("inactive").build(a -> a.getAccount().isActive() ? "1" : "0");
 | 
			
		||||
@@ -97,7 +97,7 @@ public class AccountField {
 | 
			
		||||
              a ->
 | 
			
		||||
                  FluentIterable.from(a.getExternalIds())
 | 
			
		||||
                      .transform(ExternalId::email)
 | 
			
		||||
                      .append(Collections.singleton(a.getAccount().getPreferredEmail()))
 | 
			
		||||
                      .append(Collections.singleton(a.getAccount().preferredEmail()))
 | 
			
		||||
                      .filter(Objects::nonNull)
 | 
			
		||||
                      .transform(String::toLowerCase)
 | 
			
		||||
                      .toSet());
 | 
			
		||||
@@ -106,15 +106,15 @@ public class AccountField {
 | 
			
		||||
      prefix("preferredemail")
 | 
			
		||||
          .build(
 | 
			
		||||
              a -> {
 | 
			
		||||
                String preferredEmail = a.getAccount().getPreferredEmail();
 | 
			
		||||
                String preferredEmail = a.getAccount().preferredEmail();
 | 
			
		||||
                return preferredEmail != null ? preferredEmail.toLowerCase() : null;
 | 
			
		||||
              });
 | 
			
		||||
 | 
			
		||||
  public static final FieldDef<AccountState, String> PREFERRED_EMAIL_EXACT =
 | 
			
		||||
      exact("preferredemail_exact").build(a -> a.getAccount().getPreferredEmail());
 | 
			
		||||
      exact("preferredemail_exact").build(a -> a.getAccount().preferredEmail());
 | 
			
		||||
 | 
			
		||||
  public static final FieldDef<AccountState, Timestamp> REGISTERED =
 | 
			
		||||
      timestamp("registered").build(a -> a.getAccount().getRegisteredOn());
 | 
			
		||||
      timestamp("registered").build(a -> a.getAccount().registeredOn());
 | 
			
		||||
 | 
			
		||||
  public static final FieldDef<AccountState, String> USERNAME =
 | 
			
		||||
      exact("username").build(a -> a.getUserName().map(String::toLowerCase).orElse(""));
 | 
			
		||||
@@ -138,14 +138,14 @@ public class AccountField {
 | 
			
		||||
      storedOnly("ref_state")
 | 
			
		||||
          .buildRepeatable(
 | 
			
		||||
              a -> {
 | 
			
		||||
                if (a.getAccount().getMetaId() == null) {
 | 
			
		||||
                if (a.getAccount().metaId() == null) {
 | 
			
		||||
                  return ImmutableList.of();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return ImmutableList.of(
 | 
			
		||||
                    RefState.create(
 | 
			
		||||
                            RefNames.refsUsers(a.getAccount().getId()),
 | 
			
		||||
                            ObjectId.fromString(a.getAccount().getMetaId()))
 | 
			
		||||
                            RefNames.refsUsers(a.getAccount().id()),
 | 
			
		||||
                            ObjectId.fromString(a.getAccount().metaId()))
 | 
			
		||||
                        // We use the default AllUsers name to avoid having to pass around that
 | 
			
		||||
                        // variable just for indexing.
 | 
			
		||||
                        // This field is only used for staleness detection which will discover the
 | 
			
		||||
@@ -169,7 +169,7 @@ public class AccountField {
 | 
			
		||||
                      .collect(toSet()));
 | 
			
		||||
 | 
			
		||||
  private static final Set<String> getNameParts(AccountState a, Iterable<String> emails) {
 | 
			
		||||
    String fullName = a.getAccount().getFullName();
 | 
			
		||||
    String fullName = a.getAccount().fullName();
 | 
			
		||||
    Set<String> parts = SchemaUtil.getNameParts(fullName, emails);
 | 
			
		||||
 | 
			
		||||
    // Additional values not currently added by getPersonParts.
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,7 @@ public class MailUtil {
 | 
			
		||||
  @SuppressWarnings("deprecation")
 | 
			
		||||
  private static Account.Id toAccountId(AccountResolver accountResolver, String nameOrEmail)
 | 
			
		||||
      throws UnprocessableEntityException, IOException, ConfigInvalidException {
 | 
			
		||||
    return accountResolver.resolveByNameOrEmail(nameOrEmail).asUnique().getAccount().getId();
 | 
			
		||||
    return accountResolver.resolveByNameOrEmail(nameOrEmail).asUnique().getAccount().id();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static boolean isReviewer(FooterLine candidateFooterLine) {
 | 
			
		||||
 
 | 
			
		||||
@@ -79,7 +79,7 @@ public class AddKeySender extends OutgoingEmail {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getEmail() {
 | 
			
		||||
    return user.getAccount().getPreferredEmail();
 | 
			
		||||
    return user.getAccount().preferredEmail();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getUserNameEmail() {
 | 
			
		||||
 
 | 
			
		||||
@@ -75,7 +75,7 @@ public class DeleteKeySender extends OutgoingEmail {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getEmail() {
 | 
			
		||||
    return user.getAccount().getPreferredEmail();
 | 
			
		||||
    return user.getAccount().preferredEmail();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getUserNameEmail() {
 | 
			
		||||
 
 | 
			
		||||
@@ -124,8 +124,8 @@ public class FromAddressGeneratorProvider implements Provider<FromAddressGenerat
 | 
			
		||||
      String senderName;
 | 
			
		||||
      if (fromId != null) {
 | 
			
		||||
        Optional<Account> a = accountCache.get(fromId).map(AccountState::getAccount);
 | 
			
		||||
        String fullName = a.map(Account::getFullName).orElse(null);
 | 
			
		||||
        String userEmail = a.map(Account::getPreferredEmail).orElse(null);
 | 
			
		||||
        String fullName = a.map(Account::fullName).orElse(null);
 | 
			
		||||
        String userEmail = a.map(Account::preferredEmail).orElse(null);
 | 
			
		||||
        if (canRelay(userEmail)) {
 | 
			
		||||
          return new Address(fullName, userEmail);
 | 
			
		||||
        }
 | 
			
		||||
@@ -208,8 +208,7 @@ public class FromAddressGeneratorProvider implements Provider<FromAddressGenerat
 | 
			
		||||
      final String senderName;
 | 
			
		||||
 | 
			
		||||
      if (fromId != null) {
 | 
			
		||||
        String fullName =
 | 
			
		||||
            accountCache.get(fromId).map(a -> a.getAccount().getFullName()).orElse(null);
 | 
			
		||||
        String fullName = accountCache.get(fromId).map(a -> a.getAccount().fullName()).orElse(null);
 | 
			
		||||
        if (fullName == null || "".equals(fullName)) {
 | 
			
		||||
          fullName = anonymousCowardName;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -59,7 +59,7 @@ public class HttpPasswordUpdateSender extends OutgoingEmail {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getEmail() {
 | 
			
		||||
    return user.getAccount().getPreferredEmail();
 | 
			
		||||
    return user.getAccount().preferredEmail();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getUserNameEmail() {
 | 
			
		||||
 
 | 
			
		||||
@@ -144,7 +144,7 @@ public abstract class OutgoingEmail {
 | 
			
		||||
          } else if (useHtml() && prefs.getEmailFormat() == EmailFormat.PLAINTEXT) {
 | 
			
		||||
            removeUser(thisUserAccount);
 | 
			
		||||
            smtpRcptToPlaintextOnly.add(
 | 
			
		||||
                new Address(thisUserAccount.getFullName(), thisUserAccount.getPreferredEmail()));
 | 
			
		||||
                new Address(thisUserAccount.fullName(), thisUserAccount.preferredEmail()));
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        if (smtpRcptTo.isEmpty() && smtpRcptToPlaintextOnly.isEmpty()) {
 | 
			
		||||
@@ -250,8 +250,8 @@ public abstract class OutgoingEmail {
 | 
			
		||||
    StringBuilder f = new StringBuilder();
 | 
			
		||||
    Optional<Account> account = args.accountCache.get(fromId).map(AccountState::getAccount);
 | 
			
		||||
    if (account.isPresent()) {
 | 
			
		||||
      String name = account.get().getFullName();
 | 
			
		||||
      String email = account.get().getPreferredEmail();
 | 
			
		||||
      String name = account.get().fullName();
 | 
			
		||||
      String email = account.get().preferredEmail();
 | 
			
		||||
      if ((name != null && !name.isEmpty()) || (email != null && !email.isEmpty())) {
 | 
			
		||||
        f.append("From");
 | 
			
		||||
        if (name != null && !name.isEmpty()) {
 | 
			
		||||
@@ -327,9 +327,9 @@ public abstract class OutgoingEmail {
 | 
			
		||||
    Optional<Account> account = args.accountCache.get(accountId).map(AccountState::getAccount);
 | 
			
		||||
    String name = null;
 | 
			
		||||
    if (account.isPresent()) {
 | 
			
		||||
      name = account.get().getFullName();
 | 
			
		||||
      name = account.get().fullName();
 | 
			
		||||
      if (name == null) {
 | 
			
		||||
        name = account.get().getPreferredEmail();
 | 
			
		||||
        name = account.get().preferredEmail();
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (name == null) {
 | 
			
		||||
@@ -348,8 +348,8 @@ public abstract class OutgoingEmail {
 | 
			
		||||
  protected String getNameEmailFor(Account.Id accountId) {
 | 
			
		||||
    Optional<Account> account = args.accountCache.get(accountId).map(AccountState::getAccount);
 | 
			
		||||
    if (account.isPresent()) {
 | 
			
		||||
      String name = account.get().getFullName();
 | 
			
		||||
      String email = account.get().getPreferredEmail();
 | 
			
		||||
      String name = account.get().fullName();
 | 
			
		||||
      String email = account.get().preferredEmail();
 | 
			
		||||
      if (name != null && email != null) {
 | 
			
		||||
        return name + " <" + email + ">";
 | 
			
		||||
      } else if (name != null) {
 | 
			
		||||
@@ -375,8 +375,8 @@ public abstract class OutgoingEmail {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Account account = accountState.get().getAccount();
 | 
			
		||||
    String name = account.getFullName();
 | 
			
		||||
    String email = account.getPreferredEmail();
 | 
			
		||||
    String name = account.fullName();
 | 
			
		||||
    String email = account.preferredEmail();
 | 
			
		||||
    if (name != null && email != null) {
 | 
			
		||||
      return name + " <" + email + ">";
 | 
			
		||||
    } else if (email != null) {
 | 
			
		||||
@@ -511,11 +511,11 @@ public abstract class OutgoingEmail {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Account account = accountState.get();
 | 
			
		||||
    String e = account.getPreferredEmail();
 | 
			
		||||
    String e = account.preferredEmail();
 | 
			
		||||
    if (!account.isActive() || e == null) {
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
    return new Address(account.getFullName(), e);
 | 
			
		||||
    return new Address(account.fullName(), e);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected void setupSoyContext() {
 | 
			
		||||
@@ -553,7 +553,7 @@ public abstract class OutgoingEmail {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected void removeUser(Account user) {
 | 
			
		||||
    String fromEmail = user.getPreferredEmail();
 | 
			
		||||
    String fromEmail = user.preferredEmail();
 | 
			
		||||
    for (Iterator<Address> j = smtpRcptTo.iterator(); j.hasNext(); ) {
 | 
			
		||||
      if (j.next().getEmail().equals(fromEmail)) {
 | 
			
		||||
        j.remove();
 | 
			
		||||
 
 | 
			
		||||
@@ -66,7 +66,7 @@ public class ProjectWatch {
 | 
			
		||||
    Set<Account.Id> projectWatchers = new HashSet<>();
 | 
			
		||||
 | 
			
		||||
    for (AccountState a : args.accountQueryProvider.get().byWatchedProject(project)) {
 | 
			
		||||
      Account.Id accountId = a.getAccount().getId();
 | 
			
		||||
      Account.Id accountId = a.getAccount().id();
 | 
			
		||||
      for (Map.Entry<ProjectWatchKey, ImmutableSet<NotifyType>> e :
 | 
			
		||||
          a.getProjectWatches().entrySet()) {
 | 
			
		||||
        if (project.equals(e.getKey().project())
 | 
			
		||||
@@ -81,7 +81,7 @@ public class ProjectWatch {
 | 
			
		||||
      for (Map.Entry<ProjectWatchKey, ImmutableSet<NotifyType>> e :
 | 
			
		||||
          a.getProjectWatches().entrySet()) {
 | 
			
		||||
        if (args.allProjectsName.equals(e.getKey().project())) {
 | 
			
		||||
          Account.Id accountId = a.getAccount().getId();
 | 
			
		||||
          Account.Id accountId = a.getAccount().id();
 | 
			
		||||
          if (!projectWatchers.contains(accountId)) {
 | 
			
		||||
            add(matching, accountId, e.getKey(), e.getValue(), type);
 | 
			
		||||
          }
 | 
			
		||||
 
 | 
			
		||||
@@ -96,8 +96,8 @@ public class ChangeNoteUtil {
 | 
			
		||||
  @VisibleForTesting
 | 
			
		||||
  public PersonIdent newIdent(Account author, Date when, PersonIdent serverIdent) {
 | 
			
		||||
    return new PersonIdent(
 | 
			
		||||
        "Gerrit User " + author.getId(),
 | 
			
		||||
        author.getId().get() + "@" + serverId,
 | 
			
		||||
        "Gerrit User " + author.id(),
 | 
			
		||||
        author.id().get() + "@" + serverId,
 | 
			
		||||
        when,
 | 
			
		||||
        serverIdent.getTimeZone());
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -58,7 +58,7 @@ public class LegacyChangeNoteWrite {
 | 
			
		||||
  @VisibleForTesting
 | 
			
		||||
  public PersonIdent newIdent(Account author, Date when, PersonIdent serverIdent) {
 | 
			
		||||
    return new PersonIdent(
 | 
			
		||||
        author.toString(), author.getId().get() + "@" + serverId, when, serverIdent.getTimeZone());
 | 
			
		||||
        author.toString(), author.id().get() + "@" + serverId, when, serverIdent.getTimeZone());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getServerId() {
 | 
			
		||||
 
 | 
			
		||||
@@ -77,6 +77,6 @@ public class AccountQueryProcessor extends QueryProcessor<AccountState> {
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String formatForLogging(AccountState accountState) {
 | 
			
		||||
    return accountState.getAccount().getId().toString();
 | 
			
		||||
    return accountState.getAccount().id().toString();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,7 @@ public class CanSeeChangePredicate extends PostFilterPredicate<AccountState> {
 | 
			
		||||
  public boolean match(AccountState accountState) {
 | 
			
		||||
    try {
 | 
			
		||||
      permissionBackend
 | 
			
		||||
          .absentUser(accountState.getAccount().getId())
 | 
			
		||||
          .absentUser(accountState.getAccount().id())
 | 
			
		||||
          .change(changeNotes)
 | 
			
		||||
          .check(ChangePermission.READ);
 | 
			
		||||
      return true;
 | 
			
		||||
 
 | 
			
		||||
@@ -82,7 +82,7 @@ public class InternalAccountQuery extends InternalQuery<AccountState, InternalAc
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return query(AccountPredicates.preferredEmail(email)).stream()
 | 
			
		||||
        .filter(a -> a.getAccount().getPreferredEmail().equals(email))
 | 
			
		||||
        .filter(a -> a.getAccount().preferredEmail().equals(email))
 | 
			
		||||
        .collect(toList());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -117,7 +117,7 @@ public class InternalAccountQuery extends InternalQuery<AccountState, InternalAc
 | 
			
		||||
      String email = emailList.get(i);
 | 
			
		||||
      Set<AccountState> matchingAccounts =
 | 
			
		||||
          r.get(i).stream()
 | 
			
		||||
              .filter(a -> a.getAccount().getPreferredEmail().equals(email))
 | 
			
		||||
              .filter(a -> a.getAccount().preferredEmail().equals(email))
 | 
			
		||||
              .collect(toSet());
 | 
			
		||||
      accountsByEmail.putAll(email, matchingAccounts);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1326,7 +1326,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData, ChangeQueryBuil
 | 
			
		||||
  private Set<Account.Id> getMembers(AccountGroup.UUID g) throws IOException {
 | 
			
		||||
    Set<Account.Id> accounts;
 | 
			
		||||
    Set<Account.Id> allMembers =
 | 
			
		||||
        args.groupMembers.listAccounts(g).stream().map(Account::getId).collect(toSet());
 | 
			
		||||
        args.groupMembers.listAccounts(g).stream().map(Account::id).collect(toSet());
 | 
			
		||||
    int maxTerms = args.indexConfig.maxTerms();
 | 
			
		||||
    if (allMembers.size() > maxTerms) {
 | 
			
		||||
      // limit the number of query terms otherwise Gerrit will barf
 | 
			
		||||
 
 | 
			
		||||
@@ -104,7 +104,7 @@ public class AddSshKey
 | 
			
		||||
        addKeyFactory.create(user, sshKey).send();
 | 
			
		||||
      } catch (EmailException e) {
 | 
			
		||||
        logger.atSevere().withCause(e).log(
 | 
			
		||||
            "Cannot send SSH key added message to %s", user.getAccount().getPreferredEmail());
 | 
			
		||||
            "Cannot send SSH key added message to %s", user.getAccount().preferredEmail());
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      user.getUserName().ifPresent(sshKeyCache::evict);
 | 
			
		||||
 
 | 
			
		||||
@@ -74,7 +74,7 @@ public class DeleteSshKey implements RestModifyView<AccountResource.SshKey, Inpu
 | 
			
		||||
      deleteKeySenderFactory.create(user, rsrc.getSshKey()).send();
 | 
			
		||||
    } catch (EmailException e) {
 | 
			
		||||
      logger.atSevere().withCause(e).log(
 | 
			
		||||
          "Cannot send SSH key deletion message to %s", user.getAccount().getPreferredEmail());
 | 
			
		||||
          "Cannot send SSH key deletion message to %s", user.getAccount().preferredEmail());
 | 
			
		||||
    }
 | 
			
		||||
    user.getUserName().ifPresent(sshKeyCache::evict);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -63,7 +63,7 @@ public class EmailsCollection implements ChildCollection<AccountResource, Accoun
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ("preferred".equals(id.get())) {
 | 
			
		||||
      String email = rsrc.getUser().getAccount().getPreferredEmail();
 | 
			
		||||
      String email = rsrc.getUser().getAccount().preferredEmail();
 | 
			
		||||
      if (Strings.isNullOrEmpty(email)) {
 | 
			
		||||
        throw new ResourceNotFoundException(id);
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -38,8 +38,8 @@ public class GetDetail implements RestReadView<AccountResource> {
 | 
			
		||||
  @Override
 | 
			
		||||
  public AccountDetailInfo apply(AccountResource rsrc) throws PermissionBackendException {
 | 
			
		||||
    Account a = rsrc.getUser().getAccount();
 | 
			
		||||
    AccountDetailInfo info = new AccountDetailInfo(a.getId().get());
 | 
			
		||||
    info.registeredOn = a.getRegisteredOn();
 | 
			
		||||
    AccountDetailInfo info = new AccountDetailInfo(a.id().get());
 | 
			
		||||
    info.registeredOn = a.registeredOn();
 | 
			
		||||
    info.inactive = !a.isActive() ? true : null;
 | 
			
		||||
    directory.fillAccountInfo(Collections.singleton(info), EnumSet.allOf(FillOptions.class));
 | 
			
		||||
    return info;
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@ public class GetEmail implements RestReadView<AccountResource.Email> {
 | 
			
		||||
  public EmailInfo apply(AccountResource.Email rsrc) {
 | 
			
		||||
    EmailInfo e = new EmailInfo();
 | 
			
		||||
    e.email = rsrc.getEmail();
 | 
			
		||||
    e.preferred(rsrc.getUser().getAccount().getPreferredEmail());
 | 
			
		||||
    e.preferred(rsrc.getUser().getAccount().preferredEmail());
 | 
			
		||||
    return e;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -58,7 +58,7 @@ public class GetEmails implements RestReadView<AccountResource> {
 | 
			
		||||
  private static EmailInfo toEmailInfo(AccountResource rsrc, String email) {
 | 
			
		||||
    EmailInfo e = new EmailInfo();
 | 
			
		||||
    e.email = email;
 | 
			
		||||
    e.preferred(rsrc.getUser().getAccount().getPreferredEmail());
 | 
			
		||||
    e.preferred(rsrc.getUser().getAccount().preferredEmail());
 | 
			
		||||
    return e;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,6 @@ import com.google.inject.Singleton;
 | 
			
		||||
public class GetName implements RestReadView<AccountResource> {
 | 
			
		||||
  @Override
 | 
			
		||||
  public String apply(AccountResource rsrc) {
 | 
			
		||||
    return Strings.nullToEmpty(rsrc.getUser().getAccount().getFullName());
 | 
			
		||||
    return Strings.nullToEmpty(rsrc.getUser().getAccount().fullName());
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,6 @@ import com.google.inject.Singleton;
 | 
			
		||||
public class GetStatus implements RestReadView<AccountResource> {
 | 
			
		||||
  @Override
 | 
			
		||||
  public String apply(AccountResource rsrc) {
 | 
			
		||||
    return Strings.nullToEmpty(rsrc.getUser().getAccount().getStatus());
 | 
			
		||||
    return Strings.nullToEmpty(rsrc.getUser().getAccount().status());
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -93,7 +93,7 @@ public class PutAgreement implements RestModifyView<AccountResource, AgreementIn
 | 
			
		||||
 | 
			
		||||
    AccountState accountState = self.get().state();
 | 
			
		||||
    try {
 | 
			
		||||
      addMembers.addMembers(uuid, ImmutableSet.of(accountState.getAccount().getId()));
 | 
			
		||||
      addMembers.addMembers(uuid, ImmutableSet.of(accountState.getAccount().id()));
 | 
			
		||||
    } catch (NoSuchGroupException e) {
 | 
			
		||||
      throw new ResourceConflictException("autoverify group not found");
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -131,7 +131,7 @@ public class PutHttpPassword implements RestModifyView<AccountResource, HttpPass
 | 
			
		||||
          .send();
 | 
			
		||||
    } catch (EmailException e) {
 | 
			
		||||
      logger.atSevere().withCause(e).log(
 | 
			
		||||
          "Cannot send HttpPassword update message to %s", user.getAccount().getPreferredEmail());
 | 
			
		||||
          "Cannot send HttpPassword update message to %s", user.getAccount().preferredEmail());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return Strings.isNullOrEmpty(newPassword) ? Response.none() : Response.ok(newPassword);
 | 
			
		||||
 
 | 
			
		||||
@@ -84,8 +84,8 @@ public class PutName implements RestModifyView<AccountResource, NameInput> {
 | 
			
		||||
            .get()
 | 
			
		||||
            .update("Set Full Name via API", user.getAccountId(), u -> u.setFullName(newName))
 | 
			
		||||
            .orElseThrow(() -> new ResourceNotFoundException("account not found"));
 | 
			
		||||
    return Strings.isNullOrEmpty(accountState.getAccount().getFullName())
 | 
			
		||||
    return Strings.isNullOrEmpty(accountState.getAccount().fullName())
 | 
			
		||||
        ? Response.none()
 | 
			
		||||
        : Response.ok(accountState.getAccount().getFullName());
 | 
			
		||||
        : Response.ok(accountState.getAccount().fullName());
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -85,7 +85,7 @@ public class PutPreferred implements RestModifyView<AccountResource.Email, Input
 | 
			
		||||
            "Set Preferred Email via API",
 | 
			
		||||
            user.getAccountId(),
 | 
			
		||||
            (a, u) -> {
 | 
			
		||||
              if (preferredEmail.equals(a.getAccount().getPreferredEmail())) {
 | 
			
		||||
              if (preferredEmail.equals(a.getAccount().preferredEmail())) {
 | 
			
		||||
                alreadyPreferred.set(true);
 | 
			
		||||
              } else {
 | 
			
		||||
                // check if the user has a matching email
 | 
			
		||||
@@ -128,7 +128,7 @@ public class PutPreferred implements RestModifyView<AccountResource.Email, Input
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    // claim the email now
 | 
			
		||||
                    u.addExternalId(ExternalId.createEmail(a.getAccount().getId(), preferredEmail));
 | 
			
		||||
                    u.addExternalId(ExternalId.createEmail(a.getAccount().id(), preferredEmail));
 | 
			
		||||
                    matchingEmail = preferredEmail;
 | 
			
		||||
                  } else {
 | 
			
		||||
                    // Realm says that the email doesn't belong to the user. This can only happen as
 | 
			
		||||
 
 | 
			
		||||
@@ -73,8 +73,8 @@ public class PutStatus implements RestModifyView<AccountResource, StatusInput> {
 | 
			
		||||
            .get()
 | 
			
		||||
            .update("Set Status via API", user.getAccountId(), u -> u.setStatus(newStatus))
 | 
			
		||||
            .orElseThrow(() -> new ResourceNotFoundException("account not found"));
 | 
			
		||||
    return Strings.isNullOrEmpty(accountState.getAccount().getStatus())
 | 
			
		||||
    return Strings.isNullOrEmpty(accountState.getAccount().status())
 | 
			
		||||
        ? Response.none()
 | 
			
		||||
        : Response.ok(accountState.getAccount().getStatus());
 | 
			
		||||
        : Response.ok(accountState.getAccount().status());
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -209,7 +209,7 @@ public class QueryAccounts implements RestReadView<TopLevelResource> {
 | 
			
		||||
      }
 | 
			
		||||
      QueryResult<AccountState> result = queryProcessor.query(queryPred);
 | 
			
		||||
      for (AccountState accountState : result.entities()) {
 | 
			
		||||
        Account.Id id = accountState.getAccount().getId();
 | 
			
		||||
        Account.Id id = accountState.getAccount().id();
 | 
			
		||||
        matches.put(id, accountLoader.get(id));
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -105,7 +105,7 @@ public class DeleteAssignee
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Account.Id getDeletedAssignee() {
 | 
			
		||||
      return deletedAssignee != null ? deletedAssignee.getAccount().getId() : null;
 | 
			
		||||
      return deletedAssignee != null ? deletedAssignee.getAccount().id() : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void addMessage(
 | 
			
		||||
 
 | 
			
		||||
@@ -170,7 +170,7 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
 | 
			
		||||
      boolean found = false;
 | 
			
		||||
      LabelTypes labelTypes = projectState.getLabelTypes(ctx.getNotes());
 | 
			
		||||
 | 
			
		||||
      Account.Id accountId = accountState.getAccount().getId();
 | 
			
		||||
      Account.Id accountId = accountState.getAccount().id();
 | 
			
		||||
 | 
			
		||||
      for (PatchSetApproval a :
 | 
			
		||||
          approvalsUtil.byPatchSetUser(
 | 
			
		||||
 
 | 
			
		||||
@@ -405,7 +405,7 @@ public class ReviewersUtil {
 | 
			
		||||
 | 
			
		||||
      // require that at least one member in the group can see the change
 | 
			
		||||
      for (Account account : members) {
 | 
			
		||||
        if (visibilityControl.isVisibleTo(account.getId())) {
 | 
			
		||||
        if (visibilityControl.isVisibleTo(account.id())) {
 | 
			
		||||
          if (needsConfirmation) {
 | 
			
		||||
            result.allowedWithConfirmation = true;
 | 
			
		||||
          } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -130,7 +130,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
 | 
			
		||||
        throw new UnprocessableEntityException(
 | 
			
		||||
            String.format("Account Inactive: %s", nameOrEmailOrId));
 | 
			
		||||
      }
 | 
			
		||||
      newMemberIds.add(a.getId());
 | 
			
		||||
      newMemberIds.add(a.id());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
 | 
			
		||||
 
 | 
			
		||||
@@ -148,7 +148,7 @@ public class CreateGroup
 | 
			
		||||
          throw new UnprocessableEntityException(
 | 
			
		||||
              String.format("Account Inactive: %s", nameOrEmailOrId));
 | 
			
		||||
        }
 | 
			
		||||
        members.add(a.getId());
 | 
			
		||||
        members.add(a.id());
 | 
			
		||||
      }
 | 
			
		||||
      args.initialMembers = members;
 | 
			
		||||
    } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -68,7 +68,7 @@ public class DeleteMembers implements RestModifyView<GroupResource, Input> {
 | 
			
		||||
 | 
			
		||||
    Set<Account.Id> membersToRemove = new HashSet<>();
 | 
			
		||||
    for (String nameOrEmail : input.members) {
 | 
			
		||||
      membersToRemove.add(accountResolver.resolve(nameOrEmail).asUnique().getAccount().getId());
 | 
			
		||||
      membersToRemove.add(accountResolver.resolve(nameOrEmail).asUnique().getAccount().id());
 | 
			
		||||
    }
 | 
			
		||||
    AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
 | 
			
		||||
    try {
 | 
			
		||||
 
 | 
			
		||||
@@ -72,7 +72,7 @@ public class CheckAccess implements RestModifyView<ProjectResource, AccessCheckI
 | 
			
		||||
      throw new BadRequestException("input requires 'account'");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Account.Id match = accountResolver.resolve(input.account).asUnique().getAccount().getId();
 | 
			
		||||
    Account.Id match = accountResolver.resolve(input.account).asUnique().getAccount().id();
 | 
			
		||||
 | 
			
		||||
    AccessCheckInfo info = new AccessCheckInfo();
 | 
			
		||||
    try {
 | 
			
		||||
 
 | 
			
		||||
@@ -387,8 +387,8 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
 | 
			
		||||
    requireNonNull(submitter, "getByAccountName called before submitter populated");
 | 
			
		||||
    Optional<Account> account =
 | 
			
		||||
        args.accountCache.get(submitter.accountId()).map(AccountState::getAccount);
 | 
			
		||||
    if (account.isPresent() && account.get().getFullName() != null) {
 | 
			
		||||
      return " by " + account.get().getFullName();
 | 
			
		||||
    if (account.isPresent() && account.get().fullName() != null) {
 | 
			
		||||
      return " by " + account.get().fullName();
 | 
			
		||||
    }
 | 
			
		||||
    return "";
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -77,6 +77,6 @@ class GerritGSSAuthenticator extends GSSAuthenticator {
 | 
			
		||||
        sshScope,
 | 
			
		||||
        sshLog,
 | 
			
		||||
        sd,
 | 
			
		||||
        SshUtil.createUser(sd, userFactory, account.get().getId()));
 | 
			
		||||
        SshUtil.createUser(sd, userFactory, account.get().id()));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -145,7 +145,7 @@ class NoShell implements Factory<Command> {
 | 
			
		||||
      msg.append("\r\n");
 | 
			
		||||
 | 
			
		||||
      Account account = user.getAccount();
 | 
			
		||||
      String name = account.getFullName();
 | 
			
		||||
      String name = account.fullName();
 | 
			
		||||
      if (name == null || name.isEmpty()) {
 | 
			
		||||
        name = user.getUserName().orElse(anonymousCowardName);
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -76,7 +76,7 @@ public class LsUserRefs extends SshCommand {
 | 
			
		||||
  protected void run() throws Failure {
 | 
			
		||||
    Account.Id userAccountId;
 | 
			
		||||
    try {
 | 
			
		||||
      userAccountId = accountResolver.resolve(userName).asUnique().getAccount().getId();
 | 
			
		||||
      userAccountId = accountResolver.resolve(userName).asUnique().getAccount().id();
 | 
			
		||||
    } catch (UnprocessableEntityException e) {
 | 
			
		||||
      stdout.println(e.getMessage());
 | 
			
		||||
      stdout.flush();
 | 
			
		||||
 
 | 
			
		||||
@@ -140,7 +140,7 @@ public class SetMembersCommand extends SshCommand {
 | 
			
		||||
                    return "n/a";
 | 
			
		||||
                  }
 | 
			
		||||
                  return MoreObjects.firstNonNull(
 | 
			
		||||
                      accountState.get().getAccount().getPreferredEmail(), "n/a");
 | 
			
		||||
                      accountState.get().getAccount().preferredEmail(), "n/a");
 | 
			
		||||
                })
 | 
			
		||||
            .collect(joining(", "));
 | 
			
		||||
    out.write(
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,10 @@ public class FakeAccountCache implements AccountCache {
 | 
			
		||||
    if (state != null) {
 | 
			
		||||
      return state;
 | 
			
		||||
    }
 | 
			
		||||
    return newState(new Account(accountId, TimeUtil.nowTs()));
 | 
			
		||||
    return newState(
 | 
			
		||||
        Account.builder(accountId, TimeUtil.nowTs())
 | 
			
		||||
            .setMetaId("1234567812345678123456781234567812345678")
 | 
			
		||||
            .build());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
@@ -72,7 +75,7 @@ public class FakeAccountCache implements AccountCache {
 | 
			
		||||
 | 
			
		||||
  public synchronized void put(Account account) {
 | 
			
		||||
    AccountState state = newState(account);
 | 
			
		||||
    byId.put(account.getId(), state);
 | 
			
		||||
    byId.put(account.id(), state);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static AccountState newState(Account account) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user