Add Follow-Up change UiAction to change screen
Change-Id: If4c9ef331a4646c736720f22fa9f921962f7147f
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.AcceptsPost;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
@@ -24,7 +23,7 @@ import com.google.gerrit.extensions.restapi.RestCollection;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
@@ -34,33 +33,32 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class ChangesCollection implements
|
||||
RestCollection<TopLevelResource, ChangeResource>,
|
||||
AcceptsPost<TopLevelResource> {
|
||||
private final Provider<ReviewDb> db;
|
||||
private final Provider<CurrentUser> user;
|
||||
private final ChangeControl.GenericFactory changeControlFactory;
|
||||
private final Provider<QueryChanges> queryFactory;
|
||||
private final DynamicMap<RestView<ChangeResource>> views;
|
||||
private final ChangeUtil changeUtil;
|
||||
private final CreateChange createChange;
|
||||
|
||||
@Inject
|
||||
ChangesCollection(
|
||||
Provider<ReviewDb> dbProvider,
|
||||
Provider<CurrentUser> user,
|
||||
ChangeControl.GenericFactory changeControlFactory,
|
||||
Provider<QueryChanges> queryFactory,
|
||||
DynamicMap<RestView<ChangeResource>> views,
|
||||
ChangeUtil changeUtil,
|
||||
CreateChange createChange) {
|
||||
this.db = dbProvider;
|
||||
this.user = user;
|
||||
this.changeControlFactory = changeControlFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
this.views = views;
|
||||
this.changeUtil = changeUtil;
|
||||
this.createChange = createChange;
|
||||
}
|
||||
|
||||
@@ -77,7 +75,7 @@ public class ChangesCollection implements
|
||||
@Override
|
||||
public ChangeResource parse(TopLevelResource root, IdString id)
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
List<Change> changes = findChanges(id.encoded());
|
||||
List<Change> changes = changeUtil.findChanges(id.encoded());
|
||||
if (changes.size() != 1) {
|
||||
throw new ResourceNotFoundException(id);
|
||||
}
|
||||
@@ -101,39 +99,6 @@ public class ChangesCollection implements
|
||||
return new ChangeResource(control);
|
||||
}
|
||||
|
||||
private List<Change> findChanges(String id)
|
||||
throws OrmException, ResourceNotFoundException {
|
||||
// Try legacy id
|
||||
if (id.matches("^[1-9][0-9]*$")) {
|
||||
Change c = db.get().changes().get(Change.Id.parse(id));
|
||||
if (c != null) {
|
||||
return ImmutableList.of(c);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// Try isolated changeId
|
||||
if (!id.contains("~")) {
|
||||
Change.Key key = new Change.Key(id);
|
||||
if (key.get().length() == 41) {
|
||||
return db.get().changes().byKey(key).toList();
|
||||
} else {
|
||||
return db.get().changes().byKeyRange(key, key.max()).toList();
|
||||
}
|
||||
}
|
||||
|
||||
// Try change triplet
|
||||
ChangeTriplet triplet;
|
||||
try {
|
||||
triplet = new ChangeTriplet(id);
|
||||
} catch (ChangeTriplet.ParseException e) {
|
||||
throw new ResourceNotFoundException(id);
|
||||
}
|
||||
return db.get().changes().byBranchKey(
|
||||
triplet.getBranchNameKey(),
|
||||
triplet.getChangeKey()).toList();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public CreateChange post(TopLevelResource parent) throws RestApiException {
|
||||
|
||||
Reference in New Issue
Block a user