mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 06:07:57 +01:00
Add filter for avoiding multiple emails on error reporting.
This commit is contained in:
parent
1fee2bc349
commit
04a221799a
@ -16,5 +16,6 @@ WISE_BIN_FILE_PATH=./target/${WISE_BIN_FILE_NAME}
|
|||||||
scp ${WISE_BIN_FILE_PATH} thecrow@wisemapping.com:${SERVER_DOWNLOAD_DIR}
|
scp ${WISE_BIN_FILE_PATH} thecrow@wisemapping.com:${SERVER_DOWNLOAD_DIR}
|
||||||
|
|
||||||
# It's there ?
|
# It's there ?
|
||||||
|
cd target
|
||||||
wget -S http://downloads.wisemapping.org/stable/${WISE_BIN_FILE_NAME}
|
wget -S http://downloads.wisemapping.org/stable/${WISE_BIN_FILE_NAME}
|
||||||
#wget -S http://downloads.wisemapping.org/stable/${WISE_SRC_FILE_NAME}
|
#wget -S http://downloads.wisemapping.org/stable/${WISE_SRC_FILE_NAME}
|
||||||
|
@ -41,9 +41,10 @@ final public class NotificationService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Mailer mailer;
|
private Mailer mailer;
|
||||||
private String baseUrl;
|
private String baseUrl;
|
||||||
|
private NotifierFilter notificationFilter;
|
||||||
|
|
||||||
public NotificationService() {
|
public NotificationService() {
|
||||||
|
this.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) {
|
||||||
@ -141,14 +142,14 @@ final public class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendRegistrationEmail(@NotNull User user) {
|
public void sendRegistrationEmail(@NotNull User user) {
|
||||||
throw new UnsupportedOperationException("Not implemented yet");
|
// throw new UnsupportedOperationException("Not implemented yet");
|
||||||
// try {
|
// try {
|
||||||
// final Map<String, Object> model = new HashMap<String, Object>();
|
// final Map<String, String> model = new HashMap<String, String>();
|
||||||
// model.put("user", user);
|
// model.put("email", user.getEmail());
|
||||||
// final String activationUrl = "http://wisemapping.com/c/activation?code=" + user.getActivationCode();
|
//// final String activationUrl = "http://wisemapping.com/c/activation?code=" + user.getActivationCode();
|
||||||
// model.put("emailcheck", activationUrl);
|
//// model.put("emailcheck", activationUrl);
|
||||||
// mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "Welcome to Wisemapping!", model,
|
//// mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "Welcome to Wisemapping!", model,
|
||||||
// "confirmationMail.vm");
|
//// "confirmationMail.vm");
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// handleException(e);
|
// handleException(e);
|
||||||
// }
|
// }
|
||||||
@ -156,22 +157,24 @@ final public class NotificationService {
|
|||||||
|
|
||||||
public void reportJavascriptException(@NotNull Mindmap mindmap, @Nullable User user, @Nullable String jsErrorMsg, @NotNull HttpServletRequest request) {
|
public void reportJavascriptException(@NotNull Mindmap mindmap, @Nullable User user, @Nullable String jsErrorMsg, @NotNull HttpServletRequest request) {
|
||||||
|
|
||||||
final Map<String, Object> model = new HashMap<String, Object>();
|
final Map<String, String> model = new HashMap<String, String>();
|
||||||
model.put("errorMsg", jsErrorMsg);
|
model.put("errorMsg", jsErrorMsg);
|
||||||
try {
|
try {
|
||||||
model.put("mapXML", StringEscapeUtils.escapeXml(mindmap.getXmlStr()));
|
model.put("mapXML", StringEscapeUtils.escapeXml(mindmap.getXmlStr()));
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
// Ignore ...
|
// Ignore ...
|
||||||
}
|
}
|
||||||
model.put("mapId", mindmap.getId());
|
model.put("mapId", Integer.toString(mindmap.getId()));
|
||||||
model.put("mapTitle", mindmap.getTitle());
|
model.put("mapTitle", mindmap.getTitle());
|
||||||
|
|
||||||
sendNotification(model, user, request);
|
sendNotification(model, user, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotification(@NotNull Map<String, Object> model, @Nullable User user, @NotNull HttpServletRequest request) {
|
private void sendNotification(@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'"));
|
||||||
model.put("email", (user != null ? user.getEmail() : "'anonymous'"));
|
final String userEmail = user != null ? user.getEmail() : "'anonymous'";
|
||||||
|
|
||||||
|
model.put("email", userEmail);
|
||||||
model.put("userAgent", request.getHeader(UserAgent.USER_AGENT_HEADER));
|
model.put("userAgent", request.getHeader(UserAgent.USER_AGENT_HEADER));
|
||||||
model.put("server", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort());
|
model.put("server", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort());
|
||||||
model.put("requestURI", request.getRequestURI());
|
model.put("requestURI", request.getRequestURI());
|
||||||
@ -181,8 +184,11 @@ final public class NotificationService {
|
|||||||
try {
|
try {
|
||||||
final String errorReporterEmail = mailer.getErrorReporterEmail();
|
final String errorReporterEmail = mailer.getErrorReporterEmail();
|
||||||
if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) {
|
if (errorReporterEmail != null && !errorReporterEmail.isEmpty()) {
|
||||||
mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Bug from '" + (user != null ? user.getEmail() + "'" : "'anonymous'"), model,
|
|
||||||
"errorNotification.vm");
|
if (!notificationFilter.hasBeenSend(userEmail, model)) {
|
||||||
|
mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Bug from '" + (user != null ? user.getEmail() + "'" : "'anonymous'"), model,
|
||||||
|
"errorNotification.vm");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
@ -190,7 +196,7 @@ final public class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull String content, @NotNull HttpServletRequest request) {
|
public void reportJavaException(@NotNull Throwable exception, @Nullable User user, @NotNull String content, @NotNull HttpServletRequest request) {
|
||||||
final Map<String, Object> model = new HashMap<String, Object>();
|
final Map<String, String> model = new HashMap<String, String>();
|
||||||
model.put("errorMsg", stackTraceToString(exception));
|
model.put("errorMsg", stackTraceToString(exception));
|
||||||
model.put("mapXML", StringEscapeUtils.escapeXml(content));
|
model.put("mapXML", StringEscapeUtils.escapeXml(content));
|
||||||
|
|
||||||
@ -198,7 +204,7 @@ final public class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, Object> model = new HashMap<String, Object>();
|
final Map<String, String> model = new HashMap<String, String>();
|
||||||
model.put("errorMsg", stackTraceToString(exception));
|
model.put("errorMsg", stackTraceToString(exception));
|
||||||
|
|
||||||
sendNotification(model, user, request);
|
sendNotification(model, user, request);
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.wisemapping.mail;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.util.DigestUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class NotifierFilter {
|
||||||
|
public static final int MAX_CACHE_ENTRY = 500;
|
||||||
|
private final Map<String, String> emailByMd5 = Collections.synchronizedMap(new LinkedHashMap<String, String>() {
|
||||||
|
protected boolean removeEldestEntry(Map.Entry eldest) {
|
||||||
|
return size() > MAX_CACHE_ENTRY;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
public boolean hasBeenSend(@NotNull final String email, @NotNull final Map<String, String> model) {
|
||||||
|
|
||||||
|
final StringBuilder buff = new StringBuilder();
|
||||||
|
for (String key : model.keySet()) {
|
||||||
|
buff.append(key);
|
||||||
|
buff.append("=");
|
||||||
|
buff.append(model.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String digest = DigestUtils.md5DigestAsHex(buff.toString().getBytes());
|
||||||
|
boolean result = emailByMd5.containsKey(digest);
|
||||||
|
if (!result) {
|
||||||
|
emailByMd5.put(digest, email);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user