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

@ -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<String, String> model = new HashMap<String, String>();
final Map<String, String> 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<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'"));
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,
logErrorMessage(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) {
final Map<String, String> model = new HashMap<String, String>();
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 {

View File

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

View File

@ -95,6 +95,7 @@
<bean id="notificationService" class="com.wisemapping.mail.NotificationService">
<property name="baseUrl" value="${site.baseurl}"/>
<property name="mailer" ref="mailer"/>
<property name="velocityEngineWrapper" ref="velocityEngineWrapper"/>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">