From 5aff2e6a634c33a13aec1855d36990cae81446b9 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Fri, 10 Nov 2023 09:14:08 -0500 Subject: [PATCH 1/3] fix(NotificationUtils): Fix string length handling, refactor push json body. --- .../middleware/utils/NotificationUtils.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java b/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java index 7e4c0fcb2..12ecb24f9 100644 --- a/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java +++ b/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java @@ -1,5 +1,6 @@ package org.opentripplanner.middleware.utils; +import com.google.gson.Gson; import com.sparkpost.Client; import com.sparkpost.model.responses.Response; import com.twilio.Twilio; @@ -80,14 +81,8 @@ public static String sendPush(OtpUser otpUser, String textTemplate, Object templ */ static String sendPush(String toUser, String body) { try { - var jsonBody = String.format( - "{\"user\":\"%s\",\"message\":\"%s\"}", - toUser, - body - // Escape carriage returns and trim message length (iOS limitation). - .replace("\n", "\\n") - .substring(0, PUSH_MESSAGE_MAX_LENGTH - 1) - ); + NotificationInfo notifInfo = new NotificationInfo(toUser, body.substring(0, Math.min(PUSH_MESSAGE_MAX_LENGTH, body.length()))); + var jsonBody = new Gson().toJson(notifInfo); Map headers = Map.of( "Accept", "application/json", "Content-Type", "application/json" @@ -151,9 +146,9 @@ public static String sendSMS(String toPhone, String body) { toPhoneNumber, fromPhoneNumber, // Trim body to max message length - body.substring(0, SMS_MAX_LENGTH - 1) + body.substring(0, Math.min(SMS_MAX_LENGTH, body.length())) ).create(); - LOG.debug("SMS ({}) sent successfully", message.getSid()); + LOG.info("SMS ({}) sent successfully", message.getSid()); return message.getSid(); // TODO: Is there a more specific exception we're ok with here? } catch (Exception e) { @@ -329,4 +324,13 @@ public static int getPushInfo(String toUser) { return 0; } + static class NotificationInfo { + public String user; + public String message; + + public NotificationInfo(String user, String message) { + this.user = user; + this.message = message; + } + } } From 0fd1f70ce696edc828ceb2aba52727196a65ecc1 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Fri, 10 Nov 2023 09:26:43 -0500 Subject: [PATCH 2/3] fix(LocalizedAlert): Add new alert id field. --- .../opentripplanner/middleware/otp/response/LocalizedAlert.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/opentripplanner/middleware/otp/response/LocalizedAlert.java b/src/main/java/org/opentripplanner/middleware/otp/response/LocalizedAlert.java index 369c9d0ab..ad48cd680 100644 --- a/src/main/java/org/opentripplanner/middleware/otp/response/LocalizedAlert.java +++ b/src/main/java/org/opentripplanner/middleware/otp/response/LocalizedAlert.java @@ -11,6 +11,8 @@ public class LocalizedAlert { public Date effectiveEndDate; + public String id; + @Override public int hashCode() { return Objects.hash(alertHeaderText, alertDescriptionText, alertUrl, effectiveStartDate, effectiveEndDate); From 0d73cb2faaa0de4f77205bc2a07b3f32b8c4bd91 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Fri, 10 Nov 2023 09:32:44 -0500 Subject: [PATCH 3/3] test(swagger): Update snapshot --- src/main/resources/latest-spark-swagger-output.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/latest-spark-swagger-output.yaml b/src/main/resources/latest-spark-swagger-output.yaml index 4cf74df2b..d3bc90e19 100644 --- a/src/main/resources/latest-spark-swagger-output.yaml +++ b/src/main/resources/latest-spark-swagger-output.yaml @@ -2437,6 +2437,8 @@ definitions: effectiveEndDate: type: "string" format: "date" + id: + type: "string" MonitoredTrip: type: "object" properties: