InlineEdit: Make revision resource change edit aware
In some cases client fire requests for cnange edit and Revisions collection parser needs to be extended to understand what change edit is. We have two cases either the patch set id is passed (0) or revId is passed and cannot be found in the databases. Change-Id: I5dd069e43679b67ab319e43ed40fd710ecbac12c
This commit is contained in:
@@ -14,8 +14,10 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.ChildCollection;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
@@ -24,11 +26,15 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.edit.ChangeEdit;
|
||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -36,12 +42,15 @@ import java.util.List;
|
||||
public class Revisions implements ChildCollection<ChangeResource, RevisionResource> {
|
||||
private final DynamicMap<RestView<RevisionResource>> views;
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final ChangeEditUtil editUtil;
|
||||
|
||||
@Inject
|
||||
Revisions(DynamicMap<RestView<RevisionResource>> views,
|
||||
Provider<ReviewDb> dbProvider) {
|
||||
Provider<ReviewDb> dbProvider,
|
||||
ChangeEditUtil editUtil) {
|
||||
this.views = views;
|
||||
this.dbProvider = dbProvider;
|
||||
this.editUtil = editUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +96,9 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
||||
throws OrmException {
|
||||
ReviewDb db = dbProvider.get();
|
||||
|
||||
if (id.length() < 6 && id.matches("^[1-9][0-9]{0,4}$")) {
|
||||
if (id.equals("0")) {
|
||||
return loadEdit(change, null);
|
||||
} else if (id.length() < 6 && id.matches("^[1-9][0-9]{0,4}$")) {
|
||||
// Legacy patch set number syntax.
|
||||
PatchSet ps = dbProvider.get().patchSets().get(new PatchSet.Id(
|
||||
change.getChange().getId(),
|
||||
@@ -107,7 +118,11 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
||||
// for all patch sets in the change.
|
||||
RevId revid = new RevId(id);
|
||||
if (revid.isComplete()) {
|
||||
return db.patchSets().byRevision(revid).toList();
|
||||
List<PatchSet> list = db.patchSets().byRevision(revid).toList();
|
||||
if (list.isEmpty()) {
|
||||
return loadEdit(change, revid);
|
||||
}
|
||||
return list;
|
||||
} else {
|
||||
return db.patchSets().byRevisionRange(revid, revid.max()).toList();
|
||||
}
|
||||
@@ -122,4 +137,22 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
private List<PatchSet> loadEdit(ChangeResource change, RevId revid)
|
||||
throws OrmException {
|
||||
try {
|
||||
Optional<ChangeEdit> edit = editUtil.byChange(change.getChange());
|
||||
if (edit.isPresent()) {
|
||||
PatchSet ps = new PatchSet(new PatchSet.Id(
|
||||
change.getChange().getId(), 0));
|
||||
ps.setRevision(edit.get().getRevision());
|
||||
if (revid == null || edit.get().getRevision().equals(revid)) {
|
||||
return Collections.singletonList(ps);
|
||||
}
|
||||
}
|
||||
} catch (AuthException | IOException | InvalidChangeOperationException e) {
|
||||
throw new OrmException(e);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user