From 6293c55c33312e48d243ab70df140ae0fc47ebbc Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Wed, 24 Feb 2016 10:59:27 -0500 Subject: [PATCH] Create BatchUpdates using InternalUser where appropriate Change-Id: I05adcac1f5d221f9e36f74ae8d4829d13cd230c7 --- .../com/google/gerrit/server/change/Abandon.java | 14 ++++++++------ .../google/gerrit/server/change/AbandonUtil.java | 13 ++++++------- .../java/com/google/gerrit/server/git/MergeOp.java | 11 +++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Abandon.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Abandon.java index 2c93ae38b8..d8fbd3bc49 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Abandon.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Abandon.java @@ -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, 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; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java index 65d250ab44..efb2d4d44d 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/AbandonUtil.java @@ -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()); } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java index 5297881214..bb818ed033 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java @@ -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 {