InlineEdit: Add GET /changes/<id>/edit REST endpoint
Add get REST endpoint to read details of change edit. Result is a EditInfo JSON response or no content when edit doesn't exist for this change. Change-Id: I72969cea48b4b1f13154bfa93d403405bec37494
This commit is contained in:
@@ -14,21 +14,37 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gerrit.extensions.common.EditInfo;
|
||||
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;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.server.edit.ChangeEdit;
|
||||
import com.google.gerrit.server.edit.ChangeEditJson;
|
||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Singleton
|
||||
class ChangeEdits implements
|
||||
ChildCollection<ChangeResource, ChangeEditResource> {
|
||||
private final DynamicMap<RestView<ChangeEditResource>> views;
|
||||
private final Detail detail;
|
||||
|
||||
@Inject
|
||||
ChangeEdits(DynamicMap<RestView<ChangeEditResource>> views) {
|
||||
ChangeEdits(DynamicMap<RestView<ChangeEditResource>> views,
|
||||
Detail detail) {
|
||||
this.views = views;
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,11 +54,35 @@ class ChangeEdits implements
|
||||
|
||||
@Override
|
||||
public RestView<ChangeResource> list() {
|
||||
throw new IllegalStateException("not yet implemented");
|
||||
return detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeEditResource parse(ChangeResource change, IdString id) {
|
||||
throw new IllegalStateException("not yet implemented");
|
||||
}
|
||||
|
||||
@Singleton
|
||||
static class Detail implements RestReadView<ChangeResource> {
|
||||
private final ChangeEditUtil editUtil;
|
||||
private final ChangeEditJson editJson;
|
||||
|
||||
@Inject
|
||||
Detail(ChangeEditJson editJson,
|
||||
ChangeEditUtil editUtil) {
|
||||
this.editJson = editJson;
|
||||
this.editUtil = editUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<EditInfo> apply(ChangeResource rsrc) throws AuthException,
|
||||
IOException, NoSuchChangeException, InvalidChangeOperationException,
|
||||
ResourceNotFoundException {
|
||||
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
|
||||
if (edit.isPresent()) {
|
||||
return Response.ok(editJson.toEditInfo(edit.get()));
|
||||
}
|
||||
return Response.none();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user