use of com.google.gerrit.server.change.SetTopicOp in project gerrit by GerritCodeReview.
the class SetTopicCommand method run.
@Override
public void run() throws Exception {
if (topic != null) {
topic = topic.trim();
}
if (topic != null && topic.length() > ChangeUtil.TOPIC_MAX_LENGTH) {
throw new BadRequestException(String.format("topic length exceeds the limit (%s)", ChangeUtil.TOPIC_MAX_LENGTH));
}
for (ChangeResource r : changes.values()) {
SetTopicOp op = topicOpFactory.create(topic);
try (BatchUpdate u = updateFactory.create(r.getChange().getProject(), user, TimeUtil.now())) {
u.addOp(r.getId(), op);
u.execute();
}
}
}
use of com.google.gerrit.server.change.SetTopicOp 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