mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-06 15:18:49 +00:00
Navitia: Support Ambiguous QueryTripsResult
This commit is contained in:
parent
d245c294e3
commit
17e54c4d62
3 changed files with 68 additions and 2 deletions
|
@ -1191,10 +1191,36 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider
|
|||
throw new ParserException(jsonExc);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (from != null && to != null)
|
||||
{
|
||||
return new QueryTripsResult(resultHeader, QueryTripsResult.Status.NO_TRIPS);
|
||||
List<Location> ambiguousFrom = null, ambiguousTo = null;
|
||||
Location newFrom = null, newTo = null;
|
||||
|
||||
if (!from.isIdentified() && from.hasName())
|
||||
{
|
||||
ambiguousFrom = suggestLocations(from.name).getLocations();
|
||||
if (ambiguousFrom.isEmpty())
|
||||
return new QueryTripsResult(resultHeader, QueryTripsResult.Status.UNKNOWN_FROM);
|
||||
if (ambiguousFrom.size() == 1 && ambiguousFrom.get(0).isIdentified())
|
||||
newFrom = ambiguousFrom.get(0);
|
||||
}
|
||||
|
||||
if (!to.isIdentified() && to.hasName())
|
||||
{
|
||||
ambiguousTo = suggestLocations(to.name).getLocations();
|
||||
if (ambiguousTo.isEmpty())
|
||||
return new QueryTripsResult(resultHeader, QueryTripsResult.Status.UNKNOWN_TO);
|
||||
if (ambiguousTo.size() == 1 && ambiguousTo.get(0).isIdentified())
|
||||
newTo = ambiguousTo.get(0);
|
||||
}
|
||||
|
||||
if (newTo != null && newFrom != null)
|
||||
return queryTrips(newFrom, via, newTo, date, dep, products, optimize, walkSpeed, accessibility, options);
|
||||
|
||||
if (ambiguousFrom != null || ambiguousTo != null)
|
||||
return new QueryTripsResult(resultHeader, ambiguousFrom, null, ambiguousTo);
|
||||
}
|
||||
return new QueryTripsResult(resultHeader, QueryTripsResult.Status.NO_TRIPS);
|
||||
}
|
||||
catch (final NotFoundException fnfExc)
|
||||
{
|
||||
|
|
|
@ -224,6 +224,32 @@ public abstract class AbstractNavitiaProviderLiveTest extends AbstractProviderLi
|
|||
print(result);
|
||||
}
|
||||
|
||||
protected final void queryTripAmbiguousFrom(final Location from, final CharSequence to) throws IOException
|
||||
{
|
||||
final SuggestLocationsResult toResult = suggestLocations(to);
|
||||
assertTrue(toResult.getLocations().size() > 0);
|
||||
|
||||
final QueryTripsResult result = queryTrips(from, null, toResult.getLocations().get(0), new Date(), true,
|
||||
Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
|
||||
assertEquals(QueryTripsResult.Status.AMBIGUOUS, result.status);
|
||||
assertTrue(result.ambiguousFrom != null);
|
||||
assertTrue(result.ambiguousFrom.size() > 0);
|
||||
print(result);
|
||||
}
|
||||
|
||||
protected final void queryTripAmbiguousTo(final CharSequence from, final Location to) throws IOException
|
||||
{
|
||||
final SuggestLocationsResult fromResult = suggestLocations(from);
|
||||
assertTrue(fromResult.getLocations().size() > 0);
|
||||
|
||||
final QueryTripsResult result = queryTrips(fromResult.getLocations().get(0), null, to, new Date(), true,
|
||||
Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
|
||||
assertEquals(QueryTripsResult.Status.AMBIGUOUS, result.status);
|
||||
assertTrue(result.ambiguousTo != null);
|
||||
assertTrue(result.ambiguousTo.size() > 0);
|
||||
print(result);
|
||||
}
|
||||
|
||||
protected final void queryTripSlowWalk(final CharSequence from, final CharSequence to) throws IOException
|
||||
{
|
||||
final SuggestLocationsResult fromResult = suggestLocations(from);
|
||||
|
|
|
@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue;
|
|||
import org.junit.Test;
|
||||
|
||||
import de.schildbach.pte.ParisProvider;
|
||||
import de.schildbach.pte.dto.Location;
|
||||
import de.schildbach.pte.dto.LocationType;
|
||||
import de.schildbach.pte.dto.Point;
|
||||
|
||||
/**
|
||||
|
@ -178,6 +180,18 @@ public class ParisProviderLiveTest extends AbstractNavitiaProviderLiveTest
|
|||
queryTripUnknownTo("secretan buttes chaumont paris");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryTripAmbiguousFrom() throws Exception
|
||||
{
|
||||
queryTripAmbiguousFrom(new Location(LocationType.ANY, "ambiguous", null, "Eiffel"), "Gare St-Lazare");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryTripAmbiguousTo() throws Exception
|
||||
{
|
||||
queryTripAmbiguousTo("Gare St-Lazare", new Location(LocationType.ANY, "ambiguous", null, "Eiffel"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryTripSlowWalk() throws Exception
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue