AbstractHafasMobileProvider: If address is passed to jsonTripSearch() without id, always use first identified address.

This commit is contained in:
Andreas Schildbach 2017-02-16 16:42:20 +01:00
parent 82f09b16d8
commit 43abca08f5
2 changed files with 34 additions and 24 deletions

View file

@ -347,36 +347,36 @@ public abstract class AbstractHafasMobileProvider extends AbstractHafasProvider
private static final Joiner JOINER = Joiner.on(' ').skipNulls(); private static final Joiner JOINER = Joiner.on(' ').skipNulls();
private Location jsonTripSearchIdentify(final Location location) throws IOException {
if (location.hasName()) {
final List<Location> locations = jsonLocMatch(JOINER.join(location.place, location.name)).getLocations();
if (!locations.isEmpty())
return locations.get(0);
}
return null;
}
protected final QueryTripsResult jsonTripSearch(Location from, @Nullable Location via, Location to, final Date time, protected final QueryTripsResult jsonTripSearch(Location from, @Nullable Location via, Location to, final Date time,
final boolean dep, final @Nullable Set<Product> products, final String moreContext) throws IOException { final boolean dep, final @Nullable Set<Product> products, final String moreContext) throws IOException {
if (!from.hasId() && from.hasName()) { if (!from.hasId()) {
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT); from = jsonTripSearchIdentify(from);
final List<Location> locations = suggestLocations(JOINER.join(from.place, from.name)).getLocations(); if (from == null)
if (locations.isEmpty()) return new QueryTripsResult(new ResultHeader(network, SERVER_PRODUCT),
return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_FROM); QueryTripsResult.Status.UNKNOWN_FROM);
if (locations.size() > 1)
return new QueryTripsResult(header, locations, null, null);
from = locations.get(0);
} }
if (via != null && !via.hasId() && via.hasName()) { if (via != null && !via.hasId()) {
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT); via = jsonTripSearchIdentify(via);
final List<Location> locations = suggestLocations(JOINER.join(via.place, via.name)).getLocations(); if (via == null)
if (locations.isEmpty()) return new QueryTripsResult(new ResultHeader(network, SERVER_PRODUCT),
return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_VIA); QueryTripsResult.Status.UNKNOWN_VIA);
if (locations.size() > 1)
return new QueryTripsResult(header, locations, null, null);
via = locations.get(0);
} }
if (!to.hasId() && to.hasName()) { if (!to.hasId()) {
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT); to = jsonTripSearchIdentify(to);
final List<Location> locations = suggestLocations(JOINER.join(to.place, to.name)).getLocations(); if (to == null)
if (locations.isEmpty()) return new QueryTripsResult(new ResultHeader(network, SERVER_PRODUCT),
return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_TO); QueryTripsResult.Status.UNKNOWN_TO);
if (locations.size() > 1)
return new QueryTripsResult(header, null, null, locations);
to = locations.get(0);
} }
final Calendar c = new GregorianCalendar(timeZone); final Calendar c = new GregorianCalendar(timeZone);

View file

@ -229,4 +229,14 @@ public class BvgProviderLiveTest extends AbstractProviderLiveTest {
final QueryTripsResult laterResult = queryMoreTrips(result.context, true); final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
print(laterResult); print(laterResult);
} }
@Test
public void tripAddressWithoutId() throws Exception {
final QueryTripsResult result = queryTrips(
new Location(LocationType.ADDRESS, null, 52481922, 13388383, null,
"Bayernring, 12101 Berlin, Deutschland"),
null, new Location(LocationType.STATION, "9064301", 52429099, 13328081, null, "S Lichterfelde Ost Bhf"),
new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
print(result);
}
} }