Add report notification by email support.
This commit is contained in:
@@ -60,7 +60,7 @@ public class BrowserSupportInterceptor extends HandlerInterceptorAdapter {
|
||||
}
|
||||
|
||||
// Is a Explorer 9 or less without Google Chrome Frame ?.
|
||||
if (!userAgent.needsGCF()) {
|
||||
if (userAgent.needsGCF()) {
|
||||
throw new GoogleChromeFrameRequiredException();
|
||||
}
|
||||
|
||||
|
@@ -331,9 +331,7 @@ public class UserAgent implements Serializable {
|
||||
}
|
||||
|
||||
public boolean needsGCF() {
|
||||
return true;
|
||||
// final UserAgent.Product product = this.getProduct();
|
||||
// return product == UserAgent.Product.EXPLORER && this.isVersionLessThan(9) && this.getOs() == UserAgent.OS.WINDOWS && !this.hasGCFInstalled;
|
||||
final UserAgent.Product product = this.getProduct();
|
||||
return product == UserAgent.Product.EXPLORER && this.isVersionLessThan(9) && this.getOs() == UserAgent.OS.WINDOWS && !this.hasGCFInstalled;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -37,12 +37,14 @@ public final class Mailer {
|
||||
private VelocityEngine velocityEngine;
|
||||
private String serverFromEmail;
|
||||
private String supportEmail;
|
||||
private String errorReporterEmail;
|
||||
|
||||
//~ Methods ..............................................................................................
|
||||
|
||||
public Mailer(@NotNull String siteEmail, @NotNull String supportEmail) {
|
||||
public Mailer(@NotNull String siteEmail, @NotNull String supportEmail,@NotNull String errorReporterEmail) {
|
||||
this.serverFromEmail = siteEmail;
|
||||
this.supportEmail = supportEmail;
|
||||
this.errorReporterEmail = errorReporterEmail;
|
||||
}
|
||||
|
||||
public String getServerSenderEmail() {
|
||||
@@ -79,4 +81,8 @@ public final class Mailer {
|
||||
public String getSupportEmail() {
|
||||
return supportEmail;
|
||||
}
|
||||
|
||||
public String getErrorReporterEmail() {
|
||||
return errorReporterEmail;
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -140,6 +143,65 @@ final public class NotificationService {
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "Welcome to Wisemapping!", model,
|
||||
"confirmationMail.vm");
|
||||
}
|
||||
|
||||
public void reportMindmapEditorError(@NotNull MindMap mindmap, @NotNull User user, @NotNull String userAgent, @Nullable String jsErrorMsg) {
|
||||
|
||||
try {
|
||||
final Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("user", user);
|
||||
model.put("errorMsg", jsErrorMsg);
|
||||
model.put("mapXML", mindmap.getXmlStr().replaceAll("<", "<"));
|
||||
model.put("mapId", mindmap.getId());
|
||||
model.put("mapTitle", mindmap.getTitle());
|
||||
model.put("userAgent", userAgent);
|
||||
|
||||
final String errorReporterEmail = mailer.getErrorReporterEmail();
|
||||
if (errorReporterEmail != null) {
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Editor error from " + user.getEmail(), model,
|
||||
"editorErrorReport.vm");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void reportMindmapExportError(@NotNull String exportContent, @NotNull User user, @NotNull String userAgent, @NotNull Throwable exception) {
|
||||
try {
|
||||
final Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("user", user);
|
||||
model.put("errorMsg", stackTraceToString(exception));
|
||||
model.put("mapXML", exportContent.replaceAll("<", "<"));
|
||||
model.put("userAgent", userAgent);
|
||||
|
||||
final String errorReporterEmail = mailer.getErrorReporterEmail();
|
||||
if (errorReporterEmail != null) {
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), errorReporterEmail, "[WiseMapping] Export error from " + user.getEmail(), model,
|
||||
"editorErrorReport.vm");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String stackTraceToString(@NotNull Throwable e) {
|
||||
String retValue = null;
|
||||
StringWriter sw = null;
|
||||
PrintWriter pw = null;
|
||||
try {
|
||||
sw = new StringWriter();
|
||||
pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
retValue = sw.toString();
|
||||
} finally {
|
||||
try {
|
||||
if (pw != null) pw.close();
|
||||
if (sw != null) sw.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -198,8 +198,4 @@ public class MindmapController {
|
||||
private MindMapBean findMindmapBean(long mapId) {
|
||||
return new MindMapBean(findMindmap(mapId), Utils.getUser());
|
||||
}
|
||||
|
||||
private boolean isWelcomeMap(MindMapBean map) {
|
||||
return map.getTitle().startsWith("Welcome ");
|
||||
}
|
||||
}
|
||||
|
@@ -18,8 +18,12 @@
|
||||
|
||||
package com.wisemapping.rest;
|
||||
|
||||
import com.wisemapping.mail.NotificationService;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.rest.model.RestLogItem;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.MindmapService;
|
||||
import com.wisemapping.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -33,6 +37,13 @@ public class AccountController extends BaseController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Qualifier("mindmapService")
|
||||
@Autowired
|
||||
private MindmapService mindmapService;
|
||||
|
||||
@Autowired
|
||||
private NotificationService notificationService;
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "account/password", consumes = {"text/plain"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void changePassword(@RequestBody String password) {
|
||||
@@ -68,4 +79,13 @@ public class AccountController extends BaseController {
|
||||
user.setLastname(lastname);
|
||||
userService.updateUser(user);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "logger/editor", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void changePassword(@RequestBody RestLogItem item) {
|
||||
final MindMap mindmap = mindmapService.findMindmapById(item.getMapId());
|
||||
final User user = Utils.getUser();
|
||||
notificationService.reportMindmapEditorError(mindmap, user, item.getUserAgent(), item.getJsErrorMsg() + "\n" + item.getJsStack());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,56 @@
|
||||
package com.wisemapping.rest.model;
|
||||
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "logitem")
|
||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||
@JsonAutoDetect(
|
||||
fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
||||
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
|
||||
isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
|
||||
public class RestLogItem {
|
||||
|
||||
private String jsStack;
|
||||
private String userAgent;
|
||||
private String jsErrorMsg;
|
||||
|
||||
public int getMapId() {
|
||||
return mapId;
|
||||
}
|
||||
|
||||
public void setMapId(int mapId) {
|
||||
this.mapId = mapId;
|
||||
}
|
||||
|
||||
private int mapId;
|
||||
|
||||
public String getJsStack() {
|
||||
return jsStack;
|
||||
}
|
||||
|
||||
public void setJsStack(@NotNull String jsStack) {
|
||||
this.jsStack = jsStack;
|
||||
}
|
||||
|
||||
public String getUserAgent() {
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
public void setUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
|
||||
public String getJsErrorMsg() {
|
||||
return jsErrorMsg;
|
||||
}
|
||||
|
||||
public void setJsErrorMsg(String jsErrorMsg) {
|
||||
this.jsErrorMsg = jsErrorMsg;
|
||||
}
|
||||
}
|
@@ -18,25 +18,38 @@
|
||||
|
||||
package com.wisemapping.rest.view;
|
||||
|
||||
import com.wisemapping.exporter.ExportException;
|
||||
import com.wisemapping.exporter.ExportFormat;
|
||||
import com.wisemapping.exporter.ExportProperties;
|
||||
import com.wisemapping.exporter.ExporterFactory;
|
||||
import com.wisemapping.mail.NotificationService;
|
||||
import com.wisemapping.security.Utils;
|
||||
import org.apache.batik.transcoder.TranscoderException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class TransformView extends AbstractView {
|
||||
|
||||
private String contentType;
|
||||
private ExportFormat exportFormat;
|
||||
private NotificationService notificationService;
|
||||
|
||||
@Autowired
|
||||
private Jaxb2Marshaller jaxbMarshaller;
|
||||
|
||||
@@ -75,16 +88,20 @@ public class TransformView extends AbstractView {
|
||||
// Change image link URL.
|
||||
setBaseBaseImgUrl(exportFormat, properties);
|
||||
|
||||
// Write the conversion content ...
|
||||
final ServletOutputStream outputStream = response.getOutputStream();
|
||||
if (exportFormat == ExportFormat.FREEMIND) {
|
||||
ExporterFactory.export(properties, content, outputStream, null);
|
||||
} else if (exportFormat == ExportFormat.WISEMAPPING) {
|
||||
final Object mindmap = viewMap.get("mindmap");
|
||||
final StreamResult result = new StreamResult(outputStream);
|
||||
jaxbMarshaller.marshal(mindmap, result);
|
||||
} else {
|
||||
ExporterFactory.export(properties, null, outputStream, content);
|
||||
try {
|
||||
// Write the conversion content ...
|
||||
final ServletOutputStream outputStream = response.getOutputStream();
|
||||
if (exportFormat == ExportFormat.FREEMIND) {
|
||||
ExporterFactory.export(properties, content, outputStream, null);
|
||||
} else if (exportFormat == ExportFormat.WISEMAPPING) {
|
||||
final Object mindmap = viewMap.get("mindmap");
|
||||
final StreamResult result = new StreamResult(outputStream);
|
||||
jaxbMarshaller.marshal(mindmap, result);
|
||||
} else {
|
||||
ExporterFactory.export(properties, null, outputStream, content);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
notificationService.reportMindmapExportError(content, Utils.getUser(), request.getHeader("User-Agent"),e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user