Search in sources :

Example 1 with Input

use of com.google.gerrit.server.group.PutDescription.Input in project gerrit by GerritCodeReview.

the class PutDescription method apply.

@Override
public Response<String> apply(GroupResource resource, Input input) throws AuthException, MethodNotAllowedException, ResourceNotFoundException, OrmException, IOException {
    if (input == null) {
        // Delete would set description to null.
        input = new Input();
    }
    if (resource.toAccountGroup() == null) {
        throw new MethodNotAllowedException();
    } else if (!resource.getControl().isOwner()) {
        throw new AuthException("Not group owner");
    }
    AccountGroup group = db.get().accountGroups().get(resource.toAccountGroup().getId());
    if (group == null) {
        throw new ResourceNotFoundException();
    }
    group.setDescription(Strings.emptyToNull(input.description));
    db.get().accountGroups().update(Collections.singleton(group));
    groupCache.evict(group);
    return Strings.isNullOrEmpty(input.description) ? Response.<String>none() : Response.ok(input.description);
}
Also used : DefaultInput(com.google.gerrit.extensions.restapi.DefaultInput) Input(com.google.gerrit.server.group.PutDescription.Input) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AuthException(com.google.gerrit.extensions.restapi.AuthException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

AuthException (com.google.gerrit.extensions.restapi.AuthException)1 DefaultInput (com.google.gerrit.extensions.restapi.DefaultInput)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)1 Input (com.google.gerrit.server.group.PutDescription.Input)1