Skip to content

Commit

Permalink
[bugfix] v2 isochrone requests now respect max_locations from app.con…
Browse files Browse the repository at this point in the history
…fig, #482
  • Loading branch information
nilsnolde authored and Timothy Ellersiek committed May 23, 2019
1 parent 0ed6c71 commit 2d088ec
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Makes docker and docker-compose deployment of openrouteservice more customizable (Issue #434)
- Add the possibility to predefine standard maximum search radii in general and for each used profile in the config file (Issue #418)
### Fixed
- v2 isochrones now respects max_locations in app.config (#482)
- Updated documentation to reflect correct isochrone smoothing algorithm (Issue #471)
- Enable > 2 waypoints when geometry_simplify=true (#457)
- Made it so that the wheelchair profile only goes over bridleways if they are set to be foot or wheelchair accessible (#415)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,21 @@ public ParamsTest() {
secondLocation.put(8.684177);
secondLocation.put(49.421034);

//JSONArray thirdLocation = new JSONArray();
//thirdLocation.put(8.684177);
//thirdLocation.put(49.421034);
JSONArray thirdLocation = new JSONArray();
thirdLocation.put(8.684177);
thirdLocation.put(49.421034);

JSONArray locations_1 = new JSONArray();
locations_1.put(firstLocation);

JSONArray locations_2 = new JSONArray();
locations_2.put(firstLocation);
locations_2.put(secondLocation);
//locations.put(thirdLocation);

JSONArray locations_3 = new JSONArray();
locations_3.put(firstLocation);
locations_3.put(secondLocation);
locations_3.put(thirdLocation);

JSONArray ranges_2 = new JSONArray();
ranges_2.put(1800);
Expand All @@ -84,6 +88,7 @@ public ParamsTest() {

addParameter("locations_1", locations_1);
addParameter("locations_2", locations_2);
addParameter("locations_3", locations_3);
addParameter("ranges_2", ranges_2);
addParameter("ranges_1800", ranges_1800);
addParameter("interval_100", interval_100);
Expand Down Expand Up @@ -227,7 +232,7 @@ public void testTooManyIntervals() {
public void testTooManyLocations() {

JSONObject body = new JSONObject();
body.put("locations", getParameter("locations_2"));
body.put("locations", getParameter("locations_3"));
body.put("range", getParameter("ranges_1800"));
body.put("range_type", "time");
body.put("interval", getParameter("interval_100"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public ResponseEntity<Object> handleReadingBodyException(final Exception e) {
return errorHandler.handleStatusCodeException(new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_VALUE, ((InvalidDefinitionException) cause).getPath().get(0).getFieldName()));
} else if (cause instanceof MismatchedInputException) {
return errorHandler.handleStatusCodeException(new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_FORMAT, ((MismatchedInputException) cause).getPath().get(0).getFieldName()));
} else if (cause instanceof InvalidDefinitionException) {
return errorHandler.handleStatusCodeException((new ParameterOutOfRangeException(IsochronesErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, ((InvalidDefinitionException) cause).getPath().get(0).getFieldName())));
} else {
// Check if we are missing the body as a whole
if (e.getLocalizedMessage().startsWith("Required request body is missing")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,6 @@ public class IsochronesRequest {
public IsochronesRequest() {
}

@JsonCreator
public IsochronesRequest(@JsonProperty(value = "locations", required = true) Double[][] locations) throws ParameterValueException {
int maximumLocations = IsochronesServiceSettings.getMaximumLocations();
if (locations.length > maximumLocations)
throw new ParameterValueException(IsochronesErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "locations");
if (locations.length < 1)
throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_FORMAT, "locations");
for (Double[] location : locations) {
if (location.length != 2)
throw new ParameterValueException(IsochronesErrorCodes.INVALID_PARAMETER_FORMAT, "locations");
}
this.locations = locations;
}


public String getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,8 @@ Coordinate convertSingleCoordinate(Double[] coordinate) throws ParameterValueExc
IsochroneRequest convertIsochroneRequest(IsochronesRequest request) throws Exception {
IsochroneRequest convertedIsochroneRequest = new IsochroneRequest();
Double[][] locations = request.getLocations();
for (int i = 0; i < request.getLocations().length; i++) {
if (locations.length > 2)
throw new ParameterValueException(IsochronesErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, IsochronesRequest.PARAM_LOCATIONS, Arrays.toString(locations), IsochronesRequest.PARAM_LOCATIONS + " is limited to 2");

for (int i = 0; i < request.getLocations().length; i++) {
Double[] location = locations[i];
TravellerInfo travellerInfo = constructTravellerInfo(location, request);
travellerInfo.setId(Integer.toString(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class ParameterOutOfRangeException extends StatusCodeException
{
private static final long serialVersionUID = 7728944138955234463L;

public ParameterOutOfRangeException(int errorCode, String paramName)
{
super(StatusCode.BAD_REQUEST, errorCode, "Parameter '" + paramName + "' is out of range.");
}

public ParameterOutOfRangeException(int errorCode, String paramName, String value, String maxRangeValue)
{
super(StatusCode.BAD_REQUEST, errorCode, "Parameter '" + paramName + "="+ value +"' is out of range. Maximum possible value is " + maxRangeValue + ".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import heigit.ors.common.DistanceUnit;
import heigit.ors.common.TravelRangeType;
import heigit.ors.common.TravellerInfo;
import heigit.ors.exceptions.ParameterOutOfRangeException;
import heigit.ors.exceptions.ParameterValueException;
import heigit.ors.isochrones.IsochroneRequest;
import heigit.ors.routing.*;
Expand Down Expand Up @@ -61,7 +62,8 @@ public void init() throws Exception {
coords[0] = new Double[]{24.5, 39.2};
coords[1] = new Double[]{27.4, 38.6};

request = new IsochronesRequest(coords);
request = new IsochronesRequest();
request.setLocations(coords);

request.setProfile(APIEnums.Profile.DRIVING_CAR);
request.setAttributes(new IsochronesRequestEnums.Attributes[]{IsochronesRequestEnums.Attributes.AREA, IsochronesRequestEnums.Attributes.REACH_FACTOR});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,24 +240,6 @@ public void setIntervalTest() {
Assert.assertEquals(new Double("0.0"), request.getInterval());
}

@Test(expected = ParameterValueException.class)
public void tooSmallLocationTest() throws ParameterValueException {
Double[][] double_array = {{1.0}, {1.0, 3.0}};
new IsochronesRequest(double_array);
}

@Test(expected = ParameterValueException.class)
public void exceedingLocationMaximumTest() throws ParameterValueException {
Double[][] exceedingLocationsMaximumCoords = fakeArrayLocations(IsochronesServiceSettings.getMaximumLocations() + 1, 2);
new IsochronesRequest(exceedingLocationsMaximumCoords);
}

@Test(expected = ParameterValueException.class)
public void tooLargeLocationTest() throws ParameterValueException {
Double[][] exceedingLocationsMaximumCoords = {{1.0, 3.0, 4.0}, {1.0, 3.0}};
new IsochronesRequest(exceedingLocationsMaximumCoords);
}

@Test
public void detailedOptionsTest() {
IsochronesRequest request = new IsochronesRequest();
Expand Down

0 comments on commit 2d088ec

Please sign in to comment.