RestApiModule: Support binding a RestView for resource creation
Instead of handling resource creation by implementing AcceptsCreate in the RestCollection, add a new RestCreateView that can be bound via RestApiModule. This improves code readability since by reading the Module class we can now directly see which REST collections support resource creation. In addition we no longer need factories to create the REST view that creates the resource. This allows us at Google to bind a different REST view for the resource creation internally while we still use the upstream REST collection for parsing and listing. Without this change we would need to subclass the upstream RestCollection and override the create method which is error-prone. This change adds REST tests for creating a resource on a root collection (com.google.gerrit.acceptance.rest.account.CreateAccountIT#createAccountRestApi) and for creating a resource on a child collection (com.google.gerrit.acceptance.rest.account.CreateBranchIT#createBranchRestApi), however it doesn't test resource creation via REST for all possible resource types. There are more things that we likely also want to replace by bindings (AcceptsPost, AcceptsDelete, listing members). This should be done by follow-up changes. Change-Id: I5cd61f77aad2a59a02333b5f68b86bda6c353879 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -17,7 +17,6 @@ package com.google.gerrit.server.restapi.project;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.AcceptsCreate;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
@@ -46,16 +45,13 @@ import org.eclipse.jgit.lib.Constants;
|
||||
|
||||
@Singleton
|
||||
public class ProjectsCollection
|
||||
implements RestCollection<TopLevelResource, ProjectResource>,
|
||||
AcceptsCreate<TopLevelResource>,
|
||||
NeedsParams {
|
||||
implements RestCollection<TopLevelResource, ProjectResource>, NeedsParams {
|
||||
private final DynamicMap<RestView<ProjectResource>> views;
|
||||
private final Provider<ListProjects> list;
|
||||
private final Provider<QueryProjects> queryProjects;
|
||||
private final ProjectCache projectCache;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final Provider<CurrentUser> user;
|
||||
private final CreateProject.Factory createProjectFactory;
|
||||
|
||||
private boolean hasQuery;
|
||||
|
||||
@@ -66,7 +62,6 @@ public class ProjectsCollection
|
||||
Provider<QueryProjects> queryProjects,
|
||||
ProjectCache projectCache,
|
||||
PermissionBackend permissionBackend,
|
||||
CreateProject.Factory factory,
|
||||
Provider<CurrentUser> user) {
|
||||
this.views = views;
|
||||
this.list = list;
|
||||
@@ -74,7 +69,6 @@ public class ProjectsCollection
|
||||
this.projectCache = projectCache;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.user = user;
|
||||
this.createProjectFactory = factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,9 +173,4 @@ public class ProjectsCollection
|
||||
public DynamicMap<RestView<ProjectResource>> views() {
|
||||
return views;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreateProject create(TopLevelResource parent, IdString name) throws RestApiException {
|
||||
return createProjectFactory.create(name.get());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user