diff options
author | Haakon Dybdahl <dybis@users.noreply.github.com> | 2017-01-26 12:13:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-26 12:13:35 +0100 |
commit | 0b3a1b088dbe245b4b3e1cb8736ee9b6f21bdce2 (patch) | |
tree | a79afe94a44dc96a13085cd78349cb1e0d917604 /vespaclient-container-plugin | |
parent | d724f46259ac6984e51e7cb68b94adab543d4fde (diff) | |
parent | 1bcfdab09979a45a6d0facc3c98730add4826f62 (diff) |
Merge pull request #1614 from yahoo/dybdahl/tune-rest-api
Allow visiting based on group selection automatically.
Diffstat (limited to 'vespaclient-container-plugin')
2 files changed, 23 insertions, 9 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java index f6a6ed05e57..18628af3eca 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java @@ -204,14 +204,16 @@ public class RestApi extends LoggingRequestHandler { } private HttpResponse handleVisit(RestUri restUri, HttpRequest request) throws RestApiException { + String documentSelection = Optional.ofNullable(request.getProperty(SELECTION)).orElse(""); if (restUri.getGroup().isPresent() && ! restUri.getGroup().get().value.isEmpty()) { - return Response.createErrorResponse( - 400, - "Visiting does not support setting value for group/value, try using expression parameter instead.", - restUri); - + if (! documentSelection.isEmpty()) { + return Response.createErrorResponse( + 400, + "Visiting does not support setting value for group/value in combination with expression, try using only expression parameter instead.", + restUri); + } + documentSelection = "id.group='" + restUri.getGroup().get().value + "'"; } - String documentSelection = Optional.ofNullable(request.getProperty(SELECTION)).orElse(""); Optional<String> cluster = Optional.ofNullable(request.getProperty(CLUSTER)); Optional<String> continuation = Optional.ofNullable(request.getProperty(CONTINUATION)); final OperationHandler.VisitResult visit = operationHandler.visit(restUri, documentSelection, cluster, continuation); diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java index f098e00ec6d..3971b4320b5 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java @@ -271,8 +271,8 @@ public class RestApiTest { assertThat(rest, containsString(visit_response_part3)); } - String visit_test_bad_uri = "/document/v1/namespace/document-type/group/abc?continuation=abc"; - String visit_test_bad_response = "Visiting does not support setting value for group/value,"; + String visit_test_bad_uri = "/document/v1/namespace/document-type/group/abc?continuation=abc&selection=foo"; + String visit_test_bad_response = "Visiting does not support setting value for group/value in combination with expression"; @Test @@ -283,10 +283,22 @@ public class RestApiTest { assertThat(rest, containsString(visit_test_bad_response)); } + String visit_test_uri_selection_rewrite = "/document/v1/namespace/document-type/group/abc?continuation=abc"; + String visit_test_response_selection_rewrite = "doc selection: 'id.group='abc''"; + + + @Test + public void testUseExpressionOnVisit() throws Exception { + Request request = new Request("http://localhost:" + getFirstListenPort() + visit_test_uri_selection_rewrite); + HttpGet get = new HttpGet(request.getUri()); + String rest = doRest(get); + assertThat(rest, containsString(visit_test_response_selection_rewrite)); + } + private String doRest(HttpRequestBase request) throws IOException { HttpClient client = HttpClientBuilder.create().build(); HttpResponse response = client.execute(request); - assertThat(response.getEntity().getContentType().getValue().toString(), is("application/json;charset=utf-8")); + assertThat(response.getEntity().getContentType().getValue().toString(), startsWith("application/json;")); HttpEntity entity = response.getEntity(); return EntityUtils.toString(entity); } |