Search in sources :

Example 1 with Input

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

the class PutName method apply.

public Response<String> apply(IdentifiedUser user, Input input) throws MethodNotAllowedException, ResourceNotFoundException, OrmException, IOException {
    if (input == null) {
        input = new Input();
    }
    if (!realm.allowsEdit(AccountFieldName.FULL_NAME)) {
        throw new MethodNotAllowedException("realm does not allow editing name");
    }
    String newName = input.name;
    Account a = dbProvider.get().accounts().atomicUpdate(user.getAccountId(), new AtomicUpdate<Account>() {

        @Override
        public Account update(Account a) {
            a.setFullName(newName);
            return a;
        }
    });
    if (a == null) {
        throw new ResourceNotFoundException("account not found");
    }
    byIdCache.evict(a.getId());
    return Strings.isNullOrEmpty(a.getFullName()) ? Response.<String>none() : Response.ok(a.getFullName());
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) DefaultInput(com.google.gerrit.extensions.restapi.DefaultInput) Input(com.google.gerrit.server.account.PutName.Input) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

DefaultInput (com.google.gerrit.extensions.restapi.DefaultInput)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 Account (com.google.gerrit.reviewdb.client.Account)1 Input (com.google.gerrit.server.account.PutName.Input)1