Add report notification by email support.

This commit is contained in:
Paulo Gustavo Veiga
2012-06-23 14:39:50 -03:00
parent 2d8fa5c259
commit c8837baadd
16 changed files with 250 additions and 39 deletions

View File

@@ -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());
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}