use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class ListRevisionReviewers method apply.
@Override
public List<ReviewerInfo> apply(RevisionResource rsrc) throws OrmException, MethodNotAllowedException, PermissionBackendException {
if (!rsrc.isCurrent()) {
throw new MethodNotAllowedException("Cannot list reviewers on non-current patch set");
}
Map<String, ReviewerResource> reviewers = new LinkedHashMap<>();
ReviewDb db = dbProvider.get();
for (Account.Id accountId : approvalsUtil.getReviewers(db, rsrc.getNotes()).all()) {
if (!reviewers.containsKey(accountId.toString())) {
reviewers.put(accountId.toString(), resourceFactory.create(rsrc, accountId));
}
}
for (Address address : rsrc.getNotes().getReviewersByEmail().all()) {
if (!reviewers.containsKey(address.toString())) {
reviewers.put(address.toString(), new ReviewerResource(rsrc, address));
}
}
return json.format(reviewers.values());
}
use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class PreviewSubmit method getBundles.
private BinaryResult getBundles(BatchUpdate.Factory updateFactory, RevisionResource rsrc, ArchiveFormat f) throws OrmException, RestApiException {
ReviewDb db = dbProvider.get();
ChangeControl control = rsrc.getControl();
IdentifiedUser caller = control.getUser().asIdentifiedUser();
Change change = rsrc.getChange();
// Returned BinaryResult takes ownership and handles closing.
@SuppressWarnings("resource") MergeOp op = mergeOpFactory.create(updateFactory);
try {
op.merge(db, change, caller, false, new SubmitInput(), true);
BinaryResult bin = new SubmitPreviewResult(op, f, maxBundleSize);
bin.disableGzip().setContentType(f.getMimeType()).setAttachmentName("submit-preview-" + change.getChangeId() + "." + format);
return bin;
} catch (OrmException | RestApiException | RuntimeException e) {
op.close();
throw e;
}
}
use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class AllGroupsIndexer method collectGroups.
private List<AccountGroup.UUID> collectGroups(ProgressMonitor progress) throws OrmException {
progress.beginTask("Collecting groups", ProgressMonitor.UNKNOWN);
List<AccountGroup.UUID> uuids = new ArrayList<>();
try (ReviewDb db = schemaFactory.open()) {
for (AccountGroup group : db.accountGroups().all()) {
uuids.add(group.getGroupUUID());
}
}
progress.endTask();
return uuids;
}
use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class DbGroupMemberAuditListener method onDeleteAccountsFromGroup.
@Override
public void onDeleteAccountsFromGroup(Account.Id me, Collection<AccountGroupMember> removed) {
List<AccountGroupMemberAudit> auditInserts = new ArrayList<>();
List<AccountGroupMemberAudit> auditUpdates = new ArrayList<>();
try (ReviewDb db = schema.open()) {
for (AccountGroupMember m : removed) {
AccountGroupMemberAudit audit = null;
for (AccountGroupMemberAudit a : db.accountGroupMembersAudit().byGroupAccount(m.getAccountGroupId(), m.getAccountId())) {
if (a.isActive()) {
audit = a;
break;
}
}
if (audit != null) {
audit.removed(me, TimeUtil.nowTs());
auditUpdates.add(audit);
} else {
audit = new AccountGroupMemberAudit(m, me, TimeUtil.nowTs());
audit.removedLegacy();
auditInserts.add(audit);
}
}
db.accountGroupMembersAudit().update(auditUpdates);
db.accountGroupMembersAudit().insert(auditInserts);
} catch (OrmException e) {
logOrmExceptionForAccounts("Cannot log delete accounts from group event performed by user", me, removed, e);
}
}
use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class DbGroupMemberAuditListener method onAddGroupsToGroup.
@Override
public void onAddGroupsToGroup(Account.Id me, Collection<AccountGroupById> added) {
List<AccountGroupByIdAud> includesAudit = new ArrayList<>();
for (AccountGroupById groupInclude : added) {
AccountGroupByIdAud audit = new AccountGroupByIdAud(groupInclude, me, TimeUtil.nowTs());
includesAudit.add(audit);
}
try (ReviewDb db = schema.open()) {
db.accountGroupByIdAud().insert(includesAudit);
} catch (OrmException e) {
logOrmExceptionForGroups("Cannot log add groups to group event performed by user", me, added, e);
}
}
Aggregations