From 17363ac3b484da890fbdbf4e7e0f56ad7143d694 Mon Sep 17 00:00:00 2001 From: Robin Beer Date: Fri, 13 Dec 2024 11:01:26 +0000 Subject: [PATCH] refactor(Refactored otp user to provide display name): --- .../org/opentripplanner/middleware/models/OtpUser.java | 6 +++--- .../middleware/models/TripMonitorNotification.java | 10 ++++++++-- .../middleware/tripmonitor/TrustedCompanion.java | 2 +- .../tripmonitor/jobs/CheckMonitoredTrip.java | 2 +- .../middleware/utils/NotificationUtils.java | 3 +-- .../tripmonitor/jobs/CheckMonitoredTripTest.java | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/opentripplanner/middleware/models/OtpUser.java b/src/main/java/org/opentripplanner/middleware/models/OtpUser.java index 852a0c5ec..2992378e5 100644 --- a/src/main/java/org/opentripplanner/middleware/models/OtpUser.java +++ b/src/main/java/org/opentripplanner/middleware/models/OtpUser.java @@ -213,9 +213,9 @@ public Optional findLastTripSurveyNotificationSent() { } /** - * Use name if available, if not fallback on their email (which is a required field). + * Use name if available, if not fallback on email (which is a required field). */ - public String getAddressee() { - return Strings.isBlank(name) ? email : name; + public String getDisplayedName() { + return Strings.isBlank(name) ? email.replace("@", " at ") : name; } } diff --git a/src/main/java/org/opentripplanner/middleware/models/TripMonitorNotification.java b/src/main/java/org/opentripplanner/middleware/models/TripMonitorNotification.java index cf5fa174b..5a6d8f256 100644 --- a/src/main/java/org/opentripplanner/middleware/models/TripMonitorNotification.java +++ b/src/main/java/org/opentripplanner/middleware/models/TripMonitorNotification.java @@ -17,8 +17,8 @@ public class TripMonitorNotification extends Model { private static final Logger LOG = LoggerFactory.getLogger(TripMonitorNotification.class); public static final String STOPWATCH_ICON = "⏱"; - public final NotificationType type; - public final String body; + public NotificationType type; + public String body; /** Getter functions are used by HTML template renderer */ public String getBody() { @@ -29,6 +29,12 @@ public NotificationType getType() { return type; } + /** + * This no-arg constructor exists to make MongoDB happy. + */ + public TripMonitorNotification() { + } + public TripMonitorNotification(NotificationType type, String body) { this.type = type; this.body = body; diff --git a/src/main/java/org/opentripplanner/middleware/tripmonitor/TrustedCompanion.java b/src/main/java/org/opentripplanner/middleware/tripmonitor/TrustedCompanion.java index 3b3bea599..6e796ab6c 100644 --- a/src/main/java/org/opentripplanner/middleware/tripmonitor/TrustedCompanion.java +++ b/src/main/java/org/opentripplanner/middleware/tripmonitor/TrustedCompanion.java @@ -192,7 +192,7 @@ private static boolean sendAcceptDependentEmail(OtpUser dependentUser, OtpUser r "acceptDependentLinkLabelAndUrl", label(acceptDependentLinkLabel, acceptDependentUrl, locale), "acceptDependentUrl", acceptDependentUrl, "emailFooter", Message.ACCEPT_DEPENDENT_EMAIL_FOOTER.get(locale), - "emailGreeting", String.format(Message.ACCEPT_DEPENDENT_EMAIL_GREETING.get(locale), dependentUser.getAddressee()), + "emailGreeting", String.format(Message.ACCEPT_DEPENDENT_EMAIL_GREETING.get(locale), dependentUser.getDisplayedName()), "manageLinkUrl", String.format("%s%s", OTP_UI_URL, SETTINGS_PATH), "manageLinkText", Message.ACCEPT_DEPENDENT_EMAIL_MANAGE.get(locale) ) 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 b8178b226..0a70fedff 100644 --- a/src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java +++ b/src/main/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTrip.java @@ -259,7 +259,7 @@ public void processLegTransition(NotificationType notificationType, TravelerPosi if (observer != null) { enqueueNotification( new LegTransitionNotification( - tripOwner.getAddressee(), + tripOwner.getDisplayedName(), notificationType, travelerPosition, I18nUtils.getOtpUserLocale(observer) diff --git a/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java b/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java index 251f39240..e94233f08 100644 --- a/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java +++ b/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java @@ -498,8 +498,7 @@ public static String replaceUserNameInFromEmail(String fromEmail, OtpUser otpUse int lastBracketIndex = fromEmail.indexOf('>'); // HACK: If falling back on email, replace the "@" sign so that the user's email does not override the // application email in brackets. - String displayedName = Strings.isBlank(otpUser.name) ? otpUser.email.replace("@", " at ") : otpUser.name; - return String.format("%s %s", displayedName, fromEmail.substring(firstBracketIndex, lastBracketIndex + 1)); + return String.format("%s %s", otpUser.getDisplayedName(), fromEmail.substring(firstBracketIndex, lastBracketIndex + 1)); } /** 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 720f1f476..80d90ff00 100644 --- a/src/test/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTripTest.java +++ b/src/test/java/org/opentripplanner/middleware/tripmonitor/jobs/CheckMonitoredTripTest.java @@ -807,4 +807,4 @@ private static Stream createCanUnsnoozeTripCases() { Arguments.of(noonMonday8June2020, tuesday, true) ); } -} \ No newline at end of file +}