use of com.google.gerrit.extensions.api.accounts.DisplayNameInput in project gerrit by GerritCodeReview.
the class PutDisplayName method apply.
@Override
public Response<String> apply(AccountResource rsrc, @Nullable DisplayNameInput input) throws AuthException, ResourceNotFoundException, IOException, PermissionBackendException, ConfigInvalidException {
IdentifiedUser user = rsrc.getUser();
if (!self.get().hasSameAccountId(user)) {
permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
}
if (input == null) {
input = new DisplayNameInput();
}
String newDisplayName = input.displayName;
AccountState accountState = accountsUpdateProvider.get().update("Set Display Name via API", user.getAccountId(), u -> u.setDisplayName(newDisplayName)).orElseThrow(() -> new ResourceNotFoundException("account not found"));
return Strings.isNullOrEmpty(accountState.account().displayName()) ? Response.none() : Response.ok(accountState.account().displayName());
}
Aggregations