Search in sources :

Example 1 with RemoveFromAttentionSetOp

use of com.google.gerrit.server.change.RemoveFromAttentionSetOp in project gerrit by GerritCodeReview.

the class RemoveFromAttentionSet method apply.

@Override
public Response<Object> apply(AttentionSetEntryResource attentionResource, AttentionSetInput input) throws RestApiException, PermissionBackendException, IOException, ConfigInvalidException, UpdateException {
    if (input == null) {
        throw new BadRequestException("input may not be null");
    }
    input.reason = Strings.nullToEmpty(input.reason).trim();
    if (input.reason.isEmpty()) {
        throw new BadRequestException("missing field: reason");
    }
    input.user = Strings.nullToEmpty(input.user).trim();
    if (!input.user.isEmpty()) {
        Account.Id attentionUserId = AttentionSetUtil.resolveAccount(accountResolver, attentionResource.getChangeResource().getNotes(), input.user);
        if (attentionUserId.get() != attentionResource.getAccountId().get()) {
            throw new BadRequestException("The field \"user\" must be empty, or must match the user specified in the URL.");
        }
    }
    ChangeResource changeResource = attentionResource.getChangeResource();
    try (BatchUpdate bu = updateFactory.create(changeResource.getProject(), changeResource.getUser(), TimeUtil.now())) {
        RemoveFromAttentionSetOp op = opFactory.create(attentionResource.getAccountId(), input.reason, true);
        bu.addOp(changeResource.getId(), op);
        NotifyHandling notify = input.notify == null ? NotifyHandling.OWNER : input.notify;
        NotifyResolver.Result notifyResult = notifyResolver.resolve(notify, input.notifyDetails);
        bu.setNotify(notifyResult);
        bu.execute();
    }
    return Response.none();
}
Also used : Account(com.google.gerrit.entities.Account) NotifyResolver(com.google.gerrit.server.change.NotifyResolver) ChangeResource(com.google.gerrit.server.change.ChangeResource) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RemoveFromAttentionSetOp(com.google.gerrit.server.change.RemoveFromAttentionSetOp) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 2 with RemoveFromAttentionSetOp

use of com.google.gerrit.server.change.RemoveFromAttentionSetOp in project gerrit by GerritCodeReview.

the class ReplyAttentionSetUpdates method removeFromAttentionSet.

/**
 * Removes the user from the attention set
 *
 * @param bu BatchUpdate to perform the updates to the attention set.
 * @param changeNotes current change.
 * @param user user to add remove from the attention set.
 * @param reason reason for removing.
 * @param notify whether or not to notify about this removal.
 */
private void removeFromAttentionSet(BatchUpdate bu, ChangeNotes changeNotes, Account.Id user, String reason, boolean notify) {
    RemoveFromAttentionSetOp removeFromAttentionSetOp = removeFromAttentionSetOpFactory.create(user, reason, notify);
    bu.addOp(changeNotes.getChangeId(), removeFromAttentionSetOp);
}
Also used : RemoveFromAttentionSetOp(com.google.gerrit.server.change.RemoveFromAttentionSetOp)

Aggregations

RemoveFromAttentionSetOp (com.google.gerrit.server.change.RemoveFromAttentionSetOp)2 Account (com.google.gerrit.entities.Account)1 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 ChangeResource (com.google.gerrit.server.change.ChangeResource)1 NotifyResolver (com.google.gerrit.server.change.NotifyResolver)1 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)1