Map are loaded using Rest service.

This commit is contained in:
Paulo Gustavo Veiga 2013-01-31 22:50:21 -03:00
parent e734ea350c
commit cabca992d1
4 changed files with 42 additions and 15 deletions

View File

@ -20,13 +20,13 @@ mindplot.RESTPersistenceManager = new Class({
Extends:mindplot.PersistenceManager,
initialize:function (options) {
this.parent();
$assert(options.saveUrl, "saveUrl can not be null");
$assert(options.documentUrl, "documentUrl can not be null");
$assert(options.revertUrl, "revertUrl can not be null");
$assert(options.lockUrl, "lockUrl can not be null");
$assert(options.session, "session can not be null");
$assert(options.timestamp, "timestamp can not be null");
this.saveUrl = options.saveUrl;
this.documentUrl = options.documentUrl;
this.revertUrl = options.revertUrl;
this.lockUrl = options.lockUrl;
this.timestamp = options.timestamp;
@ -56,7 +56,7 @@ mindplot.RESTPersistenceManager = new Class({
}, 10000);
var request = new Request({
url:this.saveUrl.replace("{id}", mapId) + "?" + query,
url:this.documentUrl.replace("{id}", mapId) + "?" + query,
method:'put',
async:!sync,
@ -100,10 +100,6 @@ mindplot.RESTPersistenceManager = new Class({
}
events.onError(userMsg);
persistence.onSave = false;
// if (this.status != 0) {
// throw new Error("responseText:" + responseText + ",status:" + this.status);
// }
},
headers:{"Content-Type":"application/json", "Accept":"application/json"},
@ -164,6 +160,29 @@ mindplot.RESTPersistenceManager = new Class({
severity = "INFO";
}
return {severity:severity, message:message};
},
loadMapDom:function (mapId) {
// Let's try to open one from the local directory ...
var xml;
var xmlRequest = new Request({
url:this.documentUrl.replace("{id}", mapId) + "/xml",
method:'get',
async:false,
headers:{"Content-Type":"text/plain","Accept":"application/xml"},
onSuccess:function (responseText) {
xml = responseText;
}
});
xmlRequest.send();
// If I could not load it from a file, hard code one.
if (xml == null) {
throw new Error("Map could not be loaded");
}
var parser = new DOMParser();
return parser.parseFromString(xml, "text/xml");
}
}
);

View File

@ -30,6 +30,7 @@ function createStorageManager(mindplot) {
},
loadMapDom : function(mapId) {
var xml;
var xmlRequest = new Request({
url: this.backendUrl + mapId,
method: 'get',

View File

@ -173,6 +173,15 @@ public class MindmapController extends BaseController {
return lockInfo.getTimestamp();
}
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/document/xml",consumes = {"text/plain"}, produces = {"application/xml"})
@ResponseBody
public String retrieveDocument(@PathVariable int id, @NotNull HttpServletResponse response) throws WiseMappingException, IOException {
response.setCharacterEncoding("UTF-8");
final Mindmap mindmap = mindmapService.findMindmapById(id);
return mindmap.getXmlStr();
}
private void verifyLock(@NotNull Mindmap mindmap, @NotNull User user, long session, long timestamp) throws WiseMappingException {
// The lock was lost, reclaim as the ownership of it.

View File

@ -31,14 +31,13 @@
$(document).addEvent('loadcomplete', function (resource) {
try {
var mapId = '${mindmap.id}';
var mapXml = '${mindmap.xmlAsJsLiteral}';
// Configure designer options ...
var options = loadDesignerOptions();
<c:if test="${!memoryPersistence && !readOnlyMode}">
options.persistenceManager = new mindplot.RESTPersistenceManager(
{
saveUrl:"c/restful/maps/{id}/document",
documentUrl:"c/restful/maps/{id}/document",
revertUrl:"c/restful/maps/{id}/history/latest",
lockUrl:"c/restful/maps/{id}/lock",
timestamp: ${lockTimestamp},
@ -58,12 +57,11 @@
// Build designer ...
var designer = buildDesigner(options);
// Load map from XML ...
var parser = new DOMParser();
var domDocument = parser.parseFromString(mapXml, "text/xml");
var mindmap = mindplot.PersistenceManager.loadFromDom(mapId, domDocument);
// Load map from XML file persisted on disk...
var persistence = mindplot.PersistenceManager.getInstance();
var mindmap = mindmap = persistence.load(mapId);
designer.loadMap(mindmap);
} catch (e) {
logStackTrace(e);
throw e;