From 38660e634dcf3a7949d9ead4c3f6f19342099e4b Mon Sep 17 00:00:00 2001 From: Jym Dyer Date: Thu, 31 Aug 2023 14:23:13 -0700 Subject: [PATCH] Make public static methods contingent on setting PUSH_API_KEY/PUSH_API_URL. Make inner sendPush() method package scope. --- .../middleware/utils/NotificationUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java b/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java index ae0299a37..c84387da3 100644 --- a/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java +++ b/src/main/java/org/opentripplanner/middleware/utils/NotificationUtils.java @@ -50,6 +50,8 @@ public class NotificationUtils { * @param templateData template data */ public static String sendPush(OtpUser otpUser, String textTemplate, Object templateData) { + // If Push API config properties aren't set, do nothing. + if (PUSH_API_KEY.equals(null) || PUSH_API_URL.equals(null)) return null; try { String body = TemplateUtils.renderTemplate(textTemplate, templateData); String toUser = otpUser.email; @@ -67,7 +69,7 @@ public static String sendPush(OtpUser otpUser, String textTemplate, Object templ * @param body message body * @return "OK" if message was successful (null otherwise) */ - public static String sendPush(String toUser, String body) { + static String sendPush(String toUser, String body) { try { var jsonBody = "{\"user\":\"" + toUser + "\",\"message\":\"" + body + "\"}"; Map headers = Map.of("Accept", "application/json"); @@ -280,8 +282,11 @@ public static boolean sendEmailViaSparkpost( * to obtain this value, as the publish endpoint returns success even for zero devices. * * @param toUser email address of user that devices are indexed by + * @return number of devices registered, 0 can mean zero devices or an error obtaining the number */ public static int getPushInfo(String toUser) { + // If Push API config properties aren't set, no info can be obtained. + if (PUSH_API_KEY.equals(null) || PUSH_API_URL.equals(null)) return 0; try { Map headers = Map.of("Accept", "application/json"); var httpResponse = HttpUtils.httpRequestRawResponse(