Search in sources :

Example 1 with TopicInput

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);
    }
}
Also used : TopicInput(com.google.gerrit.extensions.api.changes.TopicInput) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) IllegalLabelException(com.google.gerrit.server.StarredChangesUtil.IllegalLabelException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) StorageException(com.google.gerrit.exceptions.StorageException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 2 with TopicInput

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

TopicInput (com.google.gerrit.extensions.api.changes.TopicInput)2 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)2 StorageException (com.google.gerrit.exceptions.StorageException)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 IllegalLabelException (com.google.gerrit.server.StarredChangesUtil.IllegalLabelException)1 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)1 SetTopicOp (com.google.gerrit.server.change.SetTopicOp)1 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1