Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix value mapping for bikesAllowed in GTFS GraphQL API #5368

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/GraphQL-Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GraphQL query in the left hand panel of the page:
name
}
mode
bikesAllowed
}
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.opentripplanner.ext.gtfsgraphqlapi.mapping;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import org.junit.jupiter.api.Test;
import org.opentripplanner.transit.model.network.BikeAccess;

class BikesAllowedMapperTest {

@Test
void mapping() {
Arrays
.stream(BikeAccess.values())
.filter(ba -> ba != BikeAccess.UNKNOWN)
.forEach(d -> {
var mapped = BikesAllowedMapper.map(d);
assertEquals(d.toString(), mapped.toString());
});
}
}
42 changes: 28 additions & 14 deletions src/ext-test/resources/gtfsgraphqlapi/expectations/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "CARPOOL"
"mode" : "CARPOOL",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for SUBWAY",
Expand All @@ -19,7 +20,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "SUBWAY"
"mode" : "SUBWAY",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for BUS",
Expand All @@ -29,7 +31,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "BUS"
"mode" : "BUS",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for FERRY",
Expand All @@ -39,7 +42,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "FERRY"
"mode" : "FERRY",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for COACH",
Expand All @@ -49,7 +53,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "COACH"
"mode" : "COACH",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for TRAM",
Expand All @@ -59,7 +64,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "TRAM"
"mode" : "TRAM",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for CABLE_CAR",
Expand All @@ -69,7 +75,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "CABLE_CAR"
"mode" : "CABLE_CAR",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for FUNICULAR",
Expand All @@ -79,7 +86,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "FUNICULAR"
"mode" : "FUNICULAR",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for RAIL",
Expand All @@ -89,7 +97,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "RAIL"
"mode" : "RAIL",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for MONORAIL",
Expand All @@ -99,7 +108,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "MONORAIL"
"mode" : "MONORAIL",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for GONDOLA",
Expand All @@ -109,7 +119,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "GONDOLA"
"mode" : "GONDOLA",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for TROLLEYBUS",
Expand All @@ -119,7 +130,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "TROLLEYBUS"
"mode" : "TROLLEYBUS",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for AIRPLANE",
Expand All @@ -129,7 +141,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "AIRPLANE"
"mode" : "AIRPLANE",
"bikesAllowed" : "NO_INFORMATION"
},
{
"longName" : "Long name for TAXI",
Expand All @@ -139,7 +152,8 @@
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "TAXI"
"mode" : "TAXI",
"bikesAllowed" : "NO_INFORMATION"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
name
}
mode
bikesAllowed
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.opentripplanner.ext.gtfsgraphqlapi.GraphQLUtils;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLDataFetchers;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLBikesAllowed;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLTransitMode;
import org.opentripplanner.ext.gtfsgraphqlapi.mapping.BikesAllowedMapper;
import org.opentripplanner.routing.alertpatch.EntitySelector;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.routing.services.TransitAlertService;
Expand Down Expand Up @@ -131,13 +133,8 @@ public DataFetcher<Iterable<TransitAlert>> alerts() {
}

@Override
public DataFetcher<String> bikesAllowed() {
return environment ->
switch (getSource(environment).getBikesAllowed()) {
case UNKNOWN -> "NO_INFORMATION";
case ALLOWED -> "POSSIBLE";
case NOT_ALLOWED -> "NOT_POSSIBLE";
};
public DataFetcher<GraphQLBikesAllowed> bikesAllowed() {
return environment -> BikesAllowedMapper.map(getSource(environment).getBikesAllowed());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.opentripplanner.ext.gtfsgraphqlapi.GraphQLUtils;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLDataFetchers;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLBikesAllowed;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLWheelchairBoarding;
import org.opentripplanner.ext.gtfsgraphqlapi.mapping.BikesAllowedMapper;
import org.opentripplanner.framework.time.ServiceDateUtils;
import org.opentripplanner.model.Timetable;
import org.opentripplanner.model.TripTimeOnDate;
Expand Down Expand Up @@ -165,13 +167,8 @@ public DataFetcher<TripTimeOnDate> arrivalStoptime() {
}

@Override
public DataFetcher<String> bikesAllowed() {
return environment ->
switch (getSource(environment).getBikesAllowed()) {
case UNKNOWN -> "NO_INFORMATION";
case ALLOWED -> "POSSIBLE";
case NOT_ALLOWED -> "NOT_POSSIBLE";
};
public DataFetcher<GraphQLBikesAllowed> bikesAllowed() {
return environment -> BikesAllowedMapper.map(getSource(environment).getBikesAllowed());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLAlertCauseType;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLAlertEffectType;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLAlertSeverityLevelType;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLBikesAllowed;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLInputField;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLRelativeDirection;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLRoutingErrorCode;
Expand Down Expand Up @@ -309,9 +310,12 @@ public interface GraphQLDefaultFareProduct {
}

/**
* Departure row is a location, which lists departures of a certain pattern from a
* stop. Departure rows are identified with the pattern, so querying departure rows
* will return only departures from one stop per pattern
* Departure row is a combination of a pattern and a stop of that pattern.
*
* They are de-duplicated so for each pattern there will only be a single departure row.
*
* This is useful if you want to show a list of stop/pattern combinations but want each pattern to be
* listed only once.
*/
public interface GraphQLDepartureRow {
public DataFetcher<graphql.relay.Relay.ResolvedGlobalId> id();
Expand Down Expand Up @@ -789,7 +793,7 @@ public interface GraphQLRoute {

public DataFetcher<Iterable<TransitAlert>> alerts();

public DataFetcher<String> bikesAllowed();
public DataFetcher<GraphQLBikesAllowed> bikesAllowed();

public DataFetcher<String> color();

Expand Down Expand Up @@ -1015,7 +1019,7 @@ public interface GraphQLTrip {

public DataFetcher<TripTimeOnDate> arrivalStoptime();

public DataFetcher<String> bikesAllowed();
public DataFetcher<GraphQLBikesAllowed> bikesAllowed();

public DataFetcher<String> blockId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ config:
VehicleRentalStation: org.opentripplanner.service.vehiclerental.model.VehicleRentalStation#VehicleRentalStation
RentalVehicle: org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle#VehicleRentalVehicle
VehicleRentalUris: org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris#VehicleRentalStationUris
BikesAllowed: String
BikesAllowed: org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLBikesAllowed#GraphQLBikesAllowed
BookingInfo: org.opentripplanner.model.BookingInfo
BookingTime: org.opentripplanner.model.BookingTime
CarPark: org.opentripplanner.routing.vehicle_parking.VehicleParking#VehicleParking
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.opentripplanner.ext.gtfsgraphqlapi.mapping;

import javax.annotation.Nonnull;
import org.opentripplanner.ext.gtfsgraphqlapi.generated.GraphQLTypes.GraphQLBikesAllowed;
import org.opentripplanner.transit.model.network.BikeAccess;

public class BikesAllowedMapper {

@Nonnull
public static GraphQLBikesAllowed map(@Nonnull BikeAccess bikesAllowed) {
return switch (bikesAllowed) {
case UNKNOWN -> GraphQLBikesAllowed.NO_INFORMATION;
case ALLOWED -> GraphQLBikesAllowed.ALLOWED;
case NOT_ALLOWED -> GraphQLBikesAllowed.NOT_ALLOWED;
};
}
}