Search in sources :

Example 41 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class DeleteChangeOp method deleteChangeElementsFromDb.

private void deleteChangeElementsFromDb(ChangeContext ctx, Change.Id id) throws OrmException {
    // Only delete from ReviewDb here; deletion from NoteDb is handled in
    // BatchUpdate.
    ReviewDb db = unwrap(ctx.getDb());
    db.patchComments().delete(db.patchComments().byChange(id));
    db.patchSetApprovals().delete(db.patchSetApprovals().byChange(id));
    db.patchSets().delete(db.patchSets().byChange(id));
    db.changeMessages().delete(db.changeMessages().byChange(id));
}
Also used : ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) BatchUpdateReviewDb(com.google.gerrit.server.update.BatchUpdateReviewDb)

Example 42 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class ListReviewers method apply.

@Override
public List<ReviewerInfo> apply(ChangeResource rsrc) throws OrmException, PermissionBackendException {
    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 adr : rsrc.getNotes().getReviewersByEmail().all()) {
        if (!reviewers.containsKey(adr.toString())) {
            reviewers.put(adr.toString(), new ReviewerResource(rsrc, adr));
        }
    }
    return json.format(reviewers.values());
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Address(com.google.gerrit.server.mail.Address) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) LinkedHashMap(java.util.LinkedHashMap)

Example 43 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class PatchSetInserter method updateChange.

@Override
public boolean updateChange(ChangeContext ctx) throws ResourceConflictException, OrmException, IOException {
    ReviewDb db = ctx.getDb();
    ChangeControl ctl = ctx.getControl();
    change = ctx.getChange();
    ChangeUpdate update = ctx.getUpdate(psId);
    update.setSubjectForCommit("Create patch set " + psId.get());
    if (!change.getStatus().isOpen() && !allowClosed) {
        throw new ResourceConflictException(String.format("Cannot create new patch set of change %s because it is %s", change.getId(), ChangeUtil.status(change)));
    }
    List<String> newGroups = groups;
    if (newGroups.isEmpty()) {
        PatchSet prevPs = psUtil.current(db, ctx.getNotes());
        if (prevPs != null) {
            newGroups = prevPs.getGroups();
        }
    }
    patchSet = psUtil.insert(db, ctx.getRevWalk(), ctx.getUpdate(psId), psId, commitId, draft, newGroups, null, description);
    if (notify != NotifyHandling.NONE) {
        oldReviewers = approvalsUtil.getReviewers(db, ctl.getNotes());
    }
    if (message != null) {
        changeMessage = ChangeMessagesUtil.newMessage(patchSet.getId(), ctx.getUser(), ctx.getWhen(), message, ChangeMessagesUtil.TAG_UPLOADED_PATCH_SET);
        changeMessage.setMessage(message);
    }
    patchSetInfo = patchSetInfoFactory.get(ctx.getRevWalk(), ctx.getRevWalk().parseCommit(commitId), psId);
    if (change.getStatus() != Change.Status.DRAFT && !allowClosed) {
        change.setStatus(Change.Status.NEW);
    }
    change.setCurrentPatchSet(patchSetInfo);
    if (copyApprovals) {
        approvalCopier.copy(db, ctl, patchSet);
    }
    if (changeMessage != null) {
        cmUtil.addChangeMessage(db, update, changeMessage);
    }
    return true;
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ChangeControl(com.google.gerrit.server.project.ChangeControl) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate)

Example 44 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class ProjectWatch method deliverToMembers.

private void deliverToMembers(Watchers.List matching, AccountGroup.UUID startUUID) throws OrmException {
    ReviewDb db = args.db.get();
    Set<AccountGroup.UUID> seen = new HashSet<>();
    List<AccountGroup.UUID> q = new ArrayList<>();
    seen.add(startUUID);
    q.add(startUUID);
    while (!q.isEmpty()) {
        AccountGroup.UUID uuid = q.remove(q.size() - 1);
        GroupDescription.Basic group = args.groupBackend.get(uuid);
        if (!Strings.isNullOrEmpty(group.getEmailAddress())) {
            // If the group has an email address, do not expand membership.
            matching.emails.add(new Address(group.getEmailAddress()));
            continue;
        }
        AccountGroup ig = GroupDescriptions.toAccountGroup(group);
        if (ig == null) {
            // Non-internal groups cannot be expanded by the server.
            continue;
        }
        for (AccountGroupMember m : db.accountGroupMembers().byGroup(ig.getId())) {
            matching.accounts.add(m.getAccountId());
        }
        for (AccountGroup.UUID m : args.groupIncludes.subgroupsOf(uuid)) {
            if (seen.add(m)) {
                q.add(m);
            }
        }
    }
}
Also used : GroupDescription(com.google.gerrit.common.data.GroupDescription) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) Address(com.google.gerrit.server.mail.Address) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) ArrayList(java.util.ArrayList) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) HashSet(java.util.HashSet)

Example 45 with ReviewDb

use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method setUpDatabase.

protected void setUpDatabase() throws Exception {
    try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
        schemaCreator.create(underlyingDb);
    }
    db = schemaFactory.open();
    userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    Account userAccount = db.accounts().get(userId);
    String email = "user@example.com";
    externalIdsUpdate.create().insert(ExternalId.createEmail(userId, email));
    userAccount.setPreferredEmail(email);
    db.accounts().update(ImmutableList.of(userAccount));
    user = userFactory.create(userId);
    requestContext.setContext(newRequestContext(userAccount.getId()));
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) 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