Search in sources :

Example 1 with SetTopicOp

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();
        }
    }
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) SetTopicOp(com.google.gerrit.server.change.SetTopicOp) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 2 with SetTopicOp

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);
}
Also used : TopicInput(com.google.gerrit.extensions.api.changes.TopicInput) SetTopicOp(com.google.gerrit.server.change.SetTopicOp) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Aggregations

BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)2 SetTopicOp (com.google.gerrit.server.change.SetTopicOp)2 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)2 TopicInput (com.google.gerrit.extensions.api.changes.TopicInput)1 ChangeResource (com.google.gerrit.server.change.ChangeResource)1