mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 00:50:31 +00:00
VBB: Migrate to Hafas client interface.
This commit is contained in:
parent
a9ee06de7f
commit
87a327cedb
2 changed files with 29 additions and 79 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2010-2015 the original author or authors.
|
||||
* Copyright the original author or authors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -22,9 +22,8 @@ import java.util.Set;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
|
||||
import de.schildbach.pte.dto.Line;
|
||||
import de.schildbach.pte.dto.Product;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
@ -32,20 +31,23 @@ import okhttp3.HttpUrl;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VbbProvider extends AbstractHafasLegacyProvider {
|
||||
public class VbbProvider extends AbstractHafasClientInterfaceProvider {
|
||||
private static final HttpUrl API_BASE = HttpUrl.parse("https://fahrinfo.vbb.de/bin/");
|
||||
private static final Product[] PRODUCTS_MAP = { Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS,
|
||||
Product.FERRY, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, null, null, Product.BUS /* SEV */ };
|
||||
Product.FERRY, Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, null, null, Product.BUS /* BEV */ };
|
||||
private static final Set<Product> ALL_EXCEPT_HIGHSPEED_AND_ONDEMAND = EnumSet
|
||||
.complementOf(EnumSet.of(Product.HIGH_SPEED_TRAIN, Product.ON_DEMAND));
|
||||
|
||||
public VbbProvider() {
|
||||
super(NetworkId.VBB, API_BASE, "dn", PRODUCTS_MAP);
|
||||
this("{\"type\":\"AID\",\"aid\":\"hafas-vbb-apps\"}");
|
||||
}
|
||||
|
||||
setRequestUrlEncoding(Charsets.UTF_8);
|
||||
setJsonGetStopsUseWeight(false);
|
||||
setJsonNearbyLocationsEncoding(Charsets.UTF_8);
|
||||
setClientType(null);
|
||||
public VbbProvider(final String apiAuthorization) {
|
||||
super(NetworkId.VBB, API_BASE, PRODUCTS_MAP);
|
||||
setApiVersion("1.14");
|
||||
setApiClient("{\"id\":\"VBB\",\"type\":\"AND\"}");
|
||||
setApiAuthorization(apiAuthorization);
|
||||
setRequestMicMacSalt(BaseEncoding.base16().lowerCase().decode("5243544a4d3266467846667878516649"));
|
||||
httpClient.setTrustAllCertificates(true);
|
||||
}
|
||||
|
||||
|
@ -88,7 +90,6 @@ public class VbbProvider 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);
|
||||
}
|
||||
|
||||
|
@ -97,7 +98,6 @@ public class VbbProvider 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);
|
||||
}
|
||||
|
||||
|
@ -105,12 +105,4 @@ public class VbbProvider extends AbstractHafasLegacyProvider {
|
|||
public Set<Product> defaultProducts() {
|
||||
return ALL_EXCEPT_HIGHSPEED_AND_ONDEMAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Line parseLineAndType(final String lineAndType) {
|
||||
if ("X#".equals(lineAndType))
|
||||
return newLine(Product.HIGH_SPEED_TRAIN, "X", null); // InterConnex
|
||||
else
|
||||
return super.parseLineAndType(lineAndType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,18 +43,6 @@ public class VbbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
super(new VbbProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStations() throws Exception {
|
||||
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "9007102"));
|
||||
print(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStationsInvalidStation() throws Exception {
|
||||
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "2449475"));
|
||||
assertEquals(NearbyLocationsResult.Status.INVALID_ID, result.status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStationsByCoordinate() throws Exception {
|
||||
final NearbyLocationsResult result = queryNearbyStations(Location.coord(52548505, 13388640));
|
||||
|
@ -95,12 +83,13 @@ public class VbbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
public void suggestLocationsPOI() throws Exception {
|
||||
final SuggestLocationsResult result = suggestLocations("schwules museum");
|
||||
print(result);
|
||||
Assert.assertThat(result.getLocations(), hasItem(new Location(LocationType.POI, "900980141")));
|
||||
Assert.assertThat(result.getLocations(), hasItem(new Location(LocationType.POI,
|
||||
"A=4@O=Berlin, Schwules Museum@X=13357979@Y=52504519@U=104@L=900980141@B=1@V=3.9,@p=1542286309@")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suggestLocationsAddress() throws Exception {
|
||||
final SuggestLocationsResult result = suggestLocations("Sophienstr. 24");
|
||||
final SuggestLocationsResult result = suggestLocations("10178 Berlin, Sophienstr. 24");
|
||||
print(result);
|
||||
Assert.assertEquals("Sophienstr. 24", result.getLocations().get(0).name);
|
||||
}
|
||||
|
@ -113,14 +102,12 @@ public class VbbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void shortTrip() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(
|
||||
new Location(LocationType.STATION, "900056102", "Berlin", "Nollendorfplatz"), null,
|
||||
new Location(LocationType.STATION, "900013103", "Berlin", "Prinzenstraße"), new Date(), true, null);
|
||||
final Location from = new Location(LocationType.STATION, "900056102", "Berlin", "Nollendorfplatz");
|
||||
final Location to = new Location(LocationType.STATION, "900013103", "Berlin", "Prinzenstraße");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
|
||||
final QueryTripsResult earlierResult = queryMoreTrips(laterResult.context, false);
|
||||
print(earlierResult);
|
||||
}
|
||||
|
@ -133,53 +120,36 @@ public class VbbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
"12357 Berlin-Buckow", "Distelfinkweg 35");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortViaTrip() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(
|
||||
new Location(LocationType.STATION, "900056102", "Berlin", "Nollendorfplatz"),
|
||||
new Location(LocationType.STATION, "900044202", "Berlin", "Bundesplatz"),
|
||||
new Location(LocationType.STATION, "900013103", "Berlin", "Prinzenstraße"), new Date(), true, null);
|
||||
final Location from = new Location(LocationType.STATION, "900056102", "Berlin", "Nollendorfplatz");
|
||||
final Location via = new Location(LocationType.STATION, "900044202", "Berlin", "Bundesplatz");
|
||||
final Location to = new Location(LocationType.STATION, "900013103", "Berlin", "Prinzenstraße");
|
||||
final QueryTripsResult result = queryTrips(from, via, to, new Date(), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tripBetweenCoordinates() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(Location.coord(52501507, 13357026), null,
|
||||
Location.coord(52513639, 13568648), new Date(), true, null);
|
||||
final Location from = Location.coord(Point.fromDouble(52.5249451, 13.3696614)); // Berlin Hbf
|
||||
final Location to = Location.coord(Point.fromDouble(52.5071378, 13.3318680)); // S Zoologischer Garten
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void viaTripBetweenCoordinates() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(Location.coord(52501507, 13357026),
|
||||
Location.coord(52479868, 13324247), Location.coord(52513639, 13568648), new Date(), true, null);
|
||||
final Location from = Location.coord(Point.fromDouble(52.4999599, 13.3619411)); // U Kurfürsterstr.
|
||||
final Location via = Location.coord(Point.fromDouble(52.4778673, 13.3286942)); // S+U Bundesplatz
|
||||
final Location to = Location.coord(Point.fromDouble(52.5126122, 13.5752134)); // S+U Wuhletal
|
||||
final QueryTripsResult result = queryTrips(from, via, to, new Date(), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -190,12 +160,6 @@ public class VbbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
"10437 Berlin-Prenzlauer Berg", "Göhrener Str. 5");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -208,11 +172,5 @@ public class VbbProviderLiveTest extends AbstractProviderLiveTest {
|
|||
"10178 Berlin-Mitte", "Sophienstr. 24");
|
||||
final QueryTripsResult result = queryTrips(from, via, to, new Date(), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue