ChangesCollection: Simplify parsing a change number
We don't need to convert to a string to pass to findChagnes just to have that string get regex matched as a legacy ID and parsed back to an int. Change-Id: Ideb6d8e72c012d0fa26aa3b3c36dfc74e11de7ac
This commit is contained in:
@@ -29,6 +29,7 @@ import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.index.ChangeIndexer;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.query.change.QueryChanges;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -44,6 +45,7 @@ public class ChangesCollection implements
|
||||
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;
|
||||
@@ -54,6 +56,7 @@ public class ChangesCollection implements
|
||||
ChangesCollection(
|
||||
Provider<ReviewDb> db,
|
||||
Provider<CurrentUser> user,
|
||||
ChangeControl.GenericFactory changeControlFactory,
|
||||
Provider<QueryChanges> queryFactory,
|
||||
DynamicMap<RestView<ChangeResource>> views,
|
||||
ChangeUtil changeUtil,
|
||||
@@ -61,6 +64,7 @@ public class ChangesCollection implements
|
||||
ChangeIndexer changeIndexer) {
|
||||
this.db = db;
|
||||
this.user = user;
|
||||
this.changeControlFactory = changeControlFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
this.views = views;
|
||||
this.changeUtil = changeUtil;
|
||||
@@ -108,8 +112,19 @@ public class ChangesCollection implements
|
||||
|
||||
public ChangeResource parse(Change.Id id)
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
return parse(TopLevelResource.INSTANCE,
|
||||
IdString.fromUrl(Integer.toString(id.get())));
|
||||
try {
|
||||
ChangeControl ctl = changeControlFactory.controlFor(id, user.get());
|
||||
if (!ctl.isVisible(db.get())) {
|
||||
throw new ResourceNotFoundException(toIdString(id));
|
||||
}
|
||||
return new ChangeResource(ctl);
|
||||
} catch (NoSuchChangeException e) {
|
||||
throw new ResourceNotFoundException(toIdString(id));
|
||||
}
|
||||
}
|
||||
|
||||
private static IdString toIdString(Change.Id id) {
|
||||
return IdString.fromDecoded(id.toString());
|
||||
}
|
||||
|
||||
public ChangeResource parse(ChangeControl control) {
|
||||
|
||||
Reference in New Issue
Block a user