Search in sources :

Example 1 with DescriptionInput

use of com.google.gerrit.extensions.common.DescriptionInput in project gerrit by GerritCodeReview.

the class RevisionApiImpl method description.

@Override
public void description(String description) throws RestApiException {
    DescriptionInput in = new DescriptionInput();
    in.description = description;
    try {
        putDescription.apply(revision, in);
    } catch (Exception e) {
        throw asRestApiException("Cannot set description", e);
    }
}
Also used : DescriptionInput(com.google.gerrit.extensions.common.DescriptionInput) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 2 with DescriptionInput

use of com.google.gerrit.extensions.common.DescriptionInput in project gerrit by GerritCodeReview.

the class GroupApiImpl method description.

@Override
public void description(String description) throws RestApiException {
    DescriptionInput in = new DescriptionInput();
    in.description = description;
    try {
        putDescription.apply(rsrc, in);
    } catch (Exception e) {
        throw asRestApiException("Cannot put group description", e);
    }
}
Also used : DescriptionInput(com.google.gerrit.extensions.common.DescriptionInput) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 3 with DescriptionInput

use of com.google.gerrit.extensions.common.DescriptionInput in project gerrit by GerritCodeReview.

the class PutDescription method apply.

@Override
public Response<String> apply(RevisionResource rsrc, DescriptionInput input) throws UpdateException, RestApiException, PermissionBackendException {
    rsrc.permissions().check(ChangePermission.EDIT_DESCRIPTION);
    Op op = new Op(input != null ? input : new DescriptionInput(), rsrc.getPatchSet().id());
    try (BatchUpdate u = updateFactory.create(rsrc.getChange().getProject(), rsrc.getUser(), TimeUtil.now())) {
        u.addOp(rsrc.getChange().getId(), op);
        u.execute();
    }
    return Strings.isNullOrEmpty(op.newDescription) ? Response.none() : Response.ok(op.newDescription);
}
Also used : BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) DescriptionInput(com.google.gerrit.extensions.common.DescriptionInput) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 4 with DescriptionInput

use of com.google.gerrit.extensions.common.DescriptionInput in project gerrit by GerritCodeReview.

the class PutDescription method apply.

@Override
public Response<String> apply(GroupResource resource, DescriptionInput input) throws AuthException, NotInternalGroupException, ResourceNotFoundException, IOException, ConfigInvalidException {
    if (input == null) {
        // Delete would set description to null.
        input = new DescriptionInput();
    }
    GroupDescription.Internal internalGroup = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
    if (!resource.getControl().isOwner()) {
        throw new AuthException("Not group owner");
    }
    String currentDescription = Strings.nullToEmpty(internalGroup.getDescription());
    String newDescription = Strings.nullToEmpty(input.description);
    if (!Objects.equals(currentDescription, newDescription)) {
        AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
        GroupDelta groupDelta = GroupDelta.builder().setDescription(newDescription).build();
        try {
            groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
        } catch (NoSuchGroupException e) {
            throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
        }
    }
    return Strings.isNullOrEmpty(input.description) ? Response.none() : Response.ok(input.description);
}
Also used : GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) DescriptionInput(com.google.gerrit.extensions.common.DescriptionInput) AuthException(com.google.gerrit.extensions.restapi.AuthException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Aggregations

DescriptionInput (com.google.gerrit.extensions.common.DescriptionInput)4 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)2 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)2 AccountGroup (com.google.gerrit.entities.AccountGroup)1 GroupDescription (com.google.gerrit.entities.GroupDescription)1 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 GroupDelta (com.google.gerrit.server.group.db.GroupDelta)1 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)1 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)1