diff --git a/src/main/java/org/opentripplanner/middleware/i18n/Message.java b/src/main/java/org/opentripplanner/middleware/i18n/Message.java index 9f9eb590..a590b199 100644 --- a/src/main/java/org/opentripplanner/middleware/i18n/Message.java +++ b/src/main/java/org/opentripplanner/middleware/i18n/Message.java @@ -50,6 +50,8 @@ public enum Message { TRIP_INVITE_COMPANION, TRIP_INVITE_PRIMARY_TRAVELER, TRIP_INVITE_OBSERVER, + TRIP_NAME_UNDEFINED, + TRIP_TRAVELER_GENERIC_NAME, TRIP_NOT_FOUND_NOTIFICATION, TRIP_NO_LONGER_POSSIBLE_NOTIFICATION, TRIP_REMINDER_NOTIFICATION, diff --git a/src/main/java/org/opentripplanner/middleware/models/LegTransitionNotification.java b/src/main/java/org/opentripplanner/middleware/models/LegTransitionNotification.java new file mode 100644 index 00000000..d3efa746 --- /dev/null +++ b/src/main/java/org/opentripplanner/middleware/models/LegTransitionNotification.java @@ -0,0 +1,103 @@ +package org.opentripplanner.middleware.models; + +import org.opentripplanner.middleware.i18n.Message; +import org.opentripplanner.middleware.tripmonitor.jobs.NotificationType; +import org.opentripplanner.middleware.triptracker.TravelerPosition; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +public class LegTransitionNotification { + + public String travelerName; + public NotificationType notificationType; + public TravelerPosition travelerPosition; + public Locale observerLocale; + public TripMonitorNotification tripMonitorNotification; + + public LegTransitionNotification( + String travelerName, + NotificationType notificationType, + TravelerPosition travelerPosition, + Locale observerLocale + ) { + this.travelerName = travelerName; + this.notificationType = notificationType; + this.travelerPosition = travelerPosition; + this.observerLocale = observerLocale; + this.tripMonitorNotification = createTripMonitorNotification(notificationType); + } + + /** + * Create {@link TripMonitorNotification} for leg transition based on notification type. + */ + @Nullable + public TripMonitorNotification createTripMonitorNotification(NotificationType notificationType) { + String body; + switch (notificationType) { + case MODE_CHANGE_NOTIFICATION: + body = String.format( + Message.MODE_CHANGE_NOTIFICATION.get(travelerPosition.locale), + getTravelerName(), + travelerPosition.expectedLeg.mode, + travelerPosition.nextLeg.mode + ); + break; + case DEPARTED_NOTIFICATION: + body = String.format( + Message.DEPARTED_NOTIFICATION.get(observerLocale), + getTravelerName(), + travelerPosition.expectedLeg.from.name + ); + break; + case ARRIVED_NOTIFICATION: + body = String.format( + Message.ARRIVED_NOTIFICATION.get(travelerPosition.locale), + getTravelerName(), + travelerPosition.expectedLeg.to.name + ); + break; + default: + body = null; + } + return (body != null) ? new TripMonitorNotification(notificationType, body) : null; + } + + /** + * Get the traveler's name if available, if not provide a generic traveler name. + */ + private String getTravelerName() { + if (travelerName != null) { + return travelerName; + } else { + return Message.TRIP_TRAVELER_GENERIC_NAME.get(observerLocale); + } + } + + /** + * Create locale specific notifications. + */ + public static TripMonitorNotification[] createLegTransitionNotifications( + List legTransitionTypes, + String travelerName, + TravelerPosition travelerPosition, + Locale observerLocale + ) { + List tripMonitorNotifications = new ArrayList<>(); + // Create locale specific notifications. + for (NotificationType legTransitionType : legTransitionTypes) { + LegTransitionNotification legTransitionNotification = new LegTransitionNotification( + travelerName, + legTransitionType, + travelerPosition, + observerLocale + ); + if (legTransitionNotification.tripMonitorNotification != null) { + tripMonitorNotifications.add(legTransitionNotification.tripMonitorNotification); + } + } + return tripMonitorNotifications.toArray(new TripMonitorNotification[0]); + } +} diff --git a/src/main/java/org/opentripplanner/middleware/models/TripMonitorNotification.java b/src/main/java/org/opentripplanner/middleware/models/TripMonitorNotification.java index faaca35f..98597037 100644 --- a/src/main/java/org/opentripplanner/middleware/models/TripMonitorNotification.java +++ b/src/main/java/org/opentripplanner/middleware/models/TripMonitorNotification.java @@ -2,7 +2,6 @@ import org.opentripplanner.middleware.i18n.Message; import org.opentripplanner.middleware.tripmonitor.jobs.NotificationType; -import org.opentripplanner.middleware.triptracker.TravelerPosition; import org.opentripplanner.middleware.utils.DateTimeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -111,53 +110,4 @@ public static TripMonitorNotification createInitialReminderNotification( ) ); } - - /** - * Creates a departed notification. - */ - public static TripMonitorNotification createDepartedNotification( - NotificationType legTransitionType, - TravelerPosition travelerPosition - ) { - return new TripMonitorNotification( - legTransitionType, - String.format( - Message.DEPARTED_NOTIFICATION.get(travelerPosition.locale), - travelerPosition.expectedLeg.from.name - ) - ); - } - - /** - * Creates a mode change notification. - */ - public static TripMonitorNotification createModeChangeNotification( - NotificationType legTransitionType, - TravelerPosition travelerPosition - ) { - return new TripMonitorNotification( - legTransitionType, - String.format( - Message.MODE_CHANGE_NOTIFICATION.get(travelerPosition.locale), - travelerPosition.expectedLeg.mode, - travelerPosition.nextLeg.mode - ) - ); - } - - /** - * Creates an arrived notification. - */ - public static TripMonitorNotification createArrivedNotification( - NotificationType legTransitionType, - TravelerPosition travelerPosition - ) { - return new TripMonitorNotification( - legTransitionType, - String.format( - Message.ARRIVED_NOTIFICATION.get(travelerPosition.locale), - travelerPosition.expectedLeg.to.name - ) - ); - } } diff --git a/src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java b/src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java index c7dde055..3411602b 100644 --- a/src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java +++ b/src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java @@ -2,12 +2,12 @@ import org.opentripplanner.middleware.i18n.Message; import org.opentripplanner.middleware.models.ItineraryExistence; +import org.opentripplanner.middleware.models.LegTransitionNotification; import org.opentripplanner.middleware.models.MonitoredTrip; import org.opentripplanner.middleware.models.OtpUser; import org.opentripplanner.middleware.models.TripMonitorAlertNotification; import org.opentripplanner.middleware.models.TripMonitorNotification; import org.opentripplanner.middleware.otp.OtpGraphQLVariables; -import org.opentripplanner.middleware.otp.response.Leg; import org.opentripplanner.middleware.tripmonitor.TripStatus; import org.opentripplanner.middleware.otp.OtpDispatcher; import org.opentripplanner.middleware.otp.response.Itinerary; @@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory; import org.slf4j.MDC; -import javax.annotation.Nullable; import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; @@ -43,9 +42,8 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; -import java.util.stream.IntStream; -import static org.opentripplanner.middleware.utils.I18nUtils.label; +import static com.mongodb.client.model.Filters.eq; /** * This job handles the primary functions for checking a {@link MonitoredTrip}, including: @@ -252,11 +250,29 @@ private boolean isTrackingOngoing() { return trip.journeyState.tripStatus == TripStatus.TRIP_ACTIVE && TripTrackingData.getOngoingTrackedJourney(trip.id) != null; } - public void processLegTransition(List legTransitionTypes , TravelerPosition travelerPosition) { - for (NotificationType legTransitionType : legTransitionTypes) { - enqueueNotification(createLegTransitionNotification(legTransitionType, travelerPosition)); + /** + * Process leg transition notifications. + */ + public void processLegTransition(List legTransitionTypes, TravelerPosition travelerPosition) { + OtpUser otpUser = getOtpUser(); + if (otpUser != null) { + otpUser.relatedUsers.forEach(relatedUser -> { + if (relatedUser.isConfirmed()) { + OtpUser observer = Persistence.otpUsers.getOneFiltered(eq("email", relatedUser.email)); + if (observer != null) { + enqueueNotification( + LegTransitionNotification.createLegTransitionNotifications( + legTransitionTypes, + otpUser.name, + travelerPosition, + I18nUtils.getOtpUserLocale(observer) + ) + ); + sendNotifications(observer); + } + } + }); } - sendNotifications(); } /** @@ -509,26 +525,8 @@ public TripMonitorNotification checkTripForDelay(NotificationType delayType) { return null; } - @Nullable - public TripMonitorNotification createLegTransitionNotification( - NotificationType legTransitionType, - TravelerPosition travelerPosition - ) { - switch (legTransitionType) { - case MODE_CHANGE_NOTIFICATION: - return TripMonitorNotification.createModeChangeNotification(legTransitionType, travelerPosition); - case DEPARTED_NOTIFICATION: - return TripMonitorNotification.createDepartedNotification(legTransitionType, travelerPosition); - case ARRIVED_NOTIFICATION: - return TripMonitorNotification.createArrivedNotification(legTransitionType, travelerPosition); - default: - return null; - } - } - /** - * Compose a message for any enqueued notifications and send to {@link OtpUser} based on their notification - * preferences. + * Send notification to user associated with the trip. */ private void sendNotifications() { OtpUser otpUser = getOtpUser(); @@ -537,6 +535,14 @@ private void sendNotifications() { // TODO: Bugsnag / delete monitored trip? return; } + sendNotifications(otpUser); + } + + /** + * Compose a message for any enqueued notifications and send to {@link OtpUser} based on their notification + * preferences. + */ + private void sendNotifications(OtpUser otpUser) { // Update push notification devices count, which may change asynchronously NotificationUtils.updatePushDevices(otpUser); @@ -554,9 +560,12 @@ private void sendNotifications() { return; } + Locale locale = getOtpUserLocale(); String tripNameOrReminder = hasInitialReminder ? initialReminderNotification.body : trip.tripName; + if (tripNameOrReminder == null) { + tripNameOrReminder = Message.TRIP_NAME_UNDEFINED.get(locale); + } - Locale locale = getOtpUserLocale(); // A HashMap is needed instead of a Map for template data to be serialized to the template renderer. Map templateData = new HashMap<>(); templateData.putAll(Map.of( diff --git a/src/main/resources/Message.properties b/src/main/resources/Message.properties index e97d1e9a..651cbfeb 100644 --- a/src/main/resources/Message.properties +++ b/src/main/resources/Message.properties @@ -4,10 +4,10 @@ ACCEPT_DEPENDENT_EMAIL_LINK_TEXT = Accept trusted companion ACCEPT_DEPENDENT_EMAIL_SUBJECT = Trusted companion request ACCEPT_DEPENDENT_EMAIL_MANAGE = Manage settings ACCEPT_DEPENDENT_ERROR = Unable to accept trusted companion. -ARRIVED_NOTIFICATION = The traveler has arrived at %s. +ARRIVED_NOTIFICATION = %s has arrived at %s. LABEL_AND_CONTENT = %s: %s -MODE_CHANGE_NOTIFICATION = The traveler has changed mode from %s to %s. -DEPARTED_NOTIFICATION = The traveler has departed %s. +MODE_CHANGE_NOTIFICATION = %s has changed transit from %s to %s. +DEPARTED_NOTIFICATION = %s has departed %s. SMS_STOP_NOTIFICATIONS = To stop receiving notifications, reply STOP. TRIP_EMAIL_SUBJECT = %s Notification TRIP_EMAIL_SUBJECT_FOR_USER = Trip for %s Notification @@ -35,6 +35,8 @@ TRIP_DELAY_MINUTES = %d minutes TRIP_INVITE_COMPANION = %s added you as a companion for their trip. TRIP_INVITE_PRIMARY_TRAVELER = %s made you the primary traveler on this trip. TRIP_INVITE_OBSERVER = %s added you as an observer for their trip. +TRIP_NAME_UNDEFINED = Trip name undefined +TRIP_TRAVELER_GENERIC_NAME = Traveler TRIP_NOT_FOUND_NOTIFICATION = Your itinerary was not found in today's trip planner results. Please check real-time conditions and plan a new trip. TRIP_NO_LONGER_POSSIBLE_NOTIFICATION = Your itinerary is no longer possible on any monitored day of the week. Please plan and save a new trip. TRIP_REMINDER_NOTIFICATION = Reminder for %s at %s. diff --git a/src/main/resources/Message_fr.properties b/src/main/resources/Message_fr.properties index 70166698..1a0a88c5 100644 --- a/src/main/resources/Message_fr.properties +++ b/src/main/resources/Message_fr.properties @@ -35,6 +35,8 @@ TRIP_DELAY_MINUTES = %d minutes TRIP_INVITE_COMPANION = %s vous a ajouté comme accompagnateur·trice pour un trajet. TRIP_INVITE_PRIMARY_TRAVELER = %s vous a fait le voyageur principal sur ce trajet. TRIP_INVITE_OBSERVER = %s vous a ajouté comme observateur·trice pour un trajet. +TRIP_NAME_UNDEFINED = TODO +TRIP_TRAVELER_GENERIC_NAME = TODO TRIP_NOT_FOUND_NOTIFICATION = Votre trajet est introuvable aujourd'hui. Veuillez vérifier les conditions en temps-réel et recherchez un nouveau trajet. TRIP_NO_LONGER_POSSIBLE_NOTIFICATION = Votre trajet n'est plus possible dans aucun jour de suivi de la semaine. Veuillez rechercher et enregistrer un nouveau trajet. TRIP_REMINDER_NOTIFICATION = Rappel pour %s à %s. diff --git a/src/main/resources/latest-spark-swagger-output.yaml b/src/main/resources/latest-spark-swagger-output.yaml index 1f9ad76c..3d4e09dc 100644 --- a/src/main/resources/latest-spark-swagger-output.yaml +++ b/src/main/resources/latest-spark-swagger-output.yaml @@ -56,10 +56,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/AdminUser" responseSchema: $ref: "#/definitions/AdminUser" + schema: + $ref: "#/definitions/AdminUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -90,10 +90,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/AdminUser" responseSchema: $ref: "#/definitions/AdminUser" + schema: + $ref: "#/definitions/AdminUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -123,10 +123,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/Job" responseSchema: $ref: "#/definitions/Job" + schema: + $ref: "#/definitions/Job" /api/admin/user: get: tags: @@ -155,10 +155,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/ResponseList" responseSchema: $ref: "#/definitions/ResponseList" + schema: + $ref: "#/definitions/ResponseList" post: tags: - "api/admin/user" @@ -178,10 +178,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/AdminUser" responseSchema: $ref: "#/definitions/AdminUser" + schema: + $ref: "#/definitions/AdminUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -220,10 +220,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/AdminUser" responseSchema: $ref: "#/definitions/AdminUser" + schema: + $ref: "#/definitions/AdminUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -269,10 +269,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/AdminUser" responseSchema: $ref: "#/definitions/AdminUser" + schema: + $ref: "#/definitions/AdminUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -309,10 +309,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/AdminUser" responseSchema: $ref: "#/definitions/AdminUser" + schema: + $ref: "#/definitions/AdminUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -356,10 +356,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/ApiUser" responseSchema: $ref: "#/definitions/ApiUser" + schema: + $ref: "#/definitions/ApiUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -402,10 +402,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/ApiUser" responseSchema: $ref: "#/definitions/ApiUser" + schema: + $ref: "#/definitions/ApiUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -447,10 +447,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/TokenHolder" responseSchema: $ref: "#/definitions/TokenHolder" + schema: + $ref: "#/definitions/TokenHolder" /api/secure/application/fromtoken: get: tags: @@ -464,10 +464,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/ApiUser" responseSchema: $ref: "#/definitions/ApiUser" + schema: + $ref: "#/definitions/ApiUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -498,10 +498,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/ApiUser" responseSchema: $ref: "#/definitions/ApiUser" + schema: + $ref: "#/definitions/ApiUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -531,10 +531,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/Job" responseSchema: $ref: "#/definitions/Job" + schema: + $ref: "#/definitions/Job" /api/secure/application: get: tags: @@ -563,10 +563,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/ResponseList" responseSchema: $ref: "#/definitions/ResponseList" + schema: + $ref: "#/definitions/ResponseList" post: tags: - "api/secure/application" @@ -586,10 +586,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/ApiUser" responseSchema: $ref: "#/definitions/ApiUser" + schema: + $ref: "#/definitions/ApiUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -628,10 +628,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/ApiUser" responseSchema: $ref: "#/definitions/ApiUser" + schema: + $ref: "#/definitions/ApiUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -677,10 +677,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/ApiUser" responseSchema: $ref: "#/definitions/ApiUser" + schema: + $ref: "#/definitions/ApiUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -717,10 +717,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/ApiUser" responseSchema: $ref: "#/definitions/ApiUser" + schema: + $ref: "#/definitions/ApiUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -754,10 +754,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/CDPUser" responseSchema: $ref: "#/definitions/CDPUser" + schema: + $ref: "#/definitions/CDPUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -788,10 +788,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/CDPUser" responseSchema: $ref: "#/definitions/CDPUser" + schema: + $ref: "#/definitions/CDPUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -821,10 +821,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/Job" responseSchema: $ref: "#/definitions/Job" + schema: + $ref: "#/definitions/Job" /api/secure/cdp: get: tags: @@ -853,10 +853,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/ResponseList" responseSchema: $ref: "#/definitions/ResponseList" + schema: + $ref: "#/definitions/ResponseList" post: tags: - "api/secure/cdp" @@ -876,10 +876,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/CDPUser" responseSchema: $ref: "#/definitions/CDPUser" + schema: + $ref: "#/definitions/CDPUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -918,10 +918,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/CDPUser" responseSchema: $ref: "#/definitions/CDPUser" + schema: + $ref: "#/definitions/CDPUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -967,10 +967,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/CDPUser" responseSchema: $ref: "#/definitions/CDPUser" + schema: + $ref: "#/definitions/CDPUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1007,10 +1007,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/CDPUser" responseSchema: $ref: "#/definitions/CDPUser" + schema: + $ref: "#/definitions/CDPUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1050,10 +1050,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/ItineraryExistence" responseSchema: $ref: "#/definitions/ItineraryExistence" + schema: + $ref: "#/definitions/ItineraryExistence" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1102,10 +1102,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/ResponseList" responseSchema: $ref: "#/definitions/ResponseList" + schema: + $ref: "#/definitions/ResponseList" post: tags: - "api/secure/monitoredtrip" @@ -1125,10 +1125,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/MonitoredTrip" responseSchema: $ref: "#/definitions/MonitoredTrip" + schema: + $ref: "#/definitions/MonitoredTrip" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1167,10 +1167,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/MonitoredTrip" responseSchema: $ref: "#/definitions/MonitoredTrip" + schema: + $ref: "#/definitions/MonitoredTrip" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1216,10 +1216,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/MonitoredTrip" responseSchema: $ref: "#/definitions/MonitoredTrip" + schema: + $ref: "#/definitions/MonitoredTrip" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1257,10 +1257,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/MonitoredTrip" responseSchema: $ref: "#/definitions/MonitoredTrip" + schema: + $ref: "#/definitions/MonitoredTrip" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1298,10 +1298,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/TrackingResponse" responseSchema: $ref: "#/definitions/TrackingResponse" + schema: + $ref: "#/definitions/TrackingResponse" /api/secure/monitoredtrip/updatetracking: post: tags: @@ -1319,10 +1319,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/TrackingResponse" responseSchema: $ref: "#/definitions/TrackingResponse" + schema: + $ref: "#/definitions/TrackingResponse" /api/secure/monitoredtrip/track: post: tags: @@ -1340,10 +1340,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/TrackingResponse" responseSchema: $ref: "#/definitions/TrackingResponse" + schema: + $ref: "#/definitions/TrackingResponse" /api/secure/monitoredtrip/endtracking: post: tags: @@ -1361,10 +1361,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/EndTrackingResponse" responseSchema: $ref: "#/definitions/EndTrackingResponse" + schema: + $ref: "#/definitions/EndTrackingResponse" /api/secure/monitoredtrip/forciblyendtracking: post: tags: @@ -1382,10 +1382,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/EndTrackingResponse" responseSchema: $ref: "#/definitions/EndTrackingResponse" + schema: + $ref: "#/definitions/EndTrackingResponse" /api/secure/triprequests: get: tags: @@ -1430,10 +1430,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/TripRequest" responseSchema: $ref: "#/definitions/TripRequest" + schema: + $ref: "#/definitions/TripRequest" /api/secure/monitoredcomponent: get: tags: @@ -1462,10 +1462,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/ResponseList" responseSchema: $ref: "#/definitions/ResponseList" + schema: + $ref: "#/definitions/ResponseList" post: tags: - "api/secure/monitoredcomponent" @@ -1485,10 +1485,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/MonitoredComponent" responseSchema: $ref: "#/definitions/MonitoredComponent" + schema: + $ref: "#/definitions/MonitoredComponent" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1527,10 +1527,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/MonitoredComponent" responseSchema: $ref: "#/definitions/MonitoredComponent" + schema: + $ref: "#/definitions/MonitoredComponent" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1576,10 +1576,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/MonitoredComponent" responseSchema: $ref: "#/definitions/MonitoredComponent" + schema: + $ref: "#/definitions/MonitoredComponent" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1617,10 +1617,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/MonitoredComponent" responseSchema: $ref: "#/definitions/MonitoredComponent" + schema: + $ref: "#/definitions/MonitoredComponent" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1651,10 +1651,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/OtpUser" responseSchema: $ref: "#/definitions/OtpUser" + schema: + $ref: "#/definitions/OtpUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1686,10 +1686,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/MobilityProfileLite" responseSchema: $ref: "#/definitions/MobilityProfileLite" + schema: + $ref: "#/definitions/MobilityProfileLite" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1729,10 +1729,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/VerificationResult" responseSchema: $ref: "#/definitions/VerificationResult" + schema: + $ref: "#/definitions/VerificationResult" /api/secure/user/{id}/verify_sms/{code}: post: tags: @@ -1752,10 +1752,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/VerificationResult" responseSchema: $ref: "#/definitions/VerificationResult" + schema: + $ref: "#/definitions/VerificationResult" /api/secure/user/fromtoken: get: tags: @@ -1769,10 +1769,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/OtpUser" responseSchema: $ref: "#/definitions/OtpUser" + schema: + $ref: "#/definitions/OtpUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1803,10 +1803,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/OtpUser" responseSchema: $ref: "#/definitions/OtpUser" + schema: + $ref: "#/definitions/OtpUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1836,10 +1836,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/Job" responseSchema: $ref: "#/definitions/Job" + schema: + $ref: "#/definitions/Job" /api/secure/user: get: tags: @@ -1868,10 +1868,10 @@ paths: responses: "200": description: "successful operation" - schema: - $ref: "#/definitions/ResponseList" responseSchema: $ref: "#/definitions/ResponseList" + schema: + $ref: "#/definitions/ResponseList" post: tags: - "api/secure/user" @@ -1891,10 +1891,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/OtpUser" responseSchema: $ref: "#/definitions/OtpUser" + schema: + $ref: "#/definitions/OtpUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1933,10 +1933,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/OtpUser" responseSchema: $ref: "#/definitions/OtpUser" + schema: + $ref: "#/definitions/OtpUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -1982,10 +1982,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/OtpUser" responseSchema: $ref: "#/definitions/OtpUser" + schema: + $ref: "#/definitions/OtpUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -2022,10 +2022,10 @@ paths: "200": description: "Successful operation" examples: {} - schema: - $ref: "#/definitions/OtpUser" responseSchema: $ref: "#/definitions/OtpUser" + schema: + $ref: "#/definitions/OtpUser" "400": description: "The request was not formed properly (e.g., some required parameters\ \ may be missing). See the details of the returned response to determine\ @@ -2079,11 +2079,11 @@ paths: responses: "200": description: "successful operation" - schema: + responseSchema: type: "array" items: $ref: "#/definitions/ApiUsageResult" - responseSchema: + schema: type: "array" items: $ref: "#/definitions/ApiUsageResult" @@ -2110,11 +2110,11 @@ paths: responses: "200": description: "successful operation" - schema: + responseSchema: type: "array" items: $ref: "#/definitions/BugsnagEvent" - responseSchema: + schema: type: "array" items: $ref: "#/definitions/BugsnagEvent" @@ -2141,11 +2141,11 @@ paths: responses: "200": description: "successful operation" - schema: + responseSchema: type: "array" items: $ref: "#/definitions/CDPFile" - responseSchema: + schema: type: "array" items: $ref: "#/definitions/CDPFile" @@ -2166,11 +2166,11 @@ paths: responses: "200": description: "successful operation" - schema: + responseSchema: type: "array" items: $ref: "#/definitions/URL" - responseSchema: + schema: type: "array" items: $ref: "#/definitions/URL" diff --git a/src/test/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTripTest.java b/src/test/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTripTest.java index 6376e34d..f6140a1e 100644 --- a/src/test/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTripTest.java +++ b/src/test/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTripTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.opentripplanner.middleware.models.ItineraryExistence; +import org.opentripplanner.middleware.models.LegTransitionNotification; import org.opentripplanner.middleware.models.TrackedJourney; import org.opentripplanner.middleware.otp.response.Leg; import org.opentripplanner.middleware.testutils.OtpMiddlewareTestEnvironment; @@ -37,6 +38,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; @@ -219,22 +221,27 @@ private static Stream createDelayNotificationTestCases() { } @ParameterizedTest - @MethodSource("createMajorChangeNotificationTestCases") - void testMajorChangeNotifications( + @MethodSource("createLegTransitionNotificationTestCases") + void testLegTransitionNotifications( NotificationType legTransitionType, - String message, - TravelerPosition travelerPosition - ) throws Exception { - CheckMonitoredTrip check = createCheckMonitoredTrip(this::mockOtpPlanResponse); - TripMonitorNotification notification = check.createLegTransitionNotification( - legTransitionType, - travelerPosition - ); - assertNotNull(notification); - assertEquals(message, notification.body); + String travelerName, + TravelerPosition travelerPosition, + Locale locale, + String message + ) { + TripMonitorNotification[] notification = LegTransitionNotification.createLegTransitionNotifications( + List.of(legTransitionType), + travelerName, + travelerPosition, + locale + ); + assertNotNull(notification[0]); + assertEquals(message, notification[0].body); } - private static Stream createMajorChangeNotificationTestCases() throws Exception { + private static Stream createLegTransitionNotificationTestCases() throws Exception { + String travelerName = "Obi-Wan"; + Locale locale = Locale.US; Itinerary itinerary = createDefaultItinerary(); Leg expectedLeg = itinerary.legs.get(1); Coordinates expectedLegDestinationCoords = new Coordinates(expectedLeg.to); @@ -243,18 +250,31 @@ private static Stream createMajorChangeNotificationTestCases() throws return Stream.of( Arguments.of( NotificationType.MODE_CHANGE_NOTIFICATION, - "The traveler has changed mode from TRAM to WALK.", - new TravelerPosition(expectedLeg, nextLeg, expectedLegDestinationCoords) + travelerName, + new TravelerPosition(expectedLeg, nextLeg, expectedLegDestinationCoords), + locale, + "Obi-Wan has changed transit from TRAM to WALK." ), Arguments.of( NotificationType.DEPARTED_NOTIFICATION, - "The traveler has departed Providence Park MAX Station.", - new TravelerPosition(expectedLeg, nextLeg, nextLegDepartureCoords) + travelerName, + new TravelerPosition(expectedLeg, nextLeg, nextLegDepartureCoords), + locale, + "Obi-Wan has departed Providence Park MAX Station." + ), + Arguments.of( + NotificationType.ARRIVED_NOTIFICATION, + travelerName, + new TravelerPosition(expectedLeg, nextLeg, expectedLegDestinationCoords), + locale, + "Obi-Wan has arrived at Pioneer Square South MAX Station." ), Arguments.of( NotificationType.ARRIVED_NOTIFICATION, - "The traveler has arrived at Pioneer Square South MAX Station.", - new TravelerPosition(expectedLeg, nextLeg, expectedLegDestinationCoords) + null, + new TravelerPosition(expectedLeg, nextLeg, expectedLegDestinationCoords), + locale, + "Traveler has arrived at Pioneer Square South MAX Station." ) ); }