diff --git a/enabler/src/de/schildbach/pte/AbstractHafasMobileProvider.java b/enabler/src/de/schildbach/pte/AbstractHafasMobileProvider.java index ab8f2de7..b9eebfcb 100644 --- a/enabler/src/de/schildbach/pte/AbstractHafasMobileProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractHafasMobileProvider.java @@ -347,36 +347,36 @@ public abstract class AbstractHafasMobileProvider extends AbstractHafasProvider private static final Joiner JOINER = Joiner.on(' ').skipNulls(); + private Location jsonTripSearchIdentify(final Location location) throws IOException { + if (location.hasName()) { + final List 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, final boolean dep, final @Nullable Set products, final String moreContext) throws IOException { - if (!from.hasId() && from.hasName()) { - final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT); - final List locations = suggestLocations(JOINER.join(from.place, from.name)).getLocations(); - if (locations.isEmpty()) - return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_FROM); - if (locations.size() > 1) - return new QueryTripsResult(header, locations, null, null); - from = locations.get(0); + if (!from.hasId()) { + from = jsonTripSearchIdentify(from); + if (from == null) + return new QueryTripsResult(new ResultHeader(network, SERVER_PRODUCT), + QueryTripsResult.Status.UNKNOWN_FROM); } - if (via != null && !via.hasId() && via.hasName()) { - final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT); - final List locations = suggestLocations(JOINER.join(via.place, via.name)).getLocations(); - if (locations.isEmpty()) - return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_VIA); - if (locations.size() > 1) - return new QueryTripsResult(header, locations, null, null); - via = locations.get(0); + if (via != null && !via.hasId()) { + via = jsonTripSearchIdentify(via); + if (via == null) + return new QueryTripsResult(new ResultHeader(network, SERVER_PRODUCT), + QueryTripsResult.Status.UNKNOWN_VIA); } - if (!to.hasId() && to.hasName()) { - final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT); - final List locations = suggestLocations(JOINER.join(to.place, to.name)).getLocations(); - if (locations.isEmpty()) - return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_TO); - if (locations.size() > 1) - return new QueryTripsResult(header, null, null, locations); - to = locations.get(0); + if (!to.hasId()) { + to = jsonTripSearchIdentify(to); + if (to == null) + return new QueryTripsResult(new ResultHeader(network, SERVER_PRODUCT), + QueryTripsResult.Status.UNKNOWN_TO); } final Calendar c = new GregorianCalendar(timeZone); diff --git a/enabler/test/de/schildbach/pte/live/BvgProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/BvgProviderLiveTest.java index 68ed5b7c..4c2d2a05 100644 --- a/enabler/test/de/schildbach/pte/live/BvgProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/BvgProviderLiveTest.java @@ -229,4 +229,14 @@ public class BvgProviderLiveTest extends AbstractProviderLiveTest { final QueryTripsResult laterResult = queryMoreTrips(result.context, true); 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); + } }