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