use of com.google.gerrit.reviewdb.client.PatchSetApproval in project gerrit by GerritCodeReview.
the class ApprovalsUtil method addReviewers.
private List<PatchSetApproval> addReviewers(ReviewDb db, ChangeUpdate update, LabelTypes labelTypes, Change change, PatchSet.Id psId, Account.Id authorId, Account.Id committerId, Iterable<Account.Id> wantReviewers, Collection<Account.Id> existingReviewers) throws OrmException {
List<LabelType> allTypes = labelTypes.getLabelTypes();
if (allTypes.isEmpty()) {
return ImmutableList.of();
}
Set<Account.Id> need = Sets.newLinkedHashSet(wantReviewers);
if (authorId != null && canSee(db, update.getNotes(), authorId)) {
need.add(authorId);
}
if (committerId != null && canSee(db, update.getNotes(), committerId)) {
need.add(committerId);
}
need.remove(change.getOwner());
need.removeAll(existingReviewers);
if (need.isEmpty()) {
return ImmutableList.of();
}
List<PatchSetApproval> cells = Lists.newArrayListWithCapacity(need.size());
LabelId labelId = Iterables.getLast(allTypes).getLabelId();
for (Account.Id account : need) {
cells.add(new PatchSetApproval(new PatchSetApproval.Key(psId, account, labelId), (short) 0, update.getWhen()));
update.putReviewer(account, REVIEWER);
}
db.patchSetApprovals().upsert(cells);
return Collections.unmodifiableList(cells);
}
Aggregations