mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 00:09:55 +00:00
Negentwee: Skip LocationTypes that cause API to fail.
This commit is contained in:
parent
79e8470284
commit
7763182bec
1 changed files with 32 additions and 23 deletions
|
@ -38,6 +38,8 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import de.schildbach.pte.dto.Departure;
|
import de.schildbach.pte.dto.Departure;
|
||||||
import de.schildbach.pte.dto.Fare;
|
import de.schildbach.pte.dto.Fare;
|
||||||
import de.schildbach.pte.dto.Line;
|
import de.schildbach.pte.dto.Line;
|
||||||
|
@ -207,17 +209,10 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
List<QueryParameter> queryParameters = new ArrayList<>();
|
List<QueryParameter> queryParameters = new ArrayList<>();
|
||||||
queryParameters.add(new QueryParameter("q", locationName));
|
queryParameters.add(new QueryParameter("q", locationName));
|
||||||
|
|
||||||
if (!types.contains(LocationType.ANY) && types.size() > 0) {
|
// Add types if specified
|
||||||
StringBuilder typeValue = new StringBuilder();
|
String locationTypes = locationTypesToQueryParameterString(types);
|
||||||
for (LocationType type : types) {
|
if (locationTypes.length() > 0)
|
||||||
for (String addition : locationStringsFromLocationType(type)) {
|
queryParameters.add(new QueryParameter("types", locationTypes));
|
||||||
if (typeValue.length() > 0)
|
|
||||||
typeValue.append(",");
|
|
||||||
typeValue.append(addition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
queryParameters.add(new QueryParameter("type", typeValue.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpUrl url = buildApiUrl("locations", queryParameters);
|
HttpUrl url = buildApiUrl("locations", queryParameters);
|
||||||
final CharSequence page = httpClient.get(url);
|
final CharSequence page = httpClient.get(url);
|
||||||
|
@ -324,6 +319,27 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Including these type names will cause the locations API to fail, skip them
|
||||||
|
private static final ImmutableSet<String> DISALLOWED_TYPE_NAMES = ImmutableSet.of("latlong", "streetrange");
|
||||||
|
|
||||||
|
private String locationTypesToQueryParameterString(EnumSet<LocationType> types) {
|
||||||
|
StringBuilder typeValue = new StringBuilder();
|
||||||
|
if (!types.contains(LocationType.ANY) && types.size() > 0) {
|
||||||
|
for (LocationType type : types) {
|
||||||
|
for (String addition : locationStringsFromLocationType(type)) {
|
||||||
|
if (DISALLOWED_TYPE_NAMES.contains(addition))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (typeValue.length() > 0)
|
||||||
|
typeValue.append(",");
|
||||||
|
typeValue.append(addition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return typeValue.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private Date dateFromJSONObject(JSONObject obj, String key) throws JSONException {
|
private Date dateFromJSONObject(JSONObject obj, String key) throws JSONException {
|
||||||
try {
|
try {
|
||||||
return dateTimeParser.parse(obj.getString(key));
|
return dateTimeParser.parse(obj.getString(key));
|
||||||
|
@ -695,18 +711,11 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
||||||
queryParameters.add(new QueryParameter("rows",
|
queryParameters.add(new QueryParameter("rows",
|
||||||
String.valueOf(Math.min((maxLocations <= 0) ? DEFAULT_MAX_LOCATIONS : maxLocations, 100))));
|
String.valueOf(Math.min((maxLocations <= 0) ? DEFAULT_MAX_LOCATIONS : maxLocations, 100))));
|
||||||
|
|
||||||
// Add type if specified
|
// Add types if specified
|
||||||
if (!types.contains(LocationType.ANY) && types.size() > 0) {
|
String locationTypes = locationTypesToQueryParameterString(types);
|
||||||
StringBuilder typeValue = new StringBuilder();
|
if (locationTypes.length() > 0)
|
||||||
for (LocationType type : types) {
|
queryParameters.add(new QueryParameter("types", locationTypes));
|
||||||
for (String addition : locationStringsFromLocationType(type)) {
|
|
||||||
if (typeValue.length() > 0)
|
|
||||||
typeValue.append(",");
|
|
||||||
typeValue.append(addition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
queryParameters.add(new QueryParameter("type", typeValue.toString()));
|
|
||||||
}
|
|
||||||
HttpUrl url = buildApiUrl("locations", queryParameters);
|
HttpUrl url = buildApiUrl("locations", queryParameters);
|
||||||
|
|
||||||
CharSequence page;
|
CharSequence page;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue