AccountsUpdate: Return AccountState instead of Account
On insert/update of an account the updated Account instance was returned. However on insert/update of an account not only account properties can be set, but also external IDs, watched projectis and general preferences. To be consistent we should rather return the updated AccountState which includes external IDs, watched projects and general preferences in addition to the account. Change-Id: Iff30984fe39551f88480399b57ce9cb3a90a10e2 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -360,7 +360,7 @@ public class AccountsUpdate {
|
||||
* @throws OrmException if creating the user branch fails
|
||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||
*/
|
||||
public Account insert(
|
||||
public AccountState insert(
|
||||
String message, Account.Id accountId, Consumer<InternalAccountUpdate.Builder> init)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
return insert(message, accountId, AccountUpdater.fromConsumer(init));
|
||||
@@ -378,7 +378,7 @@ public class AccountsUpdate {
|
||||
* @throws OrmException if creating the user branch fails
|
||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||
*/
|
||||
public Account insert(String message, Account.Id accountId, AccountUpdater updater)
|
||||
public AccountState insert(String message, Account.Id accountId, AccountUpdater updater)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
return updateAccount(
|
||||
r -> {
|
||||
@@ -399,7 +399,8 @@ public class AccountsUpdate {
|
||||
accountConfig.setAccountUpdate(update);
|
||||
ExternalIdNotes extIdNotes =
|
||||
createExternalIdNotes(r, accountConfig.getExternalIdsRev(), accountId, update);
|
||||
UpdatedAccount updatedAccounts = new UpdatedAccount(message, accountConfig, extIdNotes);
|
||||
UpdatedAccount updatedAccounts =
|
||||
new UpdatedAccount(allUsersName, externalIds, message, accountConfig, extIdNotes);
|
||||
updatedAccounts.setCreated(true);
|
||||
return updatedAccounts;
|
||||
});
|
||||
@@ -418,7 +419,7 @@ public class AccountsUpdate {
|
||||
* @throws OrmException if updating the user branch fails
|
||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||
*/
|
||||
public Account update(
|
||||
public AccountState update(
|
||||
String message, Account.Id accountId, Consumer<InternalAccountUpdate.Builder> update)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
return update(message, accountId, AccountUpdater.fromConsumer(update));
|
||||
@@ -438,7 +439,7 @@ public class AccountsUpdate {
|
||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||
*/
|
||||
@Nullable
|
||||
public Account update(String message, Account.Id accountId, AccountUpdater updater)
|
||||
public AccountState update(String message, Account.Id accountId, AccountUpdater updater)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
return updateAccount(
|
||||
r -> {
|
||||
@@ -456,7 +457,8 @@ public class AccountsUpdate {
|
||||
accountConfig.setAccountUpdate(update);
|
||||
ExternalIdNotes extIdNotes =
|
||||
createExternalIdNotes(r, accountConfig.getExternalIdsRev(), accountId, update);
|
||||
UpdatedAccount updatedAccounts = new UpdatedAccount(message, accountConfig, extIdNotes);
|
||||
UpdatedAccount updatedAccounts =
|
||||
new UpdatedAccount(allUsersName, externalIds, message, accountConfig, extIdNotes);
|
||||
return updatedAccounts;
|
||||
});
|
||||
}
|
||||
@@ -468,7 +470,7 @@ public class AccountsUpdate {
|
||||
return accountConfig;
|
||||
}
|
||||
|
||||
private Account updateAccount(AccountUpdate accountUpdate)
|
||||
private AccountState updateAccount(AccountUpdate accountUpdate)
|
||||
throws IOException, ConfigInvalidException, OrmException {
|
||||
return retryHelper.execute(
|
||||
ActionType.ACCOUNT_UPDATE,
|
||||
@@ -508,6 +510,7 @@ public class AccountsUpdate {
|
||||
beforeCommit.run();
|
||||
|
||||
BatchRefUpdate batchRefUpdate = allUsersRepo.getRefDatabase().newBatchUpdate();
|
||||
|
||||
if (updatedAccount.isCreated()) {
|
||||
commitNewAccountConfig(
|
||||
updatedAccount.getMessage(),
|
||||
@@ -527,6 +530,7 @@ public class AccountsUpdate {
|
||||
allUsersRepo,
|
||||
batchRefUpdate,
|
||||
updatedAccount.getExternalIdNotes());
|
||||
|
||||
RefUpdateUtil.executeChecked(batchRefUpdate, allUsersRepo);
|
||||
updatedAccount.getExternalIdNotes().updateCaches();
|
||||
gitRefUpdated.fire(
|
||||
@@ -599,6 +603,8 @@ public class AccountsUpdate {
|
||||
}
|
||||
|
||||
private static class UpdatedAccount {
|
||||
private final AllUsersName allUsersName;
|
||||
private final ExternalIds externalIds;
|
||||
private final String message;
|
||||
private final AccountConfig accountConfig;
|
||||
private final ExternalIdNotes extIdNotes;
|
||||
@@ -606,8 +612,14 @@ public class AccountsUpdate {
|
||||
private boolean created;
|
||||
|
||||
private UpdatedAccount(
|
||||
String message, AccountConfig accountConfig, ExternalIdNotes extIdNotes) {
|
||||
AllUsersName allUsersName,
|
||||
ExternalIds externalIds,
|
||||
String message,
|
||||
AccountConfig accountConfig,
|
||||
ExternalIdNotes extIdNotes) {
|
||||
checkState(!Strings.isNullOrEmpty(message), "message for account update must be set");
|
||||
this.allUsersName = checkNotNull(allUsersName);
|
||||
this.externalIds = checkNotNull(externalIds);
|
||||
this.message = checkNotNull(message);
|
||||
this.accountConfig = checkNotNull(accountConfig);
|
||||
this.extIdNotes = checkNotNull(extIdNotes);
|
||||
@@ -621,8 +633,16 @@ public class AccountsUpdate {
|
||||
return accountConfig;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return accountConfig.getLoadedAccount().get();
|
||||
public AccountState getAccount() throws IOException {
|
||||
Account account = accountConfig.getLoadedAccount().get();
|
||||
return new AccountState(
|
||||
allUsersName,
|
||||
account,
|
||||
extIdNotes.getRevision() != null
|
||||
? externalIds.byAccount(account.getId(), extIdNotes.getRevision())
|
||||
: ImmutableSet.of(),
|
||||
accountConfig.getProjectWatches(),
|
||||
accountConfig.getGeneralPreferences());
|
||||
}
|
||||
|
||||
public ExternalIdNotes getExternalIdNotes() {
|
||||
|
||||
Reference in New Issue
Block a user