Skip to content

Commit

Permalink
refactor(Fixed merge conflicts):
Browse files Browse the repository at this point in the history
  • Loading branch information
br648 committed Oct 29, 2024
2 parents 4df263b + a5fe446 commit f135775
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import static org.opentripplanner.middleware.utils.ConfigUtils.getConfigPropertyAsInt;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getFirstLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getRouteIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getRouteGtfsIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.isBusLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.legsMatch;
import static org.opentripplanner.middleware.utils.JsonUtils.logMessageAndHalt;
Expand Down Expand Up @@ -180,7 +180,7 @@ private static void cancelBusNotification(TravelerPosition travelerPosition, Iti
*/
public static Leg getLegToCancel(TravelerPosition travelerPosition, Leg firstLegOfTrip) {
if (legsMatch(travelerPosition.expectedLeg, firstLegOfTrip) && isBusLeg(travelerPosition.expectedLeg)) {
var routeId = getRouteIdFromLeg(travelerPosition.expectedLeg);
var routeId = getRouteGtfsIdFromLeg(travelerPosition.expectedLeg);
if (routeId != null && travelerPosition.trackedJourney.busNotificationMessages.containsKey(routeId)) {
return firstLegOfTrip;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.io.InputStream;
import java.util.List;

import static org.opentripplanner.middleware.utils.ItineraryUtils.getAgencyIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getAgencyGtfsIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.removeAgencyPrefix;

/** Holds configured bus notification actions. */
Expand Down Expand Up @@ -49,7 +49,7 @@ public BusOperatorActions(List<AgencyAction> agencyActions) {
* Get the action that matches the given agency id.
*/
public AgencyAction getAgencyAction(Leg busLeg) {
String agencyId = removeAgencyPrefix(getAgencyIdFromLeg(busLeg));
String agencyId = removeAgencyPrefix(getAgencyGtfsIdFromLeg(busLeg));
if (agencyId != null) {
for (AgencyAction agencyAction : agencyActions) {
if (agencyAction.agencyId.equalsIgnoreCase(agencyId)) {
Expand All @@ -73,6 +73,8 @@ public void handleSendNotificationAction(TravelerPosition travelerPosition, Leg
LOG.error("Could not trigger class {} for agency {}", action.trigger, action.agencyId, e);
throw new RuntimeException(e);
}
} else {
LOG.warn("No bus notification action was found for location {}.", travelerPosition.currentPosition);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import java.util.Map;

import static org.opentripplanner.middleware.utils.DateTimeUtils.getOtpZoneId;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getAgencyIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getRouteIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getStopIdFromPlace;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getTripIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getAgencyGtfsIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getRouteGtfsIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getStopGtfsIdFromPlace;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getTripGtfsIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.removeAgencyPrefix;

/**
Expand Down Expand Up @@ -81,15 +81,15 @@ private static Map<String, Integer> createMobilityCodesLookup() {
public UsRideGwinnettBusOpNotificationMessage(Instant currentTime, TravelerPosition travelerPosition) {
var nextLeg = travelerPosition.nextLeg;
this.timestamp = BUS_OPERATOR_NOTIFIER_API_DATE_FORMAT.format(currentTime.atZone(ZoneOffset.UTC));
this.agency_id = removeAgencyPrefix(getAgencyIdFromLeg(nextLeg));
this.from_route_id = removeAgencyPrefix(getRouteIdFromLeg(nextLeg));
this.from_trip_id = removeAgencyPrefix(getTripIdFromLeg(nextLeg));
this.from_stop_id = removeAgencyPrefix(getStopIdFromPlace(nextLeg.from));
this.agency_id = removeAgencyPrefix(getAgencyGtfsIdFromLeg(nextLeg));
this.from_route_id = removeAgencyPrefix(getRouteGtfsIdFromLeg(nextLeg));
this.from_trip_id = removeAgencyPrefix(getTripGtfsIdFromLeg(nextLeg));
this.from_stop_id = removeAgencyPrefix(getStopGtfsIdFromPlace(nextLeg.from));
// For now, assume one notification request is made per transit leg.
// TODO: Determine how interlined legs should be handled.
this.to_route_id = this.from_route_id;
this.to_trip_id = this.from_trip_id;
this.to_stop_id = removeAgencyPrefix(getStopIdFromPlace(nextLeg.to));
this.to_stop_id = removeAgencyPrefix(getStopGtfsIdFromPlace(nextLeg.to));
this.from_arrival_time = BUS_OPERATOR_NOTIFIER_API_TIME_FORMAT.format(
nextLeg.getScheduledStartTime()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Map;

import static org.opentripplanner.middleware.utils.ConfigUtils.getConfigPropertyAsText;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getRouteIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.getRouteGtfsIdFromLeg;
import static org.opentripplanner.middleware.utils.ItineraryUtils.isBusLeg;

/**
Expand Down Expand Up @@ -80,7 +80,7 @@ private static List<String> getBusOperatorNotifierQualifyingRoutes() {
* Stage notification to bus operator by making sure all required conditions are met.
*/
public void sendNotification(TravelerPosition travelerPosition, Leg busLeg) {
var routeId = getRouteIdFromLeg(busLeg);
var routeId = getRouteGtfsIdFromLeg(busLeg);
try {
if (
hasNotSentNotificationForRoute(travelerPosition.trackedJourney, routeId) &&
Expand All @@ -101,7 +101,7 @@ public void sendNotification(TravelerPosition travelerPosition, Leg busLeg) {
* Cancel a previously sent notification for the expected or next leg.
*/
public void cancelNotification(TravelerPosition travelerPosition, Leg busLeg) {
var routeId = getRouteIdFromLeg(busLeg);
var routeId = getRouteGtfsIdFromLeg(busLeg);
try {
if (
isBusLeg(busLeg) && routeId != null &&
Expand All @@ -128,6 +128,8 @@ public void cancelNotification(TravelerPosition travelerPosition, Leg busLeg) {
* Makes a call to the bus driver notification API, followed by a call to the bus priority API.
*/
private static void makeApiRequests(TravelerPosition travelerPosition, String body, String routeId, String action) {
LOG.info("Sending bus operator/priority requests: {}", body);

var httpStatus = postBusDriverNotification(body);
if (httpStatus == HttpStatus.OK_200) {
travelerPosition.trackedJourney.updateNotificationMessage(routeId, body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,38 +327,38 @@ public static String removeAgencyPrefix(String idParts) {
}

/**
* Get the route id from leg.
* Get the route GTFS id from leg.
*/
public static String getRouteIdFromLeg(Leg leg) {
return (leg != null) ? leg.routeId : null;
public static String getRouteGtfsIdFromLeg(Leg leg) {
return (leg != null && leg.route != null) ? leg.route.gtfsId : null;
}

/**
* Get the agency id from leg.
* Get the agency GTFS id from leg.
*/
public static String getAgencyIdFromLeg(Leg leg) {
return (leg != null) ? leg.agencyId : null;
public static String getAgencyGtfsIdFromLeg(Leg leg) {
return (leg != null && leg.agency != null) ? leg.agency.gtfsId : null;
}

/**
* Get the trip id from leg.
* Get the trip GTFS id from leg.
*/
public static String getTripIdFromLeg(Leg leg) {
return (leg != null) ? leg.tripId : null;
public static String getTripGtfsIdFromLeg(Leg leg) {
return (leg != null && leg.trip != null) ? leg.trip.gtfsId : null;
}

/**
* Get the stop id from place.
* Get the stop GTFS id from place.
*/
public static String getStopIdFromPlace(Place place) {
return (place != null) ? place.stopId : null;
public static String getStopGtfsIdFromPlace(Place place) {
return (place != null && place.stop != null) ? place.stop.gtfsId : null;
}

/**
* Get the route short name from leg.
*/
public static String getRouteShortNameFromLeg(Leg leg) {
return leg.routeShortName;
return (leg != null && leg.route != null) ? leg.route.shortName : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static Stream<Arguments> creatNotifyBusOperatorForScheduledDepartureTrac
void canGetCorrectLegToCancelNotification(Leg expected, Leg next, String message) {
Leg first = firstLegBusTransit.legs.get(0);
TrackedJourney journey = new TrackedJourney();
journey.busNotificationMessages.put("GwinnettCountyTransit:40", "{\"msg_type\": 1}");
journey.busNotificationMessages.put(routeId, "{\"msg_type\": 1}");
TravelerPosition travelerPosition = new TravelerPosition(expected, next, journey);
assertTrue(legsMatch(expected, ManageTripTracking.getLegToCancel(travelerPosition, first)), message);
}
Expand All @@ -128,7 +128,7 @@ private static Stream<Arguments> creatGetCorrectLegToCancelNotificationTrace() {
Arguments.of(
firstLegBusTransit.legs.get(1),
firstLegBusTransit.legs.get(1),
"Traveler is already passed the first leg, no need to cancel notification for first leg."
"Traveler has passed the first leg, no need to cancel notification for first leg."
)
);
}
Expand Down
Loading

0 comments on commit f135775

Please sign in to comment.