Cleanup implementation of REST views
- specify return type if possible - remove unnecessary throw declarations - convert some of the thrown exceptions to RestExceptions - do not throw Exception but specific exceptions - sort throw declarations (first RestExceptions, then other exceptions) Having explicit return types and exceptions makes it easier to programatically invoke the REST views, e.g. if a plugin wants to add a REST view that wraps a Gerrit core REST view. Change-Id: I5c59553b6cfad457f7ec037cceb08936247bf8e8 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -19,9 +19,7 @@ import com.google.common.io.ByteSource;
|
||||
import com.google.gerrit.common.errors.InvalidSshKeyException;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.RawInput;
|
||||
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.reviewdb.client.AccountSshKey;
|
||||
@@ -57,8 +55,7 @@ public class AddSshKey implements RestModifyView<AccountResource, Input> {
|
||||
|
||||
@Override
|
||||
public Response<SshKeyInfo> apply(AccountResource rsrc, Input input)
|
||||
throws AuthException, MethodNotAllowedException, BadRequestException,
|
||||
ResourceConflictException, OrmException, IOException {
|
||||
throws AuthException, BadRequestException, OrmException, IOException {
|
||||
if (self.get() != rsrc.getUser()
|
||||
&& !self.get().getCapabilities().canAdministrateServer()) {
|
||||
throw new AuthException("not allowed to add SSH keys");
|
||||
|
@@ -89,7 +89,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(TopLevelResource rsrc, Input input)
|
||||
public Response<AccountInfo> apply(TopLevelResource rsrc, Input input)
|
||||
throws BadRequestException, ResourceConflictException,
|
||||
UnprocessableEntityException, OrmException {
|
||||
if (input == null) {
|
||||
|
@@ -78,8 +78,8 @@ public class CreateEmail implements RestModifyView<AccountResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(AccountResource rsrc, Input input) throws AuthException,
|
||||
BadRequestException, ResourceConflictException,
|
||||
public Response<EmailInfo> apply(AccountResource rsrc, Input input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
ResourceNotFoundException, OrmException, EmailException,
|
||||
MethodNotAllowedException {
|
||||
if (self.get() != rsrc.getUser()
|
||||
|
@@ -43,7 +43,7 @@ public class DeleteActive implements RestModifyView<AccountResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(AccountResource rsrc, Input input)
|
||||
public Response<?> apply(AccountResource rsrc, Input input)
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
Account a = dbProvider.get().accounts().get(rsrc.getUser().getAccountId());
|
||||
if (a == null) {
|
||||
|
@@ -48,7 +48,7 @@ public class DeleteEmail implements RestModifyView<AccountResource.Email, Input>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(AccountResource.Email rsrc, Input input)
|
||||
public Response<?> apply(AccountResource.Email rsrc, Input input)
|
||||
throws AuthException, ResourceNotFoundException,
|
||||
ResourceConflictException, MethodNotAllowedException, OrmException {
|
||||
if (self.get() != rsrc.getUser()
|
||||
|
@@ -40,7 +40,7 @@ public class DeleteSshKey implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(AccountResource.SshKey rsrc, Input input)
|
||||
public Response<?> apply(AccountResource.SshKey rsrc, Input input)
|
||||
throws OrmException {
|
||||
dbProvider.get().accountSshKeys()
|
||||
.deleteKeys(Collections.singleton(rsrc.getSshKey().getKey()));
|
||||
|
@@ -36,7 +36,6 @@ import com.google.gerrit.common.data.PermissionRange;
|
||||
import com.google.gerrit.extensions.config.CapabilityDefinition;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
@@ -79,8 +78,7 @@ class GetCapabilities implements RestReadView<AccountResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(AccountResource resource)
|
||||
throws BadRequestException, Exception {
|
||||
public Object apply(AccountResource resource) throws AuthException {
|
||||
if (self.get() != resource.getUser()
|
||||
&& !self.get().getCapabilities().canAdministrateServer()) {
|
||||
throw new AuthException("restricted to administrator");
|
||||
@@ -178,7 +176,7 @@ class GetCapabilities implements RestReadView<AccountResource> {
|
||||
|
||||
static class CheckOne implements RestReadView<AccountResource.Capability> {
|
||||
@Override
|
||||
public Object apply(Capability resource) {
|
||||
public BinaryResult apply(Capability resource) {
|
||||
return BinaryResult.create("ok\n");
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
@@ -33,7 +32,7 @@ public class GetHttpPassword implements RestReadView<AccountResource> {
|
||||
|
||||
@Override
|
||||
public String apply(AccountResource rsrc) throws AuthException,
|
||||
ResourceNotFoundException, OrmException {
|
||||
ResourceNotFoundException {
|
||||
if (self.get() != rsrc.getUser()
|
||||
&& !self.get().getCapabilities().canAdministrateServer()) {
|
||||
throw new AuthException("not allowed to get http password");
|
||||
|
@@ -43,7 +43,7 @@ public class PutActive implements RestModifyView<AccountResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(AccountResource rsrc, Input input)
|
||||
public Response<String> apply(AccountResource rsrc, Input input)
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
Account a = dbProvider.get().accounts().get(rsrc.getUser().getAccountId());
|
||||
if (a == null) {
|
||||
|
@@ -15,12 +15,13 @@
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
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.server.account.CreateEmail.Input;
|
||||
|
||||
public class PutEmail implements RestModifyView<AccountResource.Email, Input> {
|
||||
@Override
|
||||
public Object apply(AccountResource.Email rsrc, Input input)
|
||||
public Response<?> apply(AccountResource.Email rsrc, Input input)
|
||||
throws ResourceConflictException {
|
||||
throw new ResourceConflictException("email exists");
|
||||
}
|
||||
|
@@ -157,7 +157,7 @@ class StarredChanges implements
|
||||
|
||||
@Override
|
||||
public Response<?> apply(AccountResource.StarredChange rsrc, EmptyInput in)
|
||||
throws AuthException, OrmException {
|
||||
throws AuthException {
|
||||
if (self.get() != rsrc.getUser()) {
|
||||
throw new AuthException("not allowed update starred changes");
|
||||
}
|
||||
|
@@ -28,7 +28,6 @@ import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.Restore;
|
||||
import com.google.gerrit.server.change.Revert;
|
||||
import com.google.gerrit.server.change.Revisions;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -138,8 +137,6 @@ class ChangeApiImpl implements ChangeApi {
|
||||
throw new RestApiException("Cannot revert change", e);
|
||||
} catch (IOException e) {
|
||||
throw new RestApiException("Cannot revert change", e);
|
||||
} catch (NoSuchChangeException e) {
|
||||
throw new RestApiException("Cannot revert change", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ import com.google.common.util.concurrent.CheckedFuture;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.extensions.api.changes.AbandonInput;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
@@ -69,9 +68,9 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource req, AbandonInput input)
|
||||
throws BadRequestException, AuthException,
|
||||
ResourceConflictException, OrmException, IOException {
|
||||
public ChangeInfo apply(ChangeResource req, AbandonInput input)
|
||||
throws AuthException, ResourceConflictException, OrmException,
|
||||
IOException {
|
||||
ChangeControl control = req.getControl();
|
||||
IdentifiedUser caller = (IdentifiedUser) control.getCurrentUser();
|
||||
Change change = req.getChange();
|
||||
|
@@ -14,22 +14,29 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.common.errors.EmailException;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gerrit.server.change.CherryPick.Input;
|
||||
import com.google.gerrit.server.git.MergeException;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.project.RefControl;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class CherryPick implements RestModifyView<RevisionResource, Input>,
|
||||
UiAction<RevisionResource> {
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
@@ -51,9 +58,9 @@ class CherryPick implements RestModifyView<RevisionResource, Input>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource revision, Input input)
|
||||
public ChangeInfo apply(RevisionResource revision, Input input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
Exception {
|
||||
ResourceNotFoundException, OrmException, IOException, EmailException {
|
||||
final ChangeControl control = revision.getControl();
|
||||
|
||||
if (input.message == null || input.message.trim().isEmpty()) {
|
||||
@@ -89,6 +96,8 @@ class CherryPick implements RestModifyView<RevisionResource, Input>,
|
||||
throw new BadRequestException(e.getMessage());
|
||||
} catch (MergeException e) {
|
||||
throw new ResourceConflictException(e.getMessage());
|
||||
} catch (NoSuchChangeException e) {
|
||||
throw new ResourceNotFoundException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -16,9 +16,7 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.common.changes.Side;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
@@ -44,7 +42,7 @@ class CreateDraft implements RestModifyView<RevisionResource, Input> {
|
||||
|
||||
@Override
|
||||
public Response<CommentInfo> apply(RevisionResource rsrc, Input in)
|
||||
throws AuthException, BadRequestException, ResourceConflictException, OrmException {
|
||||
throws BadRequestException, OrmException {
|
||||
if (Strings.isNullOrEmpty(in.path)) {
|
||||
throw new BadRequestException("path must be non-empty");
|
||||
} else if (in.message == null || in.message.trim().isEmpty()) {
|
||||
|
@@ -36,7 +36,8 @@ class DeleteDraft implements RestModifyView<DraftResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(DraftResource rsrc, Input input) throws OrmException {
|
||||
public Response<CommentInfo> apply(DraftResource rsrc, Input input)
|
||||
throws OrmException {
|
||||
db.get().patchComments().delete(Collections.singleton(rsrc.getComment()));
|
||||
return Response.none();
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ public class DeleteDraftChange implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc, Input input)
|
||||
public Response<?> apply(ChangeResource rsrc, Input input)
|
||||
throws ResourceConflictException, AuthException,
|
||||
ResourceNotFoundException, OrmException, IOException {
|
||||
if (rsrc.getChange().getStatus() != Status.DRAFT) {
|
||||
|
@@ -64,9 +64,9 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource rsrc, Input input)
|
||||
throws ResourceNotFoundException, AuthException, OrmException,
|
||||
IOException, ResourceConflictException {
|
||||
public Response<?> apply(RevisionResource rsrc, Input input)
|
||||
throws AuthException, ResourceNotFoundException,
|
||||
ResourceConflictException, OrmException, IOException {
|
||||
PatchSet patchSet = rsrc.getPatchSet();
|
||||
PatchSet.Id patchSetId = patchSet.getId();
|
||||
Change change = rsrc.getChange();
|
||||
|
@@ -50,7 +50,7 @@ public class DeleteReviewer implements RestModifyView<ReviewerResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ReviewerResource rsrc, Input input)
|
||||
public Response<?> apply(ReviewerResource rsrc, Input input)
|
||||
throws AuthException, ResourceNotFoundException, OrmException,
|
||||
IOException {
|
||||
ChangeControl control = rsrc.getControl();
|
||||
|
@@ -78,8 +78,8 @@ class EditMessage implements RestModifyView<RevisionResource, Input>,
|
||||
|
||||
@Override
|
||||
public ChangeInfo apply(RevisionResource rsrc, Input input)
|
||||
throws BadRequestException, ResourceConflictException, EmailException,
|
||||
OrmException, ResourceNotFoundException, IOException {
|
||||
throws BadRequestException, ResourceConflictException,
|
||||
ResourceNotFoundException, EmailException, OrmException, IOException {
|
||||
if (Strings.isNullOrEmpty(input.message)) {
|
||||
throw new BadRequestException("message must be non-empty");
|
||||
}
|
||||
|
@@ -117,13 +117,12 @@ class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource resource)
|
||||
throws ResourceNotFoundException, OrmException,
|
||||
PatchListNotAvailableException, BadRequestException, AuthException {
|
||||
public Response<?> apply(RevisionResource resource) throws AuthException,
|
||||
BadRequestException, ResourceNotFoundException, OrmException {
|
||||
if (base != null && reviewed) {
|
||||
throw new BadRequestException("cannot combine base and reviewed");
|
||||
} else if (reviewed) {
|
||||
return reviewed(resource);
|
||||
return Response.ok(reviewed(resource));
|
||||
}
|
||||
|
||||
PatchSet basePatchSet = null;
|
||||
@@ -132,6 +131,7 @@ class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
resource.getChangeResource(), IdString.fromDecoded(base));
|
||||
basePatchSet = baseResource.getPatchSet();
|
||||
}
|
||||
try {
|
||||
Response<Map<String, FileInfo>> r = Response.ok(fileInfoJson.toFileInfoMap(
|
||||
resource.getChange(),
|
||||
resource.getPatchSet(),
|
||||
@@ -140,9 +140,12 @@ class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));
|
||||
}
|
||||
return r;
|
||||
} catch (PatchListNotAvailableException e) {
|
||||
throw new ResourceNotFoundException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Object reviewed(RevisionResource resource)
|
||||
private List<String> reviewed(RevisionResource resource)
|
||||
throws AuthException, OrmException {
|
||||
CurrentUser user = self.get();
|
||||
if (!(user.isIdentifiedUser())) {
|
||||
|
@@ -18,6 +18,7 @@ import com.google.gerrit.common.changes.ListChangesOption;
|
||||
import com.google.gerrit.extensions.restapi.CacheControl;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -44,15 +45,15 @@ public class GetChange implements RestReadView<ChangeResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc) throws OrmException {
|
||||
public Response<ChangeInfo> apply(ChangeResource rsrc) throws OrmException {
|
||||
return cache(json.format(rsrc));
|
||||
}
|
||||
|
||||
Object apply(RevisionResource rsrc) throws OrmException {
|
||||
Response<ChangeInfo> apply(RevisionResource rsrc) throws OrmException {
|
||||
return cache(json.format(rsrc));
|
||||
}
|
||||
|
||||
private Object cache(Object res) {
|
||||
private Response<ChangeInfo> cache(ChangeInfo res) {
|
||||
return Response.ok(res)
|
||||
.caching(CacheControl.PRIVATE(0, TimeUnit.SECONDS).setMustRevalidate());
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ class GetComment implements RestReadView<CommentResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(CommentResource rsrc) throws OrmException {
|
||||
public CommentInfo apply(CommentResource rsrc) throws OrmException {
|
||||
AccountInfo.Loader accountLoader = accountLoaderFactory.create(true);
|
||||
CommentInfo ci = new CommentInfo(rsrc.getComment(), accountLoader);
|
||||
accountLoader.fill();
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.CacheControl;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ChangeJson.CommitInfo;
|
||||
@@ -34,11 +35,16 @@ public class GetCommit implements RestReadView<RevisionResource> {
|
||||
|
||||
@Override
|
||||
public Response<CommitInfo> apply(RevisionResource resource)
|
||||
throws OrmException, PatchSetInfoNotAvailableException {
|
||||
Response<CommitInfo> r = Response.ok(json.toCommit(resource.getPatchSet()));
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
try {
|
||||
Response<CommitInfo> r =
|
||||
Response.ok(json.toCommit(resource.getPatchSet()));
|
||||
if (resource.isCacheable()) {
|
||||
r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));
|
||||
}
|
||||
return r;
|
||||
} catch (PatchSetInfoNotAvailableException e) {
|
||||
throw new ResourceNotFoundException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,9 @@
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.common.changes.ListChangesOption;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -44,7 +46,7 @@ public class GetDetail implements RestReadView<ChangeResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc) throws OrmException {
|
||||
public Response<ChangeInfo> apply(ChangeResource rsrc) throws OrmException {
|
||||
return delegate.apply(rsrc);
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import com.google.gerrit.common.data.PatchScript.DisplayMethod;
|
||||
import com.google.gerrit.common.data.PatchScript.FileMode;
|
||||
import com.google.gerrit.extensions.restapi.CacheControl;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
@@ -38,6 +39,7 @@ import com.google.gerrit.server.git.LargeObjectException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.diff.Edit;
|
||||
import org.eclipse.jgit.diff.ReplaceEdit;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
@@ -76,8 +78,8 @@ public class GetDiff implements RestReadView<FileResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(FileResource resource)
|
||||
throws OrmException, NoSuchChangeException, LargeObjectException, ResourceNotFoundException {
|
||||
public Response<Result> apply(FileResource resource)
|
||||
throws ResourceConflictException, ResourceNotFoundException, OrmException {
|
||||
PatchSet.Id basePatchSet = null;
|
||||
if (base != null) {
|
||||
RevisionResource baseResource = revisions.get().parse(
|
||||
@@ -89,6 +91,7 @@ public class GetDiff implements RestReadView<FileResource> {
|
||||
prefs.setContext(context);
|
||||
prefs.setIntralineDifference(intraline);
|
||||
|
||||
try {
|
||||
PatchScript ps = patchScriptFactoryFactory.create(
|
||||
resource.getRevision().getControl(),
|
||||
resource.getPatchKey().getFileName(),
|
||||
@@ -157,6 +160,11 @@ public class GetDiff implements RestReadView<FileResource> {
|
||||
r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));
|
||||
}
|
||||
return r;
|
||||
} catch (NoSuchChangeException e) {
|
||||
throw new ResourceNotFoundException(e.getMessage());
|
||||
} catch (LargeObjectException e) {
|
||||
throw new ResourceConflictException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
static class Result {
|
||||
|
@@ -14,15 +14,11 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
|
||||
class GetDraft implements RestReadView<DraftResource> {
|
||||
@Override
|
||||
public Object apply(DraftResource rsrc) throws AuthException,
|
||||
BadRequestException, ResourceConflictException, Exception {
|
||||
public CommentInfo apply(DraftResource rsrc) {
|
||||
return new CommentInfo(rsrc.getComment(), null);
|
||||
}
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource rsrc)
|
||||
public RelatedInfo apply(RevisionResource rsrc)
|
||||
throws RepositoryNotFoundException, IOException, OrmException {
|
||||
Repository git = gitMgr.openRepository(rsrc.getChange().getProject());
|
||||
try {
|
||||
|
@@ -15,7 +15,9 @@
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.common.changes.ListChangesOption;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -30,7 +32,7 @@ public class GetReview implements RestReadView<RevisionResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource rsrc) throws OrmException {
|
||||
public Response<ChangeInfo> apply(RevisionResource rsrc) throws OrmException {
|
||||
return delegate.apply(rsrc);
|
||||
}
|
||||
}
|
||||
|
@@ -15,9 +15,12 @@
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ReviewerJson.ReviewerInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GetReviewer implements RestReadView<ReviewerResource> {
|
||||
private final ReviewerJson json;
|
||||
|
||||
@@ -27,7 +30,7 @@ public class GetReviewer implements RestReadView<ReviewerResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ReviewerResource rsrc) throws OrmException {
|
||||
public List<ReviewerInfo> apply(ReviewerResource rsrc) throws OrmException {
|
||||
return json.format(rsrc);
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,10 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
|
||||
class GetTopic implements RestReadView<ChangeResource> {
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc) throws OrmException {
|
||||
public String apply(ChangeResource rsrc) {
|
||||
return Strings.nullToEmpty(rsrc.getChange().getTopic());
|
||||
}
|
||||
}
|
||||
|
@@ -47,8 +47,8 @@ class IncludedIn implements RestReadView<ChangeResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc) throws OrmException, IOException,
|
||||
BadRequestException, ResourceConflictException {
|
||||
public IncludedInInfo apply(ChangeResource rsrc) throws BadRequestException,
|
||||
ResourceConflictException, OrmException, IOException {
|
||||
ChangeControl ctl = rsrc.getControl();
|
||||
PatchSet ps =
|
||||
db.patchSets().get(ctl.getChange().currentPatchSetId());
|
||||
|
@@ -37,7 +37,7 @@ public class Index implements RestModifyView<ChangeResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc, Input input) throws IOException {
|
||||
public Response<?> apply(ChangeResource rsrc, Input input) throws IOException {
|
||||
indexer.index(rsrc.getChange());
|
||||
return Response.none();
|
||||
}
|
||||
|
@@ -19,9 +19,6 @@ import static com.google.common.base.Objects.firstNonNull;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.changes.Side;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@@ -58,8 +55,8 @@ class ListDrafts implements RestReadView<RevisionResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource rsrc) throws AuthException,
|
||||
BadRequestException, ResourceConflictException, Exception {
|
||||
public Map<String, List<CommentInfo>> apply(RevisionResource rsrc)
|
||||
throws OrmException {
|
||||
Map<String, List<CommentInfo>> out = Maps.newTreeMap();
|
||||
AccountInfo.Loader accountLoader =
|
||||
includeAuthorInfo() ? accountLoaderFactory.create(true) : null;
|
||||
|
@@ -15,16 +15,17 @@
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.change.ReviewerJson.ReviewerInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class ListReviewers implements RestReadView<ChangeResource> {
|
||||
@@ -42,8 +43,7 @@ class ListReviewers implements RestReadView<ChangeResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc) throws BadRequestException,
|
||||
OrmException {
|
||||
public List<ReviewerInfo> apply(ChangeResource rsrc) throws OrmException {
|
||||
Map<Account.Id, ReviewerResource> reviewers = Maps.newLinkedHashMap();
|
||||
ReviewDb db = dbProvider.get();
|
||||
Change.Id changeId = rsrc.getChange().getId();
|
||||
|
@@ -35,7 +35,6 @@ import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.AnyObjectId;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -80,9 +79,8 @@ public class Mergeable implements RestReadView<RevisionResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeableInfo apply(RevisionResource resource)
|
||||
throws ResourceConflictException, BadRequestException, AuthException,
|
||||
OrmException, RepositoryNotFoundException, IOException {
|
||||
public MergeableInfo apply(RevisionResource resource) throws AuthException,
|
||||
ResourceConflictException, BadRequestException, OrmException, IOException {
|
||||
Change change = resource.getChange();
|
||||
PatchSet ps = resource.getPatchSet();
|
||||
MergeableInfo result = new MergeableInfo();
|
||||
|
@@ -98,9 +98,9 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource revision, ReviewInput input)
|
||||
throws AuthException, BadRequestException, OrmException,
|
||||
UnprocessableEntityException, IOException {
|
||||
public Output apply(RevisionResource revision, ReviewInput input)
|
||||
throws AuthException, BadRequestException, UnprocessableEntityException,
|
||||
OrmException, IOException {
|
||||
if (input.onBehalfOf != null) {
|
||||
revision = onBehalfOf(revision, input);
|
||||
}
|
||||
|
@@ -28,7 +28,6 @@ import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -132,8 +131,8 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
|
||||
@Override
|
||||
public PostResult apply(ChangeResource rsrc, Input input)
|
||||
throws BadRequestException, ResourceNotFoundException, AuthException,
|
||||
UnprocessableEntityException, OrmException, EmailException, IOException {
|
||||
throws AuthException, BadRequestException, UnprocessableEntityException,
|
||||
OrmException, EmailException, IOException {
|
||||
if (input.reviewer == null) {
|
||||
throw new BadRequestException("missing reviewer field");
|
||||
}
|
||||
|
@@ -59,9 +59,9 @@ public class Publish implements RestModifyView<RevisionResource, Input>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource rsrc, Input input) throws IOException,
|
||||
ResourceNotFoundException, ResourceConflictException,
|
||||
OrmException, AuthException {
|
||||
public Response<?> apply(RevisionResource rsrc, Input input)
|
||||
throws AuthException, ResourceNotFoundException,
|
||||
ResourceConflictException, OrmException, IOException {
|
||||
if (!rsrc.getPatchSet().isDraft()) {
|
||||
throw new ResourceConflictException("Patch set is not a draft");
|
||||
}
|
||||
@@ -148,9 +148,9 @@ public class Publish implements RestModifyView<RevisionResource, Input>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc, Input input) throws AuthException,
|
||||
ResourceConflictException, ResourceConflictException, IOException,
|
||||
OrmException, ResourceNotFoundException, AuthException {
|
||||
public Response<?> apply(ChangeResource rsrc, Input input)
|
||||
throws AuthException, ResourceConflictException,
|
||||
ResourceNotFoundException, IOException, OrmException {
|
||||
PatchSet ps = dbProvider.get().patchSets()
|
||||
.get(rsrc.getChange().currentPatchSetId());
|
||||
if (ps == null) {
|
||||
|
@@ -15,15 +15,14 @@
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.common.changes.Side;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
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.Url;
|
||||
import com.google.gerrit.reviewdb.client.CommentRange;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.CommentRange;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.change.PutDraft.Input;
|
||||
import com.google.gerrit.server.util.TimeUtil;
|
||||
@@ -59,8 +58,8 @@ class PutDraft implements RestModifyView<DraftResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(DraftResource rsrc, Input in) throws AuthException,
|
||||
BadRequestException, ResourceConflictException, OrmException {
|
||||
public Response<CommentInfo> apply(DraftResource rsrc, Input in) throws
|
||||
BadRequestException, OrmException {
|
||||
PatchLineComment c = rsrc.getComment();
|
||||
if (in == null || in.message == null || in.message.trim().isEmpty()) {
|
||||
return delete.get().apply(rsrc, null);
|
||||
@@ -90,7 +89,7 @@ class PutDraft implements RestModifyView<DraftResource, Input> {
|
||||
} else {
|
||||
db.get().patchComments().update(Collections.singleton(update(c, in)));
|
||||
}
|
||||
return new CommentInfo(c, null);
|
||||
return Response.ok(new CommentInfo(c, null));
|
||||
}
|
||||
|
||||
private PatchLineComment update(PatchLineComment e, Input in) {
|
||||
|
@@ -18,9 +18,7 @@ import com.google.common.base.Strings;
|
||||
import com.google.common.util.concurrent.CheckedFuture;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
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.webui.UiAction;
|
||||
@@ -34,6 +32,7 @@ import com.google.gerrit.server.index.ChangeIndexer;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.util.TimeUtil;
|
||||
import com.google.gwtorm.server.AtomicUpdate;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
@@ -61,9 +60,8 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource req, Input input)
|
||||
throws BadRequestException, AuthException,
|
||||
ResourceConflictException, Exception {
|
||||
public Response<String> apply(ChangeResource req, Input input)
|
||||
throws AuthException, OrmException, IOException {
|
||||
if (input == null) {
|
||||
input = new Input();
|
||||
}
|
||||
@@ -123,8 +121,8 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
indexFuture.checkedGet();
|
||||
}
|
||||
return Strings.isNullOrEmpty(newTopicName)
|
||||
? Response.none()
|
||||
: newTopicName;
|
||||
? Response.<String>none()
|
||||
: Response.ok(newTopicName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -69,9 +69,9 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource req, RestoreInput input)
|
||||
throws OrmException, IOException, AuthException,
|
||||
ResourceConflictException {
|
||||
public ChangeInfo apply(ChangeResource req, RestoreInput input)
|
||||
throws AuthException, ResourceConflictException, OrmException,
|
||||
IOException {
|
||||
ChangeControl control = req.getControl();
|
||||
IdentifiedUser caller = (IdentifiedUser) control.getCurrentUser();
|
||||
Change change = req.getChange();
|
||||
|
@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.api.changes.RevertInput;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -82,8 +83,8 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
|
||||
|
||||
@Override
|
||||
public ChangeInfo apply(ChangeResource req, RevertInput input)
|
||||
throws AuthException, ResourceConflictException, IOException,
|
||||
NoSuchChangeException, EmailException, OrmException, BadRequestException {
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
ResourceNotFoundException, IOException, OrmException, EmailException {
|
||||
ChangeControl control = req.getControl();
|
||||
Change change = req.getChange();
|
||||
if (!control.canAddPatchSet()) {
|
||||
@@ -108,6 +109,8 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
|
||||
return json.format(revertedChangeId);
|
||||
} catch (InvalidChangeOperationException e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
} catch (NoSuchChangeException e) {
|
||||
throw new ResourceNotFoundException(e.getMessage());
|
||||
} finally {
|
||||
git.close();
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ class Reviewed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(FileResource resource, Input input)
|
||||
public Response<String> apply(FileResource resource, Input input)
|
||||
throws OrmException {
|
||||
ReviewDb db = dbProvider.get();
|
||||
AccountPatchReview apr = getExisting(db, resource);
|
||||
@@ -66,7 +66,7 @@ class Reviewed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(FileResource resource, Input input)
|
||||
public Response<?> apply(FileResource resource, Input input)
|
||||
throws OrmException {
|
||||
ReviewDb db = dbProvider.get();
|
||||
AccountPatchReview apr = getExisting(db, resource);
|
||||
|
@@ -35,6 +35,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.ProjectUtil;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.MergeQueue;
|
||||
import com.google.gerrit.server.index.ChangeIndexer;
|
||||
@@ -332,7 +333,7 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ChangeResource rsrc, SubmitInput input)
|
||||
public ChangeInfo apply(ChangeResource rsrc, SubmitInput input)
|
||||
throws AuthException, ResourceConflictException,
|
||||
RepositoryNotFoundException, IOException, OrmException {
|
||||
PatchSet ps = dbProvider.get().patchSets()
|
||||
|
@@ -72,8 +72,8 @@ public class TestSubmitRule implements RestModifyView<RevisionResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(RevisionResource rsrc, Input input) throws OrmException,
|
||||
BadRequestException, AuthException {
|
||||
public List<Record> apply(RevisionResource rsrc, Input input)
|
||||
throws AuthException, BadRequestException, OrmException {
|
||||
if (input == null) {
|
||||
input = new Input();
|
||||
}
|
||||
|
@@ -28,7 +28,6 @@ import com.google.gerrit.server.change.TestSubmitRule.Input;
|
||||
import com.google.gerrit.server.project.RuleEvalException;
|
||||
import com.google.gerrit.server.project.SubmitRuleEvaluator;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import com.googlecode.prolog_cafe.lang.SymbolTerm;
|
||||
@@ -54,7 +53,7 @@ public class TestSubmitType implements RestModifyView<RevisionResource, Input> {
|
||||
|
||||
@Override
|
||||
public SubmitType apply(RevisionResource rsrc, Input input)
|
||||
throws OrmException, BadRequestException, AuthException {
|
||||
throws AuthException, BadRequestException {
|
||||
if (input == null) {
|
||||
input = new Input();
|
||||
}
|
||||
@@ -120,7 +119,7 @@ public class TestSubmitType implements RestModifyView<RevisionResource, Input> {
|
||||
|
||||
@Override
|
||||
public SubmitType apply(RevisionResource resource)
|
||||
throws BadRequestException, OrmException, AuthException {
|
||||
throws AuthException, BadRequestException {
|
||||
return test.apply(resource, null);
|
||||
}
|
||||
}
|
||||
|
@@ -19,9 +19,6 @@ import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.config.CapabilityDefinition;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -43,9 +40,7 @@ public class ListCapabilities implements RestReadView<ConfigResource> {
|
||||
|
||||
@Override
|
||||
public Map<String, CapabilityInfo> apply(ConfigResource resource)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
IllegalArgumentException, SecurityException, IllegalAccessException,
|
||||
NoSuchFieldException {
|
||||
throws IllegalAccessException, NoSuchFieldException {
|
||||
Map<String, CapabilityInfo> output = Maps.newTreeMap();
|
||||
collectCoreCapabilities(output);
|
||||
collectPluginCapabilities(output);
|
||||
|
@@ -31,7 +31,7 @@ class ListTopMenus implements RestReadView<ConfigResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ConfigResource resource) {
|
||||
public List<TopMenu.MenuEntry> apply(ConfigResource resource) {
|
||||
List<TopMenu.MenuEntry> entries = Lists.newArrayList();
|
||||
for (TopMenu extension : extensions) {
|
||||
entries.addAll(extension.getEntries());
|
||||
|
@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.data.GroupDescription;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
@@ -87,7 +86,7 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
|
||||
|
||||
@Override
|
||||
public List<GroupInfo> apply(GroupResource resource, Input input)
|
||||
throws MethodNotAllowedException, AuthException, BadRequestException,
|
||||
throws MethodNotAllowedException, AuthException,
|
||||
UnprocessableEntityException, OrmException {
|
||||
AccountGroup group = resource.toAccountGroup();
|
||||
if (group == null) {
|
||||
@@ -149,7 +148,7 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
|
||||
|
||||
@Override
|
||||
public GroupInfo apply(GroupResource resource, Input input)
|
||||
throws MethodNotAllowedException, AuthException, BadRequestException,
|
||||
throws AuthException, MethodNotAllowedException,
|
||||
UnprocessableEntityException, OrmException {
|
||||
AddIncludedGroups.Input in = new AddIncludedGroups.Input();
|
||||
in.groups = ImmutableList.of(id);
|
||||
@@ -173,8 +172,8 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(IncludedGroupResource resource,
|
||||
PutIncludedGroup.Input input) throws MethodNotAllowedException, OrmException {
|
||||
public GroupInfo apply(IncludedGroupResource resource,
|
||||
PutIncludedGroup.Input input) throws OrmException {
|
||||
// Do nothing, the group is already included.
|
||||
return get.get().apply(resource);
|
||||
}
|
||||
|
@@ -200,7 +200,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(GroupResource resource, PutMember.Input input)
|
||||
public AccountInfo apply(GroupResource resource, PutMember.Input input)
|
||||
throws AuthException, MethodNotAllowedException,
|
||||
UnprocessableEntityException, OrmException {
|
||||
AddMembers.Input in = new AddMembers.Input();
|
||||
@@ -225,7 +225,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(MemberResource resource, PutMember.Input input)
|
||||
public AccountInfo apply(MemberResource resource, PutMember.Input input)
|
||||
throws OrmException {
|
||||
// Do nothing, the user is already a member.
|
||||
return get.get().apply(resource);
|
||||
|
@@ -24,6 +24,7 @@ import com.google.gerrit.common.errors.PermissionDeniedException;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
@@ -79,7 +80,7 @@ class CreateGroup implements RestModifyView<TopLevelResource, Input> {
|
||||
@Override
|
||||
public GroupInfo apply(TopLevelResource resource, Input input)
|
||||
throws AuthException, BadRequestException, UnprocessableEntityException,
|
||||
NameAlreadyUsedException, OrmException {
|
||||
ResourceConflictException, OrmException {
|
||||
if (input == null) {
|
||||
input = new Input();
|
||||
}
|
||||
@@ -101,6 +102,8 @@ class CreateGroup implements RestModifyView<TopLevelResource, Input> {
|
||||
null);
|
||||
} catch (PermissionDeniedException e) {
|
||||
throw new AuthException(e.getMessage());
|
||||
} catch (NameAlreadyUsedException e) {
|
||||
throw new ResourceConflictException(e.getMessage());
|
||||
}
|
||||
return json.format(GroupDescriptions.forAccountGroup(group));
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.data.GroupDescription;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
@@ -59,8 +58,8 @@ public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(GroupResource resource, Input input)
|
||||
throws MethodNotAllowedException, AuthException, BadRequestException,
|
||||
public Response<?> apply(GroupResource resource, Input input)
|
||||
throws AuthException, MethodNotAllowedException,
|
||||
UnprocessableEntityException, OrmException {
|
||||
AccountGroup internalGroup = resource.toAccountGroup();
|
||||
if (internalGroup == null) {
|
||||
@@ -143,8 +142,8 @@ public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(IncludedGroupResource resource, Input input)
|
||||
throws MethodNotAllowedException, AuthException, BadRequestException,
|
||||
public Response<?> apply(IncludedGroupResource resource, Input input)
|
||||
throws AuthException, MethodNotAllowedException,
|
||||
UnprocessableEntityException, OrmException {
|
||||
AddIncludedGroups.Input in = new AddIncludedGroups.Input();
|
||||
in.groups = ImmutableList.of(resource.getMember().get());
|
||||
|
@@ -16,7 +16,6 @@ package com.google.gerrit.server.group;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
@@ -57,7 +56,7 @@ public class DeleteMembers implements RestModifyView<GroupResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(GroupResource resource, Input input)
|
||||
public Response<?> apply(GroupResource resource, Input input)
|
||||
throws AuthException, MethodNotAllowedException,
|
||||
UnprocessableEntityException, OrmException {
|
||||
AccountGroup internalGroup = resource.toAccountGroup();
|
||||
@@ -141,9 +140,9 @@ public class DeleteMembers implements RestModifyView<GroupResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(MemberResource resource, Input input)
|
||||
public Response<?> apply(MemberResource resource, Input input)
|
||||
throws AuthException, MethodNotAllowedException,
|
||||
UnprocessableEntityException, OrmException, NoSuchGroupException {
|
||||
UnprocessableEntityException, OrmException {
|
||||
AddMembers.Input in = new AddMembers.Input();
|
||||
in._oneMember = resource.getMember().getAccountId().toString();
|
||||
return delete.get().apply(resource, in);
|
||||
|
@@ -23,9 +23,6 @@ import com.google.gerrit.common.data.GroupDescriptions;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.common.groups.ListGroupsOption;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
@@ -132,8 +129,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(TopLevelResource resource) throws AuthException,
|
||||
BadRequestException, ResourceConflictException, Exception {
|
||||
public Object apply(TopLevelResource resource) throws OrmException {
|
||||
final Map<String, GroupInfo> output = Maps.newTreeMap();
|
||||
for (GroupInfo info : get()) {
|
||||
output.put(Objects.firstNonNull(
|
||||
|
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.server.group;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
@@ -47,8 +46,8 @@ public class PutDescription implements RestModifyView<GroupResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(GroupResource resource, Input input)
|
||||
throws MethodNotAllowedException, AuthException, NoSuchGroupException,
|
||||
public Response<String> apply(GroupResource resource, Input input)
|
||||
throws AuthException, MethodNotAllowedException,
|
||||
ResourceNotFoundException, OrmException {
|
||||
if (input == null) {
|
||||
input = new Input(); // Delete would set description to null.
|
||||
@@ -71,7 +70,7 @@ public class PutDescription implements RestModifyView<GroupResource, Input> {
|
||||
groupCache.evict(group);
|
||||
|
||||
return Strings.isNullOrEmpty(input.description)
|
||||
? Response.none()
|
||||
: input.description;
|
||||
? Response.<String>none()
|
||||
: Response.ok(input.description);
|
||||
}
|
||||
}
|
||||
|
@@ -15,12 +15,13 @@
|
||||
package com.google.gerrit.server.group;
|
||||
|
||||
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.server.group.CreateGroup.Input;
|
||||
|
||||
public class PutGroup implements RestModifyView<GroupResource, Input> {
|
||||
@Override
|
||||
public Object apply(GroupResource resource, Input input)
|
||||
public Response<?> apply(GroupResource resource, Input input)
|
||||
throws ResourceConflictException {
|
||||
throw new ResourceConflictException("Group already exists");
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.plugins.DisablePlugin.Input;
|
||||
import com.google.gerrit.server.plugins.ListPlugins.PluginInfo;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
|
||||
@@ -34,9 +35,9 @@ class DisablePlugin implements RestModifyView<PluginResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(PluginResource resource, Input input) {
|
||||
public PluginInfo apply(PluginResource resource, Input input) {
|
||||
String name = resource.getName();
|
||||
loader.disablePlugins(ImmutableSet.of(name));
|
||||
return new ListPlugins.PluginInfo(loader.get(name));
|
||||
return new PluginInfo(loader.get(name));
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.plugins.EnablePlugin.Input;
|
||||
import com.google.gerrit.server.plugins.ListPlugins.PluginInfo;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
@@ -38,7 +39,7 @@ class EnablePlugin implements RestModifyView<PluginResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(PluginResource resource, Input input)
|
||||
public PluginInfo apply(PluginResource resource, Input input)
|
||||
throws ResourceConflictException {
|
||||
String name = resource.getName();
|
||||
try {
|
||||
@@ -51,6 +52,6 @@ class EnablePlugin implements RestModifyView<PluginResource, Input> {
|
||||
pw.flush();
|
||||
throw new ResourceConflictException(buf.toString());
|
||||
}
|
||||
return new ListPlugins.PluginInfo(loader.get(name));
|
||||
return new PluginInfo(loader.get(name));
|
||||
}
|
||||
}
|
||||
|
@@ -15,10 +15,11 @@
|
||||
package com.google.gerrit.server.plugins;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.plugins.ListPlugins.PluginInfo;
|
||||
|
||||
class GetStatus implements RestReadView<PluginResource> {
|
||||
@Override
|
||||
public Object apply(PluginResource resource) {
|
||||
return new ListPlugins.PluginInfo(resource.getPlugin());
|
||||
public PluginInfo apply(PluginResource resource) {
|
||||
return new PluginInfo(resource.getPlugin());
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.server.plugins.InstallPlugin.Input;
|
||||
import com.google.gerrit.server.plugins.ListPlugins.PluginInfo;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -52,7 +53,7 @@ class InstallPlugin implements RestModifyView<TopLevelResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<ListPlugins.PluginInfo> apply(TopLevelResource resource,
|
||||
public Response<PluginInfo> apply(TopLevelResource resource,
|
||||
Input input) throws BadRequestException, IOException {
|
||||
try {
|
||||
InputStream in;
|
||||
@@ -101,7 +102,7 @@ class InstallPlugin implements RestModifyView<TopLevelResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<ListPlugins.PluginInfo> apply(PluginResource resource,
|
||||
public Response<PluginInfo> apply(PluginResource resource,
|
||||
Input input) throws BadRequestException, IOException {
|
||||
return new InstallPlugin(loader, resource.getName(), false)
|
||||
.apply(TopLevelResource.INSTANCE, input);
|
||||
|
@@ -19,9 +19,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
@@ -69,8 +66,8 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(TopLevelResource resource) throws AuthException,
|
||||
BadRequestException, ResourceConflictException, Exception {
|
||||
public Object apply(TopLevelResource resource)
|
||||
throws UnsupportedEncodingException {
|
||||
format = OutputFormat.JSON;
|
||||
return display(null);
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.plugins.ListPlugins.PluginInfo;
|
||||
import com.google.gerrit.server.plugins.ReloadPlugin.Input;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -38,7 +39,7 @@ class ReloadPlugin implements RestModifyView<PluginResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(PluginResource resource, Input input) throws ResourceConflictException {
|
||||
public PluginInfo apply(PluginResource resource, Input input) throws ResourceConflictException {
|
||||
String name = resource.getName();
|
||||
try {
|
||||
loader.reload(ImmutableList.of(name));
|
||||
@@ -52,6 +53,6 @@ class ReloadPlugin implements RestModifyView<PluginResource, Input> {
|
||||
pw.flush();
|
||||
throw new ResourceConflictException(buf.toString());
|
||||
}
|
||||
return new ListPlugins.PluginInfo(loader.get(name));
|
||||
return new PluginInfo(loader.get(name));
|
||||
}
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.group.GroupsCollection;
|
||||
import com.google.gerrit.server.project.CreateProject.Input;
|
||||
import com.google.gerrit.server.project.ProjectJson.ProjectInfo;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
@@ -82,7 +83,7 @@ public class CreateProject implements RestModifyView<TopLevelResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(TopLevelResource resource, Input input)
|
||||
public Response<ProjectInfo> apply(TopLevelResource resource, Input input)
|
||||
throws BadRequestException, UnprocessableEntityException,
|
||||
ProjectCreationFailedException, IOException {
|
||||
if (input == null) {
|
||||
|
@@ -59,7 +59,7 @@ public class DeleteBranch implements RestModifyView<BranchResource, Input>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(BranchResource rsrc, Input input) throws AuthException,
|
||||
public Response<?> apply(BranchResource rsrc, Input input) throws AuthException,
|
||||
ResourceConflictException, OrmException, IOException {
|
||||
if (!rsrc.getControl().controlForRef(rsrc.getBranchKey()).canDelete()) {
|
||||
throw new AuthException("Cannot delete branch");
|
||||
|
@@ -18,11 +18,16 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.project.DashboardsCollection.DashboardInfo;
|
||||
import com.google.gerrit.server.project.DeleteDashboard.Input;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class DeleteDashboard implements RestModifyView<DashboardResource, Input> {
|
||||
static class Input {
|
||||
String commitMessage;
|
||||
@@ -36,9 +41,9 @@ class DeleteDashboard implements RestModifyView<DashboardResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(DashboardResource resource, Input input)
|
||||
public Response<DashboardInfo> apply(DashboardResource resource, Input input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
Exception {
|
||||
ResourceNotFoundException, MethodNotAllowedException, IOException {
|
||||
if (resource.isProjectDefault()) {
|
||||
SetDashboard.Input in = new SetDashboard.Input();
|
||||
in.commitMessage = input != null ? input.commitMessage : null;
|
||||
|
@@ -20,6 +20,7 @@ import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
@@ -45,7 +46,7 @@ class GetDashboard implements RestReadView<DashboardResource> {
|
||||
|
||||
@Override
|
||||
public DashboardInfo apply(DashboardResource resource)
|
||||
throws ResourceNotFoundException, IOException, ConfigInvalidException {
|
||||
throws ResourceNotFoundException, ResourceConflictException, IOException {
|
||||
if (inherited && !resource.isProjectDefault()) {
|
||||
// inherited flag can only be used with default.
|
||||
throw new ResourceNotFoundException("inherited");
|
||||
@@ -54,7 +55,11 @@ class GetDashboard implements RestReadView<DashboardResource> {
|
||||
String project = resource.getControl().getProject().getName();
|
||||
if (resource.isProjectDefault()) {
|
||||
// The default is not resolved to a definition yet.
|
||||
try {
|
||||
resource = defaultOf(resource.getControl());
|
||||
} catch (ConfigInvalidException e) {
|
||||
throw new ResourceConflictException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return DashboardsCollection.parse(
|
||||
|
@@ -20,7 +20,7 @@ import com.google.gerrit.reviewdb.client.Project;
|
||||
|
||||
class GetDescription implements RestReadView<ProjectResource> {
|
||||
@Override
|
||||
public Object apply(ProjectResource resource) {
|
||||
public String apply(ProjectResource resource) {
|
||||
Project project = resource.getControl().getProject();
|
||||
return Strings.nullToEmpty(project.getDescription());
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ class GetParent implements RestReadView<ProjectResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ProjectResource resource) {
|
||||
public String apply(ProjectResource resource) {
|
||||
Project project = resource.getControl().getProject();
|
||||
Project.NameKey parentName = project.getParent(allProjectsName);
|
||||
return parentName != null ? parentName.get() : "";
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.project.ProjectJson.ProjectInfo;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
class GetProject implements RestReadView<ProjectResource> {
|
||||
@@ -27,7 +28,7 @@ class GetProject implements RestReadView<ProjectResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ProjectResource rsrc) {
|
||||
public ProjectInfo apply(ProjectResource rsrc) {
|
||||
return json.format(rsrc);
|
||||
}
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ProjectResource resource)
|
||||
public List<?> apply(ProjectResource resource)
|
||||
throws ResourceNotFoundException, IOException {
|
||||
ProjectControl ctl = resource.getControl();
|
||||
String project = ctl.getProject().getName();
|
||||
|
@@ -17,7 +17,6 @@ package com.google.gerrit.server.project;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
@@ -57,8 +56,8 @@ class PutDescription implements RestModifyView<ProjectResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ProjectResource resource, Input input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
public Response<String> apply(ProjectResource resource, Input input)
|
||||
throws AuthException, ResourceConflictException,
|
||||
ResourceNotFoundException, IOException {
|
||||
if (input == null) {
|
||||
input = new Input(); // Delete would set description to null.
|
||||
@@ -92,8 +91,8 @@ class PutDescription implements RestModifyView<ProjectResource, Input> {
|
||||
project.getDescription());
|
||||
|
||||
return Strings.isNullOrEmpty(project.getDescription())
|
||||
? Response.none()
|
||||
: project.getDescription();
|
||||
? Response.<String>none()
|
||||
: Response.ok(project.getDescription());
|
||||
} finally {
|
||||
md.close();
|
||||
}
|
||||
|
@@ -15,12 +15,13 @@
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
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.server.project.CreateProject.Input;
|
||||
|
||||
public class PutProject implements RestModifyView<ProjectResource, Input> {
|
||||
@Override
|
||||
public Object apply(ProjectResource resource, Input input)
|
||||
public Response<?> apply(ProjectResource resource, Input input)
|
||||
throws ResourceConflictException {
|
||||
throw new ResourceConflictException("Project \"" + resource.getName()
|
||||
+ "\" already exists");
|
||||
|
@@ -19,11 +19,14 @@ import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.project.SetDashboard.Input;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class SetDashboard implements RestModifyView<DashboardResource, Input> {
|
||||
static class Input {
|
||||
@DefaultInput
|
||||
@@ -41,7 +44,7 @@ class SetDashboard implements RestModifyView<DashboardResource, Input> {
|
||||
@Override
|
||||
public Object apply(DashboardResource resource, Input input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
Exception {
|
||||
MethodNotAllowedException, ResourceNotFoundException, IOException {
|
||||
if (resource.isProjectDefault()) {
|
||||
return defaultSetter.get().apply(resource, input);
|
||||
}
|
||||
|
@@ -36,6 +36,8 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
|
||||
private final ProjectCache cache;
|
||||
private final MetaDataUpdate.Server updateFactory;
|
||||
@@ -57,9 +59,9 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(DashboardResource resource, Input input)
|
||||
public Response<DashboardInfo> apply(DashboardResource resource, Input input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
Exception {
|
||||
ResourceNotFoundException, IOException {
|
||||
if (input == null) {
|
||||
input = new Input(); // Delete would set input to null.
|
||||
}
|
||||
@@ -79,6 +81,8 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
|
||||
IdString.fromUrl(input.id));
|
||||
} catch (ResourceNotFoundException e) {
|
||||
throw new BadRequestException("dashboard " + input.id + " not found");
|
||||
} catch (ConfigInvalidException e) {
|
||||
throw new ResourceConflictException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +113,7 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
|
||||
if (target != null) {
|
||||
DashboardInfo info = get.get().apply(target);
|
||||
info.isDefault = true;
|
||||
return info;
|
||||
return Response.ok(info);
|
||||
}
|
||||
return Response.none();
|
||||
} finally {
|
||||
@@ -136,14 +140,13 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ProjectResource resource, Input input)
|
||||
public Response<DashboardInfo> apply(ProjectResource resource, Input input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
Exception {
|
||||
ResourceNotFoundException, IOException {
|
||||
SetDefaultDashboard set = setDefault.get();
|
||||
set.inherited = inherited;
|
||||
return Response.created(set.apply(
|
||||
DashboardResource.projectDefault(resource.getControl()),
|
||||
input));
|
||||
return set.apply(
|
||||
DashboardResource.projectDefault(resource.getControl()), input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
@@ -59,8 +58,8 @@ class SetParent implements RestModifyView<ProjectResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(final ProjectResource rsrc, Input input) throws AuthException,
|
||||
BadRequestException, ResourceConflictException,
|
||||
public String apply(final ProjectResource rsrc, Input input)
|
||||
throws AuthException, ResourceConflictException,
|
||||
ResourceNotFoundException, UnprocessableEntityException, IOException {
|
||||
ProjectControl ctl = rsrc.getControl();
|
||||
IdentifiedUser user = (IdentifiedUser) ctl.getCurrentUser();
|
||||
|
@@ -142,8 +142,6 @@ public class SetReviewersCommand extends SshCommand {
|
||||
String error;
|
||||
try {
|
||||
error = post.apply(changeRsrc, input).error;
|
||||
} catch (ResourceNotFoundException e) {
|
||||
error = String.format("could not add %s: not found", reviewer);
|
||||
} catch (Exception e) {
|
||||
error = String.format("could not add %s: %s", reviewer, e.getMessage());
|
||||
}
|
||||
|
Reference in New Issue
Block a user