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

View File

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

View File

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