Move FileInfo to FileInfoJson and implement Files.list().
Change-Id: I893dd097f2372f9a0e2a788a973fa30b53b3e0e4
This commit is contained in:
@@ -19,16 +19,28 @@ 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;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
private final DynamicMap<RestView<FileResource>> views;
|
||||
private final FileInfoJson fileInfoJson;
|
||||
private final Provider<Revisions> revisions;
|
||||
|
||||
@Inject
|
||||
Files(DynamicMap<RestView<FileResource>> views) {
|
||||
Files(DynamicMap<RestView<FileResource>> views,
|
||||
FileInfoJson fileInfoJson,
|
||||
Provider<Revisions> revisions) {
|
||||
this.views = views;
|
||||
this.fileInfoJson = fileInfoJson;
|
||||
this.revisions = revisions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +50,7 @@ class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
|
||||
@Override
|
||||
public RestView<RevisionResource> list() throws AuthException {
|
||||
throw new UnsupportedOperationException();
|
||||
return new List();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,4 +58,23 @@ class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
throws ResourceNotFoundException, OrmException, AuthException {
|
||||
return new FileResource(rev, id.get());
|
||||
}
|
||||
|
||||
private final class List implements RestReadView<RevisionResource> {
|
||||
@Option(name = "--base", metaVar = "revision-id")
|
||||
String base;
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource resource)
|
||||
throws ResourceNotFoundException, OrmException,
|
||||
PatchListNotAvailableException {
|
||||
PatchSet basePatchSet = null;
|
||||
if (base != null) {
|
||||
RevisionResource baseResource = revisions.get().parse(
|
||||
resource.getChangeResource(), IdString.fromDecoded(base));
|
||||
basePatchSet = baseResource.getPatchSet();
|
||||
}
|
||||
return fileInfoJson.toFileInfoMap(
|
||||
resource.getChange(), resource.getPatchSet(), basePatchSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user