Search in sources :

Example 6 with ReviewDb

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());
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) Address(com.google.gerrit.server.mail.Address) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with ReviewDb

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;
    }
}
Also used : MergeOp(com.google.gerrit.server.git.MergeOp) Change(com.google.gerrit.reviewdb.client.Change) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) OrmException(com.google.gwtorm.server.OrmException) ChangeControl(com.google.gerrit.server.project.ChangeControl) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult)

Example 8 with ReviewDb

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;
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) ArrayList(java.util.ArrayList) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 9 with ReviewDb

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);
    }
}
Also used : AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) OrmException(com.google.gwtorm.server.OrmException) AccountGroupMemberAudit(com.google.gerrit.reviewdb.client.AccountGroupMemberAudit) ArrayList(java.util.ArrayList) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 10 with ReviewDb

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);
    }
}
Also used : AccountGroupByIdAud(com.google.gerrit.reviewdb.client.AccountGroupByIdAud) OrmException(com.google.gwtorm.server.OrmException) ArrayList(java.util.ArrayList) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Aggregations

ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)63 OrmException (com.google.gwtorm.server.OrmException)25 Change (com.google.gerrit.reviewdb.client.Change)21 Account (com.google.gerrit.reviewdb.client.Account)17 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)12 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)10 Repository (org.eclipse.jgit.lib.Repository)9 Project (com.google.gerrit.reviewdb.client.Project)8 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)8 Provider (com.google.inject.Provider)8 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)7 Inject (com.google.inject.Inject)7 AllUsersName (com.google.gerrit.server.config.AllUsersName)6 ChangeControl (com.google.gerrit.server.project.ChangeControl)6 PersonIdent (org.eclipse.jgit.lib.PersonIdent)6 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 AccountGroupMember (com.google.gerrit.reviewdb.client.AccountGroupMember)5 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)5 GitReferenceUpdated (com.google.gerrit.server.extensions.events.GitReferenceUpdated)5