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) {
|
||||
|
||||
@@ -417,7 +417,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
"Create Account Atomically",
|
||||
accountId,
|
||||
u -> u.setFullName(fullName).addExternalId(extId));
|
||||
assertThat(accountState.getAccount().getFullName()).isEqualTo(fullName);
|
||||
assertThat(accountState.getAccount().fullName()).isEqualTo(fullName);
|
||||
|
||||
AccountInfo info = gApi.accounts().id(accountId.get()).get();
|
||||
assertThat(info.name).isEqualTo(fullName);
|
||||
@@ -461,8 +461,8 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
.update("Set status", anonymousCoward.id(), u -> u.setStatus(status));
|
||||
assertThat(accountState).isPresent();
|
||||
Account account = accountState.get().getAccount();
|
||||
assertThat(account.getFullName()).isNull();
|
||||
assertThat(account.getStatus()).isEqualTo(status);
|
||||
assertThat(account.fullName()).isNull();
|
||||
assertThat(account.status()).isEqualTo(status);
|
||||
assertUserBranch(anonymousCoward.id(), null, status);
|
||||
}
|
||||
|
||||
@@ -479,7 +479,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
assertThat(ref).isNotNull();
|
||||
RevCommit c = rw.parseCommit(ref.getObjectId());
|
||||
long timestampDiffMs =
|
||||
Math.abs(c.getCommitTime() * 1000L - getAccount(accountId).getRegisteredOn().getTime());
|
||||
Math.abs(c.getCommitTime() * 1000L - getAccount(accountId).registeredOn().getTime());
|
||||
assertThat(timestampDiffMs).isAtMost(SECONDS.toMillis(1));
|
||||
|
||||
// Check the 'account.config' file.
|
||||
@@ -565,7 +565,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
new AccountActivationValidationListener() {
|
||||
@Override
|
||||
public void validateActivation(AccountState account) throws ValidationException {
|
||||
String preferredEmail = account.getAccount().getPreferredEmail();
|
||||
String preferredEmail = account.getAccount().preferredEmail();
|
||||
if (preferredEmail == null || !preferredEmail.endsWith("@activatable.com")) {
|
||||
throw new ValidationException("not allowed to active account");
|
||||
}
|
||||
@@ -573,7 +573,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
|
||||
@Override
|
||||
public void validateDeactivation(AccountState account) throws ValidationException {
|
||||
String preferredEmail = account.getAccount().getPreferredEmail();
|
||||
String preferredEmail = account.getAccount().preferredEmail();
|
||||
if (preferredEmail == null || !preferredEmail.endsWith("@deactivatable.com")) {
|
||||
throw new ValidationException("not allowed to deactive account");
|
||||
}
|
||||
@@ -876,7 +876,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
assertThat(detail.email).isEqualTo(email);
|
||||
assertThat(detail.secondaryEmails).containsExactly(secondaryEmail);
|
||||
assertThat(detail.status).isEqualTo(status);
|
||||
assertThat(detail.registeredOn).isEqualTo(getAccount(foo.id()).getRegisteredOn());
|
||||
assertThat(detail.registeredOn).isEqualTo(getAccount(foo.id()).registeredOn());
|
||||
assertThat(detail.inactive).isNull();
|
||||
assertThat(detail._moreAccounts).isNull();
|
||||
}
|
||||
@@ -2430,22 +2430,22 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void checkMetaId() throws Exception {
|
||||
// metaId is set when account is loaded
|
||||
assertThat(accounts.get(admin.id()).get().getAccount().getMetaId())
|
||||
assertThat(accounts.get(admin.id()).get().getAccount().metaId())
|
||||
.isEqualTo(getMetaId(admin.id()));
|
||||
|
||||
// metaId is set when account is created
|
||||
AccountsUpdate au = accountsUpdateProvider.get();
|
||||
Account.Id accountId = Account.id(seq.nextAccountId());
|
||||
AccountState accountState = au.insert("Create Test Account", accountId, u -> {});
|
||||
assertThat(accountState.getAccount().getMetaId()).isEqualTo(getMetaId(accountId));
|
||||
assertThat(accountState.getAccount().metaId()).isEqualTo(getMetaId(accountId));
|
||||
|
||||
// metaId is set when account is updated
|
||||
Optional<AccountState> updatedAccountState =
|
||||
au.update("Set Full Name", accountId, u -> u.setFullName("foo"));
|
||||
assertThat(updatedAccountState).isPresent();
|
||||
Account updatedAccount = updatedAccountState.get().getAccount();
|
||||
assertThat(accountState.getAccount().getMetaId()).isNotEqualTo(updatedAccount.getMetaId());
|
||||
assertThat(updatedAccount.getMetaId()).isEqualTo(getMetaId(accountId));
|
||||
assertThat(accountState.getAccount().metaId()).isNotEqualTo(updatedAccount.metaId());
|
||||
assertThat(updatedAccount.metaId()).isEqualTo(getMetaId(accountId));
|
||||
}
|
||||
|
||||
private EmailInput newEmailInput(String email, boolean noConfirmation) {
|
||||
@@ -2587,8 +2587,8 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
|
||||
assertThat(updatedAccountState).isPresent();
|
||||
Account updatedAccount = updatedAccountState.get().getAccount();
|
||||
assertThat(updatedAccount.getStatus()).isEqualTo(status);
|
||||
assertThat(updatedAccount.getFullName()).isEqualTo(fullName);
|
||||
assertThat(updatedAccount.status()).isEqualTo(status);
|
||||
assertThat(updatedAccount.fullName()).isEqualTo(fullName);
|
||||
|
||||
accountInfo = gApi.accounts().id(admin.id().get()).get();
|
||||
assertThat(accountInfo.status).isEqualTo(status);
|
||||
@@ -2643,8 +2643,8 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
assertThat(bgCounter.get()).isEqualTo(status.size());
|
||||
|
||||
Account updatedAccount = accounts.get(admin.id()).get().getAccount();
|
||||
assertThat(updatedAccount.getStatus()).isEqualTo(Iterables.getLast(status));
|
||||
assertThat(updatedAccount.getFullName()).isEqualTo(admin.fullName());
|
||||
assertThat(updatedAccount.status()).isEqualTo(Iterables.getLast(status));
|
||||
assertThat(updatedAccount.fullName()).isEqualTo(admin.fullName());
|
||||
|
||||
accountInfo = gApi.accounts().id(admin.id().get()).get();
|
||||
assertThat(accountInfo.status).isEqualTo(Iterables.getLast(status));
|
||||
@@ -2690,12 +2690,12 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
"Set Status",
|
||||
admin.id(),
|
||||
(a, u) -> {
|
||||
if ("A-1".equals(a.getAccount().getStatus())) {
|
||||
if ("A-1".equals(a.getAccount().status())) {
|
||||
bgCounterA1.getAndIncrement();
|
||||
u.setStatus("B-1");
|
||||
}
|
||||
|
||||
if ("A-2".equals(a.getAccount().getStatus())) {
|
||||
if ("A-2".equals(a.getAccount().status())) {
|
||||
bgCounterA2.getAndIncrement();
|
||||
u.setStatus("B-2");
|
||||
}
|
||||
@@ -2705,8 +2705,8 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
assertThat(bgCounterA2.get()).isEqualTo(1);
|
||||
|
||||
assertThat(updatedAccountState).isPresent();
|
||||
assertThat(updatedAccountState.get().getAccount().getStatus()).isEqualTo("B-2");
|
||||
assertThat(accounts.get(admin.id()).get().getAccount().getStatus()).isEqualTo("B-2");
|
||||
assertThat(updatedAccountState.get().getAccount().status()).isEqualTo("B-2");
|
||||
assertThat(accounts.get(admin.id()).get().getAccount().status()).isEqualTo("B-2");
|
||||
assertThat(gApi.accounts().id(admin.id().get()).get().status).isEqualTo("B-2");
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class AccountIndexerIT {
|
||||
List<AccountState> matchedAccountStates =
|
||||
accountQueryProvider.get().byPreferredEmail(preferredEmail);
|
||||
assertThat(matchedAccountStates).hasSize(1);
|
||||
assertThat(matchedAccountStates.get(0).getAccount().getId()).isEqualTo(accountId);
|
||||
assertThat(matchedAccountStates.get(0).getAccount().id()).isEqualTo(accountId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +82,7 @@ public class AccountIndexerIT {
|
||||
List<AccountState> matchedAccountStates =
|
||||
accountQueryProvider.get().byPreferredEmail(preferredEmail);
|
||||
assertThat(matchedAccountStates).hasSize(1);
|
||||
assertThat(matchedAccountStates.get(0).getAccount().getId()).isEqualTo(accountId);
|
||||
assertThat(matchedAccountStates.get(0).getAccount().id()).isEqualTo(accountId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,10 +91,10 @@ public class AccountIndexerIT {
|
||||
loadAccountToCache(accountId);
|
||||
String status = "ooo";
|
||||
updateAccountWithoutCacheOrIndex(accountId, newAccountUpdate().setStatus(status).build());
|
||||
assertThat(accountCache.get(accountId).get().getAccount().getStatus()).isNull();
|
||||
assertThat(accountCache.get(accountId).get().getAccount().status()).isNull();
|
||||
|
||||
accountIndexer.index(accountId);
|
||||
assertThat(accountCache.get(accountId).get().getAccount().getStatus()).isEqualTo(status);
|
||||
assertThat(accountCache.get(accountId).get().getAccount().status()).isEqualTo(status);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,7 +109,7 @@ public class AccountIndexerIT {
|
||||
List<AccountState> matchedAccountStates =
|
||||
accountQueryProvider.get().byPreferredEmail(preferredEmail);
|
||||
assertThat(matchedAccountStates).hasSize(1);
|
||||
assertThat(matchedAccountStates.get(0).getAccount().getId()).isEqualTo(accountId);
|
||||
assertThat(matchedAccountStates.get(0).getAccount().id()).isEqualTo(accountId);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -192,7 +192,7 @@ public class AccountManagerIT extends AbstractDaemonTest {
|
||||
|
||||
Optional<AccountState> accountState = accounts.get(accountId);
|
||||
assertThat(accountState).isPresent();
|
||||
assertThat(accountState.get().getAccount().getPreferredEmail()).isEqualTo(newEmail);
|
||||
assertThat(accountState.get().getAccount().preferredEmail()).isEqualTo(newEmail);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,7 +217,7 @@ public class AccountManagerIT extends AbstractDaemonTest {
|
||||
|
||||
Optional<AccountState> accountState = accounts.get(accountId);
|
||||
assertThat(accountState).isPresent();
|
||||
assertThat(accountState.get().getAccount().getFullName()).isEqualTo(newName);
|
||||
assertThat(accountState.get().getAccount().fullName()).isEqualTo(newName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -433,7 +433,7 @@ public class AccountManagerIT extends AbstractDaemonTest {
|
||||
// Verify that the preferred email was not updated.
|
||||
Optional<AccountState> accountState = accounts.get(accountId);
|
||||
assertThat(accountState).isPresent();
|
||||
assertThat(accountState.get().getAccount().getPreferredEmail()).isEqualTo(email);
|
||||
assertThat(accountState.get().getAccount().preferredEmail()).isEqualTo(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,6 +30,6 @@ public class GetAccountDetailIT extends AbstractDaemonTest {
|
||||
AccountDetailInfo info = newGson().fromJson(r.getReader(), AccountDetailInfo.class);
|
||||
assertAccountInfo(admin, info);
|
||||
Account account = getAccount(admin.id());
|
||||
assertThat(info.registeredOn).isEqualTo(account.getRegisteredOn());
|
||||
assertThat(info.registeredOn).isEqualTo(account.registeredOn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,6 +340,6 @@ public class AccountResolverIT extends AbstractDaemonTest {
|
||||
accountsUpdateProvider
|
||||
.get()
|
||||
.update("Force set preferred email", id, (s, u) -> u.setPreferredEmail(email));
|
||||
assertThat(result.map(a -> a.getAccount().getPreferredEmail())).hasValue(email);
|
||||
assertThat(result.map(a -> a.getAccount().preferredEmail())).hasValue(email);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +98,11 @@ public class IdentifiedUserTest {
|
||||
Injector injector = Guice.createInjector(mod);
|
||||
injector.injectMembers(this);
|
||||
|
||||
Account account = new Account(Account.id(1), TimeUtil.nowTs());
|
||||
Account.Id ownerId = account.getId();
|
||||
Account account =
|
||||
Account.builder(Account.id(1), TimeUtil.nowTs())
|
||||
.setMetaId("1234567812345678123456781234567812345678")
|
||||
.build();
|
||||
Account.Id ownerId = account.id();
|
||||
|
||||
identifiedUser = identifiedUserFactory.create(ownerId);
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class AccountResolverTest {
|
||||
@Override
|
||||
public String toString() {
|
||||
return accounts.stream()
|
||||
.map(a -> a.getAccount().getId().toString())
|
||||
.map(a -> a.getAccount().id().toString())
|
||||
.collect(joining(",", pattern + "(", ")"));
|
||||
}
|
||||
}
|
||||
@@ -238,8 +238,8 @@ public class AccountResolverTest {
|
||||
AccountState account = newAccount(1);
|
||||
ImmutableList<Searcher<?>> searchers =
|
||||
ImmutableList.of(new TestSearcher("foo", false, account));
|
||||
assertThat(search("foo", searchers, allVisible()).asUnique().getAccount().getId())
|
||||
.isEqualTo(account.getAccount().getId());
|
||||
assertThat(search("foo", searchers, allVisible()).asUnique().getAccount().id())
|
||||
.isEqualTo(account.getAccount().id());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -328,13 +328,16 @@ public class AccountResolverTest {
|
||||
}
|
||||
|
||||
private AccountState newAccount(int id) {
|
||||
return AccountState.forAccount(new Account(Account.id(id), TimeUtil.nowTs()));
|
||||
return AccountState.forAccount(
|
||||
Account.builder(Account.id(id), TimeUtil.nowTs())
|
||||
.setMetaId("1234567812345678123456781234567812345678")
|
||||
.build());
|
||||
}
|
||||
|
||||
private AccountState newInactiveAccount(int id) {
|
||||
Account a = new Account(Account.id(id), TimeUtil.nowTs());
|
||||
Account.Builder a = Account.builder(Account.id(id), TimeUtil.nowTs());
|
||||
a.setActive(false);
|
||||
return AccountState.forAccount(a);
|
||||
return AccountState.forAccount(a.build());
|
||||
}
|
||||
|
||||
private static ImmutableSet<Account.Id> ids(int... ids) {
|
||||
@@ -348,12 +351,12 @@ public class AccountResolverTest {
|
||||
private static Supplier<Predicate<AccountState>> only(int... ids) {
|
||||
ImmutableSet<Account.Id> idSet =
|
||||
Arrays.stream(ids).mapToObj(Account::id).collect(toImmutableSet());
|
||||
return () -> a -> idSet.contains(a.getAccount().getId());
|
||||
return () -> a -> idSet.contains(a.getAccount().id());
|
||||
}
|
||||
|
||||
private static ImmutableSet<Account.Id> filteredInactiveIds(Result result) {
|
||||
return result.filteredInactive().stream()
|
||||
.map(a -> a.getAccount().getId())
|
||||
.map(a -> a.getAccount().id())
|
||||
.collect(toImmutableSet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,9 +123,9 @@ public class AbstractGroupTest {
|
||||
}
|
||||
|
||||
private static Optional<Account> getAccount(Account.Id id) {
|
||||
Account account = new Account(id, TimeUtil.nowTs());
|
||||
Account.Builder account = Account.builder(id, TimeUtil.nowTs());
|
||||
account.setFullName("Account " + id);
|
||||
return Optional.of(account);
|
||||
return Optional.of(account.build());
|
||||
}
|
||||
|
||||
private Optional<GroupDescription.Basic> getGroup(AccountGroup.UUID uuid) {
|
||||
|
||||
@@ -1275,7 +1275,7 @@ public class GroupConfigTest {
|
||||
getPrefilledGroupCreationBuilder().setGroupUUID(groupUuid).build();
|
||||
InternalGroupUpdate groupUpdate =
|
||||
InternalGroupUpdate.builder()
|
||||
.setMemberModification(members -> ImmutableSet.of(account13.getId(), account7.getId()))
|
||||
.setMemberModification(members -> ImmutableSet.of(account13.id(), account7.id()))
|
||||
.build();
|
||||
|
||||
GroupConfig groupConfig = GroupConfig.createForNewGroup(projectName, repository, groupCreation);
|
||||
@@ -1325,7 +1325,7 @@ public class GroupConfigTest {
|
||||
|
||||
InternalGroupUpdate groupUpdate =
|
||||
InternalGroupUpdate.builder()
|
||||
.setMemberModification(members -> ImmutableSet.of(account13.getId(), account7.getId()))
|
||||
.setMemberModification(members -> ImmutableSet.of(account13.id(), account7.id()))
|
||||
.build();
|
||||
updateGroup(groupUuid, groupUpdate, auditLogFormatter);
|
||||
|
||||
@@ -1347,13 +1347,13 @@ public class GroupConfigTest {
|
||||
|
||||
InternalGroupUpdate groupUpdate1 =
|
||||
InternalGroupUpdate.builder()
|
||||
.setMemberModification(members -> ImmutableSet.of(account13.getId(), account7.getId()))
|
||||
.setMemberModification(members -> ImmutableSet.of(account13.id(), account7.id()))
|
||||
.build();
|
||||
updateGroup(groupUuid, groupUpdate1, auditLogFormatter);
|
||||
|
||||
InternalGroupUpdate groupUpdate2 =
|
||||
InternalGroupUpdate.builder()
|
||||
.setMemberModification(members -> ImmutableSet.of(account7.getId()))
|
||||
.setMemberModification(members -> ImmutableSet.of(account7.id()))
|
||||
.build();
|
||||
updateGroup(groupUuid, groupUpdate2, auditLogFormatter);
|
||||
|
||||
@@ -1447,7 +1447,7 @@ public class GroupConfigTest {
|
||||
InternalGroupUpdate groupUpdate1 =
|
||||
InternalGroupUpdate.builder()
|
||||
.setName(AccountGroup.nameKey("Old name"))
|
||||
.setMemberModification(members -> ImmutableSet.of(account7.getId()))
|
||||
.setMemberModification(members -> ImmutableSet.of(account7.id()))
|
||||
.setSubgroupModification(subgroups -> ImmutableSet.of(group2.getGroupUUID()))
|
||||
.build();
|
||||
updateGroup(groupUuid, groupUpdate1, auditLogFormatter);
|
||||
@@ -1455,7 +1455,7 @@ public class GroupConfigTest {
|
||||
InternalGroupUpdate groupUpdate2 =
|
||||
InternalGroupUpdate.builder()
|
||||
.setName(AccountGroup.nameKey("New name"))
|
||||
.setMemberModification(members -> ImmutableSet.of(account13.getId()))
|
||||
.setMemberModification(members -> ImmutableSet.of(account13.id()))
|
||||
.setSubgroupModification(subgroups -> ImmutableSet.of(group1.getGroupUUID()))
|
||||
.build();
|
||||
updateGroup(groupUuid, groupUpdate2, auditLogFormatter);
|
||||
@@ -1581,9 +1581,9 @@ public class GroupConfigTest {
|
||||
}
|
||||
|
||||
private static Account createAccount(Account.Id id, String name) {
|
||||
Account account = new Account(id, TimeUtil.nowTs());
|
||||
Account.Builder account = Account.builder(id, TimeUtil.nowTs());
|
||||
account.setFullName(name);
|
||||
return account;
|
||||
return account.build();
|
||||
}
|
||||
|
||||
private static GroupDescription.Basic createGroup(AccountGroup.UUID uuid, String name) {
|
||||
|
||||
@@ -36,20 +36,24 @@ public class AccountFieldTest {
|
||||
@Test
|
||||
public void refStateFieldValues() throws Exception {
|
||||
AllUsersName allUsersName = new AllUsersName(AllUsersNameProvider.DEFAULT);
|
||||
Account account = new Account(Account.id(1), TimeUtil.nowTs());
|
||||
Account.Builder account = Account.builder(Account.id(1), TimeUtil.nowTs());
|
||||
String metaId = "0e39795bb25dc914118224995c53c5c36923a461";
|
||||
account.setMetaId(metaId);
|
||||
List<String> values = toStrings(AccountField.REF_STATE.get(AccountState.forAccount(account)));
|
||||
List<String> values =
|
||||
toStrings(AccountField.REF_STATE.get(AccountState.forAccount(account.build())));
|
||||
assertThat(values).hasSize(1);
|
||||
String expectedValue =
|
||||
allUsersName.get() + ":" + RefNames.refsUsers(account.getId()) + ":" + metaId;
|
||||
allUsersName.get() + ":" + RefNames.refsUsers(account.id()) + ":" + metaId;
|
||||
assertThat(Iterables.getOnlyElement(values)).isEqualTo(expectedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalIdStateFieldValues() throws Exception {
|
||||
Account.Id id = Account.id(1);
|
||||
Account account = new Account(id, TimeUtil.nowTs());
|
||||
Account account =
|
||||
Account.builder(id, TimeUtil.nowTs())
|
||||
.setMetaId("1234567812345678123456781234567812345678")
|
||||
.build();
|
||||
ExternalId extId1 =
|
||||
ExternalId.create(
|
||||
ExternalId.Key.create(ExternalId.SCHEME_MAILTO, "foo.bar@example.com"),
|
||||
|
||||
@@ -367,20 +367,20 @@ public class FromAddressGeneratorProviderTest {
|
||||
|
||||
private Account.Id user(String name, String email) {
|
||||
final AccountState s = makeUser(name, email);
|
||||
expect(accountCache.get(eq(s.getAccount().getId()))).andReturn(Optional.of(s));
|
||||
return s.getAccount().getId();
|
||||
expect(accountCache.get(eq(s.getAccount().id()))).andReturn(Optional.of(s));
|
||||
return s.getAccount().id();
|
||||
}
|
||||
|
||||
private Account.Id userNoLookup(String name, String email) {
|
||||
final AccountState s = makeUser(name, email);
|
||||
return s.getAccount().getId();
|
||||
return s.getAccount().id();
|
||||
}
|
||||
|
||||
private AccountState makeUser(String name, String email) {
|
||||
final Account.Id userId = Account.id(42);
|
||||
final Account account = new Account(userId, TimeUtil.nowTs());
|
||||
final Account.Builder account = Account.builder(userId, TimeUtil.nowTs());
|
||||
account.setFullName(name);
|
||||
account.setPreferredEmail(email);
|
||||
return AccountState.forAccount(account);
|
||||
return AccountState.forAccount(account.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,14 +120,14 @@ public abstract class AbstractChangeNotesTest {
|
||||
tr = new TestRepository<>(repo);
|
||||
rw = tr.getRevWalk();
|
||||
accountCache = new FakeAccountCache();
|
||||
Account co = new Account(Account.id(1), TimeUtil.nowTs());
|
||||
Account.Builder co = Account.builder(Account.id(1), TimeUtil.nowTs());
|
||||
co.setFullName("Change Owner");
|
||||
co.setPreferredEmail("change@owner.com");
|
||||
accountCache.put(co);
|
||||
Account ou = new Account(Account.id(2), TimeUtil.nowTs());
|
||||
accountCache.put(co.build());
|
||||
Account.Builder ou = Account.builder(Account.id(2), TimeUtil.nowTs());
|
||||
ou.setFullName("Other Account");
|
||||
ou.setPreferredEmail("other@account.com");
|
||||
accountCache.put(ou);
|
||||
accountCache.put(ou.build());
|
||||
assertableFanOutExecutor = new AssertableExecutorService();
|
||||
|
||||
injector =
|
||||
@@ -169,8 +169,8 @@ public abstract class AbstractChangeNotesTest {
|
||||
|
||||
injector.injectMembers(this);
|
||||
repoManager.createRepository(allUsers);
|
||||
changeOwner = userFactory.create(co.getId());
|
||||
otherUser = userFactory.create(ou.getId());
|
||||
changeOwner = userFactory.create(co.id());
|
||||
otherUser = userFactory.create(ou.id());
|
||||
otherUserId = otherUser.getAccountId();
|
||||
internalUser = new InternalUser();
|
||||
}
|
||||
|
||||
@@ -515,8 +515,8 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
public void multipleReviewers() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().id(), REVIEWER);
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
@@ -534,8 +534,8 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
public void reviewerTypes() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().getId(), CC);
|
||||
update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().id(), CC);
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
@@ -553,7 +553,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
public void oneReviewerMultipleTypes() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(otherUser.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().id(), REVIEWER);
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
@@ -562,7 +562,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
.isEqualTo(ReviewerSet.fromTable(ImmutableTable.of(REVIEWER, Account.id(2), ts)));
|
||||
|
||||
update = newUpdate(c, otherUser);
|
||||
update.putReviewer(otherUser.getAccount().getId(), CC);
|
||||
update.putReviewer(otherUser.getAccount().id(), CC);
|
||||
update.commit();
|
||||
|
||||
notes = newNotes(c);
|
||||
@@ -575,7 +575,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
public void removeReviewer() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(otherUser.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().id(), REVIEWER);
|
||||
update.commit();
|
||||
|
||||
update = newUpdate(c, changeOwner);
|
||||
@@ -589,17 +589,17 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
ChangeNotes notes = newNotes(c);
|
||||
List<PatchSetApproval> psas = notes.getApprovals().get(c.currentPatchSetId());
|
||||
assertThat(psas).hasSize(2);
|
||||
assertThat(psas.get(0).accountId()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(psas.get(1).accountId()).isEqualTo(otherUser.getAccount().getId());
|
||||
assertThat(psas.get(0).accountId()).isEqualTo(changeOwner.getAccount().id());
|
||||
assertThat(psas.get(1).accountId()).isEqualTo(otherUser.getAccount().id());
|
||||
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.removeReviewer(otherUser.getAccount().getId());
|
||||
update.removeReviewer(otherUser.getAccount().id());
|
||||
update.commit();
|
||||
|
||||
notes = newNotes(c);
|
||||
psas = notes.getApprovals().get(c.currentPatchSetId());
|
||||
assertThat(psas).hasSize(1);
|
||||
assertThat(psas.get(0).accountId()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(psas.get(0).accountId()).isEqualTo(changeOwner.getAccount().id());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1211,11 +1211,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
List<PatchSetApproval> psas = notes.getApprovals().get(c.currentPatchSetId());
|
||||
assertThat(psas).hasSize(2);
|
||||
|
||||
assertThat(psas.get(0).accountId()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(psas.get(0).accountId()).isEqualTo(changeOwner.getAccount().id());
|
||||
assertThat(psas.get(0).label()).isEqualTo("Verified");
|
||||
assertThat(psas.get(0).value()).isEqualTo((short) 1);
|
||||
|
||||
assertThat(psas.get(1).accountId()).isEqualTo(otherUser.getAccount().getId());
|
||||
assertThat(psas.get(1).accountId()).isEqualTo(otherUser.getAccount().id());
|
||||
assertThat(psas.get(1).label()).isEqualTo("Code-Review");
|
||||
assertThat(psas.get(1).value()).isEqualTo((short) 2);
|
||||
}
|
||||
@@ -1336,14 +1336,14 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
public void changeMessageOnePatchSet() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
|
||||
update.setChangeMessage("Just a little code change.\n");
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeMessage cm = Iterables.getOnlyElement(notes.getChangeMessages());
|
||||
assertThat(cm.getMessage()).isEqualTo("Just a little code change.\n");
|
||||
assertThat(cm.getAuthor()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(cm.getAuthor()).isEqualTo(changeOwner.getAccount().id());
|
||||
assertThat(cm.getPatchSetId()).isEqualTo(c.currentPatchSetId());
|
||||
}
|
||||
|
||||
@@ -1351,7 +1351,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
public void noChangeMessage() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
@@ -1368,7 +1368,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeMessage cm1 = Iterables.getOnlyElement(notes.getChangeMessages());
|
||||
assertThat(cm1.getMessage()).isEqualTo("Testing trailing double newline\n\n");
|
||||
assertThat(cm1.getAuthor()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(cm1.getAuthor()).isEqualTo(changeOwner.getAccount().id());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1387,14 +1387,14 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
+ "Testing paragraph 2\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 3");
|
||||
assertThat(cm1.getAuthor()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(cm1.getAuthor()).isEqualTo(changeOwner.getAccount().id());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeMessagesMultiplePatchSets() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
|
||||
update.setChangeMessage("This is the change message for the first PS.");
|
||||
update.commit();
|
||||
PatchSet.Id ps1 = c.currentPatchSetId();
|
||||
@@ -1412,12 +1412,12 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
ChangeMessage cm1 = notes.getChangeMessages().get(0);
|
||||
assertThat(cm1.getPatchSetId()).isEqualTo(ps1);
|
||||
assertThat(cm1.getMessage()).isEqualTo("This is the change message for the first PS.");
|
||||
assertThat(cm1.getAuthor()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(cm1.getAuthor()).isEqualTo(changeOwner.getAccount().id());
|
||||
|
||||
ChangeMessage cm2 = notes.getChangeMessages().get(1);
|
||||
assertThat(cm2.getPatchSetId()).isEqualTo(ps2);
|
||||
assertThat(cm2.getMessage()).isEqualTo("This is the change message for the second PS.");
|
||||
assertThat(cm2.getAuthor()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(cm2.getAuthor()).isEqualTo(changeOwner.getAccount().id());
|
||||
assertThat(cm2.getPatchSetId()).isEqualTo(ps2);
|
||||
}
|
||||
|
||||
@@ -1425,14 +1425,14 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
public void changeMessageMultipleInOnePatchSet() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
|
||||
update.setChangeMessage("First change message.\n");
|
||||
update.commit();
|
||||
|
||||
PatchSet.Id ps1 = c.currentPatchSetId();
|
||||
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
|
||||
update.setChangeMessage("Second change message.\n");
|
||||
update.commit();
|
||||
|
||||
@@ -1441,10 +1441,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
List<ChangeMessage> cm = notes.getChangeMessages();
|
||||
assertThat(cm).hasSize(2);
|
||||
assertThat(cm.get(0).getMessage()).isEqualTo("First change message.\n");
|
||||
assertThat(cm.get(0).getAuthor()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(cm.get(0).getAuthor()).isEqualTo(changeOwner.getAccount().id());
|
||||
assertThat(cm.get(0).getPatchSetId()).isEqualTo(ps1);
|
||||
assertThat(cm.get(1).getMessage()).isEqualTo("Second change message.\n");
|
||||
assertThat(cm.get(1).getAuthor()).isEqualTo(changeOwner.getAccount().getId());
|
||||
assertThat(cm.get(1).getAuthor()).isEqualTo(changeOwner.getAccount().id());
|
||||
assertThat(cm.get(1).getPatchSetId()).isEqualTo(ps1);
|
||||
}
|
||||
|
||||
@@ -1681,11 +1681,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
|
||||
@Test
|
||||
public void patchLineCommentNotesFormatWeirdUser() throws Exception {
|
||||
Account account = new Account(Account.id(3), TimeUtil.nowTs());
|
||||
Account.Builder account = Account.builder(Account.id(3), TimeUtil.nowTs());
|
||||
account.setFullName("Weird\n\u0002<User>\n");
|
||||
account.setPreferredEmail(" we\r\nird@ex>ample<.com");
|
||||
accountCache.put(account);
|
||||
IdentifiedUser user = userFactory.create(account.getId());
|
||||
accountCache.put(account.build());
|
||||
IdentifiedUser user = userFactory.create(Account.id(3));
|
||||
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, user);
|
||||
@@ -2936,8 +2936,8 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
public void pendingReviewers() throws Exception {
|
||||
Address adr1 = new Address("Foo Bar1", "foo.bar1@gerritcodereview.com");
|
||||
Address adr2 = new Address("Foo Bar2", "foo.bar2@gerritcodereview.com");
|
||||
Account.Id ownerId = changeOwner.getAccount().getId();
|
||||
Account.Id otherUserId = otherUser.getAccount().getId();
|
||||
Account.Id ownerId = changeOwner.getAccount().id();
|
||||
Account.Id otherUserId = otherUser.getAccount().id();
|
||||
|
||||
ChangeNotes notes = newNotes(newChange());
|
||||
assertThat(notes.getPendingReviewers().asTable()).isEmpty();
|
||||
|
||||
@@ -44,8 +44,8 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
ChangeUpdate update = newUpdateForNewChange(c, changeOwner);
|
||||
update.putApproval("Verified", (short) 1);
|
||||
update.putApproval("Code-Review", (short) -1);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().getId(), CC);
|
||||
update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().id(), CC);
|
||||
update.commit();
|
||||
assertThat(update.getRefName()).isEqualTo("refs/changes/01/1/meta");
|
||||
|
||||
@@ -199,10 +199,13 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
|
||||
@Test
|
||||
public void anonymousUser() throws Exception {
|
||||
Account anon = new Account(Account.id(3), TimeUtil.nowTs());
|
||||
Account anon =
|
||||
Account.builder(Account.id(3), TimeUtil.nowTs())
|
||||
.setMetaId("1234567812345678123456781234567812345678")
|
||||
.build();
|
||||
accountCache.put(anon);
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, userFactory.create(anon.getId()));
|
||||
ChangeUpdate update = newUpdate(c, userFactory.create(anon.id()));
|
||||
update.setChangeMessage("Comment on the change.");
|
||||
update.commit();
|
||||
|
||||
@@ -241,7 +244,7 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
public void noChangeMessage() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals(
|
||||
|
||||
@@ -816,7 +816,7 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
}
|
||||
|
||||
protected void assertAccounts(List<AccountState> accounts, AccountInfo... expectedAccounts) {
|
||||
assertThat(accounts.stream().map(a -> a.getAccount().getId().get()).collect(toList()))
|
||||
assertThat(accounts.stream().map(a -> a.getAccount().id().get()).collect(toList()))
|
||||
.containsExactlyElementsIn(
|
||||
Arrays.asList(expectedAccounts).stream().map(a -> a._accountId).collect(toList()));
|
||||
}
|
||||
|
||||
Submodule plugins/reviewnotes updated: 436529473a...3667220b86
Submodule plugins/singleusergroup updated: ce8b761685...db5397931e
Reference in New Issue
Block a user