From 119eb03f53a90e28c5aacb203e989d2ee62f1a06 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 3 Feb 2022 21:02:28 -0800 Subject: [PATCH] Remove notifier to send emails. --- .../wisemapping/mail/NotificationService.java | 86 +++++++++---------- .../main/resources/mail/errorNotification.vm | 46 ++++------ wise-webapp/src/main/resources/mindmap.xjb | 14 --- .../src/main/webapp/WEB-INF/app.properties | 5 -- .../webapp/WEB-INF/wisemapping-service.xml | 5 +- 5 files changed, 60 insertions(+), 96 deletions(-) delete mode 100644 wise-webapp/src/main/resources/mindmap.xjb 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 a2328d6e..77327ed4 100644 --- a/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java +++ b/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java @@ -1,20 +1,20 @@ /* -* Copyright [2015] [wisemapping] -* -* Licensed under WiseMapping Public License, Version 1.0 (the "License"). -* It is basically the Apache License, Version 2.0 (the "License") plus the -* "powered by wisemapping" text requirement on every single page; -* you may not use this file except in compliance with the License. -* You may obtain a copy of the license at -* -* http://www.wisemapping.org/license -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright [2015] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.wisemapping.mail; @@ -22,8 +22,11 @@ import com.wisemapping.filter.SupportedUserAgent; import com.wisemapping.model.Collaboration; import com.wisemapping.model.Mindmap; import com.wisemapping.model.User; +import com.wisemapping.util.VelocityEngineUtils; +import com.wisemapping.util.VelocityEngineWrapper; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringEscapeUtils; +import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; @@ -36,17 +39,17 @@ import java.util.HashMap; import java.util.Map; final public class NotificationService { + final private static Logger logger = Logger.getLogger(Mailer.class); + final private static String DEFAULT_WISE_URL = "http://localhost:8080/wisemapping"; + private VelocityEngineWrapper velocityEngineWrapper; - public static final String DEFAULT_WISE_URL = "http://localhost:8080/wisemapping"; @Autowired private Mailer mailer; - private final NotifierFilter notificationFilter; - private String baseUrl; public NotificationService() { - this.notificationFilter = new NotifierFilter(); + NotifierFilter notificationFilter = new NotifierFilter(); } public void newCollaboration(@NotNull Collaboration collaboration, @NotNull Mindmap mindmap, @NotNull User user, @Nullable String message) { @@ -90,6 +93,13 @@ 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"; final String messageTitle = "Your password has been changed successfully"; @@ -154,9 +164,13 @@ final public class NotificationService { // } } + public void setVelocityEngineWrapper(VelocityEngineWrapper engine) { + this.velocityEngineWrapper = engine; + } + public void reportJavascriptException(@Nullable Mindmap mindmap, @Nullable User user, @Nullable String jsErrorMsg, @NotNull HttpServletRequest request) { - final Map model = new HashMap(); + final Map model = new HashMap<>(); model.put("errorMsg", jsErrorMsg); try { model.put("mapXML", StringEscapeUtils.escapeXml(mindmap == null ? "map not found" : mindmap.getXmlStr())); @@ -166,10 +180,10 @@ final public class NotificationService { model.put("mapId", Integer.toString(mindmap.getId())); model.put("mapTitle", mindmap.getTitle()); - sendNotification(model, user, request); + logError(model, user, request); } - private void sendNotification(@NotNull Map model, @Nullable User user, @NotNull HttpServletRequest request) { + private void logError(@NotNull Map model, @Nullable User user, @NotNull HttpServletRequest request) { model.put("fullName", (user != null ? user.getFullName() : "'anonymous'")); final String userEmail = user != null ? user.getEmail() : "'anonymous'"; @@ -180,37 +194,19 @@ final public class NotificationService { model.put("method", request.getMethod()); model.put("remoteAddress", request.getRemoteAddr()); - try { - final String errorReporterEmail = mailer.getErrorReporterEmail(); - if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) { - - if (!notificationFilter.hasBeenSend(userEmail, model)) { - mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Bug from '" + (user != null ? user.getEmail() + "'" : "'anonymous'"), model, - "errorNotification.vm"); - } - } - } catch (Exception e) { - handleException(e); - } - } - - public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull String content, @NotNull HttpServletRequest request) { - final Map model = new HashMap(); - model.put("errorMsg", stackTraceToString(exception)); - model.put("mapXML", StringEscapeUtils.escapeXml(content)); - - sendNotification(model, user, request); + logErrorMessage(model, + "errorNotification.vm"); } public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull HttpServletRequest request) { final Map model = new HashMap(); model.put("errorMsg", stackTraceToString(exception)); - sendNotification(model, user, request); + logError(model, user, request); } public String stackTraceToString(@NotNull Throwable e) { - String retValue = null; + String retValue; StringWriter sw = null; PrintWriter pw = null; try { diff --git a/wise-webapp/src/main/resources/mail/errorNotification.vm b/wise-webapp/src/main/resources/mail/errorNotification.vm index bb37aa02..baa62254 100644 --- a/wise-webapp/src/main/resources/mail/errorNotification.vm +++ b/wise-webapp/src/main/resources/mail/errorNotification.vm @@ -1,32 +1,18 @@ - - -
    -
  • 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}
-
+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 +${mapXML} +#end \ No newline at end of file diff --git a/wise-webapp/src/main/resources/mindmap.xjb b/wise-webapp/src/main/resources/mindmap.xjb deleted file mode 100644 index 1d411a86..00000000 --- a/wise-webapp/src/main/resources/mindmap.xjb +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/wise-webapp/src/main/webapp/WEB-INF/app.properties b/wise-webapp/src/main/webapp/WEB-INF/app.properties index ba6c8f27..bee03463 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/app.properties +++ b/wise-webapp/src/main/webapp/WEB-INF/app.properties @@ -68,9 +68,6 @@ mail.serverSendEmail=root@localhost # Optional: Support account that the users could use to contact you. This address will appear in emails and in some places in the site. mail.supportEmail=root@localhost -# Optional: Unexpected errors will be reported to this address. -mail.errorReporterEmail= - ################################################################################## # Users Registration Configuration ################################################################################## @@ -130,14 +127,12 @@ security.ldap.server.user=cn=pveiga,dc=wisemapping,dc=com security.ldap.server.password=password security.ldap.basedn=dc=wisemapping,dc=com - # This will be concatenated as part of the DN. In this case, I will be "ou=people". # In case this need to be changed, modify the wisemapping-security-ldap.xml. security.ldap.subDn=ou=people # Attribute used as authentication login (Eg: in this case, the user email will be used) security.ldap.auth.attribute=mail - security.ldap.lastName.attribute=sn security.ldap.firstName.attribute=givenName diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml index 97a97a3b..dc4eaba7 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml @@ -28,7 +28,7 @@ - + PROPAGATION_REQUIRED @@ -66,7 +66,7 @@ - + PROPAGATION_REQUIRED @@ -95,6 +95,7 @@ +