EFA: Fix parsing of itdOdv and handling of location IDs.

This commit is contained in:
Andreas Schildbach 2015-01-12 12:47:46 +01:00
parent 64df076576
commit bb03f45f53
14 changed files with 406 additions and 436 deletions

View file

@ -33,6 +33,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -87,7 +88,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
private String additionalQueryParameter = null;
private boolean useRealtime = true;
private boolean canAcceptPoiId = false;
private boolean needsSpEncId = false;
private boolean includeRegionId = true;
private boolean useProxFootSearch = true;
@ -216,11 +216,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
this.useStringCoordListOutputFormat = useStringCoordListOutputFormat;
}
protected void setCanAcceptPoiId(final boolean canAcceptPoiId)
{
this.canAcceptPoiId = canAcceptPoiId;
}
protected void setNeedsSpEncId(final boolean needsSpEncId)
{
this.needsSpEncId = needsSpEncId;
@ -240,6 +235,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
private final void appendCommonRequestParams(final StringBuilder uri, final String outputFormat)
{
uri.append("?outputFormat=").append(outputFormat);
uri.append("&stateless=1");
uri.append("&coordOutputFormat=WGS84");
if (additionalQueryParameter != null)
uri.append('&').append(additionalQueryParameter);
@ -306,8 +302,10 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
String type = stop.getString("type");
if ("any".equals(type))
type = stop.getString("anyType");
final String id = stop.getString("stateless");
final String name = normalizeLocationName(stop.optString("name"));
final String object = normalizeLocationName(stop.optString("object"));
final String postcode = stop.optString("postcode");
final int quality = stop.getInt("quality");
final JSONObject ref = stop.getJSONObject("ref");
String place = ref.getString("place");
@ -330,13 +328,15 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
final Location location;
if ("stop".equals(type))
location = new Location(LocationType.STATION, stop.getString("stateless"), lat, lon, place, object);
location = new Location(LocationType.STATION, id, lat, lon, place, object);
else if ("poi".equals(type))
location = new Location(LocationType.POI, null, lat, lon, place, object);
location = new Location(LocationType.POI, id, lat, lon, place, object);
else if ("crossing".equals(type))
location = new Location(LocationType.ADDRESS, null, lat, lon, place, object);
location = new Location(LocationType.ADDRESS, id, lat, lon, place, object);
else if ("street".equals(type) || "address".equals(type) || "singlehouse".equals(type) || "buildingname".equals(type))
location = new Location(LocationType.ADDRESS, null, lat, lon, place, name);
location = new Location(LocationType.ADDRESS, id, lat, lon, place, name);
else if ("postcode".equals(type))
location = new Location(LocationType.ADDRESS, id, lat, lon, place, postcode);
else
throw new JSONException("unknown type: " + type);
@ -392,42 +392,13 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
XmlPullUtil.enter(pp, "itdStopFinderRequest");
XmlPullUtil.require(pp, "itdOdv");
if (!"sf".equals(pp.getAttributeValue(null, "usage")))
throw new IllegalStateException("cannot find <itdOdv usage=\"sf\" />");
XmlPullUtil.enter(pp, "itdOdv");
XmlPullUtil.require(pp, "itdOdvPlace");
XmlPullUtil.next(pp);
XmlPullUtil.require(pp, "itdOdvName");
final String nameState = pp.getAttributeValue(null, "state");
XmlPullUtil.enter(pp, "itdOdvName");
if (XmlPullUtil.test(pp, "itdMessage"))
XmlPullUtil.next(pp);
if ("identified".equals(nameState) || "list".equals(nameState))
processItdOdv(pp, "sf", new ProcessItdOdvCallback()
{
while (XmlPullUtil.test(pp, "odvNameElem"))
public void location(final String nameState, final Location location, final int matchQuality)
{
final int matchQuality = XmlPullUtil.intAttr(pp, "matchQuality");
final Location location = processOdvNameElem(pp, null);
locations.add(new SuggestedLocation(location, matchQuality));
}
}
else if ("notidentified".equals(nameState))
{
// do nothing
}
else
{
throw new RuntimeException("unknown nameState '" + nameState + "' on " + uri);
}
XmlPullUtil.skipExit(pp, "itdOdvName");
XmlPullUtil.skipExit(pp, "itdOdv");
});
XmlPullUtil.skipExit(pp, "itdStopFinderRequest");
@ -705,6 +676,93 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
return jsonStopfinderRequest(new Location(LocationType.ANY, null, null, constraint.toString()));
}
private interface ProcessItdOdvCallback
{
void location(String nameState, Location location, int matchQuality);
}
private String processItdOdv(final XmlPullParser pp, final String expectedUsage, final ProcessItdOdvCallback callback)
throws XmlPullParserException, IOException
{
if (!XmlPullUtil.test(pp, "itdOdv"))
throw new IllegalStateException("expecting <itdOdv />");
final String usage = XmlPullUtil.attr(pp, "usage");
if (expectedUsage != null && !usage.equals(expectedUsage))
throw new IllegalStateException("expecting <itdOdv usage=\"" + expectedUsage + "\" />");
final String type = XmlPullUtil.attr(pp, "type");
XmlPullUtil.enter(pp, "itdOdv");
final String place = processItdOdvPlace(pp);
XmlPullUtil.require(pp, "itdOdvName");
final String nameState = XmlPullUtil.attr(pp, "state");
XmlPullUtil.enter(pp, "itdOdvName");
XmlPullUtil.optSkip(pp, "itdMessage");
if ("identified".equals(nameState))
{
final Location location = processOdvNameElem(pp, type, place);
if (location != null)
callback.location(nameState, location, Integer.MAX_VALUE);
}
else if ("list".equals(nameState))
{
while (XmlPullUtil.test(pp, "odvNameElem"))
{
final int matchQuality = XmlPullUtil.intAttr(pp, "matchQuality");
final Location location = processOdvNameElem(pp, type, place);
if (location != null)
callback.location(nameState, location, matchQuality);
}
}
else if ("notidentified".equals(nameState) || "empty".equals(nameState))
{
XmlPullUtil.optSkip(pp, "odvNameElem");
}
else
{
throw new RuntimeException("cannot handle nameState '" + nameState + "'");
}
while (XmlPullUtil.test(pp, "infoLink"))
XmlPullUtil.requireSkip(pp, "infoLink");
XmlPullUtil.optSkip(pp, "odvNameInput");
XmlPullUtil.exit(pp, "itdOdvName");
XmlPullUtil.optSkip(pp, "odvInfoList");
XmlPullUtil.optSkip(pp, "itdPoiHierarchyRoot");
if (XmlPullUtil.test(pp, "itdOdvAssignedStops"))
{
XmlPullUtil.enter(pp, "itdOdvAssignedStops");
while (XmlPullUtil.test(pp, "itdOdvAssignedStop"))
{
final Location stop = processItdOdvAssignedStop(pp);
if (stop != null)
callback.location("assigned", stop, 0);
}
XmlPullUtil.exit(pp, "itdOdvAssignedStops");
}
XmlPullUtil.optSkip(pp, "itdServingModes");
XmlPullUtil.optSkip(pp, "genAttrList");
XmlPullUtil.exit(pp, "itdOdv");
return nameState;
}
private String processItdOdvPlace(final XmlPullParser pp) throws XmlPullParserException, IOException
{
if (!XmlPullUtil.test(pp, "itdOdvPlace"))
@ -724,25 +782,24 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
return place;
}
private Location processOdvNameElem(final XmlPullParser pp, final String defaultPlace) throws XmlPullParserException, IOException
private Location processOdvNameElem(final XmlPullParser pp, String type, final String defaultPlace) throws XmlPullParserException, IOException
{
if (!XmlPullUtil.test(pp, "odvNameElem"))
throw new IllegalStateException("expecting <odvNameElem />");
final String anyType = pp.getAttributeValue(null, "anyType");
final String idStr = pp.getAttributeValue(null, "id");
final String stopIdStr = pp.getAttributeValue(null, "stopID");
final String poiIdStr = pp.getAttributeValue(null, "poiID");
final String streetIdStr = pp.getAttributeValue(null, "streetID");
if ("any".equals(type))
type = XmlPullUtil.attr(pp, "anyType");
final String id = XmlPullUtil.attr(pp, "stateless");
final String locality = normalizeLocationName(pp.getAttributeValue(null, "locality"));
final String objectName = normalizeLocationName(pp.getAttributeValue(null, "objectName"));
final String buildingName = XmlPullUtil.optAttr(pp, "buildingName", null);
final String buildingNumber = XmlPullUtil.optAttr(pp, "buildingNumber", null);
final String postCode = XmlPullUtil.optAttr(pp, "postCode", null);
final String mapName = XmlPullUtil.optAttr(pp, "mapName", null);
final float x = XmlPullUtil.optFloatAttr(pp, "x", 0);
final float y = XmlPullUtil.optFloatAttr(pp, "y", 0);
final String elemName = normalizeLocationName(XmlPullUtil.valueTag(pp, "odvNameElem"));
final int lat;
final int lon;
@ -761,83 +818,64 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
throw new IllegalStateException("unknown mapName=" + mapName + " x=" + x + " y=" + y);
}
final LocationType type;
final String id;
final String nameElem = normalizeLocationName(XmlPullUtil.valueTag(pp, "odvNameElem"));
final LocationType locationType;
final String place;
final String name;
if ("stop".equals(anyType))
if ("stop".equals(type))
{
type = LocationType.STATION;
id = idStr;
locationType = LocationType.STATION;
place = locality;
name = objectName;
}
else if ("poi".equals(anyType) || "poiHierarchy".equals(anyType))
else if ("poi".equals(type))
{
type = LocationType.POI;
id = idStr;
locationType = LocationType.POI;
place = locality;
name = objectName;
}
else if ("loc".equals(anyType))
else if ("loc".equals(type))
{
type = LocationType.ANY;
id = null;
place = locality;
name = locality;
return null;
}
else if ("address".equals(anyType))
else if ("address".equals(type) || "singlehouse".equals(type))
{
type = LocationType.ADDRESS;
id = null;
locationType = LocationType.ADDRESS;
place = locality;
name = objectName + (buildingNumber != null ? " " + buildingNumber : "");
}
else if ("street".equals(type) || "crossing".equals(type))
{
locationType = LocationType.ADDRESS;
place = locality;
name = objectName;
}
else if ("postcode".equals(anyType) || "street".equals(anyType) || "crossing".equals(anyType) || "singlehouse".equals(anyType)
|| "buildingname".equals(anyType))
else if ("postcode".equals(type))
{
type = LocationType.ADDRESS;
id = null;
locationType = LocationType.ADDRESS;
place = locality;
name = objectName;
name = postCode;
}
else if (anyType == null || "unknown".equals(anyType))
else if ("buildingname".equals(type))
{
if (stopIdStr != null)
{
type = LocationType.STATION;
id = stopIdStr;
locationType = LocationType.ADDRESS;
place = locality;
name = buildingName;
}
else if (poiIdStr != null)
else if ("coord".equals(type))
{
type = LocationType.POI;
id = poiIdStr;
}
else if (streetIdStr != null)
{
type = LocationType.ADDRESS;
id = streetIdStr;
}
else if (lat != 0 || lon != 0)
{
type = LocationType.ADDRESS;
id = null;
locationType = LocationType.ADDRESS;
place = defaultPlace;
name = nameElem;
}
else
{
throw new IllegalArgumentException("cannot substitute type");
throw new IllegalArgumentException("unknown type/anyType: " + type);
}
place = locality;
name = objectName;
}
else
{
throw new IllegalArgumentException("unknown type: " + anyType);
}
return new Location(type, id, lat, lon, place != null ? place : defaultPlace, name != null ? name : elemName);
return new Location(locationType, id, lat, lon, place != null ? place : defaultPlace, name != null ? name : nameElem);
}
private Location processItdOdvAssignedStop(final XmlPullParser pp) throws XmlPullParserException, IOException
@ -923,72 +961,34 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
XmlPullUtil.enter(pp, "itdDepartureMonitorRequest");
if (!XmlPullUtil.test(pp, "itdOdv") || !"dm".equals(pp.getAttributeValue(null, "usage")))
throw new IllegalStateException("cannot find <itdOdv usage=\"dm\" />");
XmlPullUtil.enter(pp, "itdOdv");
final String place = processItdOdvPlace(pp);
XmlPullUtil.require(pp, "itdOdvName");
final String nameState = pp.getAttributeValue(null, "state");
XmlPullUtil.enter(pp, "itdOdvName");
if ("identified".equals(nameState))
{
final Location ownLocation = processOdvNameElem(pp, place);
final Location ownStation = ownLocation.type == LocationType.STATION ? ownLocation : null;
XmlPullUtil.skipExit(pp, "itdOdvName");
final AtomicReference<Location> ownStation = new AtomicReference<Location>();
final List<Location> stations = new ArrayList<Location>();
if (XmlPullUtil.test(pp, "itdOdvAssignedStops"))
final String nameState = processItdOdv(pp, "dm", new ProcessItdOdvCallback()
{
XmlPullUtil.enter(pp, "itdOdvAssignedStops");
while (XmlPullUtil.test(pp, "itdOdvAssignedStop"))
public void location(final String nameState, final Location location, final int matchQuality)
{
final Location newStation = processItdOdvAssignedStop(pp);
if (newStation != null && !stations.contains(newStation))
stations.add(newStation);
if (location.type == LocationType.STATION)
{
if ("identified".equals(nameState))
ownStation.set(location);
else if ("assigned".equals(nameState))
stations.add(location);
}
XmlPullUtil.skipExit(pp, "itdOdvAssignedStops");
}
});
XmlPullUtil.skipExit(pp, "itdOdv");
if ("notidentified".equals(nameState))
return new NearbyStationsResult(header, NearbyStationsResult.Status.INVALID_STATION);
if (ownStation != null && !stations.contains(ownStation))
stations.add(ownStation);
if (ownStation.get() != null && !stations.contains(ownStation))
stations.add(ownStation.get());
if (maxStations == 0 || maxStations >= stations.size())
return new NearbyStationsResult(header, stations);
else
return new NearbyStationsResult(header, stations.subList(0, maxStations));
}
else if ("list".equals(nameState))
{
final List<Location> stations = new ArrayList<Location>();
if (XmlPullUtil.test(pp, "itdMessage"))
XmlPullUtil.next(pp);
while (XmlPullUtil.test(pp, "odvNameElem"))
{
final Location newLocation = processOdvNameElem(pp, place);
if (newLocation.type == LocationType.STATION && !stations.contains(newLocation))
stations.add(newLocation);
}
return new NearbyStationsResult(header, stations);
}
else if ("notidentified".equals(nameState))
{
return new NearbyStationsResult(header, NearbyStationsResult.Status.INVALID_STATION);
}
else
{
throw new RuntimeException("unknown nameState '" + nameState + "' on " + uri);
}
// XmlPullUtil.exit(pp, "itdOdvName");
}
catch (final XmlPullParserException x)
{
throw new ParserException("cannot parse xml: " + firstChars, x);
@ -1507,59 +1507,35 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
pp.setInput(is, null);
final ResultHeader header = enterItdRequest(pp);
XmlPullUtil.enter(pp, "itdDepartureMonitorRequest");
if (XmlPullUtil.test(pp, "itdMessage"))
XmlPullUtil.next(pp);
if (!XmlPullUtil.test(pp, "itdOdv") || !"dm".equals(XmlPullUtil.attr(pp, "usage")))
throw new IllegalStateException("cannot find <itdOdv usage=\"dm\" />, first chars: " + firstChars);
XmlPullUtil.enter(pp, "itdOdv");
final String place = processItdOdvPlace(pp);
XmlPullUtil.require(pp, "itdOdvName");
final String nameState = pp.getAttributeValue(null, "state");
XmlPullUtil.enter(pp, "itdOdvName");
if ("identified".equals(nameState))
{
final QueryDeparturesResult result = new QueryDeparturesResult(header);
final Location location = processOdvNameElem(pp, place);
result.stationDepartures.add(new StationDepartures(location, new LinkedList<Departure>(), new LinkedList<LineDestination>()));
XmlPullUtil.enter(pp, "itdDepartureMonitorRequest");
XmlPullUtil.skipExit(pp, "itdOdvName");
XmlPullUtil.optSkip(pp, "itdMessage");
if (XmlPullUtil.test(pp, "itdOdvAssignedStops"))
final String nameState = processItdOdv(pp, "dm", new ProcessItdOdvCallback()
{
XmlPullUtil.enter(pp, "itdOdvAssignedStops");
while (XmlPullUtil.test(pp, "itdOdvAssignedStop"))
public void location(final String nameState, final Location location, final int matchQuality)
{
final Location assignedLocation = processItdOdvAssignedStop(pp);
if (assignedLocation != null)
if (findStationDepartures(result.stationDepartures, assignedLocation.id) == null)
result.stationDepartures.add(new StationDepartures(assignedLocation, new LinkedList<Departure>(),
if (location.type == LocationType.STATION)
if (findStationDepartures(result.stationDepartures, location.id) == null)
result.stationDepartures.add(new StationDepartures(location, new LinkedList<Departure>(),
new LinkedList<LineDestination>()));
}
XmlPullUtil.skipExit(pp, "itdOdvAssignedStops");
}
});
XmlPullUtil.skipExit(pp, "itdOdv");
if ("notidentified".equals(nameState) || "list".equals(nameState))
return new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION);
if (XmlPullUtil.test(pp, "itdDateTime"))
XmlPullUtil.next(pp);
XmlPullUtil.optSkip(pp, "itdDateTime");
if (XmlPullUtil.test(pp, "itdDMDateTime"))
XmlPullUtil.next(pp);
XmlPullUtil.optSkip(pp, "itdDMDateTime");
if (XmlPullUtil.test(pp, "itdDateRange"))
XmlPullUtil.next(pp);
XmlPullUtil.optSkip(pp, "itdDateRange");
if (XmlPullUtil.test(pp, "itdTripOptions"))
XmlPullUtil.next(pp);
XmlPullUtil.optSkip(pp, "itdTripOptions");
if (XmlPullUtil.test(pp, "itdMessage"))
XmlPullUtil.next(pp);
XmlPullUtil.optSkip(pp, "itdMessage");
final Calendar plannedDepartureTime = new GregorianCalendar(timeZone);
final Calendar predictedDepartureTime = new GregorianCalendar(timeZone);
@ -1573,8 +1549,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
final String assignedStopId = pp.getAttributeValue(null, "assignedStopID");
final String destinationName = normalizeLocationName(pp.getAttributeValue(null, "direction"));
final String destinationId = XmlPullUtil.optAttr(pp, "destID", null);
final Location destination = new Location(destinationId != null ? LocationType.STATION : LocationType.ANY, destinationId,
null, destinationName);
final Location destination = new Location(destinationId != null ? LocationType.STATION : LocationType.ANY, destinationId, null,
destinationName);
final LineDestination line = new LineDestination(processItdServingLine(pp), destination);
StationDepartures assignedStationDepartures;
@ -1655,8 +1631,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
final String destinationName = normalizeLocationName(pp.getAttributeValue(null, "direction"));
final String destinationIdStr = XmlPullUtil.optAttr(pp, "destID", null);
final String destinationId = !"-1".equals(destinationIdStr) ? destinationIdStr : null;
final Location destination = new Location(destinationId != null ? LocationType.STATION : LocationType.ANY, destinationId,
null, destinationName);
final Location destination = new Location(destinationId != null ? LocationType.STATION : LocationType.ANY, destinationId, null,
destinationName);
final Line line = processItdServingLine(pp);
if (isRealtime && !predictedDepartureTime.isSet(Calendar.HOUR_OF_DAY))
@ -1679,15 +1655,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
return result;
}
else if ("notidentified".equals(nameState) || "list".equals(nameState))
{
return new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION);
}
else
{
throw new RuntimeException("unknown nameState '" + nameState + "' on " + uri);
}
}
catch (final XmlPullParserException x)
{
throw new ParserException("cannot parse xml: " + firstChars, x);
@ -2337,60 +2304,41 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
if (XmlPullUtil.test(pp, "itdAddress"))
XmlPullUtil.next(pp);
// parse odv name elements
List<Location> ambiguousFrom = null, ambiguousTo = null, ambiguousVia = null;
Location from = null, via = null, to = null;
while (XmlPullUtil.test(pp, "itdOdv"))
{
final String usage = XmlPullUtil.attr(pp, "usage");
XmlPullUtil.enter(pp, "itdOdv");
final String usage = pp.getAttributeValue(null, "usage");
final String place = processItdOdvPlace(pp);
if (!XmlPullUtil.test(pp, "itdOdvName"))
throw new IllegalStateException("cannot find <itdOdvName /> inside " + usage);
final String nameState = XmlPullUtil.attr(pp, "state");
XmlPullUtil.enter(pp, "itdOdvName");
if (XmlPullUtil.test(pp, "itdMessage"))
XmlPullUtil.next(pp);
final List<Location> locations = new ArrayList<Location>();
final String nameState = processItdOdv(pp, usage, new ProcessItdOdvCallback()
{
public void location(final String nameState, final Location location, final int matchQuality)
{
locations.add(location);
}
});
if ("list".equals(nameState))
{
if ("origin".equals(usage))
{
ambiguousFrom = new ArrayList<Location>();
while (XmlPullUtil.test(pp, "odvNameElem"))
ambiguousFrom.add(processOdvNameElem(pp, place));
}
ambiguousFrom = locations;
else if ("via".equals(usage))
{
ambiguousVia = new ArrayList<Location>();
while (XmlPullUtil.test(pp, "odvNameElem"))
ambiguousVia.add(processOdvNameElem(pp, place));
}
ambiguousVia = locations;
else if ("destination".equals(usage))
{
ambiguousTo = new ArrayList<Location>();
while (XmlPullUtil.test(pp, "odvNameElem"))
ambiguousTo.add(processOdvNameElem(pp, place));
}
ambiguousTo = locations;
else
{
throw new IllegalStateException("unknown usage: " + usage);
}
}
else if ("identified".equals(nameState))
{
if (!XmlPullUtil.test(pp, "odvNameElem"))
throw new IllegalStateException("cannot find <odvNameElem /> inside " + usage);
if ("origin".equals(usage))
from = processOdvNameElem(pp, place);
from = locations.get(0);
else if ("via".equals(usage))
via = processOdvNameElem(pp, place);
via = locations.get(0);
else if ("destination".equals(usage))
to = processOdvNameElem(pp, place);
to = locations.get(0);
else
throw new IllegalStateException("unknown usage: " + usage);
}
@ -2405,8 +2353,6 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
else
throw new IllegalStateException("unknown usage: " + usage);
}
XmlPullUtil.skipExit(pp, "itdOdvName");
XmlPullUtil.skipExit(pp, "itdOdv");
}
if (ambiguousFrom != null || ambiguousTo != null || ambiguousVia != null)
@ -3285,12 +3231,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
private void appendLocation(final StringBuilder uri, final Location location, final String paramSuffix)
{
if (canAcceptPoiId && location.type == LocationType.POI && location.hasId())
{
uri.append("&type_").append(paramSuffix).append("=poiID");
uri.append("&name_").append(paramSuffix).append("=").append(normalizeStationId(location.id));
}
else if ((location.type == LocationType.POI || location.type == LocationType.ADDRESS) && location.hasLocation())
if (location.type == LocationType.ADDRESS && location.hasLocation())
{
uri.append("&type_").append(paramSuffix).append("=coord");
uri.append("&name_").append(paramSuffix).append("=")
@ -3319,7 +3260,9 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
protected static final String locationValue(final Location location)
{
if ((location.type == LocationType.STATION || location.type == LocationType.POI) && location.hasId())
if (location.type == LocationType.STATION && location.hasId())
return normalizeStationId(location.id);
else if (location.type == LocationType.POI && location.hasId())
return location.id;
else
return location.name;

View file

@ -39,6 +39,7 @@ public class VrrProvider extends AbstractEfaProvider
setNeedsSpEncId(true);
setUseRouteIndexAsTripId(false);
setStyles(STYLES);
setRequestUrlEncoding(UTF_8);
}
public NetworkId id()

View file

@ -35,8 +35,6 @@ public class VvsProvider extends AbstractEfaProvider
public VvsProvider(final String apiBase)
{
super(apiBase);
setCanAcceptPoiId(true);
}
public NetworkId id()

View file

@ -49,7 +49,6 @@ public class DingProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "90001611"));
print(result);
}
@ -57,7 +56,6 @@ public class DingProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, 48401092, 9992037));
print(result);
}
@ -65,7 +63,13 @@ public class DingProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("90001611", false);
print(result);
}
@Test
public void suggestLocationsIdentified() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Ulm, Justizgebäude");
print(result);
}
@ -73,7 +77,6 @@ public class DingProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Kur");
print(result);
}
@ -81,15 +84,14 @@ public class DingProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsWithUmlaut() throws Exception
{
final SuggestLocationsResult result = suggestLocations("grün");
print(result);
}
@Test
public void shortTrip() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "9001011", null, "Justizgebäude"), null, new Location(
LocationType.STATION, "2504524", null, "Theater"), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "9001011", "Ulm", "Justizgebäude"), null, new Location(
LocationType.STATION, "9001010", "Ulm", "Theater"), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
assertEquals(QueryTripsResult.Status.OK, result.status);
assertTrue(result.trips.size() > 0);

View file

@ -49,7 +49,6 @@ public class MetProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "10001167"));
print(result);
}
@ -57,7 +56,6 @@ public class MetProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, -37800941, 144966545));
print(result);
}
@ -65,7 +63,6 @@ public class MetProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("10001167", false);
print(result);
}
@ -73,7 +70,6 @@ public class MetProviderLiveTest extends AbstractProviderLiveTest
public void queryDeparturesInvalidStation() throws Exception
{
final QueryDeparturesResult result = queryDepartures("999999", false);
assertEquals(QueryDeparturesResult.Status.INVALID_STATION, result.status);
}
@ -81,7 +77,6 @@ public class MetProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Kur");
print(result);
}
@ -113,4 +108,13 @@ public class MetProviderLiveTest extends AbstractProviderLiveTest
final QueryTripsResult earlierResult = queryMoreTrips(later2Result.context, false);
print(earlierResult);
}
@Test
public void tripToAny() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.ADDRESS, null, -37903445, 145102109, null,
"16 Burlington St, Oakleigh Victoria 3166, Australien"), null, new Location(LocationType.ANY, null, 0, 0, null,
"elizabeth st kensingtin"), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
}
}

View file

@ -50,7 +50,6 @@ public class MvvProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "350"));
print(result);
}
@ -58,7 +57,6 @@ public class MvvProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, 48135232, 11560650));
print(result);
}
@ -66,7 +64,6 @@ public class MvvProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("2", false);
assertEquals(QueryDeparturesResult.Status.OK, result.status);
print(result);
}
@ -75,15 +72,20 @@ public class MvvProviderLiveTest extends AbstractProviderLiveTest
public void queryDeparturesInvalidStation() throws Exception
{
final QueryDeparturesResult result = queryDepartures("999999", false);
assertEquals(QueryDeparturesResult.Status.INVALID_STATION, result.status);
}
@Test
public void suggestLocationsIdentified() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Starnberg, Agentur für Arbeit");
print(result);
}
@Test
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Marien");
print(result);
}
@ -91,7 +93,6 @@ public class MvvProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsWithUmlaut() throws Exception
{
final SuggestLocationsResult result = suggestLocations("grün");
print(result);
}
@ -126,10 +127,10 @@ public class MvvProviderLiveTest extends AbstractProviderLiveTest
@Test
public void longTrip() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.ANY, null, null, "Starnberg, Arbeitsamt"), null, new Location(
LocationType.STATION, null, null, "Ackermannstraße"), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "1005530", 48002924, 11340144, "Starnberg",
"Agentur für Arbeit"), null, new Location(LocationType.STATION, null, null, "Ackermannstraße"), new Date(), true, Product.ALL,
WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
// seems like there are no more trips all the time
}
@Test

View file

@ -49,7 +49,6 @@ public class SydneyProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "10101101"));
print(result);
}
@ -57,7 +56,6 @@ public class SydneyProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, -32823911, 151462824));
print(result);
}
@ -65,15 +63,13 @@ public class SydneyProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("10101101", false);
print(result);
}
@Test
public void suggestLocations() throws Exception
public void suggestLocationsIdentified() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Town Hall Station");
final SuggestLocationsResult result = suggestLocations("Sydney, Town Hall Station");
print(result);
}
@ -81,7 +77,6 @@ public class SydneyProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Kur");
print(result);
}

View file

@ -49,7 +49,6 @@ public class TfiProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "51013670"));
print(result);
}
@ -57,7 +56,6 @@ public class TfiProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, 53348656, -6262221));
print(result);
}
@ -65,7 +63,6 @@ public class TfiProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("51013670", false);
print(result);
}
@ -73,7 +70,6 @@ public class TfiProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Lower O'Connell Street");
print(result);
}
@ -81,7 +77,7 @@ public class TfiProviderLiveTest extends AbstractProviderLiveTest
public void shortTrip() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "51013670", "Dublin City South",
"O'Connell Bridge (on Lower O'Connell Street)"), null, new Location(LocationType.STATION, "52003679", "Dublin City South",
"O'Connell Bridge (on Lower O'Connell Street)"), null, new Location(LocationType.STATION, "51005661", "Dublin City South",
"Dublin (Baggot Street)"), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
assertEquals(QueryTripsResult.Status.OK, result.status);

View file

@ -90,7 +90,6 @@ public class TlemProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocations() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Lower Arncott The Plough");
print(result);
}
@ -98,7 +97,6 @@ public class TlemProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Birming");
print(result);
}
@ -187,4 +185,22 @@ public class TlemProviderLiveTest extends AbstractProviderLiveTest
final QueryTripsResult earlierResult = queryMoreTrips(later2Result.context, false);
print(earlierResult);
}
@Test
public void tripFromPOI() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.POI,
"poiID:48863:31117134:-1:Statue:Ham (London):Statue:ANY:POI:517246:826916:TFLV:uk", 51444620, -314316, "Ham (London)", "Statue"),
null, new Location(LocationType.ADDRESS, "streetID:106269::31117001:-1", "London", "Cannon Street, London"), new Date(), true,
Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
}
@Test
public void tripPostcode() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.ANY, null, null, "se7 7tr"), null, new Location(LocationType.ANY, null,
null, "n9 0nx"), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
}
}

View file

@ -49,7 +49,6 @@ public class VblProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "119"));
print(result);
}
@ -57,7 +56,6 @@ public class VblProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, 47049107, 8312502));
print(result);
}
@ -65,7 +63,13 @@ public class VblProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("717", false);
print(result);
}
@Test
public void suggestLocationsIdentified() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Luzern, Kantonalbank");
print(result);
}
@ -73,7 +77,6 @@ public class VblProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Kur");
print(result);
}
@ -81,15 +84,14 @@ public class VblProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsWithUmlaut() throws Exception
{
final SuggestLocationsResult result = suggestLocations("grün");
print(result);
}
@Test
public void shortTrip() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "119", 47050760, 8310252, "Luzern", "Luzern, Bahnhof"), null,
new Location(LocationType.STATION, "118", 47048844, 8306433, "Luzern", "Kantonalbank"), new Date(), true, Product.ALL,
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "53020041", 47050164, 8310352, "Luzern", "Bahnhof"), null,
new Location(LocationType.STATION, "53028841", 47048564, 8306016, "Luzern", "Kantonalbank"), new Date(), true, Product.ALL,
WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
assertEquals(QueryTripsResult.Status.OK, result.status);

View file

@ -46,7 +46,6 @@ public class VgnProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "3000510"));
print(result);
}
@ -54,7 +53,6 @@ public class VgnProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, 49455472, 11079655));
print(result);
}
@ -62,7 +60,6 @@ public class VgnProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("3000510", false);
print(result);
}
@ -70,7 +67,6 @@ public class VgnProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Kur");
print(result);
}
@ -78,7 +74,6 @@ public class VgnProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsWithUmlaut() throws Exception
{
final SuggestLocationsResult result = suggestLocations("grün");
print(result);
}
@ -92,6 +87,17 @@ public class VgnProviderLiveTest extends AbstractProviderLiveTest
print(laterResult);
}
@Test
public void tripToPOI() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.ADDRESS, null, 49527298, 10836204), null, new Location(LocationType.POI,
"poiID:246:9564000:1:Grundschule Grimmstr.:Nürnberg:Grundschule Grimmstr.:ANY:POI:4436708:678322:NAV4:VGN", 49468692, 11125334,
"Nürnberg", "Grundschule Grimmstr."), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
print(laterResult);
}
@Test
public void tripToAddress() throws Exception
{

View file

@ -49,7 +49,6 @@ public class VmobilProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "60001296"));
print(result);
}
@ -57,7 +56,6 @@ public class VmobilProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, 47271228, 11402063));
print(result);
}
@ -65,7 +63,13 @@ public class VmobilProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("60001296", false);
print(result);
}
@Test
public void suggestLocationsIdentified() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Katzenturm");
print(result);
}
@ -73,7 +77,6 @@ public class VmobilProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Kur");
print(result);
}
@ -81,15 +84,14 @@ public class VmobilProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsWithUmlaut() throws Exception
{
final SuggestLocationsResult result = suggestLocations("grün");
print(result);
}
@Test
public void shortTrip() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "60000822", 47238428, 9596940, "Feldkirch", "Katzenturm"),
null, new Location(LocationType.STATION, "60000305", 47240744, 9589368, "Tosters", "Vorarlberghalle"), new Date(), true, Product.ALL,
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "66200822", 47238428, 9596940, "Feldkirch", "Katzenturm"),
null, new Location(LocationType.STATION, "66200305", 47240744, 9589368, "Tosters", "Vorarlberghalle"), new Date(), true, Product.ALL,
WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
assertEquals(QueryTripsResult.Status.OK, result.status);

View file

@ -51,7 +51,6 @@ public class VorProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "60203090"));
print(result);
}
@ -59,7 +58,6 @@ public class VorProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, 48207355, 16370602));
print(result);
}
@ -67,7 +65,6 @@ public class VorProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("60203090", false);
print(result);
}
@ -75,7 +72,6 @@ public class VorProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Kur");
print(result);
}
@ -83,7 +79,6 @@ public class VorProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsWithUmlaut() throws Exception
{
final SuggestLocationsResult result = suggestLocations("grün");
print(result);
}
@ -128,6 +123,17 @@ public class VorProviderLiveTest extends AbstractProviderLiveTest
print(earlierResult);
}
@Test
public void tripToPOI() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.ADDRESS, null, 48221088, 16342658, "Wien", "Antonigasse 4"), null,
new Location(LocationType.POI, "poiID:1005:49000000:-1", 48199844, 16365834, "Wien", "Naschmarkt"), new Date(), true, Product.ALL,
WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
print(laterResult);
}
@Test
public void tripBetweenCoordinates() throws Exception
{

View file

@ -51,7 +51,6 @@ public class VrrProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.STATION, "20019904"));
print(result);
}
@ -59,11 +58,9 @@ public class VrrProviderLiveTest extends AbstractProviderLiveTest
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, 51218693, 6777785));
print(result);
final NearbyStationsResult result2 = queryNearbyStations(new Location(LocationType.ADDRESS, 51719648, 8754330));
print(result2);
}
@ -71,11 +68,9 @@ public class VrrProviderLiveTest extends AbstractProviderLiveTest
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = queryDepartures("1007258", false);
print(result);
final QueryDeparturesResult result2 = queryDepartures("20019904", false);
print(result2);
// Bonn
@ -87,7 +82,6 @@ public class VrrProviderLiveTest extends AbstractProviderLiveTest
public void queryManyDeparturesWithEquivs() throws Exception
{
final QueryDeparturesResult result = queryDepartures("20018235", true);
print(result);
}
@ -95,11 +89,9 @@ public class VrrProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIncomplete() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Kur");
print(result);
final SuggestLocationsResult paderbornResult = suggestLocations("Paderborn Hbf");
print(paderbornResult);
}
@ -107,7 +99,6 @@ public class VrrProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsWithUmlaut() throws Exception
{
final SuggestLocationsResult result = suggestLocations("grün");
print(result);
}
@ -115,7 +106,6 @@ public class VrrProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsIdentified() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Düsseldorf, Am Frohnhof");
print(result);
}
@ -147,10 +137,18 @@ public class VrrProviderLiveTest extends AbstractProviderLiveTest
public void suggestLocationsCity() throws Exception
{
final SuggestLocationsResult result = suggestLocations("Düsseldorf");
print(result);
}
@Test
public void anyTrip() throws Exception
{
final QueryTripsResult result = queryTrips(new Location(LocationType.ANY, null, null, "Köln"), null, new Location(LocationType.ANY, null,
null, "Bonn"), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
assertEquals(QueryTripsResult.Status.AMBIGUOUS, result.status);
}
@Test
public void shortTrip() throws Exception
{