Skip to content

Commit fc44291

Browse files
committed
hide the 'vehicle' EVs and vehicle names, related to graphhopper#2841
1 parent 34fc6eb commit fc44291

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 8.0 [not yet released]
22

3+
- /info endpoint does no longer return the vehicle used per profile and won't return encoded value of vehicles like car_average_speed
34
- Country rules no longer contain maxspeed handling, enable a much better alternative via `max_speed_calculator.enabled: true`. On the client side use `max_speed_estimated` to determine if max_speed is from OSM or an estimation. See #2810
45
- bike routing better avoids dangerous roads, see #2796 and #2802
56
- routing requests can be configured to timeout after some time, see #2795

web-bundle/src/main/java/com/graphhopper/resources/InfoResource.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
import javax.ws.rs.Path;
3434
import javax.ws.rs.Produces;
3535
import javax.ws.rs.core.MediaType;
36-
import java.util.ArrayList;
37-
import java.util.LinkedHashMap;
38-
import java.util.List;
39-
import java.util.Map;
36+
import java.util.*;
4037

4138
/**
4239
* @author Peter Karich
@@ -50,33 +47,37 @@ public class InfoResource {
5047
private final EncodingManager encodingManager;
5148
private final StorableProperties properties;
5249
private final boolean hasElevation;
50+
private final Set<String> privateEV;
5351

5452
@Inject
5553
public InfoResource(GraphHopperConfig config, GraphHopper graphHopper, @Named("hasElevation") Boolean hasElevation) {
5654
this.config = config;
57-
this.baseGraph = graphHopper.getBaseGraph();
5855
this.encodingManager = graphHopper.getEncodingManager();
56+
this.privateEV = new HashSet<>(Arrays.asList(config.getString("graph.encoded_values.private", "").split(",")));
57+
for (String pEV : privateEV) {
58+
if (!pEV.isEmpty() && !encodingManager.hasEncodedValue(pEV))
59+
throw new IllegalArgumentException("A private encoded value does not exist.");
60+
}
61+
this.baseGraph = graphHopper.getBaseGraph();
5962
this.properties = graphHopper.getProperties();
6063
this.hasElevation = hasElevation;
6164
}
6265

6366
public static class Info {
6467
public static class ProfileData {
68+
// for deserialization in e.g. tests
6569
public ProfileData() {
6670
}
6771

68-
public ProfileData(String name, String vehicle) {
72+
public ProfileData(String name) {
6973
this.name = name;
70-
this.vehicle = vehicle;
7174
}
7275

7376
public String name;
74-
public String vehicle;
7577
}
7678

7779
public Envelope bbox;
7880
public final List<ProfileData> profiles = new ArrayList<>();
79-
public List<String> supported_vehicles;
8081
public String version = Constants.VERSION;
8182
public boolean elevation;
8283
public Map<String, List<Object>> encoded_values;
@@ -88,27 +89,27 @@ public ProfileData(String name, String vehicle) {
8889
public Info getInfo() {
8990
final Info info = new Info();
9091
info.bbox = new Envelope(baseGraph.getBounds().minLon, baseGraph.getBounds().maxLon, baseGraph.getBounds().minLat, baseGraph.getBounds().maxLat);
92+
Set<String> defaultHiddenEVs = new HashSet<>();
9193
for (Profile p : config.getProfiles()) {
92-
Info.ProfileData profileData = new Info.ProfileData(p.getName(), p.getVehicle());
94+
Info.ProfileData profileData = new Info.ProfileData(p.getName());
9395
info.profiles.add(profileData);
96+
defaultHiddenEVs.addAll(Arrays.asList(VehiclePriority.key(p.getName()), VehicleAccess.key(p.getName()),
97+
VehicleSpeed.key(p.getName()), TurnCost.key(p.getName()), Subnetwork.key(p.getName())));
9498
}
9599
if (config.has("gtfs.file"))
96-
info.profiles.add(new Info.ProfileData("pt", "pt"));
100+
info.profiles.add(new Info.ProfileData("pt"));
97101

98102
info.elevation = hasElevation;
99-
info.supported_vehicles = encodingManager.getVehicles();
100-
if (config.has("gtfs.file")) {
101-
info.supported_vehicles.add("pt");
102-
}
103103
info.import_date = properties.get("datareader.import.date");
104104
info.data_date = properties.get("datareader.data.date");
105105

106106
List<EncodedValue> evList = encodingManager.getEncodedValues();
107107
info.encoded_values = new LinkedHashMap<>();
108108
for (EncodedValue encodedValue : evList) {
109109
List<Object> possibleValueList = new ArrayList<>();
110-
if (encodedValue.getName().contains("turn_costs")) {
111-
// skip
110+
String name = encodedValue.getName();
111+
if (privateEV.contains(name) || defaultHiddenEVs.contains(name)) {
112+
continue;
112113
} else if (encodedValue instanceof EnumEncodedValue) {
113114
for (Enum o : ((EnumEncodedValue) encodedValue).getValues()) {
114115
possibleValueList.add(o.name());
@@ -123,7 +124,7 @@ public Info getInfo() {
123124
// we only add enum, boolean and numeric encoded values to the list
124125
continue;
125126
}
126-
info.encoded_values.put(encodedValue.getName(), possibleValueList);
127+
info.encoded_values.put(name, possibleValueList);
127128
}
128129
return info;
129130
}

web/src/test/java/com/graphhopper/application/resources/PtRouteResourceTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ public void testInfo() {
179179
.request().buildGet().invoke();
180180
assertEquals(200, response.getStatus());
181181
InfoResource.Info info = response.readEntity(InfoResource.Info.class);
182-
assertTrue(info.supported_vehicles.contains("pt"));
183182
assertTrue(info.profiles.stream().anyMatch(p -> p.name.equals("pt")));
184183
}
185184

0 commit comments

Comments
 (0)