diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/thingsearch/ThingSearchRoute.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/thingsearch/ThingSearchRoute.java index 505c6d4365..731e47609e 100755 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/thingsearch/ThingSearchRoute.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/endpoints/routes/thingsearch/ThingSearchRoute.java @@ -206,7 +206,8 @@ public static List calculateOptions(final List optionsString) { } return optionsString .stream() - .flatMap(s -> Arrays.stream(s.split(","))) + .flatMap(s -> Arrays.stream(s.split("\\),"))) + .map(s -> s.endsWith(")") ? s : s + ")") .toList(); } diff --git a/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/endpoints/routes/thingsearch/ThingSearchRouteTest.java b/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/endpoints/routes/thingsearch/ThingSearchRouteTest.java index e72a3bd3bb..8f822ca7f7 100755 --- a/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/endpoints/routes/thingsearch/ThingSearchRouteTest.java +++ b/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/endpoints/routes/thingsearch/ThingSearchRouteTest.java @@ -49,7 +49,7 @@ public void postSearchThingsShouldGetParametersFromBody() { final var formData = FormData.create( List.of( new Pair<>("filter", "and(like(definition,\"*test*\"))"), - new Pair<>("option", "sort(+thingId)"), + new Pair<>("option", "sort(+thingId,-attributes/type)"), new Pair<>("option","limit(0,5)"), new Pair<>("namespaces","org.eclipse.ditto,foo.bar") )); @@ -57,7 +57,20 @@ public void postSearchThingsShouldGetParametersFromBody() { .withEntity(formData.toEntity())); result.assertStatusCode(StatusCodes.OK); - result.assertEntity("{\"type\":\"thing-search.commands:queryThings\",\"filter\":\"and(and(like(definition,\\\"*test*\\\")))\",\"options\":[\"limit(0\",\"5)\",\"sort(+thingId)\"],\"namespaces\":[\"foo.bar\",\"org.eclipse.ditto\"]}"); + result.assertEntity("{\"type\":\"thing-search.commands:queryThings\",\"filter\":\"and(and(like(definition,\\\"*test*\\\")))\",\"options\":[\"limit(0,5)\",\"sort(+thingId,-attributes/type)\"],\"namespaces\":[\"foo.bar\",\"org.eclipse.ditto\"]}"); + } + @Test + public void searchThingsShouldGetParametersFromUrl() { + + final var result = underTest.run(HttpRequest.GET( + "/search/things?" + + "namespaces=org.eclipse.ditto&" + + "fields=thingId&" + + "option=sort(%2Bfeature/property,-attributes/type,%2BthingId),size(2),cursor(nextCursor)") + ); + + result.assertStatusCode(StatusCodes.OK); + result.assertEntity("{\"type\":\"thing-search.commands:queryThings\",\"options\":[\"sort(+feature/property,-attributes/type,+thingId)\",\"size(2)\",\"cursor(nextCursor)\"],\"fields\":\"/thingId\",\"namespaces\":[\"org.eclipse.ditto\"]}"); } @Test