Merge "Only construct ChangeResources via ChangesCollection.parse"
This commit is contained in:
@@ -133,11 +133,12 @@ public class ChangeJson {
|
||||
private final IdentifiedUser.GenericFactory userFactory;
|
||||
private final ProjectControl.GenericFactory projectControlFactory;
|
||||
private final PatchSetInfoFactory patchSetInfoFactory;
|
||||
private final ChangesCollection changes;
|
||||
private final FileInfoJson fileInfoJson;
|
||||
private final AccountInfo.Loader.Factory accountLoaderFactory;
|
||||
private final DynamicMap<DownloadScheme> downloadSchemes;
|
||||
private final DynamicMap<DownloadCommand> downloadCommands;
|
||||
private final DynamicMap<RestView<ChangeResource>> changes;
|
||||
private final DynamicMap<RestView<ChangeResource>> changeViews;
|
||||
private final Revisions revisions;
|
||||
private final PatchListCache patchListCache;
|
||||
|
||||
@@ -156,11 +157,12 @@ public class ChangeJson {
|
||||
IdentifiedUser.GenericFactory uf,
|
||||
ProjectControl.GenericFactory pcf,
|
||||
PatchSetInfoFactory psi,
|
||||
ChangesCollection changes,
|
||||
FileInfoJson fileInfoJson,
|
||||
AccountInfo.Loader.Factory ailf,
|
||||
DynamicMap<DownloadScheme> downloadSchemes,
|
||||
DynamicMap<DownloadCommand> downloadCommands,
|
||||
DynamicMap<RestView<ChangeResource>> changes,
|
||||
DynamicMap<RestView<ChangeResource>> changeViews,
|
||||
Revisions revisions,
|
||||
PatchListCache patchListCache) {
|
||||
this.db = db;
|
||||
@@ -170,11 +172,12 @@ public class ChangeJson {
|
||||
this.userFactory = uf;
|
||||
this.projectControlFactory = pcf;
|
||||
this.patchSetInfoFactory = psi;
|
||||
this.changes = changes;
|
||||
this.fileInfoJson = fileInfoJson;
|
||||
this.accountLoaderFactory = ailf;
|
||||
this.downloadSchemes = downloadSchemes;
|
||||
this.downloadCommands = downloadCommands;
|
||||
this.changes = changes;
|
||||
this.changeViews = changeViews;
|
||||
this.revisions = revisions;
|
||||
this.patchListCache = patchListCache;
|
||||
|
||||
@@ -322,8 +325,8 @@ public class ChangeJson {
|
||||
if (has(CURRENT_ACTIONS) && userProvider.get().isIdentifiedUser()) {
|
||||
out.actions = Maps.newTreeMap();
|
||||
for (UiAction.Description d : UiActions.from(
|
||||
changes,
|
||||
new ChangeResource(control(cd)),
|
||||
changeViews,
|
||||
changes.parse(control(cd)),
|
||||
userProvider)) {
|
||||
out.actions.put(d.getId(), new ActionInfo(d));
|
||||
}
|
||||
@@ -821,7 +824,7 @@ public class ChangeJson {
|
||||
out.actions = Maps.newTreeMap();
|
||||
for (UiAction.Description d : UiActions.from(
|
||||
revisions,
|
||||
new RevisionResource(new ChangeResource(control(cd)), in),
|
||||
new RevisionResource(changes.parse(control(cd)), in),
|
||||
userProvider)) {
|
||||
out.actions.put(d.getId(), new ActionInfo(d));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ChangeResource implements RestResource, HasETag {
|
||||
|
||||
private final ChangeControl control;
|
||||
|
||||
public ChangeResource(ChangeControl control) {
|
||||
ChangeResource(ChangeControl control) {
|
||||
this.control = control;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,16 @@ public class ChangesCollection implements
|
||||
return new ChangeResource(control);
|
||||
}
|
||||
|
||||
public ChangeResource parse(Change.Id id)
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
return parse(TopLevelResource.INSTANCE,
|
||||
IdString.fromUrl(Integer.toString(id.get())));
|
||||
}
|
||||
|
||||
public ChangeResource parse(ChangeControl control) throws OrmException {
|
||||
return new ChangeResource(control);
|
||||
}
|
||||
|
||||
private List<Change> findChanges(String id)
|
||||
throws OrmException, ResourceNotFoundException {
|
||||
// Try legacy id
|
||||
|
||||
@@ -37,7 +37,6 @@ import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.git.WorkQueue.Executor;
|
||||
import com.google.gerrit.server.index.ChangeIndexer;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.util.RequestContext;
|
||||
import com.google.gerrit.server.util.ThreadLocalRequestContext;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -64,8 +63,8 @@ public class MergeabilityChecker implements GitReferenceUpdatedListener {
|
||||
|
||||
private final ThreadLocalRequestContext tl;
|
||||
private final SchemaFactory<ReviewDb> schemaFactory;
|
||||
private final ChangeControl.GenericFactory changeControlFactory;
|
||||
private final IdentifiedUser.GenericFactory identifiedUserFactory;
|
||||
private final ChangesCollection changes;
|
||||
private final Provider<Mergeable> mergeable;
|
||||
private final ChangeIndexer indexer;
|
||||
private final ListeningExecutorService executor;
|
||||
@@ -75,16 +74,15 @@ public class MergeabilityChecker implements GitReferenceUpdatedListener {
|
||||
@Inject
|
||||
public MergeabilityChecker(ThreadLocalRequestContext tl,
|
||||
SchemaFactory<ReviewDb> schemaFactory,
|
||||
ChangeControl.GenericFactory changeControlFactory,
|
||||
IdentifiedUser.GenericFactory identifiedUserFactory,
|
||||
Provider<Mergeable> mergeable, ChangeIndexer indexer,
|
||||
@MergeabilityChecksExecutor Executor executor,
|
||||
ChangesCollection changes, Provider<Mergeable> mergeable,
|
||||
ChangeIndexer indexer, @MergeabilityChecksExecutor Executor executor,
|
||||
MergeabilityCheckQueue mergeabilityCheckQueue,
|
||||
MetaDataUpdate.Server metaDataUpdateFactory) {
|
||||
this.tl = tl;
|
||||
this.schemaFactory = schemaFactory;
|
||||
this.changeControlFactory = changeControlFactory;
|
||||
this.identifiedUserFactory = identifiedUserFactory;
|
||||
this.changes = changes;
|
||||
this.mergeable = mergeable;
|
||||
this.indexer = indexer;
|
||||
this.executor = MoreExecutors.listeningDecorator(executor);
|
||||
@@ -263,8 +261,8 @@ public class MergeabilityChecker implements GitReferenceUpdatedListener {
|
||||
PatchSet ps = db.patchSets().get(change.currentPatchSetId());
|
||||
Mergeable m = mergeable.get();
|
||||
m.setForce(force);
|
||||
MergeableInfo info = m.apply(new RevisionResource(new ChangeResource(
|
||||
changeControlFactory.controlFor(change, context.getCurrentUser())), ps));
|
||||
MergeableInfo info = m.apply(
|
||||
new RevisionResource(changes.parse(change.getId()), ps));
|
||||
return change.isMergeable() != info.mergeable;
|
||||
} catch (ResourceConflictException e) {
|
||||
// change is closed
|
||||
|
||||
@@ -73,6 +73,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
}
|
||||
|
||||
private final Provider<ReviewDb> db;
|
||||
private final ChangesCollection changes;
|
||||
private final ChangeIndexer indexer;
|
||||
private final AccountsCollection accounts;
|
||||
private final EmailReviewComments.Factory email;
|
||||
@@ -87,11 +88,13 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
|
||||
@Inject
|
||||
PostReview(Provider<ReviewDb> db,
|
||||
ChangesCollection changes,
|
||||
ChangeIndexer indexer,
|
||||
AccountsCollection accounts,
|
||||
EmailReviewComments.Factory email,
|
||||
ChangeHooks hooks) {
|
||||
this.db = db;
|
||||
this.changes = changes;
|
||||
this.indexer = indexer;
|
||||
this.accounts = accounts;
|
||||
this.email = email;
|
||||
@@ -193,7 +196,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
}
|
||||
|
||||
ChangeControl target = caller.forUser(accounts.parse(in.onBehalfOf));
|
||||
return new RevisionResource(new ChangeResource(target), rev.getPatchSet());
|
||||
return new RevisionResource(changes.parse(target), rev.getPatchSet());
|
||||
}
|
||||
|
||||
private void checkLabels(RevisionResource revision, boolean strict,
|
||||
|
||||
@@ -69,7 +69,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.change.ChangeInserter;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.ChangesCollection;
|
||||
import com.google.gerrit.server.change.MergeabilityChecker;
|
||||
import com.google.gerrit.server.change.PatchSetInserter;
|
||||
import com.google.gerrit.server.change.PatchSetInserter.ChangeKind;
|
||||
@@ -269,6 +269,7 @@ public class ReceiveCommits {
|
||||
private final CommitValidators.Factory commitValidatorsFactory;
|
||||
private final TagCache tagCache;
|
||||
private final AccountCache accountCache;
|
||||
private final ChangesCollection changes;
|
||||
private final ChangeInserter.Factory changeInserterFactory;
|
||||
private final WorkQueue workQueue;
|
||||
private final ListeningExecutorService changeUpdateExector;
|
||||
@@ -329,6 +330,7 @@ public class ReceiveCommits {
|
||||
final TagCache tagCache,
|
||||
final AccountCache accountCache,
|
||||
final ChangeCache changeCache,
|
||||
final ChangesCollection changes,
|
||||
final ChangeInserter.Factory changeInserterFactory,
|
||||
final CommitValidators.Factory commitValidatorsFactory,
|
||||
@CanonicalWebUrl final String canonicalWebUrl,
|
||||
@@ -364,6 +366,7 @@ public class ReceiveCommits {
|
||||
this.canonicalWebUrl = canonicalWebUrl;
|
||||
this.tagCache = tagCache;
|
||||
this.accountCache = accountCache;
|
||||
this.changes = changes;
|
||||
this.changeInserterFactory = changeInserterFactory;
|
||||
this.commitValidatorsFactory = commitValidatorsFactory;
|
||||
this.workQueue = workQueue;
|
||||
@@ -1561,7 +1564,7 @@ public class ReceiveCommits {
|
||||
private void submit(ChangeControl changeCtl, PatchSet ps)
|
||||
throws OrmException, IOException {
|
||||
Submit submit = submitProvider.get();
|
||||
RevisionResource rsrc = new RevisionResource(new ChangeResource(changeCtl), ps);
|
||||
RevisionResource rsrc = new RevisionResource(changes.parse(changeCtl), ps);
|
||||
Change c = submit.submit(rsrc, currentUser);
|
||||
if (c == null) {
|
||||
addError("Submitting change " + changeCtl.getChange().getChangeId()
|
||||
|
||||
Reference in New Issue
Block a user