use of com.google.gerrit.extensions.api.changes.TopicInput in project gerrit by GerritCodeReview.
the class ChangeApiImpl method topic.
@Override
public void topic(String topic) throws RestApiException {
TopicInput in = new TopicInput();
in.topic = topic;
try {
putTopic.apply(change, in);
} catch (Exception e) {
throw asRestApiException("Cannot set topic", e);
}
}
use of com.google.gerrit.extensions.api.changes.TopicInput in project gerrit by GerritCodeReview.
the class PutTopic method apply.
@Override
public Response<String> apply(ChangeResource req, TopicInput input) throws UpdateException, RestApiException, PermissionBackendException {
req.permissions().check(ChangePermission.EDIT_TOPIC_NAME);
if (input != null && input.topic != null && input.topic.length() > ChangeUtil.TOPIC_MAX_LENGTH) {
throw new BadRequestException(String.format("topic length exceeds the limit (%s)", ChangeUtil.TOPIC_MAX_LENGTH));
}
TopicInput sanitizedInput = input == null ? new TopicInput() : input;
if (sanitizedInput.topic != null) {
sanitizedInput.topic = sanitizedInput.topic.trim();
}
SetTopicOp op = topicOpFactory.create(sanitizedInput.topic);
try (BatchUpdate u = updateFactory.create(req.getChange().getProject(), req.getUser(), TimeUtil.now())) {
u.addOp(req.getId(), op);
u.execute();
}
if (Strings.isNullOrEmpty(sanitizedInput.topic)) {
return Response.none();
}
return Response.ok(sanitizedInput.topic);
}
Aggregations