Skip to content

Commit

Permalink
fix #6242
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Nov 8, 2024
1 parent b6646f7 commit 36ef65d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public DataFetcher<Iterable<TransitAlert>> alerts() {
.anyMatch(entity ->
(
entity instanceof EntitySelector.StopAndRoute stopAndRoute &&
stopAndRoute.routeId().equals(getRoute(environment).getId())
stopAndRoute.routeId().equals(getRoute(environment).getId())
) ||
(
entity instanceof EntitySelector.StopAndTrip stopAndTrip &&
stopAndTrip.tripId().equals(getSource(environment).getId())
)
(
entity instanceof EntitySelector.StopAndTrip stopAndTrip &&
stopAndTrip.tripId().equals(getSource(environment).getId())
)
)
)
.toList()
Expand Down Expand Up @@ -143,7 +143,7 @@ public DataFetcher<TripTimeOnDate> arrivalStoptime() {
}
}

TripPattern tripPattern = getTripPattern(environment);
TripPattern tripPattern = getTripPattern(environment, serviceDate);
if (tripPattern == null) {
return null;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public DataFetcher<TripTimeOnDate> departureStoptime() {
}
}

TripPattern tripPattern = getTripPattern(environment);
TripPattern tripPattern = getTripPattern(environment, serviceDate);
if (tripPattern == null) {
return null;
}
Expand Down Expand Up @@ -301,7 +301,7 @@ public DataFetcher<Iterable<TripTimeOnDate>> stoptimesForDate() {
? ServiceDateUtils.parseString(args.getGraphQLServiceDate())
: LocalDate.now(timeZone);

TripPattern tripPattern = transitService.getPatternForTrip(trip, serviceDate);
TripPattern tripPattern = getTripPattern(environment, serviceDate);
// no matching pattern found
if (tripPattern == null) {
return List.of();
Expand Down Expand Up @@ -376,6 +376,15 @@ private TripPattern getTripPattern(DataFetchingEnvironment environment) {
return getTransitService(environment).getPatternForTrip(environment.getSource());
}

private TripPattern getTripPattern(
DataFetchingEnvironment environment,
@Nullable LocalDate date
) {
return date == null
? getTripPattern(environment)
: getTransitService(environment).getPatternForTrip(environment.getSource(), date);
}

private TransitService getTransitService(DataFetchingEnvironment environment) {
return environment.<GraphQLRequestContext>getContext().transitService();
}
Expand All @@ -389,17 +398,28 @@ private TripTimeOnDate getStoptimeAtIndex(
@Nullable LocalDate serviceDate,
int stopIndex
) {
var tripPattern = getTripPattern(environment);
var tripPattern = getTripPattern(environment, serviceDate);
var transitService = getTransitService(environment);
var timetable = serviceDate != null
? transitService.getTimetableForTripPattern(tripPattern, serviceDate)
: tripPattern.getScheduledTimetable();
if (timetable == null) {
return null;
}

var tripTimes = timetable.getTripTimes(getSource(environment));
if (tripTimes == null) {
return null;
}

return new TripTimeOnDate(
tripPattern.getScheduledTimetable().getTripTimes(getSource(environment)),
tripTimes,
stopIndex,
tripPattern,
serviceDate,
serviceDate == null
? null
: ServiceDateUtils
.asStartOfService(serviceDate, getTransitService(environment).getTimeZone())
.toInstant()
: ServiceDateUtils.asStartOfService(serviceDate, transitService.getTimeZone()).toInstant()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ public TripTimeOnDate(
/**
* Must pass in both Timetable and Trip, because TripTimes do not have a reference to
* StopPatterns.
*
* @return null if the trip does not exist in the timetable
*/
@Nullable
public static List<TripTimeOnDate> fromTripTimes(Timetable table, Trip trip) {
TripTimes times = table.getTripTimes(trip);
if (times == null) {
return null;
}
List<TripTimeOnDate> out = new ArrayList<>();
for (int i = 0; i < times.getNumStops(); ++i) {
out.add(new TripTimeOnDate(times, i, table.getPattern()));
Expand All @@ -78,14 +84,20 @@ public static List<TripTimeOnDate> fromTripTimes(Timetable table, Trip trip) {
* StopPatterns.
*
* @param serviceDate service day to set, if null none is set
* @return null if the trip does not exist in the timetable
*/

@Nullable
public static List<TripTimeOnDate> fromTripTimes(
Timetable table,
Trip trip,
LocalDate serviceDate,
Instant midnight
) {
TripTimes times = table.getTripTimes(trip);
if (times == null) {
return null;
}
List<TripTimeOnDate> out = new ArrayList<>();
for (int i = 0; i < times.getNumStops(); ++i) {
out.add(new TripTimeOnDate(times, i, table.getPattern(), serviceDate, midnight));
Expand Down

0 comments on commit 36ef65d

Please sign in to comment.