Skip to content

Commit 405a1e3

Browse files
authored
fix: decouple vehicle parameters from vehicle type (#2073)
2 parents a8f9ac2 + ee3beff commit 405a1e3

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Releasing is documented in RELEASE.md
4444
- bump deprecated CodeQL and failing Grype scan GitHub actions to their current versions ([#2061](https://github.com/GIScience/openrouteservice/pull/2061))
4545
- avoid routing on roads with access reserved to customers ([#2060](https://github.com/GIScience/openrouteservice/pull/2060))
4646
- required dynamic weights for driving-hgv with `hazmat` `false` or other default Vehicle init values ([#2071](https://github.com/GIScience/openrouteservice/pull/2071))
47+
- enable setting vehicle parameters without the need of specifying vehicle type ([#2073](https://github.com/GIScience/openrouteservice/pull/2073))
4748

4849
### Security
4950

ors-api/src/main/java/org/heigit/ors/api/services/ApiService.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,9 @@ protected ProfileParameters convertParameters(RequestOptions options, int profil
223223
}
224224

225225
if (options.getProfileParams().hasRestrictions()) {
226-
227226
RequestProfileParamsRestrictions restrictions = options.getProfileParams().getRestrictions();
228-
APIEnums.VehicleType vehicleType = options.getVehicleType();
229-
230227
validateRestrictionsForProfile(restrictions, profileType);
231-
params = convertSpecificProfileParameters(profileType, restrictions, vehicleType);
228+
params = convertSpecificProfileParameters(profileType, restrictions);
232229
}
233230

234231
if (options.getProfileParams().hasWeightings()) {
@@ -247,28 +244,26 @@ protected ProfileParameters convertParameters(RequestOptions options, int profil
247244
return params;
248245
}
249246

250-
protected ProfileParameters convertSpecificProfileParameters(int profileType, RequestProfileParamsRestrictions restrictions, APIEnums.VehicleType vehicleType) {
247+
protected ProfileParameters convertSpecificProfileParameters(int profileType, RequestProfileParamsRestrictions restrictions) {
251248
ProfileParameters params = new ProfileParameters();
252249
if (RoutingProfileType.isHeavyVehicle(profileType))
253-
params = convertHeavyVehicleParameters(restrictions, vehicleType);
250+
params = convertHeavyVehicleParameters(restrictions);
254251
if (RoutingProfileType.isWheelchair(profileType))
255252
params = convertWheelchairParamRestrictions(restrictions);
256253
return params;
257254
}
258255

259-
private VehicleParameters convertHeavyVehicleParameters(RequestProfileParamsRestrictions restrictions, APIEnums.VehicleType vehicleType) {
256+
private VehicleParameters convertHeavyVehicleParameters(RequestProfileParamsRestrictions restrictions) {
260257

261258
VehicleParameters params = new VehicleParameters();
262259

263-
if (vehicleType != null && vehicleType != APIEnums.VehicleType.UNKNOWN) {
264-
setLengthParam(restrictions, params);
265-
setWidthParam(restrictions, params);
266-
setHeightParam(restrictions, params);
267-
setWeightParam(restrictions, params);
268-
setAxleLoadParam(restrictions, params);
260+
setLengthParam(restrictions, params);
261+
setWidthParam(restrictions, params);
262+
setHeightParam(restrictions, params);
263+
setWeightParam(restrictions, params);
264+
setAxleLoadParam(restrictions, params);
269265

270-
setLoadCharacteristicsParam(restrictions, params);
271-
}
266+
setLoadCharacteristicsParam(restrictions, params);
272267

273268
return params;
274269
}

ors-api/src/test/java/org/heigit/ors/api/services/APIServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void convertParameters() throws StatusCodeException {
193193
void convertSpecificProfileParameters() {
194194
RequestProfileParamsRestrictions restrictions = new RequestProfileParamsRestrictions();
195195
restrictions.setHeight(10.0f);
196-
ProfileParameters params = apiService.convertSpecificProfileParameters(2, restrictions, APIEnums.VehicleType.HGV);
196+
ProfileParameters params = apiService.convertSpecificProfileParameters(2, restrictions);
197197
assertTrue(params instanceof VehicleParameters);
198198
assertEquals(10.0f, ((VehicleParameters) params).getHeight(), 0.0);
199199
}

ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,6 @@ void testTollwaysExtraDetails() {
12171217
params.put("restrictions", restrictions);
12181218
JSONObject options = new JSONObject();
12191219
options.put("profile_params", params);
1220-
options.put("vehicle_type", "hgv");
12211220
body.put("options", options);
12221221
body.put("continue_straight", false);
12231222

@@ -1676,7 +1675,6 @@ void testVehicleType() {
16761675
body.put("units", "m");
16771676

16781677
JSONObject options = new JSONObject();
1679-
options.put("vehicle_type", "hgv");
16801678
body.put("options", options);
16811679

16821680
// Test that buses are not allowed on Neue Schlossstraße (https://www.openstreetmap.org/way/150549948)
@@ -1718,7 +1716,6 @@ void testHGVDelivery() {
17181716
body.put("units", "m");
17191717

17201718
JSONObject options = new JSONObject();
1721-
options.put("vehicle_type", "hgv");
17221719
body.put("options", options);
17231720

17241721
given()
@@ -1763,7 +1760,6 @@ void testHGVWidthRestriction() { // check route
17631760
params.put("restrictions", restrictions);
17641761
JSONObject options = new JSONObject();
17651762
options.put("profile_params", params);
1766-
options.put("vehicle_type", "hgv");
17671763
body.put("options", options);
17681764

17691765
given()
@@ -1786,7 +1782,6 @@ void testHGVWidthRestriction() { // check route
17861782
params.put("restrictions", restrictions);
17871783
options = new JSONObject();
17881784
options.put("profile_params", params);
1789-
options.put("vehicle_type", "hgv");
17901785
body.put("options", options);
17911786

17921787
given()
@@ -1818,7 +1813,6 @@ void testHGVHeightRestriction() {
18181813
params.put("restrictions", restrictions);
18191814
JSONObject options = new JSONObject();
18201815
options.put("profile_params", params);
1821-
options.put("vehicle_type", "hgv");
18221816
body.put("options", options);
18231817

18241818
given()
@@ -1841,7 +1835,6 @@ void testHGVHeightRestriction() {
18411835
params.put("restrictions", restrictions);
18421836
options = new JSONObject();
18431837
options.put("profile_params", params);
1844-
options.put("vehicle_type", "hgv");
18451838
body.put("options", options);
18461839

18471840
given()
@@ -1873,7 +1866,6 @@ void testHGVHazmatRestriction() {
18731866
params.put("restrictions", restrictions);
18741867
JSONObject options = new JSONObject();
18751868
options.put("profile_params", params);
1876-
options.put("vehicle_type", "hgv");
18771869
body.put("options", options);
18781870

18791871
given()

0 commit comments

Comments
 (0)