mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-16 17:39:49 +00:00
NetworkProvider: Add maxLocations parameter to suggestLocations().
This commit is contained in:
parent
73cf64278f
commit
0ea83a1ad3
12 changed files with 55 additions and 33 deletions
|
@ -241,9 +241,10 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
url.addEncodedQueryParameter("coordOutputFormatTail", Integer.toString(COORD_FORMAT_TAIL));
|
||||
}
|
||||
|
||||
protected SuggestLocationsResult jsonStopfinderRequest(final Location constraint) throws IOException {
|
||||
protected SuggestLocationsResult jsonStopfinderRequest(final Location constraint, final int maxLocations)
|
||||
throws IOException {
|
||||
final HttpUrl.Builder url = stopFinderEndpoint.newBuilder();
|
||||
appendStopfinderRequestParameters(url, constraint, "JSON");
|
||||
appendStopfinderRequestParameters(url, constraint, "JSON", maxLocations);
|
||||
final CharSequence page = httpClient.get(url.build());
|
||||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||
|
||||
|
@ -350,7 +351,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
}
|
||||
|
||||
private void appendStopfinderRequestParameters(final HttpUrl.Builder url, final Location constraint,
|
||||
final String outputFormat) {
|
||||
final String outputFormat, final int maxLocations) {
|
||||
appendCommonRequestParams(url, outputFormat);
|
||||
url.addEncodedQueryParameter("locationServerActive", "1");
|
||||
if (includeRegionId)
|
||||
|
@ -364,13 +365,15 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
url.addEncodedQueryParameter("reducedAnyPostcodeObjFilter_sf", "64");
|
||||
url.addEncodedQueryParameter("reducedAnyTooManyObjFilter_sf", "2");
|
||||
url.addEncodedQueryParameter("useHouseNumberList", "true");
|
||||
url.addEncodedQueryParameter("anyMaxSizeHitList", "500");
|
||||
if (maxLocations > 0)
|
||||
url.addEncodedQueryParameter("anyMaxSizeHitList", Integer.toString(maxLocations));
|
||||
}
|
||||
}
|
||||
|
||||
protected SuggestLocationsResult mobileStopfinderRequest(final Location constraint) throws IOException {
|
||||
protected SuggestLocationsResult mobileStopfinderRequest(final Location constraint, final int maxLocations)
|
||||
throws IOException {
|
||||
final HttpUrl.Builder url = stopFinderEndpoint.newBuilder();
|
||||
appendStopfinderRequestParameters(url, constraint, "XML");
|
||||
appendStopfinderRequestParameters(url, constraint, "XML", maxLocations);
|
||||
final AtomicReference<SuggestLocationsResult> result = new AtomicReference<>();
|
||||
|
||||
final HttpClient.Callback callback = new HttpClient.Callback() {
|
||||
|
@ -604,8 +607,9 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return jsonStopfinderRequest(new Location(LocationType.ANY, null, null, constraint.toString()));
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint, final int maxLocations)
|
||||
throws IOException {
|
||||
return jsonStopfinderRequest(new Location(LocationType.ANY, null, null, constraint.toString()), maxLocations);
|
||||
}
|
||||
|
||||
private interface ProcessItdOdvCallback {
|
||||
|
|
|
@ -196,8 +196,9 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
|
|||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return jsonLocMatch(constraint, null, 0);
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint, final int maxLocations)
|
||||
throws IOException {
|
||||
return jsonLocMatch(constraint, null, maxLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -295,9 +295,10 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint, final int maxLocations)
|
||||
throws IOException {
|
||||
final HttpUrl.Builder url = getStopEndpoint.newBuilder().addPathSegment(apiLanguage);
|
||||
appendJsonGetStopsParameters(url, checkNotNull(constraint), 0);
|
||||
appendJsonGetStopsParameters(url, checkNotNull(constraint), maxLocations);
|
||||
return jsonGetStops(url.build());
|
||||
}
|
||||
|
||||
|
@ -700,7 +701,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||
|
||||
if (!from.isIdentified()) {
|
||||
final List<Location> locations = suggestLocations(from.name).getLocations();
|
||||
final List<Location> locations = suggestLocations(from.name, 0).getLocations();
|
||||
if (locations.isEmpty())
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); // TODO
|
||||
if (locations.size() > 1)
|
||||
|
@ -709,7 +710,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
if (via != null && !via.isIdentified()) {
|
||||
final List<Location> locations = suggestLocations(via.name).getLocations();
|
||||
final List<Location> locations = suggestLocations(via.name, 0).getLocations();
|
||||
if (locations.isEmpty())
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); // TODO
|
||||
if (locations.size() > 1)
|
||||
|
@ -718,7 +719,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
if (!to.isIdentified()) {
|
||||
final List<Location> locations = suggestLocations(to.name).getLocations();
|
||||
final List<Location> locations = suggestLocations(to.name, 0).getLocations();
|
||||
if (locations.isEmpty())
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); // TODO
|
||||
if (locations.size() > 1)
|
||||
|
@ -1359,7 +1360,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||
|
||||
if (!from.isIdentified()) {
|
||||
final List<Location> locations = suggestLocations(from.name).getLocations();
|
||||
final List<Location> locations = suggestLocations(from.name, 0).getLocations();
|
||||
if (locations.isEmpty())
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); // TODO
|
||||
if (locations.size() > 1)
|
||||
|
@ -1368,7 +1369,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
if (via != null && !via.isIdentified()) {
|
||||
final List<Location> locations = suggestLocations(via.name).getLocations();
|
||||
final List<Location> locations = suggestLocations(via.name, 0).getLocations();
|
||||
if (locations.isEmpty())
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); // TODO
|
||||
if (locations.size() > 1)
|
||||
|
@ -1377,7 +1378,7 @@ public abstract class AbstractHafasLegacyProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
if (!to.isIdentified()) {
|
||||
final List<Location> locations = suggestLocations(to.name).getLocations();
|
||||
final List<Location> locations = suggestLocations(to.name, 0).getLocations();
|
||||
if (locations.isEmpty())
|
||||
return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); // TODO
|
||||
if (locations.size() > 1)
|
||||
|
|
|
@ -845,7 +845,8 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint, final int maxLocations)
|
||||
throws IOException {
|
||||
final String nameCstr = constraint.toString();
|
||||
|
||||
final HttpUrl.Builder url = url().addPathSegment("places");
|
||||
|
@ -1008,7 +1009,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
|
|||
Location newFrom = null, newTo = null;
|
||||
|
||||
if (!from.isIdentified() && from.hasName()) {
|
||||
ambiguousFrom = suggestLocations(from.name).getLocations();
|
||||
ambiguousFrom = suggestLocations(from.name, 0).getLocations();
|
||||
if (ambiguousFrom.isEmpty())
|
||||
return new QueryTripsResult(resultHeader, QueryTripsResult.Status.UNKNOWN_FROM);
|
||||
if (ambiguousFrom.size() == 1 && ambiguousFrom.get(0).isIdentified())
|
||||
|
@ -1016,7 +1017,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider {
|
|||
}
|
||||
|
||||
if (!to.isIdentified() && to.hasName()) {
|
||||
ambiguousTo = suggestLocations(to.name).getLocations();
|
||||
ambiguousTo = suggestLocations(to.name, 0).getLocations();
|
||||
if (ambiguousTo.isEmpty())
|
||||
return new QueryTripsResult(resultHeader, QueryTripsResult.Status.UNKNOWN_TO);
|
||||
if (ambiguousTo.size() == 1 && ambiguousTo.get(0).isIdentified())
|
||||
|
|
|
@ -39,6 +39,7 @@ import de.schildbach.pte.dto.Position;
|
|||
import de.schildbach.pte.dto.Product;
|
||||
import de.schildbach.pte.dto.QueryTripsResult;
|
||||
import de.schildbach.pte.dto.Style;
|
||||
import de.schildbach.pte.dto.SuggestLocationsResult;
|
||||
import de.schildbach.pte.dto.TripOptions;
|
||||
import de.schildbach.pte.util.HttpClient;
|
||||
|
||||
|
@ -77,6 +78,12 @@ public abstract class AbstractNetworkProvider implements NetworkProvider {
|
|||
|
||||
protected abstract boolean hasCapability(Capability capability);
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public final SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return suggestLocations(constraint, 0);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public QueryTripsResult queryTrips(Location from, @Nullable Location via, Location to, Date date, boolean dep,
|
||||
|
|
|
@ -130,8 +130,9 @@ public class BayernProvider extends AbstractEfaProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return mobileStopfinderRequest(new Location(LocationType.ANY, null, null, constraint.toString()));
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint, final int maxLocations)
|
||||
throws IOException {
|
||||
return mobileStopfinderRequest(new Location(LocationType.ANY, null, null, constraint.toString()), maxLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -827,7 +827,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(CharSequence constraint) throws IOException {
|
||||
public SuggestLocationsResult suggestLocations(CharSequence constraint, int maxLocations) throws IOException {
|
||||
HttpUrl url = buildApiUrl("locations", Arrays.asList(new QueryParameter("q", constraint.toString())));
|
||||
final CharSequence page;
|
||||
try {
|
||||
|
|
|
@ -112,9 +112,14 @@ public interface NetworkProvider {
|
|||
*
|
||||
* @param constraint
|
||||
* input by user so far
|
||||
* @param maxLocations
|
||||
* maximum number of locations to suggest or {@code 0}
|
||||
* @return location suggestions
|
||||
* @throws IOException
|
||||
*/
|
||||
SuggestLocationsResult suggestLocations(CharSequence constraint, int maxLocations) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
SuggestLocationsResult suggestLocations(CharSequence constraint) throws IOException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,8 +72,9 @@ public class StvProvider extends AbstractEfaProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return mobileStopfinderRequest(new Location(LocationType.ANY, null, null, constraint.toString()));
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint, final int maxLocations)
|
||||
throws IOException {
|
||||
return mobileStopfinderRequest(new Location(LocationType.ANY, null, null, constraint.toString()), maxLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -573,13 +573,14 @@ public class VrsProvider extends AbstractNetworkProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
public SuggestLocationsResult suggestLocations(final CharSequence constraint, final int maxLocations)
|
||||
throws IOException {
|
||||
// sc = station count
|
||||
final int sc = 10;
|
||||
final int sc = maxLocations / 2;
|
||||
// ac = address count
|
||||
final int ac = 5;
|
||||
final int ac = maxLocations / 4;
|
||||
// pc = points of interest count
|
||||
final int pc = 5;
|
||||
final int pc = maxLocations / 4;
|
||||
// t = sap (stops and/or addresses and/or pois)
|
||||
final HttpUrl.Builder url = API_BASE.newBuilder();
|
||||
url.addQueryParameter("eID", "tx_vrsinfo_ass2_objects");
|
||||
|
@ -1126,7 +1127,7 @@ public class VrsProvider extends AbstractNetworkProvider {
|
|||
} else if (loc.coord != null) {
|
||||
return String.format(Locale.ENGLISH, "%f,%f", loc.getLatAsDouble(), loc.getLonAsDouble());
|
||||
} else {
|
||||
SuggestLocationsResult suggestLocationsResult = suggestLocations(loc.name);
|
||||
SuggestLocationsResult suggestLocationsResult = suggestLocations(loc.name, 0);
|
||||
final List<Location> suggestedLocations = suggestLocationsResult.getLocations();
|
||||
if (suggestedLocations.size() == 1) {
|
||||
return suggestedLocations.get(0).id;
|
||||
|
|
|
@ -115,7 +115,7 @@ public abstract class AbstractProviderLiveTest {
|
|||
}
|
||||
|
||||
protected final SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException {
|
||||
return provider.suggestLocations(constraint);
|
||||
return provider.suggestLocations(constraint, 0);
|
||||
}
|
||||
|
||||
protected final QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
|
||||
|
|
|
@ -90,7 +90,7 @@ public class SydneyProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void suggestLocationsEmpty() throws Exception {
|
||||
final SuggestLocationsResult result = provider.suggestLocations("kreide");
|
||||
final SuggestLocationsResult result = suggestLocations("kreide");
|
||||
print(result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue