Require REST endpoints to return Response<?>
At the moment REST endpoints can choose if they return a result object (that will be converted to JSON automatically unless it is a BinaryResult) or if they return a response object that specifies the response status code and other properties like caching behavior in addition to the result object. In addition REST endpoints can return special objects like Response.Redirect and Response.Accepted to trigger special behavior (Response.Redirect and Response.Accepted are neither a result object, nor a response object). If the first approach is chosen and a result object is returned, it is not clear from the implementation of the REST endpoint which status code is returned to the client. By default it is '200 OK', for RestCollectionCreateViews that are invoked via HTTP PUT/POST it is '201 Created' and for RestCollectionDeleteMissingViews that are invoked via HTTP DELETE it is '204 No Content'. By forcing REST endpoints to return a response object they must specify the status code. Hence implementors must explicitly think about this. Hopefully this leads to a more consistent use of status codes in our REST API. At the moment it happens frequently that status codes are wrong and need to be fixed, which is always a bit risky since callers may rely on an expected status code. Having all REST endpoints return response objects also has the advantage that wrappers around REST endpoints, such as RetryingRestModifyView, can set additional properties on the response. E.g. change I2b78cbef5 implements automatic request tracing in RetryingRestModifyView, but currently has no possibility to return the trace ID to the client. If that was possible, error popups in the frontend could display the trace ID. If the trace ID is included into bug reports, investigation of issues gets easier and faster. Response.Redirect and Response.Accepted are made subclasses of Response so that REST endpoints can still return them. Change-Id: I1dd37821a8a859ade43336eb5f6cce6bcc71fc02 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -154,13 +154,38 @@ public abstract class Response<T> {
|
||||
}
|
||||
|
||||
/** An HTTP redirect to another location. */
|
||||
public static final class Redirect {
|
||||
public static final class Redirect extends Response<Object> {
|
||||
private final String location;
|
||||
|
||||
private Redirect(String url) {
|
||||
this.location = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNone() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int statusCode() {
|
||||
return 302;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object value() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheControl caching() {
|
||||
return CacheControl.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Object> caching(CacheControl c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String location() {
|
||||
return location;
|
||||
}
|
||||
@@ -182,13 +207,38 @@ public abstract class Response<T> {
|
||||
}
|
||||
|
||||
/** Accepted as task for asynchronous execution. */
|
||||
public static final class Accepted {
|
||||
public static final class Accepted extends Response<Object> {
|
||||
private final String location;
|
||||
|
||||
private Accepted(String url) {
|
||||
this.location = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNone() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int statusCode() {
|
||||
return 202;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object value() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheControl caching() {
|
||||
return CacheControl.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Object> caching(CacheControl c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String location() {
|
||||
return location;
|
||||
}
|
||||
|
@@ -33,13 +33,24 @@ public interface RestCollectionCreateView<P extends RestResource, C extends Rest
|
||||
/**
|
||||
* Process the view operation by creating the resource.
|
||||
*
|
||||
* <p>The returned response defines the status code that is returned to the client. For
|
||||
* RestCollectionCreateViews this is usually {@code 201 Created} because a resource is created,
|
||||
* but other 2XX or 3XX status codes are also possible (e.g. {@link Response.Redirect} can be
|
||||
* returned for {@code 302 Found}).
|
||||
*
|
||||
* <p>The value of the returned response is automatically converted to JSON unless it is a {@link
|
||||
* BinaryResult}.
|
||||
*
|
||||
* <p>Throwing a subclass of {@link RestApiException} results in a 4XX response to the client. For
|
||||
* any other exception the client will get a {@code 500 Internal Server Error} response.
|
||||
*
|
||||
* @param parentResource parent resource of the resource that should be created
|
||||
* @param id the ID of the child resource that should be created
|
||||
* @param input input after parsing from request.
|
||||
* @return result to return to the client. Use {@link BinaryResult} to avoid automatic conversion
|
||||
* to JSON.
|
||||
* @return response to return to the client
|
||||
* @throws RestApiException if the resource creation is rejected
|
||||
* @throws Exception the implementation of the view failed. The exception will be logged and HTTP
|
||||
* 500 Internal Server Error will be returned to the client.
|
||||
*/
|
||||
Object apply(P parentResource, IdString id, I input) throws Exception;
|
||||
Response<?> apply(P parentResource, IdString id, I input) throws Exception;
|
||||
}
|
||||
|
@@ -37,13 +37,25 @@ public interface RestCollectionDeleteMissingView<P extends RestResource, C exten
|
||||
/**
|
||||
* Process the view operation by deleting the resource.
|
||||
*
|
||||
* <p>The returned response defines the status code that is returned to the client. For
|
||||
* RestCollectionDeleteMissingViews this is usually {@code 204 No Content} because a resource is
|
||||
* deleted, but other 2XX or 3XX status codes are also possible (e.g. {@code 200 OK}, {@code 302
|
||||
* Found} for a redirect).
|
||||
*
|
||||
* <p>The returned response usually does not have any value (status code {@code 204 No Content}).
|
||||
* If a value in the returned response is set it is automatically converted to JSON unless it is a
|
||||
* {@link BinaryResult}.
|
||||
*
|
||||
* <p>Throwing a subclass of {@link RestApiException} results in a 4XX response to the client. For
|
||||
* any other exception the client will get a {@code 500 Internal Server Error} response.
|
||||
*
|
||||
* @param parentResource parent resource of the resource that should be deleted
|
||||
* @param input input after parsing from request.
|
||||
* @return result to return to the client. Use {@link BinaryResult} to avoid automatic conversion
|
||||
* to JSON.
|
||||
* @param id the ID of the child resource that should be deleted
|
||||
* @param input input after parsing from request
|
||||
* @return response to return to the client
|
||||
* @throws RestApiException if the resource creation is rejected
|
||||
* @throws Exception the implementation of the view failed. The exception will be logged and HTTP
|
||||
* 500 Internal Server Error will be returned to the client.
|
||||
*/
|
||||
Object apply(P parentResource, IdString id, I input) throws Exception;
|
||||
Response<?> apply(P parentResource, IdString id, I input) throws Exception;
|
||||
}
|
||||
|
@@ -28,5 +28,25 @@ package com.google.gerrit.extensions.restapi;
|
||||
public interface RestCollectionModifyView<P extends RestResource, C extends RestResource, I>
|
||||
extends RestCollectionView<P, C, I> {
|
||||
|
||||
Object apply(P parentResource, I input) throws Exception;
|
||||
/**
|
||||
* Process the modification on the collection resource.
|
||||
*
|
||||
* <p>The value of the returned response is automatically converted to JSON unless it is a {@link
|
||||
* BinaryResult}.
|
||||
*
|
||||
* <p>The returned response defines the status code that is returned to the client. For
|
||||
* RestCollectionModifyViews this is usually {@code 200 OK}, but other 2XX or 3XX status codes are
|
||||
* also possible (e.g. {@code 201 Created} if a resource was created, {@code 202 Accepted} if a
|
||||
* background task was scheduled, {@code 204 No Content} if no content is returned, {@code 302
|
||||
* Found} for a redirect).
|
||||
*
|
||||
* <p>Throwing a subclass of {@link RestApiException} results in a 4XX response to the client. For
|
||||
* any other exception the client will get a {@code 500 Internal Server Error} response.
|
||||
*
|
||||
* @param parentResource the collection resource on which the modification is done
|
||||
* @return response to return to the client
|
||||
* @throws Exception the implementation of the view failed. The exception will be logged and HTTP
|
||||
* 500 Internal Server Error will be returned to the client.
|
||||
*/
|
||||
Response<?> apply(P parentResource, I input) throws Exception;
|
||||
}
|
||||
|
@@ -28,11 +28,21 @@ public interface RestModifyView<R extends RestResource, I> extends RestView<R> {
|
||||
/**
|
||||
* Process the view operation by altering the resource.
|
||||
*
|
||||
* @param resource resource to modify.
|
||||
* @param input input after parsing from request.
|
||||
* @return result to return to the client. Use {@link BinaryResult} to avoid automatic conversion
|
||||
* to JSON.
|
||||
* @throws AuthException the client is not permitted to access this view.
|
||||
* <p>The value of the returned response is automatically converted to JSON unless it is a {@link
|
||||
* BinaryResult}.
|
||||
*
|
||||
* <p>The returned response defines the status code that is returned to the client. For
|
||||
* RestModifyViews this is usually {@code 200 OK}, but other 2XX or 3XX status codes are also
|
||||
* possible (e.g. {@code 202 Accepted} if a background task was scheduled, {@code 204 No Content}
|
||||
* if no content is returned, {@code 302 Found} for a redirect).
|
||||
*
|
||||
* <p>Throwing a subclass of {@link RestApiException} results in a 4XX response to the client. For
|
||||
* any other exception the client will get a {@code 500 Internal Server Error} response.
|
||||
*
|
||||
* @param resource resource to modify
|
||||
* @param input input after parsing from request
|
||||
* @return response to return to the client
|
||||
* @throws AuthException the caller is not permitted to access this view.
|
||||
* @throws BadRequestException the request was incorrectly specified and cannot be handled by this
|
||||
* view.
|
||||
* @throws ResourceConflictException the resource state does not permit this view to make the
|
||||
@@ -40,6 +50,6 @@ public interface RestModifyView<R extends RestResource, I> extends RestView<R> {
|
||||
* @throws Exception the implementation of the view failed. The exception will be logged and HTTP
|
||||
* 500 Internal Server Error will be returned to the client.
|
||||
*/
|
||||
Object apply(R resource, I input)
|
||||
Response<?> apply(R resource, I input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException, Exception;
|
||||
}
|
||||
|
@@ -17,16 +17,27 @@ package com.google.gerrit.extensions.restapi;
|
||||
/**
|
||||
* RestView to read a resource without modification.
|
||||
*
|
||||
* <p>RestReadViews are invoked by the HTTP GET method.
|
||||
*
|
||||
* @param <R> type of resource the view reads.
|
||||
*/
|
||||
public interface RestReadView<R extends RestResource> extends RestView<R> {
|
||||
/**
|
||||
* Process the view operation by reading from the resource.
|
||||
*
|
||||
* @param resource resource to read.
|
||||
* @return result to return to the client. Use {@link BinaryResult} to avoid automatic conversion
|
||||
* to JSON.
|
||||
* @throws AuthException the client is not permitted to access this view.
|
||||
* <p>The value of the returned response is automatically converted to JSON unless it is a {@link
|
||||
* BinaryResult}.
|
||||
*
|
||||
* <p>The returned response defines the status code that is returned to the client. For
|
||||
* RestReadViews this is usually {@code 200 OK}, but other 2XX or 3XX status codes are also
|
||||
* possible (e.g. {@link Response.Redirect} can be returned for {@code 302 Found}).
|
||||
*
|
||||
* <p>Throwing a subclass of {@link RestApiException} results in a 4XX response to the client. For
|
||||
* any other exception the client will get a {@code 500 Internal Server Error} response.
|
||||
*
|
||||
* @param resource resource to read
|
||||
* @return response to return to the client
|
||||
* @throws AuthException the caller is not permitted to access this view.
|
||||
* @throws BadRequestException the request was incorrectly specified and cannot be handled by this
|
||||
* view.
|
||||
* @throws ResourceConflictException the resource state does not permit this view to make the
|
||||
@@ -34,6 +45,6 @@ public interface RestReadView<R extends RestResource> extends RestView<R> {
|
||||
* @throws Exception the implementation of the view failed. The exception will be logged and HTTP
|
||||
* 500 Internal Server Error will be returned to the client.
|
||||
*/
|
||||
Object apply(R resource)
|
||||
Response<?> apply(R resource)
|
||||
throws AuthException, BadRequestException, ResourceConflictException, Exception;
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ public class GpgApiAdapterImpl implements GpgApiAdapter {
|
||||
public Map<String, GpgKeyInfo> listGpgKeys(AccountResource account)
|
||||
throws RestApiException, GpgException {
|
||||
try {
|
||||
return gpgKeys.get().list().apply(account);
|
||||
return gpgKeys.get().list().apply(account).value();
|
||||
} catch (PGPException | IOException e) {
|
||||
throw new GpgException(e);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class GpgApiAdapterImpl implements GpgApiAdapter {
|
||||
in.add = add;
|
||||
in.delete = delete;
|
||||
try {
|
||||
return postGpgKeys.get().apply(account, in);
|
||||
return postGpgKeys.get().apply(account, in).value();
|
||||
} catch (PGPException | IOException | ConfigInvalidException e) {
|
||||
throw new GpgException(e);
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ public class GpgKeyApiImpl implements GpgKeyApi {
|
||||
@Override
|
||||
public GpgKeyInfo get() throws RestApiException {
|
||||
try {
|
||||
return get.apply(rsrc);
|
||||
return get.apply(rsrc).value();
|
||||
} catch (IOException e) {
|
||||
throw new RestApiException("Cannot get GPG key", e);
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ 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.gpg.BouncyCastleUtil;
|
||||
@@ -140,7 +141,7 @@ public class GpgKeys implements ChildCollection<AccountResource, GpgKey> {
|
||||
|
||||
public class ListGpgKeys implements RestReadView<AccountResource> {
|
||||
@Override
|
||||
public Map<String, GpgKeyInfo> apply(AccountResource rsrc)
|
||||
public Response<Map<String, GpgKeyInfo>> apply(AccountResource rsrc)
|
||||
throws PGPException, IOException, ResourceNotFoundException {
|
||||
checkVisible(self, rsrc);
|
||||
Map<String, GpgKeyInfo> keys = new HashMap<>();
|
||||
@@ -165,7 +166,7 @@ public class GpgKeys implements ChildCollection<AccountResource, GpgKey> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
return Response.ok(keys);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,12 +182,13 @@ public class GpgKeys implements ChildCollection<AccountResource, GpgKey> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GpgKeyInfo apply(GpgKey rsrc) throws IOException {
|
||||
public Response<GpgKeyInfo> apply(GpgKey rsrc) throws IOException {
|
||||
try (PublicKeyStore store = storeProvider.get()) {
|
||||
return toJson(
|
||||
rsrc.getKeyRing().getPublicKey(),
|
||||
checkerFactory.create().setExpectedUser(rsrc.getUser()),
|
||||
store);
|
||||
return Response.ok(
|
||||
toJson(
|
||||
rsrc.getKeyRing().getPublicKey(),
|
||||
checkerFactory.create().setExpectedUser(rsrc.getUser()),
|
||||
store));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.git.LockFailureException;
|
||||
@@ -120,7 +121,7 @@ public class PostGpgKeys implements RestModifyView<AccountResource, GpgKeysInput
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, GpgKeyInfo> apply(AccountResource rsrc, GpgKeysInput input)
|
||||
public Response<Map<String, GpgKeyInfo>> apply(AccountResource rsrc, GpgKeysInput input)
|
||||
throws RestApiException, PGPException, IOException, ConfigInvalidException {
|
||||
GpgKeys.checkVisible(self, rsrc);
|
||||
|
||||
@@ -153,7 +154,7 @@ public class PostGpgKeys implements RestModifyView<AccountResource, GpgKeysInput
|
||||
"Update GPG Keys via API",
|
||||
rsrc.getUser().getAccountId(),
|
||||
u -> u.replaceExternalIds(toRemove.keySet(), newExtIds));
|
||||
return toJson(newKeys, fingerprintsToRemove, store, rsrc.getUser());
|
||||
return Response.ok(toJson(newKeys, fingerprintsToRemove, store, rsrc.getUser()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -34,17 +34,14 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_CREATED;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_METHOD_NOT_ALLOWED;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_IMPLEMENTED;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_PRECONDITION_FAILED;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
|
||||
@@ -308,7 +305,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
res.setHeader("X-Content-Type-Options", "nosniff");
|
||||
int status = SC_OK;
|
||||
long responseBytes = -1;
|
||||
Object result = null;
|
||||
Response<?> response = null;
|
||||
QueryParams qp = null;
|
||||
Object inputRequestBody = null;
|
||||
RestResource rsrc = TopLevelResource.INSTANCE;
|
||||
@@ -394,7 +391,6 @@ public class RestApiServlet extends HttpServlet {
|
||||
RestView<RestResource> createView = rc.views().get(PluginName.GERRIT, "CREATE./");
|
||||
if (createView != null) {
|
||||
viewData = new ViewData(null, createView);
|
||||
status = SC_CREATED;
|
||||
path.add(id);
|
||||
} else {
|
||||
throw e;
|
||||
@@ -404,7 +400,6 @@ public class RestApiServlet extends HttpServlet {
|
||||
rc.views().get(PluginName.GERRIT, "DELETE_MISSING./");
|
||||
if (deleteView != null) {
|
||||
viewData = new ViewData(null, deleteView);
|
||||
status = SC_NO_CONTENT;
|
||||
path.add(id);
|
||||
} else {
|
||||
throw e;
|
||||
@@ -466,7 +461,6 @@ public class RestApiServlet extends HttpServlet {
|
||||
RestView<RestResource> createView = c.views().get(PluginName.GERRIT, "CREATE./");
|
||||
if (createView != null) {
|
||||
viewData = new ViewData(null, createView);
|
||||
status = SC_CREATED;
|
||||
path.add(id);
|
||||
} else {
|
||||
throw e;
|
||||
@@ -476,7 +470,6 @@ public class RestApiServlet extends HttpServlet {
|
||||
c.views().get(PluginName.GERRIT, "DELETE_MISSING./");
|
||||
if (deleteView != null) {
|
||||
viewData = new ViewData(null, deleteView);
|
||||
status = SC_NO_CONTENT;
|
||||
path.add(id);
|
||||
} else {
|
||||
throw e;
|
||||
@@ -502,7 +495,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
if (viewData.view instanceof RestReadView<?> && isRead(req)) {
|
||||
result = ((RestReadView<RestResource>) viewData.view).apply(rsrc);
|
||||
response = ((RestReadView<RestResource>) viewData.view).apply(rsrc);
|
||||
} else if (viewData.view instanceof RestModifyView<?, ?>) {
|
||||
@SuppressWarnings("unchecked")
|
||||
RestModifyView<RestResource, Object> m =
|
||||
@@ -510,7 +503,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
|
||||
Type type = inputType(m);
|
||||
inputRequestBody = parseRequest(req, type);
|
||||
result = m.apply(rsrc, inputRequestBody);
|
||||
response = m.apply(rsrc, inputRequestBody);
|
||||
if (inputRequestBody instanceof RawInput) {
|
||||
try (InputStream is = req.getInputStream()) {
|
||||
ServletUtils.consumeRequestBody(is);
|
||||
@@ -523,7 +516,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
|
||||
Type type = inputType(m);
|
||||
inputRequestBody = parseRequest(req, type);
|
||||
result = m.apply(rsrc, path.get(0), inputRequestBody);
|
||||
response = m.apply(rsrc, path.get(0), inputRequestBody);
|
||||
if (inputRequestBody instanceof RawInput) {
|
||||
try (InputStream is = req.getInputStream()) {
|
||||
ServletUtils.consumeRequestBody(is);
|
||||
@@ -536,7 +529,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
|
||||
Type type = inputType(m);
|
||||
inputRequestBody = parseRequest(req, type);
|
||||
result = m.apply(rsrc, path.get(0), inputRequestBody);
|
||||
response = m.apply(rsrc, path.get(0), inputRequestBody);
|
||||
if (inputRequestBody instanceof RawInput) {
|
||||
try (InputStream is = req.getInputStream()) {
|
||||
ServletUtils.consumeRequestBody(is);
|
||||
@@ -549,7 +542,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
|
||||
Type type = inputType(m);
|
||||
inputRequestBody = parseRequest(req, type);
|
||||
result = m.apply(rsrc, inputRequestBody);
|
||||
response = m.apply(rsrc, inputRequestBody);
|
||||
if (inputRequestBody instanceof RawInput) {
|
||||
try (InputStream is = req.getInputStream()) {
|
||||
ServletUtils.consumeRequestBody(is);
|
||||
@@ -559,36 +552,32 @@ public class RestApiServlet extends HttpServlet {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
if (result instanceof Response) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
Response<?> r = (Response) result;
|
||||
status = r.statusCode();
|
||||
configureCaching(req, res, rsrc, viewData.view, r.caching());
|
||||
} else if (result instanceof Response.Redirect) {
|
||||
if (response instanceof Response.Redirect) {
|
||||
CacheHeaders.setNotCacheable(res);
|
||||
String location = ((Response.Redirect) result).location();
|
||||
String location = ((Response.Redirect) response).location();
|
||||
res.sendRedirect(location);
|
||||
logger.atFinest().log("REST call redirected to: %s", location);
|
||||
return;
|
||||
} else if (result instanceof Response.Accepted) {
|
||||
} else if (response instanceof Response.Accepted) {
|
||||
CacheHeaders.setNotCacheable(res);
|
||||
res.setStatus(SC_ACCEPTED);
|
||||
res.setHeader(HttpHeaders.LOCATION, ((Response.Accepted) result).location());
|
||||
logger.atFinest().log("REST call succeeded: %d", SC_ACCEPTED);
|
||||
res.setStatus(response.statusCode());
|
||||
res.setHeader(HttpHeaders.LOCATION, ((Response.Accepted) response).location());
|
||||
logger.atFinest().log("REST call succeeded: %d", response.statusCode());
|
||||
return;
|
||||
} else {
|
||||
CacheHeaders.setNotCacheable(res);
|
||||
}
|
||||
|
||||
status = response.statusCode();
|
||||
configureCaching(req, res, rsrc, viewData.view, response.caching());
|
||||
res.setStatus(status);
|
||||
logger.atFinest().log("REST call succeeded: %d", status);
|
||||
}
|
||||
|
||||
if (result != Response.none()) {
|
||||
result = Response.unwrap(result);
|
||||
if (result instanceof BinaryResult) {
|
||||
responseBytes = replyBinaryResult(req, res, (BinaryResult) result);
|
||||
if (response != Response.none()) {
|
||||
Object value = Response.unwrap(response);
|
||||
if (value instanceof BinaryResult) {
|
||||
responseBytes = replyBinaryResult(req, res, (BinaryResult) value);
|
||||
} else {
|
||||
responseBytes = replyJson(req, res, false, qp.config(), result);
|
||||
responseBytes = replyJson(req, res, false, qp.config(), value);
|
||||
}
|
||||
}
|
||||
} catch (MalformedJsonException | JsonParseException e) {
|
||||
@@ -677,7 +666,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
qp != null ? qp.params() : ImmutableListMultimap.of(),
|
||||
inputRequestBody,
|
||||
status,
|
||||
result,
|
||||
response,
|
||||
rsrc,
|
||||
viewData == null ? null : viewData.view));
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.metrics.dropwizard;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
@@ -36,10 +37,10 @@ class GetMetric implements RestReadView<MetricResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricJson apply(MetricResource resource)
|
||||
public Response<MetricJson> apply(MetricResource resource)
|
||||
throws AuthException, PermissionBackendException {
|
||||
permissionBackend.currentUser().check(GlobalPermission.VIEW_CACHES);
|
||||
return new MetricJson(
|
||||
resource.getMetric(), metrics.getAnnotations(resource.getName()), dataOnly);
|
||||
return Response.ok(
|
||||
new MetricJson(resource.getMetric(), metrics.getAnnotations(resource.getName()), dataOnly));
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.metrics.dropwizard;
|
||||
|
||||
import com.codahale.metrics.Metric;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.config.ConfigResource;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
@@ -50,7 +51,7 @@ class ListMetrics implements RestReadView<ConfigResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, MetricJson> apply(ConfigResource resource)
|
||||
public Response<Map<String, MetricJson>> apply(ConfigResource resource)
|
||||
throws AuthException, PermissionBackendException {
|
||||
permissionBackend.currentUser().check(GlobalPermission.VIEW_CACHES);
|
||||
|
||||
@@ -75,7 +76,7 @@ class ListMetrics implements RestReadView<ConfigResource> {
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
return Response.ok(out);
|
||||
}
|
||||
|
||||
private MetricJson toJson(String q, Metric m) {
|
||||
|
@@ -240,7 +240,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public AccountDetailInfo detail() throws RestApiException {
|
||||
try {
|
||||
return getDetail.apply(account);
|
||||
return getDetail.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get detail", e);
|
||||
}
|
||||
@@ -274,7 +274,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public GeneralPreferencesInfo getPreferences() throws RestApiException {
|
||||
try {
|
||||
return getPreferences.apply(account);
|
||||
return getPreferences.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get preferences", e);
|
||||
}
|
||||
@@ -283,7 +283,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in) throws RestApiException {
|
||||
try {
|
||||
return setPreferences.apply(account, in);
|
||||
return setPreferences.apply(account, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set preferences", e);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public DiffPreferencesInfo getDiffPreferences() throws RestApiException {
|
||||
try {
|
||||
return getDiffPreferences.apply(account);
|
||||
return getDiffPreferences.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query diff preferences", e);
|
||||
}
|
||||
@@ -301,7 +301,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public DiffPreferencesInfo setDiffPreferences(DiffPreferencesInfo in) throws RestApiException {
|
||||
try {
|
||||
return setDiffPreferences.apply(account, in);
|
||||
return setDiffPreferences.apply(account, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set diff preferences", e);
|
||||
}
|
||||
@@ -310,7 +310,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public EditPreferencesInfo getEditPreferences() throws RestApiException {
|
||||
try {
|
||||
return getEditPreferences.apply(account);
|
||||
return getEditPreferences.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query edit preferences", e);
|
||||
}
|
||||
@@ -319,7 +319,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public EditPreferencesInfo setEditPreferences(EditPreferencesInfo in) throws RestApiException {
|
||||
try {
|
||||
return setEditPreferences.apply(account, in);
|
||||
return setEditPreferences.apply(account, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set edit preferences", e);
|
||||
}
|
||||
@@ -328,7 +328,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<ProjectWatchInfo> getWatchedProjects() throws RestApiException {
|
||||
try {
|
||||
return getWatchedProjects.apply(account);
|
||||
return getWatchedProjects.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get watched projects", e);
|
||||
}
|
||||
@@ -338,7 +338,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
public List<ProjectWatchInfo> setWatchedProjects(List<ProjectWatchInfo> in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return postWatchedProjects.apply(account, in);
|
||||
return postWatchedProjects.apply(account, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot update watched projects", e);
|
||||
}
|
||||
@@ -389,7 +389,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
public SortedSet<String> getStars(String changeId) throws RestApiException {
|
||||
try {
|
||||
AccountResource.Star rsrc = stars.parse(account, IdString.fromUrl(changeId));
|
||||
return starsGet.apply(rsrc);
|
||||
return starsGet.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get stars", e);
|
||||
}
|
||||
@@ -398,7 +398,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<ChangeInfo> getStarredChanges() throws RestApiException {
|
||||
try {
|
||||
return stars.list().apply(account);
|
||||
return stars.list().apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get starred changes", e);
|
||||
}
|
||||
@@ -407,7 +407,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<GroupInfo> getGroups() throws RestApiException {
|
||||
try {
|
||||
return getGroups.apply(account);
|
||||
return getGroups.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get groups", e);
|
||||
}
|
||||
@@ -416,7 +416,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<EmailInfo> getEmails() throws RestApiException {
|
||||
try {
|
||||
return getEmails.apply(account);
|
||||
return getEmails.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get emails", e);
|
||||
}
|
||||
@@ -475,7 +475,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<SshKeyInfo> listSshKeys() throws RestApiException {
|
||||
try {
|
||||
return getSshKeys.apply(account);
|
||||
return getSshKeys.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list SSH keys", e);
|
||||
}
|
||||
@@ -534,7 +534,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<AgreementInfo> listAgreements() throws RestApiException {
|
||||
try {
|
||||
return getAgreements.apply(account);
|
||||
return getAgreements.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get agreements", e);
|
||||
}
|
||||
@@ -563,7 +563,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<AccountExternalIdInfo> getExternalIds() throws RestApiException {
|
||||
try {
|
||||
return getExternalIds.apply(account);
|
||||
return getExternalIds.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get external IDs", e);
|
||||
}
|
||||
@@ -582,7 +582,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
public List<DeletedDraftCommentInfo> deleteDraftComments(DeleteDraftCommentsInput input)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return deleteDraftComments.apply(account, input);
|
||||
return deleteDraftComments.apply(account, input).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete draft comments", e);
|
||||
}
|
||||
|
@@ -133,7 +133,7 @@ public class AccountsImpl implements Accounts {
|
||||
myQueryAccounts.setSuggest(true);
|
||||
myQueryAccounts.setQuery(r.getQuery());
|
||||
myQueryAccounts.setLimit(r.getLimit());
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE);
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve suggested accounts", e);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class AccountsImpl implements Accounts {
|
||||
for (ListAccountsOption option : r.getOptions()) {
|
||||
myQueryAccounts.addOption(option);
|
||||
}
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE);
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve suggested accounts", e);
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ public class EmailApiImpl implements EmailApi {
|
||||
@Override
|
||||
public EmailInfo get() throws RestApiException {
|
||||
try {
|
||||
return get.apply(resource());
|
||||
return get.apply(resource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot read email", e);
|
||||
}
|
||||
|
@@ -351,7 +351,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public ChangeApi revert(RevertInput in) throws RestApiException {
|
||||
try {
|
||||
return changeApi.id(revert.apply(change, in)._number);
|
||||
return changeApi.id(revert.apply(change, in).value()._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot revert change", e);
|
||||
}
|
||||
@@ -401,7 +401,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
|
||||
@Override
|
||||
public String topic() throws RestApiException {
|
||||
return getTopic.apply(change);
|
||||
return getTopic.apply(change).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -418,7 +418,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public IncludedInInfo includedIn() throws RestApiException {
|
||||
try {
|
||||
return includedIn.apply(change);
|
||||
return includedIn.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Could not extract IncludedIn data", e);
|
||||
}
|
||||
@@ -427,7 +427,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public AddReviewerResult addReviewer(AddReviewerInput in) throws RestApiException {
|
||||
try {
|
||||
return postReviewers.apply(change, in);
|
||||
return postReviewers.apply(change, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot add change reviewer", e);
|
||||
}
|
||||
@@ -448,7 +448,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
try {
|
||||
suggestReviewers.setQuery(r.getQuery());
|
||||
suggestReviewers.setLimit(r.getLimit());
|
||||
return suggestReviewers.apply(change);
|
||||
return suggestReviewers.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve suggested reviewers", e);
|
||||
}
|
||||
@@ -457,7 +457,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public List<ReviewerInfo> reviewers() throws RestApiException {
|
||||
try {
|
||||
return listReviewers.apply(change);
|
||||
return listReviewers.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve reviewers", e);
|
||||
}
|
||||
@@ -512,7 +512,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public AccountInfo setAssignee(AssigneeInput input) throws RestApiException {
|
||||
try {
|
||||
return putAssignee.apply(change, input);
|
||||
return putAssignee.apply(change, input).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set assignee", e);
|
||||
}
|
||||
@@ -550,7 +550,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> comments() throws RestApiException {
|
||||
try {
|
||||
return listComments.apply(change);
|
||||
return listComments.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get comments", e);
|
||||
}
|
||||
@@ -559,7 +559,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public Map<String, List<RobotCommentInfo>> robotComments() throws RestApiException {
|
||||
try {
|
||||
return listChangeRobotComments.apply(change);
|
||||
return listChangeRobotComments.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get robot comments", e);
|
||||
}
|
||||
@@ -568,7 +568,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
|
||||
try {
|
||||
return listDrafts.apply(change);
|
||||
return listDrafts.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get drafts", e);
|
||||
}
|
||||
@@ -653,7 +653,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
try {
|
||||
GetPureRevert getPureRevert = getPureRevertProvider.get();
|
||||
getPureRevert.setClaimedOriginal(claimedOriginal);
|
||||
return getPureRevert.apply(change);
|
||||
return getPureRevert.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot compute pure revert", e);
|
||||
}
|
||||
@@ -662,7 +662,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public List<ChangeMessageInfo> messages() throws RestApiException {
|
||||
try {
|
||||
return changeMessages.list().apply(change);
|
||||
return changeMessages.list().apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list change messages", e);
|
||||
}
|
||||
|
@@ -221,7 +221,7 @@ public class ChangeEditApiImpl implements ChangeEditApi {
|
||||
public String getCommitMessage() throws RestApiException {
|
||||
try {
|
||||
try (BinaryResult binaryResult =
|
||||
getChangeEditCommitMessageProvider.get().apply(changeResource)) {
|
||||
getChangeEditCommitMessageProvider.get().apply(changeResource).value()) {
|
||||
return binaryResult.asString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@@ -48,7 +48,7 @@ class ChangeMessageApiImpl implements ChangeMessageApi {
|
||||
@Override
|
||||
public ChangeMessageInfo get() throws RestApiException {
|
||||
try {
|
||||
return getChangeMessage.apply(changeMessageResource);
|
||||
return getChangeMessage.apply(changeMessageResource).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve change message", e);
|
||||
}
|
||||
|
@@ -127,7 +127,7 @@ class ChangesImpl implements Changes {
|
||||
dynamicOptionParser.parseDynamicOptions(qc, q.getPluginOptions());
|
||||
|
||||
try {
|
||||
List<?> result = qc.apply(TopLevelResource.INSTANCE);
|
||||
List<?> result = qc.apply(TopLevelResource.INSTANCE).value();
|
||||
if (result.isEmpty()) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ class CommentApiImpl implements CommentApi {
|
||||
@Override
|
||||
public CommentInfo get() throws RestApiException {
|
||||
try {
|
||||
return getComment.apply(comment);
|
||||
return getComment.apply(comment).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve comment", e);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class CommentApiImpl implements CommentApi {
|
||||
@Override
|
||||
public CommentInfo delete(DeleteCommentInput input) throws RestApiException {
|
||||
try {
|
||||
return deleteComment.apply(comment, input);
|
||||
return deleteComment.apply(comment, input).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete comment", e);
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ class DraftApiImpl implements DraftApi {
|
||||
@Override
|
||||
public CommentInfo get() throws RestApiException {
|
||||
try {
|
||||
return getDraft.apply(draft);
|
||||
return getDraft.apply(draft).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve draft", e);
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ class FileApiImpl implements FileApi {
|
||||
@Override
|
||||
public BinaryResult content() throws RestApiException {
|
||||
try {
|
||||
return getContent.apply(file);
|
||||
return getContent.apply(file).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve file content", e);
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ public class ReviewerApiImpl implements ReviewerApi {
|
||||
@Override
|
||||
public Map<String, Short> votes() throws RestApiException {
|
||||
try {
|
||||
return listVotes.apply(reviewer);
|
||||
return listVotes.apply(reviewer).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list votes", e);
|
||||
}
|
||||
|
@@ -254,7 +254,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
public BinaryResult submitPreview(String format) throws RestApiException {
|
||||
try {
|
||||
submitPreview.setFormat(format);
|
||||
return submitPreview.apply(revision);
|
||||
return submitPreview.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get submit preview", e);
|
||||
}
|
||||
@@ -263,7 +263,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public ChangeApi rebase(RebaseInput in) throws RestApiException {
|
||||
try {
|
||||
return changes.id(rebase.apply(revision, in)._number);
|
||||
return changes.id(rebase.apply(revision, in).value()._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot rebase ps", e);
|
||||
}
|
||||
@@ -282,7 +282,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
|
||||
try {
|
||||
return changes.id(cherryPick.apply(revision, in)._number);
|
||||
return changes.id(cherryPick.apply(revision, in).value()._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot cherry pick", e);
|
||||
}
|
||||
@@ -291,7 +291,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public CherryPickChangeInfo cherryPickAsInfo(CherryPickInput in) throws RestApiException {
|
||||
try {
|
||||
return cherryPick.apply(revision, in);
|
||||
return cherryPick.apply(revision, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot cherry pick", e);
|
||||
}
|
||||
@@ -336,7 +336,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public MergeableInfo mergeable() throws RestApiException {
|
||||
try {
|
||||
return mergeable.apply(revision);
|
||||
return mergeable.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check mergeability", e);
|
||||
}
|
||||
@@ -346,7 +346,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
public MergeableInfo mergeableOtherBranches() throws RestApiException {
|
||||
try {
|
||||
mergeable.setOtherBranches(true);
|
||||
return mergeable.apply(revision);
|
||||
return mergeable.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check mergeability", e);
|
||||
}
|
||||
@@ -400,7 +400,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> comments() throws RestApiException {
|
||||
try {
|
||||
return listComments.apply(revision);
|
||||
return listComments.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve comments", e);
|
||||
}
|
||||
@@ -409,7 +409,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public Map<String, List<RobotCommentInfo>> robotComments() throws RestApiException {
|
||||
try {
|
||||
return listRobotComments.apply(revision);
|
||||
return listRobotComments.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve robot comments", e);
|
||||
}
|
||||
@@ -427,7 +427,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
|
||||
try {
|
||||
return listDrafts.apply(revision);
|
||||
return listDrafts.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve drafts", e);
|
||||
}
|
||||
@@ -504,7 +504,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public BinaryResult patch() throws RestApiException {
|
||||
try {
|
||||
return getPatch.apply(revision);
|
||||
return getPatch.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get patch", e);
|
||||
}
|
||||
@@ -513,7 +513,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public BinaryResult patch(String path) throws RestApiException {
|
||||
try {
|
||||
return getPatch.setPath(path).apply(revision);
|
||||
return getPatch.setPath(path).apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get patch", e);
|
||||
}
|
||||
@@ -531,7 +531,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public SubmitType submitType() throws RestApiException {
|
||||
try {
|
||||
return getSubmitType.apply(revision);
|
||||
return getSubmitType.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get submit type", e);
|
||||
}
|
||||
@@ -540,7 +540,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public SubmitType testSubmitType(TestSubmitRuleInput in) throws RestApiException {
|
||||
try {
|
||||
return testSubmitType.apply(revision, in);
|
||||
return testSubmitType.apply(revision, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot test submit type", e);
|
||||
}
|
||||
@@ -549,7 +549,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public List<TestSubmitRuleInfo> testSubmitRule(TestSubmitRuleInput in) throws RestApiException {
|
||||
try {
|
||||
return testSubmitRule.get().apply(revision, in);
|
||||
return testSubmitRule.get().apply(revision, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot test submit rule", e);
|
||||
}
|
||||
@@ -575,7 +575,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public RelatedChangesInfo related() throws RestApiException {
|
||||
try {
|
||||
return getRelated.apply(revision);
|
||||
return getRelated.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get related changes", e);
|
||||
}
|
||||
@@ -624,7 +624,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(revision);
|
||||
return getDescription.apply(revision).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -47,7 +47,7 @@ public class RevisionReviewerApiImpl implements RevisionReviewerApi {
|
||||
@Override
|
||||
public Map<String, Short> votes() throws RestApiException {
|
||||
try {
|
||||
return listVotes.apply(reviewer);
|
||||
return listVotes.apply(reviewer).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list votes", e);
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ public class RobotCommentApiImpl implements RobotCommentApi {
|
||||
@Override
|
||||
public RobotCommentInfo get() throws RestApiException {
|
||||
try {
|
||||
return getComment.apply(comment);
|
||||
return getComment.apply(comment).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve robot comment", e);
|
||||
}
|
||||
|
@@ -83,7 +83,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public ServerInfo getInfo() throws RestApiException {
|
||||
try {
|
||||
return getServerInfo.apply(new ConfigResource());
|
||||
return getServerInfo.apply(new ConfigResource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get server info", e);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public GeneralPreferencesInfo getDefaultPreferences() throws RestApiException {
|
||||
try {
|
||||
return getPreferences.apply(new ConfigResource());
|
||||
return getPreferences.apply(new ConfigResource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get default general preferences", e);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class ServerImpl implements Server {
|
||||
public GeneralPreferencesInfo setDefaultPreferences(GeneralPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setPreferences.apply(new ConfigResource(), in);
|
||||
return setPreferences.apply(new ConfigResource(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default general preferences", e);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public DiffPreferencesInfo getDefaultDiffPreferences() throws RestApiException {
|
||||
try {
|
||||
return getDiffPreferences.apply(new ConfigResource());
|
||||
return getDiffPreferences.apply(new ConfigResource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get default diff preferences", e);
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class ServerImpl implements Server {
|
||||
public DiffPreferencesInfo setDefaultDiffPreferences(DiffPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setDiffPreferences.apply(new ConfigResource(), in);
|
||||
return setDiffPreferences.apply(new ConfigResource(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default diff preferences", e);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public EditPreferencesInfo getDefaultEditPreferences() throws RestApiException {
|
||||
try {
|
||||
return getEditPreferences.apply(new ConfigResource());
|
||||
return getEditPreferences.apply(new ConfigResource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get default edit preferences", e);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class ServerImpl implements Server {
|
||||
public EditPreferencesInfo setDefaultEditPreferences(EditPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setEditPreferences.apply(new ConfigResource(), in);
|
||||
return setEditPreferences.apply(new ConfigResource(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default edit preferences", e);
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public ConsistencyCheckInfo checkConsistency(ConsistencyCheckInput in) throws RestApiException {
|
||||
try {
|
||||
return checkConsistency.get().apply(new ConfigResource(), in);
|
||||
return checkConsistency.get().apply(new ConfigResource(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check consistency", e);
|
||||
}
|
||||
|
@@ -119,7 +119,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public GroupInfo get() throws RestApiException {
|
||||
try {
|
||||
return getGroup.apply(rsrc);
|
||||
return getGroup.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve group", e);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public GroupInfo detail() throws RestApiException {
|
||||
try {
|
||||
return getDetail.apply(rsrc);
|
||||
return getDetail.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve group", e);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ class GroupApiImpl implements GroupApi {
|
||||
|
||||
@Override
|
||||
public String name() throws RestApiException {
|
||||
return getName.apply(rsrc);
|
||||
return getName.apply(rsrc).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,7 +153,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public GroupInfo owner() throws RestApiException {
|
||||
try {
|
||||
return getOwner.apply(rsrc);
|
||||
return getOwner.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get group owner", e);
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class GroupApiImpl implements GroupApi {
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(rsrc);
|
||||
return getDescription.apply(rsrc).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,7 +188,7 @@ class GroupApiImpl implements GroupApi {
|
||||
|
||||
@Override
|
||||
public GroupOptionsInfo options() throws RestApiException {
|
||||
return getOptions.apply(rsrc);
|
||||
return getOptions.apply(rsrc).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,7 +209,7 @@ class GroupApiImpl implements GroupApi {
|
||||
public List<AccountInfo> members(boolean recursive) throws RestApiException {
|
||||
listMembers.setRecursive(recursive);
|
||||
try {
|
||||
return listMembers.apply(rsrc);
|
||||
return listMembers.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list group members", e);
|
||||
}
|
||||
@@ -236,7 +236,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public List<GroupInfo> includedGroups() throws RestApiException {
|
||||
try {
|
||||
return listSubgroups.apply(rsrc);
|
||||
return listSubgroups.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list subgroups", e);
|
||||
}
|
||||
@@ -263,7 +263,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public List<? extends GroupAuditEventInfo> auditLog() throws RestApiException {
|
||||
try {
|
||||
return getAuditLog.apply(rsrc);
|
||||
return getAuditLog.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get audit log", e);
|
||||
}
|
||||
|
@@ -98,7 +98,7 @@ class GroupsImpl implements Groups {
|
||||
.currentUser()
|
||||
.checkAny(GlobalPermission.fromAnnotation(createGroup.getClass()));
|
||||
GroupInfo info =
|
||||
createGroup.apply(TopLevelResource.INSTANCE, IdString.fromDecoded(in.name), in);
|
||||
createGroup.apply(TopLevelResource.INSTANCE, IdString.fromDecoded(in.name), in).value();
|
||||
return id(info.id);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create group " + in.name, e);
|
||||
@@ -154,7 +154,7 @@ class GroupsImpl implements Groups {
|
||||
list.setMatchRegex(req.getRegex());
|
||||
list.setSuggest(req.getSuggest());
|
||||
try {
|
||||
return list.apply(tlr);
|
||||
return list.apply(tlr).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list groups", e);
|
||||
}
|
||||
@@ -184,7 +184,7 @@ class GroupsImpl implements Groups {
|
||||
for (ListGroupsOption option : r.getOptions()) {
|
||||
myQueryGroups.addOption(option);
|
||||
}
|
||||
return myQueryGroups.apply(TopLevelResource.INSTANCE);
|
||||
return myQueryGroups.apply(TopLevelResource.INSTANCE).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query groups", e);
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ public class PluginApiImpl implements PluginApi {
|
||||
|
||||
@Override
|
||||
public PluginInfo get() throws RestApiException {
|
||||
return getStatus.apply(resource);
|
||||
return getStatus.apply(resource).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -59,7 +59,7 @@ public class PluginsImpl implements Plugins {
|
||||
return new ListRequest() {
|
||||
@Override
|
||||
public SortedMap<String, PluginInfo> getAsMap() throws RestApiException {
|
||||
return listProvider.get().request(this).apply(TopLevelResource.INSTANCE);
|
||||
return listProvider.get().request(this).apply(TopLevelResource.INSTANCE).value();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -90,7 +90,7 @@ public class BranchApiImpl implements BranchApi {
|
||||
@Override
|
||||
public BranchInfo get() throws RestApiException {
|
||||
try {
|
||||
return getBranch.apply(resource());
|
||||
return getBranch.apply(resource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot read branch", e);
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class BranchApiImpl implements BranchApi {
|
||||
public BinaryResult file(String path) throws RestApiException {
|
||||
try {
|
||||
FileResource resource = filesCollection.parse(resource(), IdString.fromDecoded(path));
|
||||
return getContent.apply(resource);
|
||||
return getContent.apply(resource).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve file", e);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class BranchApiImpl implements BranchApi {
|
||||
@Override
|
||||
public List<ReflogEntryInfo> reflog() throws RestApiException {
|
||||
try {
|
||||
return getReflog.apply(resource());
|
||||
return getReflog.apply(resource()).value();
|
||||
} catch (IOException | PermissionBackendException e) {
|
||||
throw new RestApiException("Cannot retrieve reflog", e);
|
||||
}
|
||||
|
@@ -44,6 +44,6 @@ public class ChildProjectApiImpl implements ChildProjectApi {
|
||||
@Override
|
||||
public ProjectInfo get(boolean recursive) throws RestApiException {
|
||||
getChildProject.setRecursive(recursive);
|
||||
return getChildProject.apply(rsrc);
|
||||
return getChildProject.apply(rsrc).value();
|
||||
}
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ public class CommitApiImpl implements CommitApi {
|
||||
@Override
|
||||
public ChangeApi cherryPick(CherryPickInput input) throws RestApiException {
|
||||
try {
|
||||
return changes.id(cherryPickCommit.apply(commitResource, input)._number);
|
||||
return changes.id(cherryPickCommit.apply(commitResource, input).value()._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot cherry pick", e);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class CommitApiImpl implements CommitApi {
|
||||
@Override
|
||||
public IncludedInInfo includedIn() throws RestApiException {
|
||||
try {
|
||||
return includedIn.apply(commitResource);
|
||||
return includedIn.apply(commitResource).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Could not extract IncludedIn data", e);
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ public class DashboardApiImpl implements DashboardApi {
|
||||
@Override
|
||||
public DashboardInfo get(boolean inherited) throws RestApiException {
|
||||
try {
|
||||
return get.get().setInherited(inherited).apply(resource());
|
||||
return get.get().setInherited(inherited).apply(resource()).value();
|
||||
} catch (IOException | PermissionBackendException | ConfigInvalidException e) {
|
||||
throw asRestApiException("Cannot read dashboard", e);
|
||||
}
|
||||
|
@@ -368,13 +368,13 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(checkExists());
|
||||
return getDescription.apply(checkExists()).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectAccessInfo access() throws RestApiException {
|
||||
try {
|
||||
return getAccess.apply(checkExists());
|
||||
return getAccess.apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get access rights", e);
|
||||
}
|
||||
@@ -383,7 +383,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public ProjectAccessInfo access(ProjectAccessInput p) throws RestApiException {
|
||||
try {
|
||||
return setAccess.apply(checkExists(), p);
|
||||
return setAccess.apply(checkExists(), p).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put access rights", e);
|
||||
}
|
||||
@@ -401,7 +401,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public AccessCheckInfo checkAccess(AccessCheckInput in) throws RestApiException {
|
||||
try {
|
||||
return checkAccess.apply(checkExists(), in);
|
||||
return checkAccess.apply(checkExists(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check access rights", e);
|
||||
}
|
||||
@@ -410,7 +410,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public CheckProjectResultInfo check(CheckProjectInput in) throws RestApiException {
|
||||
try {
|
||||
return check.apply(checkExists(), in);
|
||||
return check.apply(checkExists(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check project", e);
|
||||
}
|
||||
@@ -427,13 +427,13 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
|
||||
@Override
|
||||
public ConfigInfo config() throws RestApiException {
|
||||
return getConfig.apply(checkExists());
|
||||
return getConfig.apply(checkExists()).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigInfo config(ConfigInput in) throws RestApiException {
|
||||
try {
|
||||
return putConfig.apply(checkExists(), in);
|
||||
return putConfig.apply(checkExists(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list tags", e);
|
||||
}
|
||||
@@ -445,7 +445,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<BranchInfo> get() throws RestApiException {
|
||||
try {
|
||||
return listBranches.get().request(this).apply(checkExists());
|
||||
return listBranches.get().request(this).apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list branches", e);
|
||||
}
|
||||
@@ -459,7 +459,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<TagInfo> get() throws RestApiException {
|
||||
try {
|
||||
return listTags.get().request(this).apply(checkExists());
|
||||
return listTags.get().request(this).apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list tags", e);
|
||||
}
|
||||
@@ -475,7 +475,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<ProjectInfo> children(boolean recursive) throws RestApiException {
|
||||
try {
|
||||
return children.list().withRecursive(recursive).apply(checkExists());
|
||||
return children.list().withRecursive(recursive).apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list children", e);
|
||||
}
|
||||
@@ -484,7 +484,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<ProjectInfo> children(int limit) throws RestApiException {
|
||||
try {
|
||||
return children.list().withLimit(limit).apply(checkExists());
|
||||
return children.list().withLimit(limit).apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list children", e);
|
||||
}
|
||||
@@ -574,7 +574,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<DashboardInfo> get() throws RestApiException {
|
||||
try {
|
||||
List<?> r = listDashboards.get().apply(checkExists());
|
||||
List<?> r = listDashboards.get().apply(checkExists()).value();
|
||||
if (r.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -592,7 +592,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public String head() throws RestApiException {
|
||||
try {
|
||||
return getHead.apply(checkExists());
|
||||
return getHead.apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get HEAD", e);
|
||||
}
|
||||
@@ -612,7 +612,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public String parent() throws RestApiException {
|
||||
try {
|
||||
return getParent.apply(checkExists());
|
||||
return getParent.apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get parent", e);
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.PluginInfo;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
@@ -44,7 +45,7 @@ public class DisablePlugin implements RestModifyView<PluginResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginInfo apply(PluginResource resource, Input input) throws RestApiException {
|
||||
public Response<PluginInfo> apply(PluginResource resource, Input input) throws RestApiException {
|
||||
try {
|
||||
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
|
||||
} catch (PermissionBackendException e) {
|
||||
@@ -56,6 +57,6 @@ public class DisablePlugin implements RestModifyView<PluginResource, Input> {
|
||||
throw new MethodNotAllowedException("Plugin " + name + " is mandatory");
|
||||
}
|
||||
loader.disablePlugins(ImmutableSet.of(name));
|
||||
return ListPlugins.toPluginInfo(loader.get(name));
|
||||
return Response.ok(ListPlugins.toPluginInfo(loader.get(name)));
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.PluginInfo;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.inject.Inject;
|
||||
@@ -39,7 +40,7 @@ public class EnablePlugin implements RestModifyView<PluginResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginInfo apply(PluginResource resource, Input input) throws RestApiException {
|
||||
public Response<PluginInfo> apply(PluginResource resource, Input input) throws RestApiException {
|
||||
loader.checkRemoteAdminEnabled();
|
||||
String name = resource.getName();
|
||||
try {
|
||||
@@ -52,6 +53,6 @@ public class EnablePlugin implements RestModifyView<PluginResource, Input> {
|
||||
pw.flush();
|
||||
throw new ResourceConflictException(buf.toString());
|
||||
}
|
||||
return ListPlugins.toPluginInfo(loader.get(name));
|
||||
return Response.ok(ListPlugins.toPluginInfo(loader.get(name)));
|
||||
}
|
||||
}
|
||||
|
@@ -15,13 +15,14 @@
|
||||
package com.google.gerrit.server.plugins;
|
||||
|
||||
import com.google.gerrit.extensions.common.PluginInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class GetStatus implements RestReadView<PluginResource> {
|
||||
@Override
|
||||
public PluginInfo apply(PluginResource resource) {
|
||||
return ListPlugins.toPluginInfo(resource.getPlugin());
|
||||
public Response<PluginInfo> apply(PluginResource resource) {
|
||||
return Response.ok(ListPlugins.toPluginInfo(resource.getPlugin()));
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.api.plugins.Plugins;
|
||||
import com.google.gerrit.extensions.common.PluginInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
@@ -111,7 +112,8 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<String, PluginInfo> apply(TopLevelResource resource) throws BadRequestException {
|
||||
public Response<SortedMap<String, PluginInfo>> apply(TopLevelResource resource)
|
||||
throws BadRequestException {
|
||||
Stream<Plugin> s = Streams.stream(pluginLoader.getPlugins(all));
|
||||
if (matchPrefix != null) {
|
||||
checkMatchOptions(matchSubstring == null && matchRegex == null);
|
||||
@@ -132,7 +134,7 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
|
||||
if (limit > 0) {
|
||||
s = s.limit(limit);
|
||||
}
|
||||
return new TreeMap<>(s.collect(toMap(Plugin::getName, ListPlugins::toPluginInfo)));
|
||||
return Response.ok(new TreeMap<>(s.collect(toMap(Plugin::getName, ListPlugins::toPluginInfo))));
|
||||
}
|
||||
|
||||
private void checkMatchOptions(boolean cond) throws BadRequestException {
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.PluginInfo;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -38,7 +39,8 @@ public class ReloadPlugin implements RestModifyView<PluginResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginInfo apply(PluginResource resource, Input input) throws ResourceConflictException {
|
||||
public Response<PluginInfo> apply(PluginResource resource, Input input)
|
||||
throws ResourceConflictException {
|
||||
String name = resource.getName();
|
||||
try {
|
||||
loader.reload(ImmutableList.of(name));
|
||||
@@ -52,6 +54,6 @@ public class ReloadPlugin implements RestModifyView<PluginResource, Input> {
|
||||
pw.flush();
|
||||
throw new ResourceConflictException(buf.toString());
|
||||
}
|
||||
return ListPlugins.toPluginInfo(loader.get(name));
|
||||
return Response.ok(ListPlugins.toPluginInfo(loader.get(name)));
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.restapi.access;
|
||||
import com.google.gerrit.extensions.api.access.ProjectAccessInfo;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
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.TopLevelResource;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
@@ -47,13 +48,13 @@ public class ListAccess implements RestReadView<TopLevelResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ProjectAccessInfo> apply(TopLevelResource resource)
|
||||
public Response<Map<String, ProjectAccessInfo>> apply(TopLevelResource resource)
|
||||
throws ResourceNotFoundException, ResourceConflictException, IOException,
|
||||
PermissionBackendException {
|
||||
Map<String, ProjectAccessInfo> access = new TreeMap<>();
|
||||
for (String p : projects) {
|
||||
access.put(p, getAccess.apply(Project.nameKey(p)));
|
||||
}
|
||||
return access;
|
||||
return Response.ok(access);
|
||||
}
|
||||
}
|
||||
|
@@ -97,11 +97,11 @@ public class CreateEmail
|
||||
throw new MethodNotAllowedException("realm does not allow adding emails");
|
||||
}
|
||||
|
||||
return apply(rsrc.getUser(), id, input);
|
||||
return Response.created(apply(rsrc.getUser(), id, input));
|
||||
}
|
||||
|
||||
/** To be used from plugins that want to create emails without permission checks. */
|
||||
public Response<EmailInfo> apply(IdentifiedUser user, IdString id, EmailInput input)
|
||||
public EmailInfo apply(IdentifiedUser user, IdString id, EmailInput input)
|
||||
throws RestApiException, EmailException, MethodNotAllowedException, IOException,
|
||||
ConfigInvalidException, PermissionBackendException {
|
||||
String email = id.get().trim();
|
||||
@@ -146,6 +146,6 @@ public class CreateEmail
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return Response.created(info);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import com.google.gerrit.extensions.client.ListChangesOption;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.index.query.Predicate;
|
||||
@@ -107,7 +108,7 @@ public class DeleteDraftComments
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<DeletedDraftCommentInfo> apply(
|
||||
public Response<ImmutableList<DeletedDraftCommentInfo>> apply(
|
||||
AccountResource rsrc, DeleteDraftCommentsInput input)
|
||||
throws RestApiException, UpdateException {
|
||||
CurrentUser user = userProvider.get();
|
||||
@@ -147,7 +148,8 @@ public class DeleteDraftComments
|
||||
// allowing partial failure would have little value.
|
||||
BatchUpdate.execute(updates.values(), BatchUpdateListener.NONE, false);
|
||||
|
||||
return ops.stream().map(Op::getResult).filter(Objects::nonNull).collect(toImmutableList());
|
||||
return Response.ok(
|
||||
ops.stream().map(Op::getResult).filter(Objects::nonNull).collect(toImmutableList()));
|
||||
}
|
||||
|
||||
private Predicate<ChangeData> predicate(Account.Id accountId, DeleteDraftCommentsInput input)
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.account.AccountLoader;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
@@ -32,10 +33,10 @@ public class GetAccount implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountInfo apply(AccountResource rsrc) throws PermissionBackendException {
|
||||
public Response<AccountInfo> apply(AccountResource rsrc) throws PermissionBackendException {
|
||||
AccountLoader loader = infoFactory.create(true);
|
||||
AccountInfo info = loader.get(rsrc.getUser().getAccountId());
|
||||
loader.fill();
|
||||
return info;
|
||||
return Response.ok(info);
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import com.google.gerrit.common.data.PermissionRule.Action;
|
||||
import com.google.gerrit.extensions.common.AgreementInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
@@ -61,7 +62,7 @@ public class GetAgreements implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AgreementInfo> apply(AccountResource resource)
|
||||
public Response<List<AgreementInfo>> apply(AccountResource resource)
|
||||
throws RestApiException, PermissionBackendException {
|
||||
if (!agreementsEnabled) {
|
||||
throw new MethodNotAllowedException("contributor agreements disabled");
|
||||
@@ -97,6 +98,6 @@ public class GetAgreements implements RestReadView<AccountResource> {
|
||||
results.add(agreementJson.format(ca));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
return Response.ok(results);
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.restapi.account;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
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.server.account.AccountResource;
|
||||
import com.google.gerrit.server.avatar.AvatarProvider;
|
||||
@@ -33,7 +34,7 @@ public class GetAvatarChangeUrl implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(AccountResource rsrc) throws ResourceNotFoundException {
|
||||
public Response<String> apply(AccountResource rsrc) throws ResourceNotFoundException {
|
||||
AvatarProvider impl = avatarProvider.get();
|
||||
if (impl == null) {
|
||||
throw new ResourceNotFoundException();
|
||||
@@ -43,6 +44,6 @@ public class GetAvatarChangeUrl implements RestReadView<AccountResource> {
|
||||
if (Strings.isNullOrEmpty(url)) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
return url;
|
||||
return Response.ok(url);
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ import com.google.gerrit.extensions.config.CapabilityDefinition;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
@@ -77,7 +78,7 @@ public class GetCapabilities implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> apply(AccountResource resource)
|
||||
public Response<Map<String, Object>> apply(AccountResource resource)
|
||||
throws RestApiException, PermissionBackendException {
|
||||
permissionBackend.checkUsesDefaultCapabilities();
|
||||
PermissionBackend.WithUser perm = permissionBackend.currentUser();
|
||||
@@ -95,7 +96,7 @@ public class GetCapabilities implements RestReadView<AccountResource> {
|
||||
addRanges(have, limits);
|
||||
addPriority(have, limits);
|
||||
|
||||
return have;
|
||||
return Response.ok(have);
|
||||
}
|
||||
|
||||
private Set<GlobalOrPluginPermission> permissionsToTest() {
|
||||
@@ -168,9 +169,9 @@ public class GetCapabilities implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult apply(Capability resource) throws ResourceNotFoundException {
|
||||
public Response<BinaryResult> apply(Capability resource) throws ResourceNotFoundException {
|
||||
permissionBackend.checkUsesDefaultCapabilities();
|
||||
return BinaryResult.create("ok\n");
|
||||
return Response.ok(BinaryResult.create("ok\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.gerrit.extensions.common.AccountDetailInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.account.AccountDirectory.FillOptions;
|
||||
@@ -36,12 +37,12 @@ public class GetDetail implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountDetailInfo apply(AccountResource rsrc) throws PermissionBackendException {
|
||||
public Response<AccountDetailInfo> apply(AccountResource rsrc) throws PermissionBackendException {
|
||||
Account a = rsrc.getUser().getAccount();
|
||||
AccountDetailInfo info = new AccountDetailInfo(a.id().get());
|
||||
info.registeredOn = a.registeredOn();
|
||||
info.inactive = !a.isActive() ? true : null;
|
||||
directory.fillAccountInfo(Collections.singleton(info), EnumSet.allOf(FillOptions.class));
|
||||
return info;
|
||||
return Response.ok(info);
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.restapi.account;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
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.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -48,16 +49,17 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffPreferencesInfo apply(AccountResource rsrc)
|
||||
public Response<DiffPreferencesInfo> apply(AccountResource rsrc)
|
||||
throws RestApiException, ConfigInvalidException, IOException, PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
|
||||
}
|
||||
|
||||
Account.Id id = rsrc.getUser().getAccountId();
|
||||
return accountCache
|
||||
.get(id)
|
||||
.map(AccountState::getDiffPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString())));
|
||||
return Response.ok(
|
||||
accountCache
|
||||
.get(id)
|
||||
.map(AccountState::getDiffPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString()))));
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.restapi.account;
|
||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
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.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -48,16 +49,17 @@ public class GetEditPreferences implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditPreferencesInfo apply(AccountResource rsrc)
|
||||
public Response<EditPreferencesInfo> apply(AccountResource rsrc)
|
||||
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
|
||||
}
|
||||
|
||||
Account.Id id = rsrc.getUser().getAccountId();
|
||||
return accountCache
|
||||
.get(id)
|
||||
.map(AccountState::getEditPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString())));
|
||||
return Response.ok(
|
||||
accountCache
|
||||
.get(id)
|
||||
.map(AccountState::getEditPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString()))));
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.gerrit.extensions.common.EmailInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.inject.Inject;
|
||||
@@ -26,10 +27,10 @@ public class GetEmail implements RestReadView<AccountResource.Email> {
|
||||
public GetEmail() {}
|
||||
|
||||
@Override
|
||||
public EmailInfo apply(AccountResource.Email rsrc) {
|
||||
public Response<EmailInfo> apply(AccountResource.Email rsrc) {
|
||||
EmailInfo e = new EmailInfo();
|
||||
e.email = rsrc.getEmail();
|
||||
e.preferred(rsrc.getUser().getAccount().preferredEmail());
|
||||
return e;
|
||||
return Response.ok(e);
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.gerrit.extensions.common.EmailInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
@@ -43,16 +44,17 @@ public class GetEmails implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmailInfo> apply(AccountResource rsrc)
|
||||
public Response<List<EmailInfo>> apply(AccountResource rsrc)
|
||||
throws AuthException, PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
|
||||
}
|
||||
return rsrc.getUser().getEmailAddresses().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(e -> toEmailInfo(rsrc, e))
|
||||
.sorted(comparing((EmailInfo e) -> e.email))
|
||||
.collect(toList());
|
||||
return Response.ok(
|
||||
rsrc.getUser().getEmailAddresses().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(e -> toEmailInfo(rsrc, e))
|
||||
.sorted(comparing((EmailInfo e) -> e.email))
|
||||
.collect(toList()));
|
||||
}
|
||||
|
||||
private static EmailInfo toEmailInfo(AccountResource rsrc, String email) {
|
||||
|
@@ -19,6 +19,7 @@ import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USE
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.common.AccountExternalIdInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
@@ -58,7 +59,7 @@ public class GetExternalIds implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AccountExternalIdInfo> apply(AccountResource resource)
|
||||
public Response<List<AccountExternalIdInfo>> apply(AccountResource resource)
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(resource.getUser())) {
|
||||
permissionBackend.currentUser().check(GlobalPermission.ACCESS_DATABASE);
|
||||
@@ -66,7 +67,7 @@ public class GetExternalIds implements RestReadView<AccountResource> {
|
||||
|
||||
Collection<ExternalId> ids = externalIds.byAccount(resource.getUser().getAccountId());
|
||||
if (ids.isEmpty()) {
|
||||
return ImmutableList.of();
|
||||
return Response.ok(ImmutableList.of());
|
||||
}
|
||||
List<AccountExternalIdInfo> result = Lists.newArrayListWithCapacity(ids.size());
|
||||
for (ExternalId id : ids) {
|
||||
@@ -83,7 +84,7 @@ public class GetExternalIds implements RestReadView<AccountResource> {
|
||||
}
|
||||
result.add(info);
|
||||
}
|
||||
return result;
|
||||
return Response.ok(result);
|
||||
}
|
||||
|
||||
private static Boolean toBoolean(boolean v) {
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.gerrit.exceptions.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.common.GroupInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
@@ -42,7 +43,8 @@ public class GetGroups implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GroupInfo> apply(AccountResource resource) throws PermissionBackendException {
|
||||
public Response<List<GroupInfo>> apply(AccountResource resource)
|
||||
throws PermissionBackendException {
|
||||
IdentifiedUser user = resource.getUser();
|
||||
Account.Id userId = user.getAccountId();
|
||||
Set<AccountGroup.UUID> knownGroups = user.getEffectiveGroups().getKnownGroups();
|
||||
@@ -58,6 +60,6 @@ public class GetGroups implements RestReadView<AccountResource> {
|
||||
visibleGroups.add(json.format(ctl.getGroup()));
|
||||
}
|
||||
}
|
||||
return visibleGroups;
|
||||
return Response.ok(visibleGroups);
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -22,7 +23,7 @@ import com.google.inject.Singleton;
|
||||
@Singleton
|
||||
public class GetName implements RestReadView<AccountResource> {
|
||||
@Override
|
||||
public String apply(AccountResource rsrc) {
|
||||
return Strings.nullToEmpty(rsrc.getUser().getAccount().fullName());
|
||||
public Response<String> apply(AccountResource rsrc) {
|
||||
return Response.ok(Strings.nullToEmpty(rsrc.getUser().getAccount().fullName()));
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.auth.oauth.OAuthToken;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
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.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
@@ -50,7 +51,7 @@ public class GetOAuthToken implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuthTokenInfo apply(AccountResource rsrc)
|
||||
public Response<OAuthTokenInfo> apply(AccountResource rsrc)
|
||||
throws AuthException, ResourceNotFoundException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
throw new AuthException("not allowed to get access token");
|
||||
@@ -66,7 +67,7 @@ public class GetOAuthToken implements RestReadView<AccountResource> {
|
||||
accessTokenInfo.providerId = accessToken.getProviderId();
|
||||
accessTokenInfo.expiresAt = Long.toString(accessToken.getExpiresAt());
|
||||
accessTokenInfo.type = BEARER_TYPE;
|
||||
return accessTokenInfo;
|
||||
return Response.ok(accessTokenInfo);
|
||||
}
|
||||
|
||||
private static String getHostName(String canonicalWebUrl) {
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.registration.Extension;
|
||||
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.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -54,7 +55,7 @@ public class GetPreferences implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo apply(AccountResource rsrc)
|
||||
public Response<GeneralPreferencesInfo> apply(AccountResource rsrc)
|
||||
throws RestApiException, PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
|
||||
@@ -66,7 +67,7 @@ public class GetPreferences implements RestReadView<AccountResource> {
|
||||
.get(id)
|
||||
.map(AccountState::getGeneralPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString())));
|
||||
return unsetDownloadSchemeIfUnsupported(preferencesInfo);
|
||||
return Response.ok(unsetDownloadSchemeIfUnsupported(preferencesInfo));
|
||||
}
|
||||
|
||||
private GeneralPreferencesInfo unsetDownloadSchemeIfUnsupported(
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.gerrit.server.account.AccountResource.SshKey;
|
||||
@@ -24,7 +25,7 @@ import com.google.inject.Singleton;
|
||||
public class GetSshKey implements RestReadView<AccountResource.SshKey> {
|
||||
|
||||
@Override
|
||||
public SshKeyInfo apply(SshKey rsrc) {
|
||||
return GetSshKeys.newSshKeyInfo(rsrc.getSshKey());
|
||||
public Response<SshKeyInfo> apply(SshKey rsrc) {
|
||||
return Response.ok(GetSshKeys.newSshKeyInfo(rsrc.getSshKey()));
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -53,13 +54,13 @@ public class GetSshKeys implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SshKeyInfo> apply(AccountResource rsrc)
|
||||
public Response<List<SshKeyInfo>> apply(AccountResource rsrc)
|
||||
throws AuthException, RepositoryNotFoundException, IOException, ConfigInvalidException,
|
||||
PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
|
||||
}
|
||||
return apply(rsrc.getUser());
|
||||
return Response.ok(apply(rsrc.getUser()));
|
||||
}
|
||||
|
||||
public List<SshKeyInfo> apply(IdentifiedUser user)
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -22,7 +23,7 @@ import com.google.inject.Singleton;
|
||||
@Singleton
|
||||
public class GetStatus implements RestReadView<AccountResource> {
|
||||
@Override
|
||||
public String apply(AccountResource rsrc) {
|
||||
return Strings.nullToEmpty(rsrc.getUser().getAccount().status());
|
||||
public Response<String> apply(AccountResource rsrc) {
|
||||
return Response.ok(Strings.nullToEmpty(rsrc.getUser().getAccount().status()));
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
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.server.account.AccountResource;
|
||||
import com.google.inject.Inject;
|
||||
@@ -27,7 +28,8 @@ public class GetUsername implements RestReadView<AccountResource> {
|
||||
public GetUsername() {}
|
||||
|
||||
@Override
|
||||
public String apply(AccountResource rsrc) throws AuthException, ResourceNotFoundException {
|
||||
return rsrc.getUser().getUserName().orElseThrow(ResourceNotFoundException::new);
|
||||
public Response<String> apply(AccountResource rsrc)
|
||||
throws AuthException, ResourceNotFoundException {
|
||||
return Response.ok(rsrc.getUser().getUserName().orElseThrow(ResourceNotFoundException::new));
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
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.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -55,7 +56,7 @@ public class GetWatchedProjects implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectWatchInfo> apply(AccountResource rsrc)
|
||||
public Response<List<ProjectWatchInfo>> apply(AccountResource rsrc)
|
||||
throws AuthException, IOException, ConfigInvalidException, PermissionBackendException,
|
||||
ResourceNotFoundException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
@@ -64,12 +65,13 @@ public class GetWatchedProjects implements RestReadView<AccountResource> {
|
||||
|
||||
Account.Id accountId = rsrc.getUser().getAccountId();
|
||||
AccountState account = accounts.get(accountId).orElseThrow(ResourceNotFoundException::new);
|
||||
return account.getProjectWatches().entrySet().stream()
|
||||
.map(e -> toProjectWatchInfo(e.getKey(), e.getValue()))
|
||||
.sorted(
|
||||
comparing((ProjectWatchInfo pwi) -> pwi.project)
|
||||
.thenComparing(pwi -> Strings.nullToEmpty(pwi.filter)))
|
||||
.collect(toList());
|
||||
return Response.ok(
|
||||
account.getProjectWatches().entrySet().stream()
|
||||
.map(e -> toProjectWatchInfo(e.getKey(), e.getValue()))
|
||||
.sorted(
|
||||
comparing((ProjectWatchInfo pwi) -> pwi.project)
|
||||
.thenComparing(pwi -> Strings.nullToEmpty(pwi.filter)))
|
||||
.collect(toList()));
|
||||
}
|
||||
|
||||
private static ProjectWatchInfo toProjectWatchInfo(
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -64,7 +65,7 @@ public class PostWatchedProjects
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectWatchInfo> apply(AccountResource rsrc, List<ProjectWatchInfo> input)
|
||||
public Response<List<ProjectWatchInfo>> apply(AccountResource rsrc, List<ProjectWatchInfo> input)
|
||||
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
|
||||
|
@@ -23,6 +23,7 @@ import com.google.gerrit.extensions.client.AccountFieldName;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
@@ -71,7 +72,7 @@ public class PutUsername implements RestModifyView<AccountResource, UsernameInpu
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(AccountResource rsrc, UsernameInput input)
|
||||
public Response<String> apply(AccountResource rsrc, UsernameInput input)
|
||||
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
|
||||
@@ -106,7 +107,7 @@ public class PutUsername implements RestModifyView<AccountResource, UsernameInpu
|
||||
// If we are using this identity, don't report the exception.
|
||||
Optional<ExternalId> other = externalIds.get(key);
|
||||
if (other.isPresent() && other.get().accountId().equals(accountId)) {
|
||||
return input.username;
|
||||
return Response.ok(input.username);
|
||||
}
|
||||
|
||||
// Otherwise, someone else has this identity.
|
||||
@@ -114,6 +115,6 @@ public class PutUsername implements RestModifyView<AccountResource, UsernameInpu
|
||||
}
|
||||
|
||||
sshKeyCache.evict(input.username);
|
||||
return input.username;
|
||||
return Response.ok(input.username);
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import com.google.gerrit.extensions.common.AccountVisibility;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
@@ -147,14 +148,14 @@ public class QueryAccounts implements RestReadView<TopLevelResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AccountInfo> apply(TopLevelResource rsrc)
|
||||
public Response<List<AccountInfo>> apply(TopLevelResource rsrc)
|
||||
throws RestApiException, PermissionBackendException {
|
||||
if (Strings.isNullOrEmpty(query)) {
|
||||
throw new BadRequestException("missing query field");
|
||||
}
|
||||
|
||||
if (suggest && (!suggestConfig || query.length() < suggestFrom)) {
|
||||
return Collections.emptyList();
|
||||
return Response.ok(Collections.emptyList());
|
||||
}
|
||||
|
||||
Set<FillOptions> fillOptions = EnumSet.of(FillOptions.ID);
|
||||
@@ -220,10 +221,10 @@ public class QueryAccounts implements RestReadView<TopLevelResource> {
|
||||
if (!sorted.isEmpty() && result.more()) {
|
||||
sorted.get(sorted.size() - 1)._moreAccounts = true;
|
||||
}
|
||||
return sorted;
|
||||
return Response.ok(sorted);
|
||||
} catch (QueryParseException e) {
|
||||
if (suggest) {
|
||||
return ImmutableList.of();
|
||||
return Response.ok(ImmutableList.of());
|
||||
}
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
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.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -53,7 +54,7 @@ public class SetDiffPreferences implements RestModifyView<AccountResource, DiffP
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffPreferencesInfo apply(AccountResource rsrc, DiffPreferencesInfo input)
|
||||
public Response<DiffPreferencesInfo> apply(AccountResource rsrc, DiffPreferencesInfo input)
|
||||
throws RestApiException, ConfigInvalidException, RepositoryNotFoundException, IOException,
|
||||
PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
@@ -65,10 +66,11 @@ public class SetDiffPreferences implements RestModifyView<AccountResource, DiffP
|
||||
}
|
||||
|
||||
Account.Id id = rsrc.getUser().getAccountId();
|
||||
return accountsUpdateProvider
|
||||
.get()
|
||||
.update("Set Diff Preferences via API", id, u -> u.setDiffPreferences(input))
|
||||
.map(AccountState::getDiffPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString())));
|
||||
return Response.ok(
|
||||
accountsUpdateProvider
|
||||
.get()
|
||||
.update("Set Diff Preferences via API", id, u -> u.setDiffPreferences(input))
|
||||
.map(AccountState::getDiffPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString()))));
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
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.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -54,7 +55,7 @@ public class SetEditPreferences implements RestModifyView<AccountResource, EditP
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditPreferencesInfo apply(AccountResource rsrc, EditPreferencesInfo input)
|
||||
public Response<EditPreferencesInfo> apply(AccountResource rsrc, EditPreferencesInfo input)
|
||||
throws RestApiException, RepositoryNotFoundException, IOException, ConfigInvalidException,
|
||||
PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
@@ -66,10 +67,11 @@ public class SetEditPreferences implements RestModifyView<AccountResource, EditP
|
||||
}
|
||||
|
||||
Account.Id id = rsrc.getUser().getAccountId();
|
||||
return accountsUpdateProvider
|
||||
.get()
|
||||
.update("Set Edit Preferences via API", id, u -> u.setEditPreferences(input))
|
||||
.map(AccountState::getEditPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString())));
|
||||
return Response.ok(
|
||||
accountsUpdateProvider
|
||||
.get()
|
||||
.update("Set Edit Preferences via API", id, u -> u.setEditPreferences(input))
|
||||
.map(AccountState::getEditPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString()))));
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import com.google.gerrit.extensions.registration.Extension;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
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.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -60,7 +61,7 @@ public class SetPreferences implements RestModifyView<AccountResource, GeneralPr
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo apply(AccountResource rsrc, GeneralPreferencesInfo input)
|
||||
public Response<GeneralPreferencesInfo> apply(AccountResource rsrc, GeneralPreferencesInfo input)
|
||||
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
|
||||
@@ -70,11 +71,12 @@ public class SetPreferences implements RestModifyView<AccountResource, GeneralPr
|
||||
Preferences.validateMy(input.my);
|
||||
Account.Id id = rsrc.getUser().getAccountId();
|
||||
|
||||
return accountsUpdateProvider
|
||||
.get()
|
||||
.update("Set General Preferences via API", id, u -> u.setGeneralPreferences(input))
|
||||
.map(AccountState::getGeneralPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString())));
|
||||
return Response.ok(
|
||||
accountsUpdateProvider
|
||||
.get()
|
||||
.update("Set General Preferences via API", id, u -> u.setGeneralPreferences(input))
|
||||
.map(AccountState::getGeneralPreferences)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(IdString.fromDecoded(id.toString()))));
|
||||
}
|
||||
|
||||
private void checkDownloadScheme(String downloadScheme) throws BadRequestException {
|
||||
|
@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ChildCollection;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
@@ -97,14 +98,24 @@ public class Stars implements ChildCollection<AccountResource, AccountResource.S
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<ChangeInfo> apply(AccountResource rsrc)
|
||||
public Response<List<ChangeInfo>> apply(AccountResource rsrc)
|
||||
throws BadRequestException, AuthException, PermissionBackendException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
throw new AuthException("not allowed to list stars of another account");
|
||||
}
|
||||
|
||||
// The type of the value in the response that is returned by QueryChanges depends on the
|
||||
// number of queries that is provided as input. If a single query is provided as input the
|
||||
// value type is {@code List<ChangeInfo>}, if multiple queries are provided as input the value
|
||||
// type is {@code List<List<ChangeInfo>>) (one {@code List<ChangeInfo>} as result to each
|
||||
// query). Since in this case we provide exactly one query ("has:stars") as input we know that
|
||||
// the value always has the type {@code List<ChangeInfo>} and hence we can safely cast the
|
||||
// value to this type.
|
||||
QueryChanges query = changes.list();
|
||||
query.addQuery("has:stars");
|
||||
return (List<ChangeInfo>) query.apply(TopLevelResource.INSTANCE);
|
||||
Response<?> response = query.apply(TopLevelResource.INSTANCE);
|
||||
List<ChangeInfo> value = (List<ChangeInfo>) response.value();
|
||||
return Response.ok(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,11 +131,12 @@ public class Stars implements ChildCollection<AccountResource, AccountResource.S
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<String> apply(AccountResource.Star rsrc) throws AuthException {
|
||||
public Response<SortedSet<String>> apply(AccountResource.Star rsrc) throws AuthException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
throw new AuthException("not allowed to get stars of another account");
|
||||
}
|
||||
return starredChangesUtil.getLabels(self.get().getAccountId(), rsrc.getChange().getId());
|
||||
return Response.ok(
|
||||
starredChangesUtil.getLabels(self.get().getAccountId(), rsrc.getChange().getId()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,18 +152,19 @@ public class Stars implements ChildCollection<AccountResource, AccountResource.S
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> apply(AccountResource.Star rsrc, StarsInput in)
|
||||
public Response<Collection<String>> apply(AccountResource.Star rsrc, StarsInput in)
|
||||
throws AuthException, BadRequestException {
|
||||
if (!self.get().hasSameAccountId(rsrc.getUser())) {
|
||||
throw new AuthException("not allowed to update stars of another account");
|
||||
}
|
||||
try {
|
||||
return starredChangesUtil.star(
|
||||
self.get().getAccountId(),
|
||||
rsrc.getChange().getProject(),
|
||||
rsrc.getChange().getId(),
|
||||
in.add,
|
||||
in.remove);
|
||||
return Response.ok(
|
||||
starredChangesUtil.star(
|
||||
self.get().getAccountId(),
|
||||
rsrc.getChange().getProject(),
|
||||
rsrc.getChange().getId(),
|
||||
in.add,
|
||||
in.remove));
|
||||
} catch (IllegalLabelException e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.exceptions.StorageException;
|
||||
import com.google.gerrit.extensions.api.changes.AbandonInput;
|
||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -67,7 +68,7 @@ public class Abandon extends RetryingRestModifyView<ChangeResource, AbandonInput
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChangeInfo applyImpl(
|
||||
protected Response<ChangeInfo> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, ChangeResource rsrc, AbandonInput input)
|
||||
throws RestApiException, UpdateException, PermissionBackendException, IOException,
|
||||
ConfigInvalidException {
|
||||
@@ -84,7 +85,7 @@ public class Abandon extends RetryingRestModifyView<ChangeResource, AbandonInput
|
||||
rsrc.getUser(),
|
||||
input.message,
|
||||
notifyResolver.resolve(notify, input.notifyDetails));
|
||||
return json.noOptions().format(change);
|
||||
return Response.ok(json.noOptions().format(change));
|
||||
}
|
||||
|
||||
private NotifyHandling defaultNotify(Change change) {
|
||||
|
@@ -377,7 +377,7 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo apply(ChangeEditResource rsrc) {
|
||||
public Response<FileInfo> apply(ChangeEditResource rsrc) {
|
||||
FileInfo r = new FileInfo();
|
||||
ChangeEdit edit = rsrc.getChangeEdit();
|
||||
Change change = edit.getChange();
|
||||
@@ -392,7 +392,7 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
|
||||
edit.getRefName(),
|
||||
rsrc.getPath());
|
||||
r.webLinks = links.isEmpty() ? null : links;
|
||||
return r;
|
||||
return Response.ok(r);
|
||||
}
|
||||
|
||||
public static class FileInfo {
|
||||
@@ -416,7 +416,7 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc, Input input)
|
||||
public Response<Object> apply(ChangeResource rsrc, Input input)
|
||||
throws AuthException, IOException, BadRequestException, ResourceConflictException,
|
||||
PermissionBackendException {
|
||||
if (input == null || Strings.isNullOrEmpty(input.message)) {
|
||||
@@ -451,7 +451,7 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult apply(ChangeResource rsrc)
|
||||
public Response<BinaryResult> apply(ChangeResource rsrc)
|
||||
throws AuthException, IOException, ResourceNotFoundException {
|
||||
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getNotes(), rsrc.getUser());
|
||||
String msg;
|
||||
@@ -466,9 +466,10 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
|
||||
msg = edit.get().getEditCommit().getFullMessage();
|
||||
}
|
||||
|
||||
return BinaryResult.create(msg)
|
||||
.setContentType(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE)
|
||||
.base64();
|
||||
return Response.ok(
|
||||
BinaryResult.create(msg)
|
||||
.setContentType(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE)
|
||||
.base64());
|
||||
}
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.IncludedInInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
@@ -37,8 +38,8 @@ public class ChangeIncludedIn implements RestReadView<ChangeResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncludedInInfo apply(ChangeResource rsrc) throws RestApiException, IOException {
|
||||
public Response<IncludedInInfo> apply(ChangeResource rsrc) throws RestApiException, IOException {
|
||||
PatchSet ps = psUtil.current(rsrc.getNotes());
|
||||
return includedIn.apply(rsrc.getProject(), ps.commitId().name());
|
||||
return Response.ok(includedIn.apply(rsrc.getProject(), ps.commitId().name()));
|
||||
}
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ public class ChangeMessages implements ChildCollection<ChangeResource, ChangeMes
|
||||
throws ResourceNotFoundException, PermissionBackendException {
|
||||
String uuid = id.get();
|
||||
|
||||
List<ChangeMessageInfo> changeMessages = listChangeMessages.apply(parent);
|
||||
List<ChangeMessageInfo> changeMessages = listChangeMessages.apply(parent).value();
|
||||
int index = -1;
|
||||
for (int i = 0; i < changeMessages.size(); ++i) {
|
||||
ChangeMessageInfo changeMessage = changeMessages.get(i);
|
||||
|
@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||
import com.google.gerrit.extensions.common.CherryPickChangeInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.BranchNameKey;
|
||||
@@ -75,7 +76,7 @@ public class CherryPick
|
||||
}
|
||||
|
||||
@Override
|
||||
public CherryPickChangeInfo applyImpl(
|
||||
public Response<CherryPickChangeInfo> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, RevisionResource rsrc, CherryPickInput input)
|
||||
throws IOException, UpdateException, RestApiException, PermissionBackendException,
|
||||
ConfigInvalidException, NoSuchProjectException {
|
||||
@@ -109,7 +110,7 @@ public class CherryPick
|
||||
.format(rsrc.getProject(), cherryPickResult.changeId(), CherryPickChangeInfo::new);
|
||||
changeInfo.containsGitConflicts =
|
||||
!cherryPickResult.filesWithGitConflicts().isEmpty() ? true : null;
|
||||
return changeInfo;
|
||||
return Response.ok(changeInfo);
|
||||
} catch (InvalidChangeOperationException e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
} catch (IntegrationException | NoSuchChangeException e) {
|
||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||
import com.google.gerrit.extensions.common.CherryPickChangeInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.BranchNameKey;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
@@ -70,7 +71,7 @@ public class CherryPickCommit
|
||||
}
|
||||
|
||||
@Override
|
||||
public CherryPickChangeInfo applyImpl(
|
||||
public Response<CherryPickChangeInfo> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, CommitResource rsrc, CherryPickInput input)
|
||||
throws IOException, UpdateException, RestApiException, PermissionBackendException,
|
||||
ConfigInvalidException, NoSuchProjectException {
|
||||
@@ -108,7 +109,7 @@ public class CherryPickCommit
|
||||
.format(projectName, cherryPickResult.changeId(), CherryPickChangeInfo::new);
|
||||
changeInfo.containsGitConflicts =
|
||||
!cherryPickResult.filesWithGitConflicts().isEmpty() ? true : null;
|
||||
return changeInfo;
|
||||
return Response.ok(changeInfo);
|
||||
} catch (InvalidChangeOperationException e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
} catch (IntegrationException e) {
|
||||
|
@@ -97,7 +97,7 @@ import org.eclipse.jgit.util.ChangeIdUtil;
|
||||
@Singleton
|
||||
public class CreateChange
|
||||
extends RetryingRestCollectionModifyView<
|
||||
TopLevelResource, ChangeResource, ChangeInput, Response<ChangeInfo>> {
|
||||
TopLevelResource, ChangeResource, ChangeInput, ChangeInfo> {
|
||||
private final String anonymousCowardName;
|
||||
private final GitRepositoryManager gitManager;
|
||||
private final Sequences seq;
|
||||
|
@@ -48,7 +48,7 @@ import java.util.Collections;
|
||||
|
||||
@Singleton
|
||||
public class CreateDraftComment
|
||||
extends RetryingRestModifyView<RevisionResource, DraftInput, Response<CommentInfo>> {
|
||||
extends RetryingRestModifyView<RevisionResource, DraftInput, CommentInfo> {
|
||||
private final Provider<CommentJson> commentJson;
|
||||
private final CommentsUtil commentsUtil;
|
||||
private final PatchSetUtil psUtil;
|
||||
|
@@ -76,7 +76,7 @@ import org.eclipse.jgit.util.ChangeIdUtil;
|
||||
|
||||
@Singleton
|
||||
public class CreateMergePatchSet
|
||||
extends RetryingRestModifyView<ChangeResource, MergePatchSetInput, Response<ChangeInfo>> {
|
||||
extends RetryingRestModifyView<ChangeResource, MergePatchSetInput, ChangeInfo> {
|
||||
private final GitRepositoryManager gitManager;
|
||||
private final CommitsCollection commits;
|
||||
private final TimeZone serverTimeZone;
|
||||
|
@@ -42,8 +42,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class DeleteAssignee
|
||||
extends RetryingRestModifyView<ChangeResource, Input, Response<AccountInfo>> {
|
||||
public class DeleteAssignee extends RetryingRestModifyView<ChangeResource, Input, AccountInfo> {
|
||||
|
||||
private final ChangeMessagesUtil cmUtil;
|
||||
private final AssigneeChanged assigneeChanged;
|
||||
|
@@ -36,7 +36,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class DeleteChange extends RetryingRestModifyView<ChangeResource, Input, Response<?>>
|
||||
public class DeleteChange extends RetryingRestModifyView<ChangeResource, Input, Object>
|
||||
implements UiAction<ChangeResource> {
|
||||
|
||||
private final DeleteChangeOp.Factory opFactory;
|
||||
@@ -48,7 +48,7 @@ public class DeleteChange extends RetryingRestModifyView<ChangeResource, Input,
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Response<?> applyImpl(
|
||||
protected Response<Object> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, ChangeResource rsrc, Input input)
|
||||
throws RestApiException, UpdateException, PermissionBackendException {
|
||||
if (!isChangeDeletable(rsrc)) {
|
||||
|
@@ -53,7 +53,7 @@ import java.util.List;
|
||||
@Singleton
|
||||
public class DeleteChangeMessage
|
||||
extends RetryingRestModifyView<
|
||||
ChangeMessageResource, DeleteChangeMessageInput, Response<ChangeMessageInfo>> {
|
||||
ChangeMessageResource, DeleteChangeMessageInput, ChangeMessageInfo> {
|
||||
|
||||
private final Provider<CurrentUser> userProvider;
|
||||
private final PermissionBackend permissionBackend;
|
||||
@@ -146,7 +146,7 @@ public class DeleteChangeMessage
|
||||
|
||||
@Singleton
|
||||
public static class DefaultDeleteChangeMessage
|
||||
extends RetryingRestModifyView<ChangeMessageResource, Input, Response<ChangeMessageInfo>> {
|
||||
extends RetryingRestModifyView<ChangeMessageResource, Input, ChangeMessageInfo> {
|
||||
private final DeleteChangeMessage deleteChangeMessage;
|
||||
|
||||
@Inject
|
||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.extensions.api.changes.DeleteCommentInput;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.Comment;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
@@ -71,7 +72,7 @@ public class DeleteComment
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentInfo applyImpl(
|
||||
public Response<CommentInfo> applyImpl(
|
||||
BatchUpdate.Factory batchUpdateFactory, CommentResource rsrc, DeleteCommentInput input)
|
||||
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException,
|
||||
UpdateException {
|
||||
@@ -100,7 +101,7 @@ public class DeleteComment
|
||||
throw new ResourceNotFoundException("comment not found: " + rsrc.getComment().key);
|
||||
}
|
||||
|
||||
return commentJson.get().newCommentFormatter().format(updatedComment.get());
|
||||
return Response.ok(commentJson.get().newCommentFormatter().format(updatedComment.get()));
|
||||
}
|
||||
|
||||
private static String getCommentNewMessage(String name, String reason) {
|
||||
|
@@ -42,7 +42,7 @@ import java.util.Optional;
|
||||
|
||||
@Singleton
|
||||
public class DeleteDraftComment
|
||||
extends RetryingRestModifyView<DraftCommentResource, Input, Response<CommentInfo>> {
|
||||
extends RetryingRestModifyView<DraftCommentResource, Input, CommentInfo> {
|
||||
|
||||
private final CommentsUtil commentsUtil;
|
||||
private final PatchSetUtil psUtil;
|
||||
|
@@ -36,7 +36,7 @@ import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class DeletePrivate
|
||||
extends RetryingRestModifyView<ChangeResource, SetPrivateOp.Input, Response<String>> {
|
||||
extends RetryingRestModifyView<ChangeResource, SetPrivateOp.Input, String> {
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final SetPrivateOp.Factory setPrivateOpFactory;
|
||||
|
||||
|
@@ -34,7 +34,7 @@ import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class DeleteReviewer
|
||||
extends RetryingRestModifyView<ReviewerResource, DeleteReviewerInput, Response<?>> {
|
||||
extends RetryingRestModifyView<ReviewerResource, DeleteReviewerInput, Object> {
|
||||
|
||||
private final DeleteReviewerOp.Factory deleteReviewerOpFactory;
|
||||
private final DeleteReviewerByEmailOp.Factory deleteReviewerByEmailOpFactory;
|
||||
@@ -50,7 +50,7 @@ public class DeleteReviewer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Response<?> applyImpl(
|
||||
protected Response<Object> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, ReviewerResource rsrc, DeleteReviewerInput input)
|
||||
throws RestApiException, UpdateException {
|
||||
if (input == null) {
|
||||
|
@@ -64,7 +64,7 @@ import java.util.Map;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
@Singleton
|
||||
public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteInput, Response<?>> {
|
||||
public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteInput, Object> {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private final ApprovalsUtil approvalsUtil;
|
||||
@@ -102,7 +102,7 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Response<?> applyImpl(
|
||||
protected Response<Object> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, VoteResource rsrc, DeleteVoteInput input)
|
||||
throws RestApiException, UpdateException, IOException, ConfigInvalidException {
|
||||
if (input == null) {
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
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.server.change.FileContentUtil;
|
||||
import com.google.gerrit.server.change.FileResource;
|
||||
@@ -40,11 +41,12 @@ public class DownloadContent implements RestReadView<FileResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult apply(FileResource rsrc)
|
||||
public Response<BinaryResult> apply(FileResource rsrc)
|
||||
throws ResourceNotFoundException, IOException, NoSuchChangeException {
|
||||
String path = rsrc.getPatchKey().fileName();
|
||||
RevisionResource rev = rsrc.getRevision();
|
||||
return fileContentUtil.downloadContent(
|
||||
projectCache.checkedGet(rev.getProject()), rev.getPatchSet().commitId(), path, parent);
|
||||
return Response.ok(
|
||||
fileContentUtil.downloadContent(
|
||||
projectCache.checkedGet(rev.getProject()), rev.getPatchSet().commitId(), path, parent));
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ArchiveFormat;
|
||||
import com.google.gerrit.server.change.RevisionResource;
|
||||
@@ -48,7 +49,7 @@ public class GetArchive implements RestReadView<RevisionResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult apply(RevisionResource rsrc)
|
||||
public Response<BinaryResult> apply(RevisionResource rsrc)
|
||||
throws BadRequestException, IOException, MethodNotAllowedException {
|
||||
if (Strings.isNullOrEmpty(format)) {
|
||||
throw new BadRequestException("format is not specified");
|
||||
@@ -94,7 +95,7 @@ public class GetArchive implements RestReadView<RevisionResource> {
|
||||
bin.disableGzip().setContentType(f.getMimeType()).setAttachmentName(name);
|
||||
|
||||
close = false;
|
||||
return bin;
|
||||
return Response.ok(bin);
|
||||
} finally {
|
||||
if (close) {
|
||||
repo.close();
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.gerrit.extensions.common.ChangeMessageInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ChangeMessageResource;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -23,7 +24,7 @@ import com.google.inject.Singleton;
|
||||
@Singleton
|
||||
public class GetChangeMessage implements RestReadView<ChangeMessageResource> {
|
||||
@Override
|
||||
public ChangeMessageInfo apply(ChangeMessageResource resource) {
|
||||
return resource.getChangeMessage();
|
||||
public Response<ChangeMessageInfo> apply(ChangeMessageResource resource) {
|
||||
return Response.ok(resource.getChangeMessage());
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.CommentResource;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -33,7 +34,7 @@ public class GetComment implements RestReadView<CommentResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentInfo apply(CommentResource rsrc) throws PermissionBackendException {
|
||||
return commentJson.get().newCommentFormatter().format(rsrc.getComment());
|
||||
public Response<CommentInfo> apply(CommentResource rsrc) throws PermissionBackendException {
|
||||
return Response.ok(commentJson.get().newCommentFormatter().format(rsrc.getComment()));
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.restapi.change;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
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.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
@@ -60,25 +61,28 @@ public class GetContent implements RestReadView<FileResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult apply(FileResource rsrc)
|
||||
public Response<BinaryResult> apply(FileResource rsrc)
|
||||
throws ResourceNotFoundException, IOException, BadRequestException {
|
||||
String path = rsrc.getPatchKey().fileName();
|
||||
if (Patch.COMMIT_MSG.equals(path)) {
|
||||
String msg = getMessage(rsrc.getRevision().getChangeResource().getNotes());
|
||||
return BinaryResult.create(msg)
|
||||
.setContentType(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE)
|
||||
.base64();
|
||||
return Response.ok(
|
||||
BinaryResult.create(msg)
|
||||
.setContentType(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE)
|
||||
.base64());
|
||||
} else if (Patch.MERGE_LIST.equals(path)) {
|
||||
byte[] mergeList = getMergeList(rsrc.getRevision().getChangeResource().getNotes());
|
||||
return BinaryResult.create(mergeList)
|
||||
.setContentType(FileContentUtil.TEXT_X_GERRIT_MERGE_LIST)
|
||||
.base64();
|
||||
return Response.ok(
|
||||
BinaryResult.create(mergeList)
|
||||
.setContentType(FileContentUtil.TEXT_X_GERRIT_MERGE_LIST)
|
||||
.base64());
|
||||
}
|
||||
return fileContentUtil.getContent(
|
||||
projectCache.checkedGet(rsrc.getRevision().getProject()),
|
||||
rsrc.getRevision().getPatchSet().commitId(),
|
||||
path,
|
||||
parent);
|
||||
return Response.ok(
|
||||
fileContentUtil.getContent(
|
||||
projectCache.checkedGet(rsrc.getRevision().getProject()),
|
||||
rsrc.getRevision().getPatchSet().commitId(),
|
||||
path,
|
||||
parent));
|
||||
}
|
||||
|
||||
private String getMessage(ChangeNotes notes) throws IOException {
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.RevisionResource;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -21,7 +22,7 @@ import com.google.inject.Singleton;
|
||||
@Singleton
|
||||
public class GetDescription implements RestReadView<RevisionResource> {
|
||||
@Override
|
||||
public String apply(RevisionResource rsrc) {
|
||||
return rsrc.getPatchSet().description().orElse("");
|
||||
public Response<String> apply(RevisionResource rsrc) {
|
||||
return Response.ok(rsrc.getPatchSet().description().orElse(""));
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.DraftCommentResource;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -33,7 +34,7 @@ public class GetDraftComment implements RestReadView<DraftCommentResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentInfo apply(DraftCommentResource rsrc) throws PermissionBackendException {
|
||||
return commentJson.get().newCommentFormatter().format(rsrc.getComment());
|
||||
public Response<CommentInfo> apply(DraftCommentResource rsrc) throws PermissionBackendException {
|
||||
return Response.ok(commentJson.get().newCommentFormatter().format(rsrc.getComment()));
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
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.server.change.RevisionResource;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
@@ -59,7 +60,7 @@ public class GetPatch implements RestReadView<RevisionResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryResult apply(RevisionResource rsrc)
|
||||
public Response<BinaryResult> apply(RevisionResource rsrc)
|
||||
throws ResourceConflictException, IOException, ResourceNotFoundException {
|
||||
final Repository repo = repoManager.openRepository(rsrc.getProject());
|
||||
boolean close = true;
|
||||
@@ -130,7 +131,7 @@ public class GetPatch implements RestReadView<RevisionResource> {
|
||||
}
|
||||
|
||||
close = false;
|
||||
return bin;
|
||||
return Response.ok(bin);
|
||||
} finally {
|
||||
if (close) {
|
||||
rw.close();
|
||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.extensions.common.PureRevertInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.PureRevert;
|
||||
@@ -46,9 +47,9 @@ public class GetPureRevert implements RestReadView<ChangeResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PureRevertInfo apply(ChangeResource rsrc)
|
||||
public Response<PureRevertInfo> apply(ChangeResource rsrc)
|
||||
throws ResourceConflictException, IOException, BadRequestException, AuthException {
|
||||
boolean isPureRevert = pureRevert.get(rsrc.getNotes(), Optional.ofNullable(claimedOriginal));
|
||||
return new PureRevertInfo(isPureRevert);
|
||||
return Response.ok(new PureRevertInfo(isPureRevert));
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo;
|
||||
import com.google.gerrit.extensions.api.changes.RelatedChangesInfo;
|
||||
import com.google.gerrit.extensions.common.CommitInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.index.IndexConfig;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -68,12 +69,12 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RelatedChangesInfo apply(RevisionResource rsrc)
|
||||
public Response<RelatedChangesInfo> apply(RevisionResource rsrc)
|
||||
throws RepositoryNotFoundException, IOException, NoSuchProjectException,
|
||||
PermissionBackendException {
|
||||
RelatedChangesInfo relatedChangesInfo = new RelatedChangesInfo();
|
||||
relatedChangesInfo.changes = getRelated(rsrc);
|
||||
return relatedChangesInfo;
|
||||
return Response.ok(relatedChangesInfo);
|
||||
}
|
||||
|
||||
private List<RelatedChangeAndCommitInfo> getRelated(RevisionResource rsrc)
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.ReviewerInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ReviewerJson;
|
||||
import com.google.gerrit.server.change.ReviewerResource;
|
||||
@@ -33,7 +34,8 @@ public class GetReviewer implements RestReadView<ReviewerResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReviewerInfo> apply(ReviewerResource rsrc) throws PermissionBackendException {
|
||||
return json.format(rsrc);
|
||||
public Response<List<ReviewerInfo>> apply(ReviewerResource rsrc)
|
||||
throws PermissionBackendException {
|
||||
return Response.ok(json.format(rsrc));
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.gerrit.extensions.common.RobotCommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.RobotCommentResource;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -33,7 +34,8 @@ public class GetRobotComment implements RestReadView<RobotCommentResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RobotCommentInfo apply(RobotCommentResource rsrc) throws PermissionBackendException {
|
||||
return commentJson.get().newRobotCommentFormatter().format(rsrc.getComment());
|
||||
public Response<RobotCommentInfo> apply(RobotCommentResource rsrc)
|
||||
throws PermissionBackendException {
|
||||
return Response.ok(commentJson.get().newRobotCommentFormatter().format(rsrc.getComment()));
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user