From d6511a1e08e26d2057bbb5206a9e6e1e6980a1cc Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Mon, 28 Oct 2024 14:42:01 +0100 Subject: [PATCH 1/3] fix(matrix): limit check counts 'all' entry as 1 passing 'all' to 'sources' or 'directions' in a request was counted as 1 instead of the amount of locations, so all-to-all matrix requests were treated as a 1x1 when checking against the 'maximum_routes' setting. Fixed by checking if sources/destinations is 'all' and then counting locations --- .../java/org/heigit/ors/api/services/MatrixService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ors-api/src/main/java/org/heigit/ors/api/services/MatrixService.java b/ors-api/src/main/java/org/heigit/ors/api/services/MatrixService.java index 3b5f6dde84..9f059d6741 100644 --- a/ors-api/src/main/java/org/heigit/ors/api/services/MatrixService.java +++ b/ors-api/src/main/java/org/heigit/ors/api/services/MatrixService.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import static org.heigit.ors.api.requests.matrix.MatrixRequest.isFlexibleMode; @@ -55,8 +56,10 @@ public org.heigit.ors.matrix.MatrixRequest convertMatrixRequest(MatrixRequest ma endpointsProperties.getMatrix().getMaximumVisitedNodes(), endpointsProperties.getMatrix().getUTurnCost()); - int numberOfSources = matrixRequest.getSources() == null ? matrixRequest.getLocations().size() : matrixRequest.getSources().length; - int numberODestinations = matrixRequest.getDestinations() == null ? matrixRequest.getLocations().size() : matrixRequest.getDestinations().length; + String[] sources = matrixRequest.getSources(); + int numberOfSources = sources == null || Objects.equals(sources[0], "all") ? matrixRequest.getLocations().size() : sources.length; + String[] destinations = matrixRequest.getDestinations(); + int numberODestinations = destinations == null || Objects.equals(destinations[0], "all") ? matrixRequest.getLocations().size() : destinations.length; Coordinate[] locations = convertLocations(matrixRequest.getLocations(), numberOfSources * numberODestinations, endpointsProperties); coreRequest.setProfileType(convertToMatrixProfileType(matrixRequest.getProfile())); From a569bc345eee19924a99a233e915cdadb421f986 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Mon, 28 Oct 2024 14:53:53 +0100 Subject: [PATCH 2/3] test(matrix): explicit all x all throws 6004 --- .../ors/apitests/matrix/ParamsTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ors-api/src/test/java/org/heigit/ors/apitests/matrix/ParamsTest.java b/ors-api/src/test/java/org/heigit/ors/apitests/matrix/ParamsTest.java index ea2ca3104d..e780cb9fcd 100644 --- a/ors-api/src/test/java/org/heigit/ors/apitests/matrix/ParamsTest.java +++ b/ors-api/src/test/java/org/heigit/ors/apitests/matrix/ParamsTest.java @@ -320,6 +320,26 @@ void expect4006004() { .statusCode(400); } + @Test + void expect4006004AllAll() { + + JSONObject body = new JSONObject(); + body.put("locations", getParameter("maximumLocations")); + body.put("sources", getParameter("sourcesAll")); + body.put("destinations", getParameter("destinationsAll")); + + given() + .headers(jsonContent) + .pathParam("profile", getParameter("carProfile")) + .body(body.toString()) + .when() + .post(getEndPointPath() + "/{profile}/json") + .then() + .assertThat() + .body("error.code", Matchers.is(MatrixErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM)) + .statusCode(400); + } + @Test void expectResolveLocations() { JSONObject body = new JSONObject(); From 57c755f87425b7d057cde94f2f8ef219556c8ca8 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Mon, 28 Oct 2024 15:13:40 +0100 Subject: [PATCH 3/3] docs: add CHANGELOG.md entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 628d6c5f97..91347d4894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ RELEASING: ### Fixed - do not enforce a time-dependent routing algorithm unless the weighting requires it ([#1865](https://github.com/GIScience/openrouteservice/pull/1865)) - failing queries that combined departure/arrival parameters with avoid polygons ([#1871](https://github.com/GIScience/openrouteservice/pull/1871)) +- matrix limit ignored for explicit 'all' value in sources or destinations([#1875](https://github.com/GIScience/openrouteservice/pull/1875)) ## [8.2.0] - 2024-10-09 ### Added