Skip to content

Commit

Permalink
AAS: The issue allows specifying several dist/time ranges in app.config
Browse files Browse the repository at this point in the history
  • Loading branch information
Rungee committed Sep 18, 2017
1 parent 5c29e5d commit 5ef294c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@
*/
package heigit.ors.services.accessibility;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.typesafe.config.ConfigObject;

import heigit.ors.common.TravelRangeType;
import heigit.ors.config.AppConfig;
import heigit.ors.routing.RoutingProfileType;

public class AccessibilityServiceSettings
{
private static int maximumLocations = 1;
private static int maximumRangeDistance = 100000; // in meters
private static Map<Integer, Integer> profileMaxRangeDistances;
private static int maximumRangeTime = 3600; // in seconds
private static Map<Integer, Integer> profileMaxRangeTimes;
private static boolean routeDetailsAllowed = false;
private static int responseLimit = 50;
private static String attribution = "";
Expand All @@ -44,9 +53,30 @@ public class AccessibilityServiceSettings
value = AppConfig.Global().getServiceParameter("accessibility", "maximum_range_distance");
if (value != null)
maximumRangeDistance = Integer.parseInt(value);
else
{
List<? extends ConfigObject> params = AppConfig.Global().getObjectList("accessibility", "maximum_range_distance");
if (params != null)
{
profileMaxRangeDistances = getParameters(params);
if (profileMaxRangeDistances.containsKey(-1))
maximumRangeDistance = profileMaxRangeDistances.get(-1);
}
}

value = AppConfig.Global().getServiceParameter("accessibility", "maximum_range_time");
if (value != null)
maximumRangeTime = Integer.parseInt(value);
else
{
List<? extends ConfigObject> params = AppConfig.Global().getObjectList("accessibility", "maximum_range_time");
if (params != null)
{
profileMaxRangeTimes = getParameters(params);
if (profileMaxRangeTimes.containsKey(-1))
maximumRangeTime = profileMaxRangeTimes.get(-1);
}
}
value = AppConfig.Global().getServiceParameter("accessibility", "route_details_allowed");
if (value != null)
routeDetailsAllowed = Boolean.parseBoolean(value);
Expand All @@ -58,6 +88,28 @@ public class AccessibilityServiceSettings
attribution = value;
}

private static Map<Integer, Integer> getParameters(List<? extends ConfigObject> params)
{
Map<Integer, Integer> result = new HashMap<Integer, Integer>();

for(ConfigObject cfgObj : params)
{
if (cfgObj.containsKey("profiles") && cfgObj.containsKey("value"))
{
String[] profiles = cfgObj.toConfig().getString("profiles").split(",");
for (String profileStr : profiles)
{
profileStr = profileStr.trim();
Integer profile = ("any".equalsIgnoreCase(profileStr)) ? -1 : RoutingProfileType.getFromString(profileStr);
if (profile != RoutingProfileType.UNKNOWN)
result.put(profile, cfgObj.toConfig().getInt("value"));
}
}
}

return result;
}

public static Boolean getEnabled() {
return enabled;
}
Expand All @@ -70,16 +122,30 @@ public static int getMaximumLocations() {
return maximumLocations;
}

public static int getMaximumRange(TravelRangeType range) {
public static int getMaximumRange(int profileType, TravelRangeType range) {
Integer res = 0;

switch(range)
{
case Distance:
return maximumRangeDistance;
res = maximumRangeDistance;

if (profileMaxRangeDistances != null && profileMaxRangeDistances.containsKey(profileType))
{
res = profileMaxRangeDistances.get(profileType);
}
break;
case Time:
return maximumRangeTime;
res = maximumRangeTime;

if (profileMaxRangeTimes != null && profileMaxRangeTimes.containsKey(profileType))
{
res = profileMaxRangeTimes.get(profileType);
}
break;
}

return 0;
return res;
}

public static boolean getRouteDetailsAllowed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
import com.vividsolutions.jts.geom.Geometry;

import heigit.ors.accessibility.AccessibilityAnalyzer;
import heigit.ors.accessibility.AccessibilityErrorCodes;
import heigit.ors.accessibility.AccessibilityRequest;
import heigit.ors.accessibility.AccessibilityResult;
import heigit.ors.common.StatusCode;
import heigit.ors.common.TravellerInfo;
import heigit.ors.exceptions.ParameterOutOfRangeException;
import heigit.ors.exceptions.StatusCodeException;
import heigit.ors.geojson.GeometryJSON;
import heigit.ors.services.accessibility.AccessibilityServiceSettings;
Expand Down Expand Up @@ -77,6 +80,20 @@ public void process(HttpServletResponse response) throws Exception

if (req == null)
throw new StatusCodeException(StatusCode.BAD_REQUEST, "AccessibilityRequest object is null.");

List<TravellerInfo> travellers = req.getTravellers();

if (travellers.size() > AccessibilityServiceSettings.getMaximumLocations())
throw new ParameterOutOfRangeException(AccessibilityErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "locations", Integer.toString(travellers.size()), Integer.toString(AccessibilityServiceSettings.getMaximumLocations()));

for (int i = 0;i < travellers.size(); ++i){
TravellerInfo traveller = travellers.get(i);
int maxAllowedRange = AccessibilityServiceSettings.getMaximumRange(traveller.getRouteSearchParameters().getProfileType(), traveller.getRangeType());
double maxRange = traveller.getMaximumRange();
if (maxRange > maxAllowedRange)
throw new ParameterOutOfRangeException(AccessibilityErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "range", Integer.toString(maxAllowedRange), Double.toString(maxRange));
}


AccessibilityResult accesibilityResult = AccessibilityAnalyzer.computeAccessibility(req);

Expand Down

0 comments on commit 5ef294c

Please sign in to comment.