Inject ApprovalsUtil in more places
Replace static methods taking a ReviewDb with instance methods. Change-Id: I12d17fe122144183eeb142918a0176bc48e1705c
This commit is contained in:
parent
2ede20d73d
commit
4f47ab7468
@ -70,11 +70,11 @@ public class ApprovalsUtil {
|
||||
*
|
||||
* @throws OrmException
|
||||
*/
|
||||
public static void copyLabels(ReviewDb db, LabelTypes labelTypes,
|
||||
public void copyLabels(LabelTypes labelTypes,
|
||||
PatchSet.Id source, PatchSet dest, ChangeKind changeKind) throws OrmException {
|
||||
Iterable<PatchSetApproval> sourceApprovals =
|
||||
db.patchSetApprovals().byPatchSet(source);
|
||||
copyLabels(db, labelTypes, sourceApprovals, source, dest, changeKind);
|
||||
copyLabels(labelTypes, sourceApprovals, source, dest, changeKind);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +82,7 @@ public class ApprovalsUtil {
|
||||
*
|
||||
* @throws OrmException
|
||||
*/
|
||||
public static void copyLabels(ReviewDb db, LabelTypes labelTypes,
|
||||
public void copyLabels(LabelTypes labelTypes,
|
||||
Iterable<PatchSetApproval> sourceApprovals, PatchSet.Id source,
|
||||
PatchSet dest, ChangeKind changeKind) throws OrmException {
|
||||
List<PatchSetApproval> copied = Lists.newArrayList();
|
||||
@ -107,7 +107,7 @@ public class ApprovalsUtil {
|
||||
db.patchSetApprovals().insert(copied);
|
||||
}
|
||||
|
||||
public void addReviewers(ReviewDb db, LabelTypes labelTypes, Change change,
|
||||
public void addReviewers(LabelTypes labelTypes, Change change,
|
||||
PatchSet ps, PatchSetInfo info, Set<Account.Id> wantReviewers,
|
||||
Set<Account.Id> existingReviewers) throws OrmException {
|
||||
List<LabelType> allTypes = labelTypes.getLabelTypes();
|
||||
|
@ -51,6 +51,7 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
||||
private final ChangeHooks hooks;
|
||||
private final AbandonedSender.Factory abandonedSenderFactory;
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final Provider<ApprovalsUtil> approvals;
|
||||
private final ChangeJson json;
|
||||
private final ChangeIndexer indexer;
|
||||
|
||||
@ -58,11 +59,13 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
||||
Abandon(ChangeHooks hooks,
|
||||
AbandonedSender.Factory abandonedSenderFactory,
|
||||
Provider<ReviewDb> dbProvider,
|
||||
Provider<ApprovalsUtil> approvals,
|
||||
ChangeJson json,
|
||||
ChangeIndexer indexer) {
|
||||
this.hooks = hooks;
|
||||
this.abandonedSenderFactory = abandonedSenderFactory;
|
||||
this.dbProvider = dbProvider;
|
||||
this.approvals = approvals;
|
||||
this.json = json;
|
||||
this.indexer = indexer;
|
||||
}
|
||||
@ -103,7 +106,7 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
||||
}
|
||||
message = newMessage(input, caller, change);
|
||||
db.changeMessages().insert(Collections.singleton(message));
|
||||
new ApprovalsUtil(db).syncChangeStatus(change);
|
||||
approvals.get().syncChangeStatus(change);
|
||||
db.commit();
|
||||
} finally {
|
||||
db.rollback();
|
||||
|
@ -75,6 +75,7 @@ public class ChangeInserter {
|
||||
|
||||
@Inject
|
||||
ChangeInserter(Provider<ReviewDb> dbProvider,
|
||||
Provider<ApprovalsUtil> approvals,
|
||||
PatchSetInfoFactory patchSetInfoFactory,
|
||||
GitReferenceUpdated gitRefUpdated,
|
||||
ChangeHooks hooks,
|
||||
@ -159,7 +160,7 @@ public class ChangeInserter {
|
||||
db.patchSets().insert(Collections.singleton(patchSet));
|
||||
db.changes().insert(Collections.singleton(change));
|
||||
LabelTypes labelTypes = refControl.getProjectControl().getLabelTypes();
|
||||
approvalsUtil.addReviewers(db, labelTypes, change, patchSet, patchSetInfo,
|
||||
approvalsUtil.addReviewers(labelTypes, change, patchSet, patchSetInfo,
|
||||
reviewers, Collections.<Account.Id> emptySet());
|
||||
db.commit();
|
||||
} finally {
|
||||
|
@ -95,6 +95,7 @@ public class PatchSetInserter {
|
||||
private final MergeabilityChecker mergeabilityChecker;
|
||||
private final ReplacePatchSetSender.Factory replacePatchSetFactory;
|
||||
private final MergeUtil.Factory mergeUtilFactory;
|
||||
private final ApprovalsUtil approvalsUtil;
|
||||
|
||||
private final Repository git;
|
||||
private final RevWalk revWalk;
|
||||
@ -120,6 +121,7 @@ public class PatchSetInserter {
|
||||
MergeabilityChecker mergeabilityChecker,
|
||||
ReplacePatchSetSender.Factory replacePatchSetFactory,
|
||||
MergeUtil.Factory mergeUtilFactory,
|
||||
ApprovalsUtil approvalsUtil,
|
||||
@Assisted Repository git,
|
||||
@Assisted RevWalk revWalk,
|
||||
@Assisted RefControl refControl,
|
||||
@ -135,6 +137,7 @@ public class PatchSetInserter {
|
||||
this.mergeabilityChecker = mergeabilityChecker;
|
||||
this.replacePatchSetFactory = replacePatchSetFactory;
|
||||
this.mergeUtilFactory = mergeUtilFactory;
|
||||
this.approvalsUtil = approvalsUtil;
|
||||
|
||||
this.git = git;
|
||||
this.revWalk = revWalk;
|
||||
@ -279,7 +282,7 @@ public class PatchSetInserter {
|
||||
ChangeKind changeKind =
|
||||
getChangeKind(mergeUtilFactory, projectState, git, priorCommit, commit);
|
||||
|
||||
ApprovalsUtil.copyLabels(db, refControl.getProjectControl()
|
||||
approvalsUtil.copyLabels(refControl.getProjectControl()
|
||||
.getLabelTypes(), currentPatchSetId, patchSet, changeKind);
|
||||
}
|
||||
db.commit();
|
||||
|
@ -52,6 +52,7 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
||||
private final ChangeHooks hooks;
|
||||
private final RestoredSender.Factory restoredSenderFactory;
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final Provider<ApprovalsUtil> approvals;
|
||||
private final ChangeJson json;
|
||||
private final ChangeIndexer indexer;
|
||||
|
||||
@ -59,11 +60,13 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
||||
Restore(ChangeHooks hooks,
|
||||
RestoredSender.Factory restoredSenderFactory,
|
||||
Provider<ReviewDb> dbProvider,
|
||||
Provider<ApprovalsUtil> approvals,
|
||||
ChangeJson json,
|
||||
ChangeIndexer indexer) {
|
||||
this.hooks = hooks;
|
||||
this.restoredSenderFactory = restoredSenderFactory;
|
||||
this.dbProvider = dbProvider;
|
||||
this.approvals = approvals;
|
||||
this.json = json;
|
||||
this.indexer = indexer;
|
||||
}
|
||||
@ -104,7 +107,7 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
||||
}
|
||||
message = newMessage(input, caller, change);
|
||||
db.changeMessages().insert(Collections.singleton(message));
|
||||
new ApprovalsUtil(db).syncChangeStatus(change);
|
||||
approvals.get().syncChangeStatus(change);
|
||||
db.commit();
|
||||
} finally {
|
||||
db.rollback();
|
||||
|
@ -1856,9 +1856,9 @@ public class ReceiveCommits {
|
||||
db.patchSetApprovals().byChange(change.getId()).toList();
|
||||
final MailRecipients oldRecipients = getRecipientsFromApprovals(
|
||||
oldChangeApprovals);
|
||||
ApprovalsUtil.copyLabels(db, labelTypes, oldChangeApprovals,
|
||||
approvalsUtil.copyLabels(labelTypes, oldChangeApprovals,
|
||||
priorPatchSet, newPatchSet, changeKind);
|
||||
approvalsUtil.addReviewers(db, labelTypes, change, newPatchSet, info,
|
||||
approvalsUtil.addReviewers(labelTypes, change, newPatchSet, info,
|
||||
recipients.getReviewers(), oldRecipients.getAll());
|
||||
recipients.add(oldRecipients);
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class PatchSetNotificationSender {
|
||||
recipients.remove(me);
|
||||
|
||||
if (newChange) {
|
||||
approvalsUtil.addReviewers(db, labelTypes,
|
||||
approvalsUtil.addReviewers(labelTypes,
|
||||
updatedChange, updatedPatchSet, info,
|
||||
recipients.getReviewers(), Collections.<Account.Id> emptySet());
|
||||
try {
|
||||
@ -122,7 +122,7 @@ public class PatchSetNotificationSender {
|
||||
updatedChange.getId()).toList();
|
||||
final MailRecipients oldRecipients =
|
||||
getRecipientsFromApprovals(patchSetApprovals);
|
||||
approvalsUtil.addReviewers(db, labelTypes, updatedChange,
|
||||
approvalsUtil.addReviewers(labelTypes, updatedChange,
|
||||
updatedPatchSet, info, recipients.getReviewers(),
|
||||
oldRecipients.getAll());
|
||||
final ChangeMessage msg =
|
||||
|
Loading…
x
Reference in New Issue
Block a user