33
33
import javax .ws .rs .Path ;
34
34
import javax .ws .rs .Produces ;
35
35
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 .*;
40
37
41
38
/**
42
39
* @author Peter Karich
@@ -50,33 +47,37 @@ public class InfoResource {
50
47
private final EncodingManager encodingManager ;
51
48
private final StorableProperties properties ;
52
49
private final boolean hasElevation ;
50
+ private final Set <String > privateEV ;
53
51
54
52
@ Inject
55
53
public InfoResource (GraphHopperConfig config , GraphHopper graphHopper , @ Named ("hasElevation" ) Boolean hasElevation ) {
56
54
this .config = config ;
57
- this .baseGraph = graphHopper .getBaseGraph ();
58
55
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 ();
59
62
this .properties = graphHopper .getProperties ();
60
63
this .hasElevation = hasElevation ;
61
64
}
62
65
63
66
public static class Info {
64
67
public static class ProfileData {
68
+ // for deserialization in e.g. tests
65
69
public ProfileData () {
66
70
}
67
71
68
- public ProfileData (String name , String vehicle ) {
72
+ public ProfileData (String name ) {
69
73
this .name = name ;
70
- this .vehicle = vehicle ;
71
74
}
72
75
73
76
public String name ;
74
- public String vehicle ;
75
77
}
76
78
77
79
public Envelope bbox ;
78
80
public final List <ProfileData > profiles = new ArrayList <>();
79
- public List <String > supported_vehicles ;
80
81
public String version = Constants .VERSION ;
81
82
public boolean elevation ;
82
83
public Map <String , List <Object >> encoded_values ;
@@ -88,27 +89,27 @@ public ProfileData(String name, String vehicle) {
88
89
public Info getInfo () {
89
90
final Info info = new Info ();
90
91
info .bbox = new Envelope (baseGraph .getBounds ().minLon , baseGraph .getBounds ().maxLon , baseGraph .getBounds ().minLat , baseGraph .getBounds ().maxLat );
92
+ Set <String > defaultHiddenEVs = new HashSet <>();
91
93
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 ());
93
95
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 ())));
94
98
}
95
99
if (config .has ("gtfs.file" ))
96
- info .profiles .add (new Info .ProfileData ("pt" , "pt" ));
100
+ info .profiles .add (new Info .ProfileData ("pt" ));
97
101
98
102
info .elevation = hasElevation ;
99
- info .supported_vehicles = encodingManager .getVehicles ();
100
- if (config .has ("gtfs.file" )) {
101
- info .supported_vehicles .add ("pt" );
102
- }
103
103
info .import_date = properties .get ("datareader.import.date" );
104
104
info .data_date = properties .get ("datareader.data.date" );
105
105
106
106
List <EncodedValue > evList = encodingManager .getEncodedValues ();
107
107
info .encoded_values = new LinkedHashMap <>();
108
108
for (EncodedValue encodedValue : evList ) {
109
109
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 ;
112
113
} else if (encodedValue instanceof EnumEncodedValue ) {
113
114
for (Enum o : ((EnumEncodedValue ) encodedValue ).getValues ()) {
114
115
possibleValueList .add (o .name ());
@@ -123,7 +124,7 @@ public Info getInfo() {
123
124
// we only add enum, boolean and numeric encoded values to the list
124
125
continue ;
125
126
}
126
- info .encoded_values .put (encodedValue . getName () , possibleValueList );
127
+ info .encoded_values .put (name , possibleValueList );
127
128
}
128
129
return info ;
129
130
}
0 commit comments