diff --git a/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLPatternImpl.java b/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLPatternImpl.java index ea9fd5476cd..4c0f1d46ebd 100644 --- a/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLPatternImpl.java +++ b/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLPatternImpl.java @@ -39,7 +39,7 @@ public DataFetcher route() { @Override public DataFetcher directionId() { - return environment -> getSource(environment).directionId; + return environment -> getSource(environment).getDirection().gtfsCode; } @Override @@ -54,7 +54,7 @@ public DataFetcher code() { @Override public DataFetcher headsign() { - return environment -> getSource(environment).getDirection(); + return environment -> getSource(environment).getTripHeadsign(); } @Override diff --git a/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLTripImpl.java b/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLTripImpl.java index ec3601b090e..2c6f7ab1601 100644 --- a/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLTripImpl.java +++ b/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLTripImpl.java @@ -79,7 +79,7 @@ public DataFetcher routeShortName() { @Override public DataFetcher directionId() { - return environment -> getSource(environment).getDirectionId(); + return environment -> getSource(environment).getGtfsDirectionIdAsString(null); } @Override diff --git a/src/ext/java/org/opentripplanner/ext/siri/SiriTripPatternIdGenerator.java b/src/ext/java/org/opentripplanner/ext/siri/SiriTripPatternIdGenerator.java index b47053f4c7a..d42877b7591 100644 --- a/src/ext/java/org/opentripplanner/ext/siri/SiriTripPatternIdGenerator.java +++ b/src/ext/java/org/opentripplanner/ext/siri/SiriTripPatternIdGenerator.java @@ -26,8 +26,7 @@ class SiriTripPatternIdGenerator { FeedScopedId generateUniqueTripPatternId(Trip trip) { Route route = trip.getRoute(); FeedScopedId routeId = route.getId(); - String directionId = trip.getDirectionId(); - if( directionId == null) { directionId = ""; } + String directionId = trip.getGtfsDirectionIdAsString(""); // OBA library uses underscore as separator, we're moving toward colon. String id = String.format("%s:%s:%03d:RT", routeId.getId(), directionId, counter.incrementAndGet()); diff --git a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java index a605fdfa877..de287b9306c 100644 --- a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java +++ b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java @@ -1,6 +1,7 @@ package org.opentripplanner.ext.transmodelapi.model; import graphql.schema.GraphQLEnumType; +import org.opentripplanner.model.Direction; import org.opentripplanner.model.TransitMode; import org.opentripplanner.model.plan.AbsoluteDirection; import org.opentripplanner.model.plan.RelativeDirection; @@ -235,11 +236,11 @@ public class EnumTypes { public static GraphQLEnumType DIRECTION_TYPE = GraphQLEnumType.newEnum() .name("DirectionType") - .value("unknown",-1) - .value("outbound", 0) - .value("inbound", 1) - .value("clockwise", 2) - .value("anticlockwise", 3) + .value("unknown", Direction.UNKNOWN) + .value("outbound", Direction.OUTBOUND) + .value("inbound", Direction.INBOUND) + .value("clockwise", Direction.CLOCKWISE) + .value("anticlockwise", Direction.ANTICLOCKWISE) .build(); public static Object enumToString(GraphQLEnumType type, Enum value) { diff --git a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/network/JourneyPatternType.java b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/network/JourneyPatternType.java index 5c16d148219..cfee2b100b7 100644 --- a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/network/JourneyPatternType.java +++ b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/network/JourneyPatternType.java @@ -42,7 +42,7 @@ public static GraphQLObjectType create( .field(GraphQLFieldDefinition.newFieldDefinition() .name("directionType") .type(EnumTypes.DIRECTION_TYPE) - .dataFetcher(environment -> ((TripPattern) environment.getSource()).directionId) + .dataFetcher(environment -> ((TripPattern) environment.getSource()).getDirection()) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name("name") diff --git a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/timetable/ServiceJourneyType.java b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/timetable/ServiceJourneyType.java index 11c9da75b82..a845a39271b 100644 --- a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/timetable/ServiceJourneyType.java +++ b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/timetable/ServiceJourneyType.java @@ -89,13 +89,12 @@ public static GraphQLObjectType create( .field(GraphQLFieldDefinition.newFieldDefinition() .name("operator") .type(operatorType) - .dataFetcher( - environment -> ((trip(environment)).getOperator())) + .dataFetcher(environment -> ((trip(environment)).getOperator())) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name("directionType") .type(EnumTypes.DIRECTION_TYPE) - .dataFetcher(environment -> directIdStringToInt(((Trip) trip(environment)).getDirectionId())) + .dataFetcher(environment -> trip(environment).getDirection()) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name("wheelchairAccessible") @@ -209,12 +208,4 @@ public static GraphQLObjectType create( private static Trip trip(DataFetchingEnvironment environment) { return environment.getSource(); } - - private static int directIdStringToInt(String directionId) { - try { - return Integer.parseInt(directionId); - } catch (NumberFormatException nfe) { - return -1; - } - } } diff --git a/src/main/java/org/opentripplanner/api/mapping/TripMapper.java b/src/main/java/org/opentripplanner/api/mapping/TripMapper.java index 0e44870cfec..469f56db601 100644 --- a/src/main/java/org/opentripplanner/api/mapping/TripMapper.java +++ b/src/main/java/org/opentripplanner/api/mapping/TripMapper.java @@ -20,7 +20,7 @@ public static ApiTrip mapToApi(Trip obj) { api.tripShortName = obj.getTripShortName(); api.tripHeadsign = obj.getTripHeadsign(); api.routeShortName = obj.getRouteShortName(); - api.directionId = obj.getDirectionId(); + api.directionId = obj.getGtfsDirectionIdAsString(null); api.blockId = obj.getBlockId(); api.shapeId = FeedScopedIdMapper.mapToApi(obj.getShapeId()); api.wheelchairAccessible = obj.getWheelchairAccessible(); @@ -42,7 +42,7 @@ public static ApiTripShort mapToApiShort(Trip domain) { // TODO OTP2 - All ids should be fully qualified including feed scope id. api.shapeId = shape == null ? null : shape.getId(); - api.direction = directionToApi(domain.getDirectionId()); + api.direction = domain.getDirection().gtfsCode; return api; } @@ -51,9 +51,4 @@ public static List mapToApiShort(Collection domain) { if(domain == null) { return null; } return domain.stream().map(TripMapper::mapToApiShort).collect(Collectors.toList()); } - - - private static Integer directionToApi(String directionId) { - return directionId == null ? null : Integer.parseInt(directionId); - } } diff --git a/src/main/java/org/opentripplanner/gtfs/GenerateTripPatternsOperation.java b/src/main/java/org/opentripplanner/gtfs/GenerateTripPatternsOperation.java index e86be7bdd78..2a27a224e75 100644 --- a/src/main/java/org/opentripplanner/gtfs/GenerateTripPatternsOperation.java +++ b/src/main/java/org/opentripplanner/gtfs/GenerateTripPatternsOperation.java @@ -7,6 +7,7 @@ import org.opentripplanner.graph_builder.issues.GTFSModeNotSupported; import org.opentripplanner.graph_builder.issues.TripDegenerate; import org.opentripplanner.graph_builder.issues.TripUndefinedService; +import org.opentripplanner.model.Direction; import org.opentripplanner.model.FeedScopedId; import org.opentripplanner.model.Frequency; import org.opentripplanner.model.Route; @@ -35,9 +36,6 @@ public class GenerateTripPatternsOperation { private final Map tripPatternIdCounters = new HashMap<>(); - - private static final int UNKNOWN_DIRECTION_ID = -1; - private final OtpTransitServiceBuilder transitDaoBuilder; private final DataImportIssueStore issueStore; private final Deduplicator deduplicator; @@ -114,7 +112,6 @@ private void buildTripPatternForTrip(Trip trip) { return; // Invalid trip, skip it, it will break later } - int directionId = getDirectionId(trip); Collection stopTimes = transitDaoBuilder.getStopTimesSortedByTrip().get(trip); // If after filtering this trip does not contain at least 2 stoptimes, it does not serve any purpose. @@ -126,8 +123,9 @@ private void buildTripPatternForTrip(Trip trip) { // Get the existing TripPattern for this filtered StopPattern, or create one. StopPattern stopPattern = new StopPattern(stopTimes); + Direction direction = trip.getDirection(); TripPattern tripPattern = findOrCreateTripPattern( - stopPattern, trip.getRoute(), directionId + stopPattern, trip.getRoute(), direction ); // Create a TripTimes object for this list of stoptimes, which form one trip. @@ -150,27 +148,14 @@ private void buildTripPatternForTrip(Trip trip) { } } - /** - * Try to get the direction id for the trip, set to UNKNOWN if not found - */ - private int getDirectionId(Trip trip) { - try { - return Integer.parseInt(trip.getDirectionId()); - } catch (NumberFormatException e) { - LOG.debug("Trip {} does not have direction id, defaults to -1", trip); - } - return UNKNOWN_DIRECTION_ID; - } - - private TripPattern findOrCreateTripPattern(StopPattern stopPattern, Route route, int directionId) { + private TripPattern findOrCreateTripPattern(StopPattern stopPattern, Route route, Direction direction) { for(TripPattern tripPattern : tripPatterns.get(stopPattern)) { - if(tripPattern.route.equals(route) && tripPattern.directionId == directionId) { + if(tripPattern.route.equals(route) && tripPattern.getDirection().equals(direction)) { return tripPattern; } } - FeedScopedId patternId = generateUniqueIdForTripPattern(route, directionId); + FeedScopedId patternId = generateUniqueIdForTripPattern(route, direction.gtfsCode); TripPattern tripPattern = new TripPattern(patternId, route, stopPattern); - tripPattern.directionId = directionId; tripPatterns.put(stopPattern, tripPattern); return tripPattern; } diff --git a/src/main/java/org/opentripplanner/gtfs/mapping/TripMapper.java b/src/main/java/org/opentripplanner/gtfs/mapping/TripMapper.java index 2f97e3f938a..099e453a479 100644 --- a/src/main/java/org/opentripplanner/gtfs/mapping/TripMapper.java +++ b/src/main/java/org/opentripplanner/gtfs/mapping/TripMapper.java @@ -1,8 +1,12 @@ package org.opentripplanner.gtfs.mapping; +import org.opentripplanner.model.Direction; import org.opentripplanner.model.Trip; import org.opentripplanner.util.MapUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -10,9 +14,11 @@ /** Responsible for mapping GTFS TripMapper into the OTP model. */ class TripMapper { + private static final Logger LOG = LoggerFactory.getLogger(TripMapper.class); + private final RouteMapper routeMapper; - private Map mappedTrips = new HashMap<>(); + private final Map mappedTrips = new HashMap<>(); TripMapper(RouteMapper routeMapper) { this.routeMapper = routeMapper; @@ -34,7 +40,7 @@ private Trip doMap(org.onebusaway.gtfs.model.Trip rhs) { lhs.setTripShortName(rhs.getTripShortName()); lhs.setTripHeadsign(rhs.getTripHeadsign()); lhs.setRouteShortName(rhs.getRouteShortName()); - lhs.setDirectionId(rhs.getDirectionId()); + lhs.setDirection(Direction.valueOfGtfsCode(mapDirectionId(rhs))); lhs.setBlockId(rhs.getBlockId()); lhs.setShapeId(AgencyAndIdMapper.mapAgencyAndId(rhs.getShapeId())); lhs.setWheelchairAccessible(rhs.getWheelchairAccessible()); @@ -45,4 +51,17 @@ private Trip doMap(org.onebusaway.gtfs.model.Trip rhs) { return lhs; } + @Nullable + private static int mapDirectionId(org.onebusaway.gtfs.model.Trip trip) { + try { + String directionId = trip.getDirectionId(); + if(directionId == null || directionId.isBlank()) { + return -1; + } + return Integer.parseInt(directionId); + } catch (NumberFormatException e) { + LOG.debug("Trip {} does not have direction id, defaults to -1", trip); + } + return -1; + } } diff --git a/src/main/java/org/opentripplanner/model/Direction.java b/src/main/java/org/opentripplanner/model/Direction.java new file mode 100644 index 00000000000..e23b37fb3cc --- /dev/null +++ b/src/main/java/org/opentripplanner/model/Direction.java @@ -0,0 +1,32 @@ +package org.opentripplanner.model; + +/** + * The direction of travel for a TripPattern. This is mapped 1-to-1 in NeTEx, while in GTFS + * only values 0 and 1 are available, so they are mapped to OUTBOUND and INBOUND. When mapping + * from the model to the REST API, CLOCKWISE and ANTICLOCKWISE are also mapped to 0 and 1 (as they + * would also fit the description in the GTFS specification). + */ +public enum Direction { + UNKNOWN(-1), + OUTBOUND(0), + INBOUND(1), + CLOCKWISE(0), + ANTICLOCKWISE(1); + + Direction(int gtfsCode) { + this.gtfsCode = gtfsCode; + } + + public final int gtfsCode; + + public static Direction valueOfGtfsCode(int gtfsCode) { + switch (gtfsCode) { + case 0: + return Direction.OUTBOUND; + case 1: + return Direction.INBOUND; + default: + return Direction.UNKNOWN; + } + } +} diff --git a/src/main/java/org/opentripplanner/model/Trip.java b/src/main/java/org/opentripplanner/model/Trip.java index f4296aff2cf..4eb6083ea20 100644 --- a/src/main/java/org/opentripplanner/model/Trip.java +++ b/src/main/java/org/opentripplanner/model/Trip.java @@ -1,6 +1,8 @@ /* This file is based on code copied from project OneBusAway, see the LICENSE file for further information. */ package org.opentripplanner.model; +import javax.validation.constraints.NotNull; + public final class Trip extends TransitEntity { private static final long serialVersionUID = 1L; @@ -19,7 +21,8 @@ public final class Trip extends TransitEntity { private String routeShortName; - private String directionId; + @NotNull + private Direction direction = Direction.UNKNOWN; private String blockId; @@ -49,7 +52,7 @@ public Trip(Trip obj) { this.tripShortName = obj.tripShortName; this.tripHeadsign = obj.tripHeadsign; this.routeShortName = obj.routeShortName; - this.directionId = obj.directionId; + this.direction = obj.direction; this.blockId = obj.blockId; this.shapeId = obj.shapeId; this.wheelchairAccessible = obj.wheelchairAccessible; @@ -133,12 +136,24 @@ public void setRouteShortName(String routeShortName) { this.routeShortName = routeShortName; } - public String getDirectionId() { - return directionId; + // TODO Consider moving this to the TripPattern class once we have refactored the transit model + /** + * The direction for this Trip (and all other Trips in this TripPattern). + */ + @NotNull + public Direction getDirection() { + return direction; + } + + public String getGtfsDirectionIdAsString(String unknownValue) { + return direction.equals(Direction.UNKNOWN) + ? unknownValue + : Integer.toString(direction.gtfsCode); } - public void setDirectionId(String directionId) { - this.directionId = directionId; + public void setDirection(Direction direction) { + // Enforce non-null + this.direction = direction != null ? direction : Direction.UNKNOWN; } public String getBlockId() { diff --git a/src/main/java/org/opentripplanner/model/TripPattern.java b/src/main/java/org/opentripplanner/model/TripPattern.java index 162308636dd..b0eecb1b71e 100644 --- a/src/main/java/org/opentripplanner/model/TripPattern.java +++ b/src/main/java/org/opentripplanner/model/TripPattern.java @@ -67,12 +67,6 @@ public class TripPattern extends TransitEntity implements Cloneable, Serializabl */ public final Route route; - /** - * The direction id for all trips in this pattern. - * Use -1 for default direction id - */ - public int directionId = -1; - /** * All trips in this pattern call at this sequence of stops. This includes information about GTFS * pick-up and drop-off types. @@ -352,6 +346,13 @@ public void setOriginalTripPattern(TripPattern originalTripPattern) { this.originalTripPattern = originalTripPattern; } + /** + * The direction for all the trips in this pattern. + */ + public Direction getDirection() { + return trips.get(0).getDirection(); + } + boolean isCreatedByRealtimeUpdater() { return createdByRealtimeUpdater; } @@ -555,7 +556,7 @@ public void setServices(BitSet services) { this.services = services; } - public String getDirection() { + public String getTripHeadsign() { return trips.get(0).getTripHeadsign(); } diff --git a/src/main/java/org/opentripplanner/netex/mapping/DirectionMapper.java b/src/main/java/org/opentripplanner/netex/mapping/DirectionMapper.java new file mode 100644 index 00000000000..85f79f7cab9 --- /dev/null +++ b/src/main/java/org/opentripplanner/netex/mapping/DirectionMapper.java @@ -0,0 +1,22 @@ +package org.opentripplanner.netex.mapping; + +import org.opentripplanner.model.Direction; +import org.rutebanken.netex.model.DirectionTypeEnumeration; + +class DirectionMapper { + static Direction map(DirectionTypeEnumeration direction) { + if (direction == null) { return Direction.UNKNOWN; } + switch (direction) { + case INBOUND: + return Direction.INBOUND; + case OUTBOUND: + return Direction.OUTBOUND; + case CLOCKWISE: + return Direction.CLOCKWISE; + case ANTICLOCKWISE: + return Direction.ANTICLOCKWISE; + default: + return Direction.UNKNOWN; + } + } +} diff --git a/src/main/java/org/opentripplanner/netex/mapping/TripMapper.java b/src/main/java/org/opentripplanner/netex/mapping/TripMapper.java index 0c9d0f5b453..932a593a3f6 100644 --- a/src/main/java/org/opentripplanner/netex/mapping/TripMapper.java +++ b/src/main/java/org/opentripplanner/netex/mapping/TripMapper.java @@ -6,6 +6,7 @@ import org.opentripplanner.model.impl.EntityById; import org.opentripplanner.netex.index.api.ReadOnlyHierarchicalMap; import org.opentripplanner.netex.mapping.support.FeedScopedIdFactory; +import org.rutebanken.netex.model.DirectionTypeEnumeration; import org.rutebanken.netex.model.JourneyPattern; import org.rutebanken.netex.model.LineRefStructure; import org.rutebanken.netex.model.Route; @@ -86,9 +87,20 @@ Trip mapServiceJourney(ServiceJourney serviceJourney){ trip.setTripShortName(serviceJourney.getPublicCode()); trip.setTripOperator(findOperator(serviceJourney)); + trip.setDirection(DirectionMapper.map(resolveDirectionType(serviceJourney))); + return trip; } + private DirectionTypeEnumeration resolveDirectionType(ServiceJourney serviceJourney) { + Route netexRoute = lookUpNetexRoute(serviceJourney); + if (netexRoute != null && netexRoute.getDirectionType() != null) { + return netexRoute.getDirectionType(); + } else { + return null; + } + } + @Nullable private FeedScopedId getShapeId(ServiceJourney serviceJourney) { JourneyPattern journeyPattern = journeyPatternsById.lookup( @@ -101,6 +113,20 @@ private FeedScopedId getShapeId(ServiceJourney serviceJourney) { return shapePointIds.contains(serviceLinkId) ? serviceLinkId : null; } + private Route lookUpNetexRoute(ServiceJourney serviceJourney) { + if(serviceJourney.getJourneyPatternRef() != null) { + JourneyPattern journeyPattern = journeyPatternsById.lookup(serviceJourney + .getJourneyPatternRef() + .getValue() + .getRef()); + if (journeyPattern != null && journeyPattern.getRouteRef() != null) { + String routeRef = journeyPattern.getRouteRef().getRef(); + return routeById.lookup(routeRef); + } + } + return null; + } + private org.opentripplanner.model.Route resolveRoute(ServiceJourney serviceJourney) { String lineRef = null; // Check for direct connection to Line diff --git a/src/main/java/org/opentripplanner/updater/GtfsRealtimeFuzzyTripMatcher.java b/src/main/java/org/opentripplanner/updater/GtfsRealtimeFuzzyTripMatcher.java index bcac418453e..575b3418f1b 100644 --- a/src/main/java/org/opentripplanner/updater/GtfsRealtimeFuzzyTripMatcher.java +++ b/src/main/java/org/opentripplanner/updater/GtfsRealtimeFuzzyTripMatcher.java @@ -80,7 +80,7 @@ public synchronized Trip getTrip (Route route, int direction, int startTime, Ser this.servicesRunningForDate = routingService.getServicesRunningForDate(date); } for (TripPattern pattern : routingService.getPatternsForRoute().get(route)) { - if (pattern.directionId != direction) continue; + if (pattern.getDirection().gtfsCode != direction) continue; for (TripTimes times : pattern.scheduledTimetable.tripTimes) { if (times.getScheduledDepartureTime(0) == startTime && servicesRunningForDate.get(times.serviceCode)) { diff --git a/src/main/java/org/opentripplanner/updater/stoptime/TripPatternCache.java b/src/main/java/org/opentripplanner/updater/stoptime/TripPatternCache.java index 4b30634df8e..aaa5c323fa3 100644 --- a/src/main/java/org/opentripplanner/updater/stoptime/TripPatternCache.java +++ b/src/main/java/org/opentripplanner/updater/stoptime/TripPatternCache.java @@ -1,5 +1,6 @@ package org.opentripplanner.updater.stoptime; +import org.opentripplanner.gtfs.GenerateTripPatternsOperation; import org.opentripplanner.model.FeedScopedId; import org.opentripplanner.model.Route; import org.opentripplanner.model.StopPattern; @@ -45,7 +46,7 @@ public synchronized TripPattern getOrCreateTripPattern( // Create TripPattern if it doesn't exist yet if (tripPattern == null) { // Generate unique code for trip pattern - var id = new FeedScopedId(route.getId().getFeedId(), generateUniqueTripPatternCode(tripPattern)); + var id = generateUniqueTripPatternCode(trip); tripPattern = new TripPattern(id, route, stopPattern); @@ -74,22 +75,18 @@ public synchronized TripPattern getOrCreateTripPattern( /** * Generate unique trip pattern code for real-time added trip pattern. This function roughly - * follows the format of {@link TripPattern#generateUniqueIds(java.util.Collection)}. - * - * @param tripPattern trip pattern to generate code for - * @return unique trip pattern code + * follows the format of the {@link GenerateTripPatternsOperation}. */ - private String generateUniqueTripPatternCode(TripPattern tripPattern) { - FeedScopedId routeId = tripPattern.route.getId(); - String direction = tripPattern.directionId != -1 ? String.valueOf(tripPattern.directionId) : ""; + private FeedScopedId generateUniqueTripPatternCode(Trip trip) { + FeedScopedId routeId = trip.getRoute().getId(); + String directionId = trip.getGtfsDirectionIdAsString(""); if (counter == Integer.MAX_VALUE) { counter = 0; } else { counter++; } // OBA library uses underscore as separator, we're moving toward colon. - String code = String.format("%s:%s:%s:rt#%d", routeId.getFeedId(), routeId.getId(), direction, counter); - return code; + String code = String.format("%s:%s:%s:rt#%d", routeId.getFeedId(), routeId.getId(), directionId, counter); + return new FeedScopedId(trip.getId().getFeedId(), code); } - } diff --git a/src/test/java/org/opentripplanner/gtfs/mapping/TripMapperTest.java b/src/test/java/org/opentripplanner/gtfs/mapping/TripMapperTest.java index 6ed3f1188ff..33a4a17c3a1 100644 --- a/src/test/java/org/opentripplanner/gtfs/mapping/TripMapperTest.java +++ b/src/test/java/org/opentripplanner/gtfs/mapping/TripMapperTest.java @@ -22,7 +22,7 @@ public class TripMapperTest { private static final String BLOCK_ID = "Block Id"; - private static final String DIRECTION_ID = "Direction Id"; + private static final int DIRECTION_ID = 1; private static final String FARE_ID = "Fare Id"; @@ -46,7 +46,7 @@ public class TripMapperTest { TRIP.setId(AGENCY_AND_ID); TRIP.setBikesAllowed(BIKES_ALLOWED); TRIP.setBlockId(BLOCK_ID); - TRIP.setDirectionId(DIRECTION_ID); + TRIP.setDirectionId(Integer.toString(DIRECTION_ID)); TRIP.setFareId(FARE_ID); TRIP.setRoute(ROUTE); TRIP.setRouteShortName(ROUTE_SHORT_NAME); @@ -74,7 +74,7 @@ public void testMap() throws Exception { assertEquals("A:1", result.getId().toString()); assertEquals(BIKES_ALLOWED, result.getBikesAllowed()); assertEquals(BLOCK_ID, result.getBlockId()); - assertEquals(DIRECTION_ID, result.getDirectionId()); + assertEquals(DIRECTION_ID, result.getDirection().gtfsCode); assertEquals(FARE_ID, result.getFareId()); assertNotNull(result.getRoute()); assertEquals(ROUTE_SHORT_NAME, result.getRouteShortName()); @@ -96,7 +96,6 @@ public void testMapWithNulls() throws Exception { assertNotNull(result.getId()); assertEquals(0, result.getBikesAllowed()); assertNull(result.getBlockId()); - assertNull(result.getDirectionId()); assertNull(result.getFareId()); assertNull(result.getRoute()); assertNull(result.getRouteShortName()); @@ -104,6 +103,7 @@ public void testMapWithNulls() throws Exception { assertNull(result.getShapeId()); assertNull(result.getTripHeadsign()); assertNull(result.getTripShortName()); + assertEquals(-1, result.getDirection().gtfsCode); assertEquals(0, result.getWheelchairAccessible()); assertEquals(0, result.getTripBikesAllowed()); } diff --git a/src/test/java/org/opentripplanner/model/impl/OtpTransitServiceBuilderLimitPeriodTest.java b/src/test/java/org/opentripplanner/model/impl/OtpTransitServiceBuilderLimitPeriodTest.java index bf341258c17..6a12ff3aa92 100644 --- a/src/test/java/org/opentripplanner/model/impl/OtpTransitServiceBuilderLimitPeriodTest.java +++ b/src/test/java/org/opentripplanner/model/impl/OtpTransitServiceBuilderLimitPeriodTest.java @@ -2,6 +2,7 @@ import org.junit.Before; import org.junit.Test; +import org.opentripplanner.model.Direction; import org.opentripplanner.model.FeedScopedId; import org.opentripplanner.model.Route; import org.opentripplanner.model.Stop; @@ -188,7 +189,7 @@ private static ServiceCalendar createServiceCalendar( private Trip createTrip(String id, FeedScopedId serviceId) { Trip trip = new Trip(new FeedScopedId(FEED_ID, id)); trip.setServiceId(serviceId); - trip.setDirectionId("1"); + trip.setDirection(Direction.valueOfGtfsCode(1)); trip.setRoute(route); return trip; } diff --git a/src/test/java/org/opentripplanner/netex/NetexBundleSmokeTest.java b/src/test/java/org/opentripplanner/netex/NetexBundleSmokeTest.java index f8da6243e6b..6361b7713c6 100644 --- a/src/test/java/org/opentripplanner/netex/NetexBundleSmokeTest.java +++ b/src/test/java/org/opentripplanner/netex/NetexBundleSmokeTest.java @@ -136,7 +136,7 @@ private void assertStations(Collection stations) { private void assertTripPatterns(Collection patterns) { Map map = patterns.stream().collect(Collectors.toMap(TripPattern::getId, s -> s)); TripPattern p = map.get(fId("RUT:JourneyPattern:12-1")); - assertEquals("Jernbanetorget", p.getDirection()); + assertEquals("Jernbanetorget", p.getTripHeadsign()); assertEquals("RB", p.getFeedId()); assertEquals("[, ]", p.getStops().toString()); assertEquals("[]", p.getTrips().toString());