public void suggestChangeReviewer(final Change.Id change,
final String query, final int limit,
final AsyncCallback<List<ReviewerInfo>> callback) {
run(callback, new Action<List<ReviewerInfo>>() {
public List<ReviewerInfo> run(final ReviewDb db) throws OrmException {
final ChangeControl changeControl;
try {
changeControl = changeControlFactory.controlFor(change);
} catch (NoSuchChangeException e) {
return Collections.emptyList();
}
VisibilityControl visibilityControl = new VisibilityControl() {
@Override
public boolean isVisible(Account account) throws OrmException {
IdentifiedUser who =
identifiedUserFactory.create(reviewDbProvider, account.getId());
// we can't use changeControl directly as it won't suggest reviewers
// to drafts
return changeControl.forUser(who).isRefVisible();
}
};
final List<AccountInfo> suggestedAccounts =
suggestAccount(db, query, Boolean.TRUE, limit, visibilityControl);
final List<ReviewerInfo> reviewer =
new ArrayList<ReviewerInfo>(suggestedAccounts.size());
for (final AccountInfo a : suggestedAccounts) {
reviewer.add(new ReviewerInfo(a));
}
final List<GroupReference> suggestedAccountGroups =
suggestAccountGroup(changeControl.getProjectControl(), query, limit);
for (final GroupReference g : suggestedAccountGroups) {
if (suggestGroupAsReviewer(changeControl.getProject().getNameKey(), g)) {
reviewer.add(new ReviewerInfo(g));
}
}
Collections.sort(reviewer);