Search in sources :

Example 1 with InvalidHashtagException

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

the class SetHashtagsOp method updateChange.

@Override
public boolean updateChange(ChangeContext ctx) throws AuthException, BadRequestException, MethodNotAllowedException, IOException {
    if (input == null || (input.add == null && input.remove == null)) {
        updatedHashtags = ImmutableSortedSet.of();
        return false;
    }
    change = ctx.getChange();
    ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId());
    ChangeNotes notes = update.getNotes().load();
    try {
        Set<String> existingHashtags = notes.getHashtags();
        Set<String> updated = new HashSet<>();
        toAdd = new HashSet<>(extractTags(input.add));
        toRemove = new HashSet<>(extractTags(input.remove));
        validationListeners.runEach(l -> l.validateHashtags(update.getChange(), toAdd, toRemove), ValidationException.class);
        updated.addAll(existingHashtags);
        toAdd.removeAll(existingHashtags);
        toRemove.retainAll(existingHashtags);
        if (updated()) {
            updated.addAll(toAdd);
            updated.removeAll(toRemove);
            update.setHashtags(updated);
            addMessage(ctx);
        }
        updatedHashtags = ImmutableSortedSet.copyOf(updated);
        return true;
    } catch (ValidationException | InvalidHashtagException e) {
        throw new BadRequestException(e.getMessage(), e);
    }
}
Also used : InvalidHashtagException(com.google.gerrit.server.change.HashtagsUtil.InvalidHashtagException) ValidationException(com.google.gerrit.server.validators.ValidationException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate) HashSet(java.util.HashSet)

Aggregations

BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 InvalidHashtagException (com.google.gerrit.server.change.HashtagsUtil.InvalidHashtagException)1 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)1 ChangeUpdate (com.google.gerrit.server.notedb.ChangeUpdate)1 ValidationException (com.google.gerrit.server.validators.ValidationException)1 HashSet (java.util.HashSet)1