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