Add new optional interface for REST collections to get request params
REST collections decide which REST endpoint is used to handle GET requests on the collection by returning the implementation of this REST endpoint from the list() method. Sometimes depending on the presence of certain URL parameters it makes sense to let different REST endpoints handle the listing. For this the REST collection needs to know which URL parameters were specified. By implementing the new NeedsParams interface the REST collection can now get to know the URL parameters. Change-Id: I78a7b7a26324c63bc7ee24e7f0928f907146981d Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -74,6 +74,7 @@ import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.ETagView;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.NeedsParams;
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
import com.google.gerrit.extensions.restapi.PreconditionFailedException;
|
||||
import com.google.gerrit.extensions.restapi.RawInput;
|
||||
@@ -245,6 +246,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
long responseBytes = -1;
|
||||
Object result = null;
|
||||
Multimap<String, String> params = LinkedHashMultimap.create();
|
||||
Multimap<String, String> config = LinkedHashMultimap.create();
|
||||
Object inputRequestBody = null;
|
||||
RestResource rsrc = TopLevelResource.INSTANCE;
|
||||
ViewData viewData = null;
|
||||
@@ -257,6 +259,8 @@ public class RestApiServlet extends HttpServlet {
|
||||
checkCors(req, res);
|
||||
checkUserSession(req);
|
||||
|
||||
ParameterParser.splitQueryString(req.getQueryString(), config, params);
|
||||
|
||||
List<IdString> path = splitPath(req);
|
||||
RestCollection<RestResource, RestResource> rc = members.get();
|
||||
CapabilityUtils.checkRequiresCapability(globals.currentUser,
|
||||
@@ -265,6 +269,10 @@ public class RestApiServlet extends HttpServlet {
|
||||
viewData = new ViewData(null, null);
|
||||
|
||||
if (path.isEmpty()) {
|
||||
if (rc instanceof NeedsParams) {
|
||||
((NeedsParams)rc).setParams(params);
|
||||
}
|
||||
|
||||
if (isRead(req)) {
|
||||
viewData = new ViewData(null, rc.list());
|
||||
} else if (rc instanceof AcceptsPost && "POST".equals(req.getMethod())) {
|
||||
@@ -357,8 +365,6 @@ public class RestApiServlet extends HttpServlet {
|
||||
return;
|
||||
}
|
||||
|
||||
Multimap<String, String> config = LinkedHashMultimap.create();
|
||||
ParameterParser.splitQueryString(req.getQueryString(), config, params);
|
||||
if (!globals.paramParser.get().parse(viewData.view, params, req, res)) {
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user