From 18c67233da1372df003f59fee9b68053dce1f937 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 11 Feb 2022 23:56:53 -0800 Subject: [PATCH] Improve JS error loggin --- .../wisemapping/mail/NotificationService.java | 22 +++++++++---------- .../main/resources/mail/errorNotification.vm | 18 --------------- 2 files changed, 10 insertions(+), 30 deletions(-) delete mode 100644 wise-webapp/src/main/resources/mail/errorNotification.vm diff --git a/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java b/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java index a735b1b6..30a1932d 100644 --- a/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java +++ b/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java @@ -37,6 +37,7 @@ import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; final public class NotificationService { final private static Logger logger = Logger.getLogger(Mailer.class); @@ -65,7 +66,7 @@ final public class NotificationService { final String subject = "[WiseMapping] " + user.getFullName() + " has shared a mindmap with you"; // Fill template properties ... - final Map model = new HashMap(); + final Map model = new HashMap<>(); model.put("mindmap", mindmap); model.put("message", "message"); model.put("ownerName", user.getFirstname()); @@ -93,12 +94,6 @@ final public class NotificationService { sendTemplateMail(user, mailSubject, messageTitle, messageBody); } - private void logErrorMessage(final Map model, - @NotNull final String templateMail) { - final String messageBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngineWrapper.getVelocityEngine(), "/mail/" + templateMail, model); - logger.error("Unexpected editor error => " + messageBody); - } - public void passwordChanged(@NotNull User user) { final String mailSubject = "[WiseMapping] Your password has been changed"; @@ -120,7 +115,7 @@ final public class NotificationService { private void sendTemplateMail(@NotNull User user, @NotNull String mailSubject, @NotNull String messageTitle, @NotNull String messageBody) { try { - final Map model = new HashMap(); + final Map model = new HashMap<>(); model.put("firstName", user.getFirstname()); model.put("messageTitle", messageTitle); model.put("messageBody", messageBody); @@ -145,7 +140,7 @@ final public class NotificationService { public void activateAccount(@NotNull User user) { - final Map model = new HashMap(); + final Map model = new HashMap<>(); model.put("user", user); mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "[WiseMapping] Active account", model, "activationAccountMail.vm"); } @@ -194,12 +189,15 @@ final public class NotificationService { model.put("method", request.getMethod()); model.put("remoteAddress", request.getRemoteAddr()); - logErrorMessage(model, - "errorNotification.vm"); + String errorAsString = model.keySet().stream() + .map(key -> key + "=" + model.get(key)) + .collect(Collectors.joining(", ", "{", "}")); + + logger.error("Unexpected editor error => " + errorAsString); } public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull HttpServletRequest request) { - final Map model = new HashMap(); + final Map model = new HashMap<>(); model.put("errorMsg", stackTraceToString(exception)); logError(model, user, request); diff --git a/wise-webapp/src/main/resources/mail/errorNotification.vm b/wise-webapp/src/main/resources/mail/errorNotification.vm deleted file mode 100644 index baa62254..00000000 --- a/wise-webapp/src/main/resources/mail/errorNotification.vm +++ /dev/null @@ -1,18 +0,0 @@ -User Name: ${fullName} - -Email: ${email} - -Server: ${server} - -RequestURI: ${requestURI} - -Method: ${method} - -User Agent: ${userAgent} - -Remote Address: ${remoteAddress} - -#if($mapId) - Mindmap Id: ${mapId} - -#end -#if($mapTitle) - Mindmap Title: ${mapTitle} - -#end -${errorMsg} - -#if($mapXML) -${mapXML} -#end \ No newline at end of file