Remove notifier to send emails.

This commit is contained in:
Paulo Gustavo Veiga 2022-02-03 21:02:28 -08:00
parent f68a3ac7bc
commit 119eb03f53
5 changed files with 60 additions and 96 deletions

View File

@ -1,20 +1,20 @@
/* /*
* Copyright [2015] [wisemapping] * Copyright [2015] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.wisemapping.mail; package com.wisemapping.mail;
@ -22,8 +22,11 @@ import com.wisemapping.filter.SupportedUserAgent;
import com.wisemapping.model.Collaboration; import com.wisemapping.model.Collaboration;
import com.wisemapping.model.Mindmap; import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User; 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.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringEscapeUtils;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -36,17 +39,17 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
final public class NotificationService { 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 @Autowired
private Mailer mailer; private Mailer mailer;
private final NotifierFilter notificationFilter;
private String baseUrl; private String baseUrl;
public NotificationService() { 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) { 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); 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) { public void passwordChanged(@NotNull User user) {
final String mailSubject = "[WiseMapping] Your password has been changed"; final String mailSubject = "[WiseMapping] Your password has been changed";
final String messageTitle = "Your password has been changed successfully"; 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) { public void reportJavascriptException(@Nullable Mindmap mindmap, @Nullable User user, @Nullable String jsErrorMsg, @NotNull HttpServletRequest request) {
final Map<String, String> model = new HashMap<String, String>(); final Map<String, String> model = new HashMap<>();
model.put("errorMsg", jsErrorMsg); model.put("errorMsg", jsErrorMsg);
try { try {
model.put("mapXML", StringEscapeUtils.escapeXml(mindmap == null ? "map not found" : mindmap.getXmlStr())); 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("mapId", Integer.toString(mindmap.getId()));
model.put("mapTitle", mindmap.getTitle()); model.put("mapTitle", mindmap.getTitle());
sendNotification(model, user, request); logError(model, user, request);
} }
private void sendNotification(@NotNull Map<String, String> model, @Nullable User user, @NotNull HttpServletRequest request) { private void logError(@NotNull Map<String, String> model, @Nullable User user, @NotNull HttpServletRequest request) {
model.put("fullName", (user != null ? user.getFullName() : "'anonymous'")); model.put("fullName", (user != null ? user.getFullName() : "'anonymous'"));
final String userEmail = user != null ? user.getEmail() : "'anonymous'"; final String userEmail = user != null ? user.getEmail() : "'anonymous'";
@ -180,37 +194,19 @@ final public class NotificationService {
model.put("method", request.getMethod()); model.put("method", request.getMethod());
model.put("remoteAddress", request.getRemoteAddr()); model.put("remoteAddress", request.getRemoteAddr());
try { logErrorMessage(model,
final String errorReporterEmail = mailer.getErrorReporterEmail(); "errorNotification.vm");
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<String, String> model = new HashMap<String, String>();
model.put("errorMsg", stackTraceToString(exception));
model.put("mapXML", StringEscapeUtils.escapeXml(content));
sendNotification(model, user, request);
} }
public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull HttpServletRequest request) { public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull HttpServletRequest request) {
final Map<String, String> model = new HashMap<String, String>(); final Map<String, String> model = new HashMap<String, String>();
model.put("errorMsg", stackTraceToString(exception)); model.put("errorMsg", stackTraceToString(exception));
sendNotification(model, user, request); logError(model, user, request);
} }
public String stackTraceToString(@NotNull Throwable e) { public String stackTraceToString(@NotNull Throwable e) {
String retValue = null; String retValue;
StringWriter sw = null; StringWriter sw = null;
PrintWriter pw = null; PrintWriter pw = null;
try { try {

View File

@ -1,32 +1,18 @@
<html> User Name: ${fullName} -
<body> Email: ${email} -
<ul> Server: ${server} -
<li>User Name: ${fullName}</li> RequestURI: ${requestURI} -
<li>Email: ${email}</li> Method: ${method} -
<li>Server: ${server}</li> User Agent: ${userAgent} -
<li>RequestURI: ${requestURI}</li> Remote Address: ${remoteAddress} -
<li>Method: ${method}</li> #if($mapId)
<li>User Agent: ${userAgent}</li> Mindmap Id: ${mapId} -
<li>Remote Address: ${remoteAddress}</li> #end
#if($mapTitle)
Mindmap Title: ${mapTitle} -
#if($mapId) #end
<li>Mindmap Id: ${mapId}</li> ${errorMsg}
#end
#if($mapTitle)
<li>Mindmap Title: ${mapTitle}</li>
#end
</ul>
<pre style="border:1px dashed #a9a9a9">
${errorMsg}
</pre>
#if($mapXML) #if($mapXML)
<pre style="border:1px dashed #a9a9a9"> ${mapXML}
${mapXML} #end
</pre>
#end
</body>
</html>

View File

@ -1,14 +0,0 @@
<jxb:bindings version="2.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="mindmap.xsd">
<jxb:schemaBindings>
<jxb:package name="com.wisemapping.jaxb.wisemap"/>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings node="/xsd:schema/xsd:complexType[@name='topicType']/xsd:attribute[@name='text']" schemaLocation="mindmap.xsd">
<jxb:property name="textAttr"/>
</jxb:bindings>
<jxb:bindings node="/xsd:schema/xsd:complexType[@name='note']/xsd:simpleContent/xsd:extension/xsd:attribute[@name='text']" schemaLocation="mindmap.xsd">
<jxb:property name="textAttr"/>
</jxb:bindings>
</jxb:bindings>

View File

@ -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. # 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 mail.supportEmail=root@localhost
# Optional: Unexpected errors will be reported to this address.
mail.errorReporterEmail=
################################################################################## ##################################################################################
# Users Registration Configuration # Users Registration Configuration
################################################################################## ##################################################################################
@ -130,14 +127,12 @@ security.ldap.server.user=cn=pveiga,dc=wisemapping,dc=com
security.ldap.server.password=password security.ldap.server.password=password
security.ldap.basedn=dc=wisemapping,dc=com security.ldap.basedn=dc=wisemapping,dc=com
# This will be concatenated as part of the DN. In this case, I will be "ou=people". # 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. # In case this need to be changed, modify the wisemapping-security-ldap.xml.
security.ldap.subDn=ou=people security.ldap.subDn=ou=people
# Attribute used as authentication login (Eg: in this case, the user email will be used) # Attribute used as authentication login (Eg: in this case, the user email will be used)
security.ldap.auth.attribute=mail security.ldap.auth.attribute=mail
security.ldap.lastName.attribute=sn security.ldap.lastName.attribute=sn
security.ldap.firstName.attribute=givenName security.ldap.firstName.attribute=givenName

View File

@ -28,7 +28,7 @@
<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/> <property name="transactionManager" ref="transactionManager"/>
<property name="target" ref="userServiceTarget" /> <property name="target" ref="userServiceTarget"/>
<property name="transactionAttributes"> <property name="transactionAttributes">
<props> <props>
<prop key="*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED</prop>
@ -66,7 +66,7 @@
<bean id="labelService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <bean id="labelService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/> <property name="transactionManager" ref="transactionManager"/>
<property name="target" ref="labelServiceTarget" /> <property name="target" ref="labelServiceTarget"/>
<property name="transactionAttributes"> <property name="transactionAttributes">
<props> <props>
<prop key="*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED</prop>
@ -95,6 +95,7 @@
<bean id="notificationService" class="com.wisemapping.mail.NotificationService"> <bean id="notificationService" class="com.wisemapping.mail.NotificationService">
<property name="baseUrl" value="${site.baseurl}"/> <property name="baseUrl" value="${site.baseurl}"/>
<property name="mailer" ref="mailer"/> <property name="mailer" ref="mailer"/>
<property name="velocityEngineWrapper" ref="velocityEngineWrapper"/>
</bean> </bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">