mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 16:29:51 +00:00
Hafas: Support via for JSON trips query.
This commit is contained in:
parent
5daefdbc56
commit
879de41cf7
5 changed files with 36 additions and 15 deletions
|
@ -149,15 +149,17 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public static class JsonContext implements QueryTripsContext {
|
public static class JsonContext implements QueryTripsContext {
|
||||||
public final Location from, to;
|
public final Location from, via, to;
|
||||||
public final Date date;
|
public final Date date;
|
||||||
public final boolean dep;
|
public final boolean dep;
|
||||||
public final Set<Product> products;
|
public final Set<Product> products;
|
||||||
public final String laterContext, earlierContext;
|
public final String laterContext, earlierContext;
|
||||||
|
|
||||||
public JsonContext(final Location from, final Location to, final Date date, final boolean dep,
|
public JsonContext(final Location from, final @Nullable Location via, final Location to, final Date date,
|
||||||
final Set<Product> products, final String laterContext, final String earlierContext) {
|
final boolean dep, final Set<Product> products, final String laterContext,
|
||||||
|
final String earlierContext) {
|
||||||
this.from = from;
|
this.from = from;
|
||||||
|
this.via = via;
|
||||||
this.to = to;
|
this.to = to;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.dep = dep;
|
this.dep = dep;
|
||||||
|
@ -1029,8 +1031,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
|
||||||
|
|
||||||
private static final Joiner JOINER = Joiner.on(' ').skipNulls();
|
private static final Joiner JOINER = Joiner.on(' ').skipNulls();
|
||||||
|
|
||||||
protected final QueryTripsResult jsonTripSearch(Location from, Location to, final Date time, final boolean dep,
|
protected final QueryTripsResult jsonTripSearch(Location from, @Nullable Location via, Location to, final Date time,
|
||||||
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() && from.hasName()) {
|
||||||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||||
final List<Location> locations = suggestLocations(JOINER.join(from.place, from.name)).getLocations();
|
final List<Location> locations = suggestLocations(JOINER.join(from.place, from.name)).getLocations();
|
||||||
|
@ -1041,6 +1043,16 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
|
||||||
from = locations.get(0);
|
from = locations.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (via != null && !via.hasId() && via.hasName()) {
|
||||||
|
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||||
|
final List<Location> 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 (!to.hasId() && to.hasName()) {
|
if (!to.hasId() && to.hasName()) {
|
||||||
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
|
||||||
final List<Location> locations = suggestLocations(JOINER.join(to.place, to.name)).getLocations();
|
final List<Location> locations = suggestLocations(JOINER.join(to.place, to.name)).getLocations();
|
||||||
|
@ -1063,6 +1075,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
|
||||||
+ jsonContext //
|
+ jsonContext //
|
||||||
+ "\"depLocL\":[" + jsonLocation(from) + "]," //
|
+ "\"depLocL\":[" + jsonLocation(from) + "]," //
|
||||||
+ "\"arrLocL\":[" + jsonLocation(to) + "]," //
|
+ "\"arrLocL\":[" + jsonLocation(to) + "]," //
|
||||||
|
+ (via != null ? "\"viaLocL\":[{\"loc\":" + jsonLocation(via) + "}]," : "") //
|
||||||
+ "\"outDate\":\"" + outDate + "\"," //
|
+ "\"outDate\":\"" + outDate + "\"," //
|
||||||
+ "\"outTime\":\"" + outTime + "\"," //
|
+ "\"outTime\":\"" + outTime + "\"," //
|
||||||
+ "\"" + outFrwdKey + "\":" + outFrwd + "," //
|
+ "\"" + outFrwdKey + "\":" + outFrwd + "," //
|
||||||
|
@ -1195,7 +1208,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider {
|
||||||
trips.add(trip);
|
trips.add(trip);
|
||||||
}
|
}
|
||||||
|
|
||||||
final JsonContext context = new JsonContext(from, to, time, dep, products, res.optString("outCtxScrF"),
|
final JsonContext context = new JsonContext(from, via, to, time, dep, products, res.optString("outCtxScrF"),
|
||||||
res.optString("outCtxScrB"));
|
res.optString("outCtxScrB"));
|
||||||
return new QueryTripsResult(header, null, from, null, to, context, trips);
|
return new QueryTripsResult(header, null, from, null, to, context, trips);
|
||||||
} catch (final JSONException x) {
|
} catch (final JSONException x) {
|
||||||
|
|
|
@ -116,14 +116,14 @@ public class ShProvider extends AbstractHafasProvider {
|
||||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||||
return jsonTripSearch(from, to, date, dep, products, null);
|
return jsonTripSearch(from, via, to, date, dep, products, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||||
final JsonContext jsonContext = (JsonContext) context;
|
final JsonContext jsonContext = (JsonContext) context;
|
||||||
return jsonTripSearch(jsonContext.from, jsonContext.to, jsonContext.date, jsonContext.dep, jsonContext.products,
|
return jsonTripSearch(jsonContext.from, jsonContext.via, jsonContext.to, jsonContext.date, jsonContext.dep,
|
||||||
later ? jsonContext.laterContext : jsonContext.earlierContext);
|
jsonContext.products, later ? jsonContext.laterContext : jsonContext.earlierContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -118,14 +118,14 @@ public class VaoProvider extends AbstractHafasProvider {
|
||||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||||
return jsonTripSearch(from, to, date, dep, products, null);
|
return jsonTripSearch(from, via, to, date, dep, products, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||||
final JsonContext jsonContext = (JsonContext) context;
|
final JsonContext jsonContext = (JsonContext) context;
|
||||||
return jsonTripSearch(jsonContext.from, jsonContext.to, jsonContext.date, jsonContext.dep, jsonContext.products,
|
return jsonTripSearch(jsonContext.from, jsonContext.via, jsonContext.to, jsonContext.date, jsonContext.dep,
|
||||||
later ? jsonContext.laterContext : jsonContext.earlierContext);
|
jsonContext.products, later ? jsonContext.laterContext : jsonContext.earlierContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||||
|
|
|
@ -115,14 +115,14 @@ public class VbnProvider extends AbstractHafasProvider {
|
||||||
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
final Date date, final boolean dep, final @Nullable Set<Product> products,
|
||||||
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
|
||||||
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
final @Nullable Accessibility accessibility, final @Nullable Set<Option> options) throws IOException {
|
||||||
return jsonTripSearch(from, to, date, dep, products, null);
|
return jsonTripSearch(from, via, to, date, dep, products, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
|
||||||
final JsonContext jsonContext = (JsonContext) context;
|
final JsonContext jsonContext = (JsonContext) context;
|
||||||
return jsonTripSearch(jsonContext.from, jsonContext.to, jsonContext.date, jsonContext.dep, jsonContext.products,
|
return jsonTripSearch(jsonContext.from, jsonContext.via, jsonContext.to, jsonContext.date, jsonContext.dep,
|
||||||
later ? jsonContext.laterContext : jsonContext.earlierContext);
|
jsonContext.products, later ? jsonContext.laterContext : jsonContext.earlierContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
private static final Map<String, Style> STYLES = new HashMap<String, Style>();
|
||||||
|
|
|
@ -115,6 +115,14 @@ public class ShProviderLiveTest extends AbstractProviderLiveTest {
|
||||||
print(result);
|
print(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tripKielVia() throws Exception {
|
||||||
|
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "3490015"),
|
||||||
|
new Location(LocationType.STATION, "3490020"), new Location(LocationType.STATION, "706923"), new Date(),
|
||||||
|
true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void trip_errorTooClose() throws Exception {
|
public void trip_errorTooClose() throws Exception {
|
||||||
final Location station = new Location(LocationType.STATION, "003665026");
|
final Location station = new Location(LocationType.STATION, "003665026");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue