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);
}
}
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);
}
}
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);
}
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);
}
Aggregations