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