Search in sources :

Example 1 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class DraftChangeIT method markChangeAsDraft.

private void markChangeAsDraft(Change.Id id) throws Exception {
    try (BatchUpdate batchUpdate = batchUpdateFactory.create(db, project, atrScope.get().getUser(), TimeUtil.nowTs())) {
        batchUpdate.addOp(id, new MarkChangeAsDraftUpdateOp());
        batchUpdate.execute();
    }
    ChangeStatus changeStatus = gApi.changes().id(id.get()).get().status;
    assertThat(changeStatus).isEqualTo(ChangeStatus.DRAFT);
}
Also used : ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 2 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class GetRelatedIT method clearGroups.

private void clearGroups(final PatchSet.Id psId) throws Exception {
    try (BatchUpdate bu = batchUpdateFactory.create(db, project, user(user), TimeUtil.nowTs())) {
        bu.addOp(psId.getParentKey(), new BatchUpdateOp() {

            @Override
            public boolean updateChange(ChangeContext ctx) throws OrmException {
                PatchSet ps = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
                psUtil.setGroups(ctx.getDb(), ctx.getUpdate(psId), ps, ImmutableList.<String>of());
                ctx.dontBumpLastUpdatedOn();
                return true;
            }
        });
        bu.execute();
    }
}
Also used : ChangeContext(com.google.gerrit.server.update.ChangeContext) OrmException(com.google.gwtorm.server.OrmException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp)

Example 3 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method incrementPatchSet.

private ChangeControl incrementPatchSet(ChangeControl ctl, RevCommit commit) throws Exception {
    PatchSetInserter ins;
    try (BatchUpdate bu = newUpdate(ctl.getChange().getOwner())) {
        ins = patchSetInserterFactory.create(ctl, nextPatchSetId(ctl), commit).setValidate(false).setFireRevisionCreated(false).setNotify(NotifyHandling.NONE);
        bu.addOp(ctl.getId(), ins).execute();
    }
    return reload(ctl);
}
Also used : PatchSetInserter(com.google.gerrit.server.change.PatchSetInserter) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 4 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class PostHashtags method applyImpl.

@Override
protected Response<ImmutableSortedSet<String>> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource req, HashtagsInput input) throws RestApiException, UpdateException, PermissionBackendException {
    req.permissions().check(ChangePermission.EDIT_HASHTAGS);
    try (BatchUpdate bu = updateFactory.create(db.get(), req.getChange().getProject(), req.getControl().getUser(), TimeUtil.nowTs())) {
        SetHashtagsOp op = hashtagsFactory.create(input);
        bu.addOp(req.getId(), op);
        bu.execute();
        return Response.<ImmutableSortedSet<String>>ok(op.getUpdatedHashtags());
    }
}
Also used : ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 5 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class PostPrivate method applyImpl.

@Override
public Response<String> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, SetPrivateOp.Input input) throws RestApiException, UpdateException {
    if (!canSetPrivate(rsrc)) {
        throw new AuthException("not allowed to mark private");
    }
    if (rsrc.getChange().isPrivate()) {
        return Response.ok("");
    }
    ChangeControl control = rsrc.getControl();
    SetPrivateOp op = new SetPrivateOp(cmUtil, true, input);
    try (BatchUpdate u = updateFactory.create(dbProvider.get(), control.getProject().getNameKey(), control.getUser(), TimeUtil.nowTs())) {
        u.addOp(control.getId(), op).execute();
    }
    return Response.created("");
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) AuthException(com.google.gerrit.extensions.restapi.AuthException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Aggregations

BatchUpdate (com.google.gerrit.server.update.BatchUpdate)54 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)26 Change (com.google.gerrit.reviewdb.client.Change)22 ObjectId (org.eclipse.jgit.lib.ObjectId)14 OrmException (com.google.gwtorm.server.OrmException)13 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)12 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)12 UpdateException (com.google.gerrit.server.update.UpdateException)12 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)11 ChangeControl (com.google.gerrit.server.project.ChangeControl)11 ChangeContext (com.google.gerrit.server.update.ChangeContext)11 AuthException (com.google.gerrit.extensions.restapi.AuthException)10 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)10 ObjectReader (org.eclipse.jgit.lib.ObjectReader)10 Repository (org.eclipse.jgit.lib.Repository)9 RevWalk (org.eclipse.jgit.revwalk.RevWalk)9 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)8 IOException (java.io.IOException)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)7