Create BatchUpdates using InternalUser where appropriate

Change-Id: I05adcac1f5d221f9e36f74ae8d4829d13cd230c7
This commit is contained in:
Dave Borowitz 2016-02-24 10:59:27 -05:00
parent cff5506568
commit 6293c55c33
3 changed files with 19 additions and 19 deletions

View File

@ -31,6 +31,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ChangeMessagesUtil; import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.ChangeUtil; import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.PatchSetUtil; import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.git.BatchUpdate; import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.BatchUpdate.ChangeContext; import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
@ -85,18 +86,19 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
if (!control.canAbandon(dbProvider.get())) { if (!control.canAbandon(dbProvider.get())) {
throw new AuthException("abandon not permitted"); throw new AuthException("abandon not permitted");
} }
Change change = abandon(control, input.message, Change change = abandon(control, input.message);
control.getUser().asIdentifiedUser().getAccount());
return json.create(ChangeJson.NO_OPTIONS).format(change); return json.create(ChangeJson.NO_OPTIONS).format(change);
} }
public Change abandon(ChangeControl control, public Change abandon(ChangeControl control, String msgTxt)
final String msgTxt, final Account account)
throws RestApiException, UpdateException { throws RestApiException, UpdateException {
CurrentUser user = control.getUser();
Account account = user.isIdentifiedUser()
? user.asIdentifiedUser().getAccount()
: null;
Op op = new Op(msgTxt, account); Op op = new Op(msgTxt, account);
try (BatchUpdate u = batchUpdateFactory.create(dbProvider.get(), try (BatchUpdate u = batchUpdateFactory.create(dbProvider.get(),
control.getProject().getNameKey(), control.getUser(), control.getProject().getNameKey(), user, TimeUtil.nowTs())) {
TimeUtil.nowTs())) {
u.addOp(control.getId(), op).execute(); u.addOp(control.getId(), op).execute();
} }
return op.change; return op.change;

View File

@ -15,7 +15,7 @@
package com.google.gerrit.server.change; package com.google.gerrit.server.change;
import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.InternalUser;
import com.google.gerrit.server.config.ChangeCleanupConfig; import com.google.gerrit.server.config.ChangeCleanupConfig;
import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.query.QueryParseException; import com.google.gerrit.server.query.QueryParseException;
@ -37,7 +37,7 @@ public class AbandonUtil {
private static final Logger log = LoggerFactory.getLogger(AbandonUtil.class); private static final Logger log = LoggerFactory.getLogger(AbandonUtil.class);
private final ChangeCleanupConfig cfg; private final ChangeCleanupConfig cfg;
private final IdentifiedUser.GenericFactory identifiedUserFactory; private final InternalUser.Factory internalUserFactory;
private final QueryProcessor queryProcessor; private final QueryProcessor queryProcessor;
private final ChangeQueryBuilder queryBuilder; private final ChangeQueryBuilder queryBuilder;
private final Abandon abandon; private final Abandon abandon;
@ -45,12 +45,12 @@ public class AbandonUtil {
@Inject @Inject
AbandonUtil( AbandonUtil(
ChangeCleanupConfig cfg, ChangeCleanupConfig cfg,
IdentifiedUser.GenericFactory identifiedUserFactory, InternalUser.Factory internalUserFactory,
QueryProcessor queryProcessor, QueryProcessor queryProcessor,
ChangeQueryBuilder queryBuilder, ChangeQueryBuilder queryBuilder,
Abandon abandon) { Abandon abandon) {
this.cfg = cfg; this.cfg = cfg;
this.identifiedUserFactory = identifiedUserFactory; this.internalUserFactory = internalUserFactory;
this.queryProcessor = queryProcessor; this.queryProcessor = queryProcessor;
this.queryBuilder = queryBuilder; this.queryBuilder = queryBuilder;
this.abandon = abandon; this.abandon = abandon;
@ -73,7 +73,7 @@ public class AbandonUtil {
int count = 0; int count = 0;
for (ChangeData cd : changesToAbandon) { for (ChangeData cd : changesToAbandon) {
try { try {
abandon.abandon(changeControl(cd), cfg.getAbandonMessage(), null); abandon.abandon(changeControl(cd), cfg.getAbandonMessage());
count++; count++;
} catch (ResourceConflictException e) { } catch (ResourceConflictException e) {
// Change was already merged or abandoned. // Change was already merged or abandoned.
@ -91,7 +91,6 @@ public class AbandonUtil {
} }
private ChangeControl changeControl(ChangeData cd) throws OrmException { private ChangeControl changeControl(ChangeData cd) throws OrmException {
return cd.changeControl( return cd.changeControl(internalUserFactory.create());
identifiedUserFactory.create(cd.change().getOwner()));
} }
} }

View File

@ -52,6 +52,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ChangeMessagesUtil; import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.ChangeUtil; import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.InternalUser;
import com.google.gerrit.server.git.BatchUpdate.ChangeContext; import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk; import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
import com.google.gerrit.server.git.strategy.SubmitStrategy; import com.google.gerrit.server.git.strategy.SubmitStrategy;
@ -309,7 +310,7 @@ public class MergeOp implements AutoCloseable {
private final ChangeMessagesUtil cmUtil; private final ChangeMessagesUtil cmUtil;
private final BatchUpdate.Factory batchUpdateFactory; private final BatchUpdate.Factory batchUpdateFactory;
private final GitRepositoryManager repoManager; private final GitRepositoryManager repoManager;
private final IdentifiedUser.GenericFactory identifiedUserFactory; private final InternalUser.Factory internalUserFactory;
private final MergeSuperSet mergeSuperSet; private final MergeSuperSet mergeSuperSet;
private final MergeValidators.Factory mergeValidatorsFactory; private final MergeValidators.Factory mergeValidatorsFactory;
private final ProjectCache projectCache; private final ProjectCache projectCache;
@ -341,7 +342,7 @@ public class MergeOp implements AutoCloseable {
MergeOp(ChangeMessagesUtil cmUtil, MergeOp(ChangeMessagesUtil cmUtil,
BatchUpdate.Factory batchUpdateFactory, BatchUpdate.Factory batchUpdateFactory,
GitRepositoryManager repoManager, GitRepositoryManager repoManager,
IdentifiedUser.GenericFactory identifiedUserFactory, InternalUser.Factory internalUserFactory,
MergeSuperSet mergeSuperSet, MergeSuperSet mergeSuperSet,
MergeValidators.Factory mergeValidatorsFactory, MergeValidators.Factory mergeValidatorsFactory,
ProjectCache projectCache, ProjectCache projectCache,
@ -351,7 +352,7 @@ public class MergeOp implements AutoCloseable {
this.cmUtil = cmUtil; this.cmUtil = cmUtil;
this.batchUpdateFactory = batchUpdateFactory; this.batchUpdateFactory = batchUpdateFactory;
this.repoManager = repoManager; this.repoManager = repoManager;
this.identifiedUserFactory = identifiedUserFactory; this.internalUserFactory = internalUserFactory;
this.mergeSuperSet = mergeSuperSet; this.mergeSuperSet = mergeSuperSet;
this.mergeValidatorsFactory = mergeValidatorsFactory; this.mergeValidatorsFactory = mergeValidatorsFactory;
this.projectCache = projectCache; this.projectCache = projectCache;
@ -877,10 +878,8 @@ public class MergeOp implements AutoCloseable {
Project.NameKey destProject) { Project.NameKey destProject) {
try { try {
for (ChangeData cd : internalChangeQuery.byProjectOpen(destProject)) { for (ChangeData cd : internalChangeQuery.byProjectOpen(destProject)) {
//TODO: Use InternalUser instead of change owner
try (BatchUpdate bu = batchUpdateFactory.create(db, destProject, try (BatchUpdate bu = batchUpdateFactory.create(db, destProject,
identifiedUserFactory.create(cd.change().getOwner()), internalUserFactory.create(), TimeUtil.nowTs())) {
TimeUtil.nowTs())) {
bu.addOp(cd.getId(), new BatchUpdate.Op() { bu.addOp(cd.getId(), new BatchUpdate.Op() {
@Override @Override
public boolean updateChange(ChangeContext ctx) throws OrmException { public boolean updateChange(ChangeContext ctx) throws OrmException {