mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 17:10:30 +00:00
OEBB: Migrate to Hafas client interface.
This commit is contained in:
parent
d0bcedc0e8
commit
f1641c5fa3
3 changed files with 31 additions and 99 deletions
|
@ -27,21 +27,18 @@ import okhttp3.HttpUrl;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class OebbProvider extends AbstractHafasLegacyProvider {
|
||||
public class OebbProvider extends AbstractHafasClientInterfaceProvider {
|
||||
private static final HttpUrl API_BASE = HttpUrl.parse("http://fahrplan.oebb.at/bin/");
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN,
|
||||
Product.BUS, Product.FERRY, Product.SUBWAY, Product.TRAM, Product.HIGH_SPEED_TRAIN, Product.ON_DEMAND,
|
||||
Product.HIGH_SPEED_TRAIN };
|
||||
|
||||
public OebbProvider() {
|
||||
super(NetworkId.OEBB, API_BASE, "dn", PRODUCTS_MAP);
|
||||
setDominantPlanStopTime(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
public OebbProvider(final String apiAuthorization) {
|
||||
super(NetworkId.OEBB, API_BASE, PRODUCTS_MAP);
|
||||
setApiVersion("1.14");
|
||||
setApiClient("{\"id\":\"OEBB\",\"type\":\"AND\"}");
|
||||
setApiAuthorization(apiAuthorization);
|
||||
}
|
||||
|
||||
private static final String[] PLACES = { "Wien", "Graz", "Linz/Donau", "Salzburg", "Innsbruck" };
|
||||
|
@ -51,7 +48,6 @@ public class OebbProvider extends AbstractHafasLegacyProvider {
|
|||
for (final String place : PLACES)
|
||||
if (name.startsWith(place + " "))
|
||||
return new String[] { place, name.substring(place.length() + 1) };
|
||||
|
||||
return super.splitStationName(name);
|
||||
}
|
||||
|
||||
|
@ -60,7 +56,6 @@ public class OebbProvider extends AbstractHafasLegacyProvider {
|
|||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
||||
return super.splitStationName(poi);
|
||||
}
|
||||
|
||||
|
@ -69,74 +64,11 @@ public class OebbProvider extends AbstractHafasLegacyProvider {
|
|||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
|
||||
return super.splitStationName(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if (ucType.equals("RR")) // Finnland, Connections only?
|
||||
return Product.HIGH_SPEED_TRAIN;
|
||||
if (ucType.equals("EE")) // Rumänien, Connections only?
|
||||
return Product.HIGH_SPEED_TRAIN;
|
||||
if (ucType.equals("OZ")) // Schweden, Oeresundzug, Connections only?
|
||||
return Product.HIGH_SPEED_TRAIN;
|
||||
if (ucType.equals("UUU")) // Italien, Nacht, Connections only?
|
||||
return Product.HIGH_SPEED_TRAIN;
|
||||
|
||||
if (ucType.equals("S2")) // Helsinki-Turku, Connections only?
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if (ucType.equals("RE")) // RegionalExpress Deutschland
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if (ucType.equals("DPN")) // Connections only? TODO nicht evtl. doch eher ne S-Bahn?
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if (ucType.equals("IP")) // Ozd, Ungarn
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if (ucType.equals("N")) // Frankreich, Tours
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if (ucType.equals("DPF")) // VX=Vogtland Express, Connections only?
|
||||
return Product.REGIONAL_TRAIN;
|
||||
if ("UAU".equals(ucType)) // Rußland
|
||||
return Product.REGIONAL_TRAIN;
|
||||
|
||||
if (ucType.equals("RSB")) // Schnellbahn Wien
|
||||
return Product.SUBURBAN_TRAIN;
|
||||
|
||||
if (ucType.equals("LKB")) // Connections only?
|
||||
return Product.TRAM;
|
||||
|
||||
if (ucType.equals("OBU")) // Connections only?
|
||||
return Product.BUS;
|
||||
if (ucType.equals("O-BUS")) // Stadtbus
|
||||
return Product.BUS;
|
||||
if (ucType.equals("O")) // Stadtbus
|
||||
return Product.BUS;
|
||||
|
||||
if (ucType.equals("SCH")) // Connections only?
|
||||
return Product.FERRY;
|
||||
if (ucType.equals("F")) // Fähre
|
||||
return Product.FERRY;
|
||||
|
||||
if (ucType.equals("LIF"))
|
||||
return Product.CABLECAR;
|
||||
if (ucType.equals("LIFT")) // Graz Uhrturm
|
||||
return Product.CABLECAR;
|
||||
if (ucType.equals("SSB")) // Graz Schlossbergbahn
|
||||
return Product.CABLECAR;
|
||||
|
||||
if (ucType.equals("U70")) // U.K., Connections only?
|
||||
return null;
|
||||
if (ucType.equals("X70")) // U.K., Connections only?
|
||||
return null;
|
||||
if (ucType.equals("R84")) // U.K., Connections only?
|
||||
return null;
|
||||
if (ucType.equals("S84")) // U.K., Connections only?
|
||||
return null;
|
||||
if (ucType.equals("T84")) // U.K., Connections only?
|
||||
return null;
|
||||
|
||||
return super.normalizeType(type);
|
||||
public Set<Product> defaultProducts() {
|
||||
return Product.ALL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import de.schildbach.pte.OebbProvider;
|
|||
import de.schildbach.pte.dto.Location;
|
||||
import de.schildbach.pte.dto.LocationType;
|
||||
import de.schildbach.pte.dto.NearbyLocationsResult;
|
||||
import de.schildbach.pte.dto.Point;
|
||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||
import de.schildbach.pte.dto.QueryTripsResult;
|
||||
import de.schildbach.pte.dto.SuggestLocationsResult;
|
||||
|
@ -37,20 +38,12 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
|
|||
*/
|
||||
public class OebbProviderLiveTest extends AbstractProviderLiveTest {
|
||||
public OebbProviderLiveTest() {
|
||||
super(new OebbProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStations() throws Exception {
|
||||
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "902006"));
|
||||
|
||||
print(result);
|
||||
super(new OebbProvider(secretProperty("oebb.api_authorization")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStationsByCoordinate() throws Exception {
|
||||
final NearbyLocationsResult result = queryNearbyStations(Location.coord(48200239, 16370773));
|
||||
|
||||
print(result);
|
||||
assertEquals(NearbyLocationsResult.Status.OK, result.status);
|
||||
assertTrue(result.locations.size() > 0);
|
||||
|
@ -59,7 +52,6 @@ public class OebbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
@Test
|
||||
public void queryDepartures() throws Exception {
|
||||
final QueryDeparturesResult result = queryDepartures("902006", false);
|
||||
|
||||
print(result);
|
||||
assertEquals(QueryDeparturesResult.Status.OK, result.status);
|
||||
assertTrue(result.stationDepartures.size() > 0);
|
||||
|
@ -68,14 +60,12 @@ public class OebbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
@Test
|
||||
public void queryDeparturesInvalidStation() throws Exception {
|
||||
final QueryDeparturesResult result = queryDepartures("999999", false);
|
||||
|
||||
assertEquals(QueryDeparturesResult.Status.INVALID_STATION, result.status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suggestLocations() throws Exception {
|
||||
final SuggestLocationsResult result = suggestLocations("Wien");
|
||||
|
||||
print(result);
|
||||
assertTrue(result.getLocations().size() > 0);
|
||||
}
|
||||
|
@ -83,14 +73,14 @@ public class OebbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
@Test
|
||||
public void suggestLocationsUmlaut() throws Exception {
|
||||
final SuggestLocationsResult result = suggestLocations("Obirhöhle");
|
||||
|
||||
print(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortTrip() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "1140101", null, "Linz"), null,
|
||||
new Location(LocationType.STATION, "1190100", null, "Wien"), new Date(), true, null);
|
||||
final Location from = new Location(LocationType.STATION, "1140101", null, "Linz");
|
||||
final Location to = new Location(LocationType.STATION, "1190100", null, "Wien");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
assertEquals(QueryTripsResult.Status.OK, result.status);
|
||||
assertTrue(result.trips.size() > 0);
|
||||
|
@ -100,8 +90,9 @@ public class OebbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void slowTrip() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(new Location(LocationType.ANY, null, null, "Ramsen Zoll!"), null,
|
||||
new Location(LocationType.ANY, null, null, "Azuga!"), new Date(), true, null);
|
||||
final Location from = new Location(LocationType.ANY, null, null, "Ramsen Zoll!");
|
||||
final Location to = new Location(LocationType.ANY, null, null, "Azuga!");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
assertEquals(QueryTripsResult.Status.OK, result.status);
|
||||
assertTrue(result.trips.size() > 0);
|
||||
|
@ -111,8 +102,9 @@ public class OebbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void tripWithFootway() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(new Location(LocationType.ANY, null, null, "Graz, Haselweg!"), null,
|
||||
new Location(LocationType.ANY, null, null, "Innsbruck, Gumppstraße 69!"), new Date(), true, null);
|
||||
final Location from = new Location(LocationType.ANY, null, null, "Graz, Haselweg!");
|
||||
final Location to = new Location(LocationType.ANY, null, null, "Innsbruck, Gumppstraße 69!");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
assertEquals(QueryTripsResult.Status.OK, result.status);
|
||||
assertTrue(result.trips.size() > 0);
|
||||
|
@ -122,14 +114,21 @@ public class OebbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void tripWithFootway2() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(
|
||||
new Location(LocationType.ANY, null, null, "Wien, Krottenbachstraße 110!"), null,
|
||||
new Location(LocationType.ADDRESS, null, null, "Wien, Meidlinger Hauptstraße 1!"), new Date(), true,
|
||||
null);
|
||||
final Location from = new Location(LocationType.ANY, null, null, "Wien, Krottenbachstraße 110!");
|
||||
final Location to = new Location(LocationType.ADDRESS, null, null, "Wien, Meidlinger Hauptstraße 1!");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
assertEquals(QueryTripsResult.Status.OK, result.status);
|
||||
assertTrue(result.trips.size() > 0);
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tripBetweenCoordinates() throws Exception {
|
||||
final Location from = Location.coord(Point.fromDouble(48.1850101, 16.3778549)); // Wien Hauptbahnhof
|
||||
final Location to = Location.coord(Point.fromDouble(48.2902408, 14.2918619)); // Linz Hauptbahnhof
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ sh.api_authorization =
|
|||
vmt.api_authorization =
|
||||
invg.api_authorization =
|
||||
avv_aachen.api_authorization =
|
||||
oebb.api_authorization =
|
||||
vor.api_authorization =
|
||||
ooevv.api_authorization =
|
||||
svv.api_authorization =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue