Working on a "REST" version of import.

This commit is contained in:
Paulo Gustavo Veiga 2012-06-03 19:19:48 -03:00
parent b914bbb8a8
commit 3907e04ff6
12 changed files with 82 additions and 222 deletions

View File

@ -1,71 +0,0 @@
/*
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.controller;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.importer.ImporterException;
import com.wisemapping.model.MindMap;
import com.wisemapping.model.User;
import com.wisemapping.security.Utils;
import com.wisemapping.service.MindmapService;
import com.wisemapping.service.UserService;
import com.wisemapping.view.ImportMapBean;
import org.springframework.validation.BindException;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.multipart.support.StringMultipartFileEditor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ImportController
extends BaseSimpleFormController {
//~ Methods ..............................................................................................
protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception {
return new ImportMapBean();
}
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
throws ServletException, WiseMappingException, ImporterException {
final ImportMapBean bean = (ImportMapBean) command;
User user = Utils.getUser();
final UserService userService = this.getUserService();
user = userService.getUserBy(user.getId());
final MindMap mindMap = bean.getImportedMap();
mindMap.setOwner(user);
final MindmapService mindmapService = this.getMindmapService();
mindmapService.addMindmap(mindMap, user);
final StringBuilder redirectionTo = new StringBuilder("redirect:" + mindMap.getId() + "/edit");
return new ModelAndView(redirectionTo.toString());
}
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
throws ServletException {
// to actually be able to convert Multipart instance to a String
// we have to register a custom editor
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
// now Spring knows how to handle multipart object and convert them
}
}

View File

@ -32,6 +32,11 @@ public class MindmapController {
return new ModelAndView("mindmapExport", "mindmap", modelObject); return new ModelAndView("mindmapExport", "mindmap", modelObject);
} }
@RequestMapping(value = "maps/import")
public ModelAndView showImportPAge() throws IOException {
return new ModelAndView("mindmapImport");
}
@RequestMapping(value = "maps/{id}/exportf") @RequestMapping(value = "maps/{id}/exportf")
public ModelAndView showExportPageFull(@PathVariable int id) throws IOException { public ModelAndView showExportPageFull(@PathVariable int id) throws IOException {
final MindMapBean modelObject = findMindmapBean(id); final MindMapBean modelObject = findMindmapBean(id);
@ -76,7 +81,6 @@ public class MindmapController {
return new ModelAndView("mindmapPublishFull", "mindmap", mindmap); return new ModelAndView("mindmapPublishFull", "mindmap", mindmap);
} }
@RequestMapping(value = "maps/{id}/edit") @RequestMapping(value = "maps/{id}/edit")
public ModelAndView editMap(@PathVariable int id, @NotNull HttpServletRequest request) { public ModelAndView editMap(@PathVariable int id, @NotNull HttpServletRequest request) {
ModelAndView view; ModelAndView view;

View File

@ -21,6 +21,10 @@ package com.wisemapping.rest;
import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.exporter.ExportFormat; import com.wisemapping.exporter.ExportFormat;
import com.wisemapping.importer.ImportFormat;
import com.wisemapping.importer.Importer;
import com.wisemapping.importer.ImporterException;
import com.wisemapping.importer.ImporterFactory;
import com.wisemapping.model.MindMap; import com.wisemapping.model.MindMap;
import com.wisemapping.model.MindmapUser; import com.wisemapping.model.MindmapUser;
import com.wisemapping.model.User; import com.wisemapping.model.User;
@ -29,6 +33,7 @@ import com.wisemapping.rest.model.RestMindmapInfo;
import com.wisemapping.rest.model.RestMindmapList; import com.wisemapping.rest.model.RestMindmapList;
import com.wisemapping.security.Utils; import com.wisemapping.security.Utils;
import com.wisemapping.service.MindmapService; import com.wisemapping.service.MindmapService;
import com.wisemapping.service.UserService;
import com.wisemapping.validator.MapInfoValidator; import com.wisemapping.validator.MapInfoValidator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -42,6 +47,7 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
@ -85,8 +91,7 @@ public class MindmapController extends BaseController {
return new ModelAndView("transformViewFreemind", values); return new ModelAndView("transformViewFreemind", values);
} }
@RequestMapping(method = RequestMethod.GET, value = "/maps/", produces = {"application/json", "text/html", "application/xml"})
@RequestMapping(method = RequestMethod.GET, value = "/maps", produces = {"application/json", "text/html", "application/xml"})
public ModelAndView retrieveList(@RequestParam(required = false) String q) throws IOException { public ModelAndView retrieveList(@RequestParam(required = false) String q) throws IOException {
final User user = com.wisemapping.security.Utils.getUser(); final User user = com.wisemapping.security.Utils.getUser();
@ -129,7 +134,6 @@ public class MindmapController extends BaseController {
saveMindmap(minor, mindMap, user); saveMindmap(minor, mindMap, user);
} }
/** /**
* The intention of this method is the update of several properties at once ... * The intention of this method is the update of several properties at once ...
*/ */
@ -299,6 +303,20 @@ public class MindmapController extends BaseController {
response.setHeader("ResourceId", Integer.toString(delegated.getId())); response.setHeader("ResourceId", Integer.toString(delegated.getId()));
} }
@RequestMapping(method = RequestMethod.POST, value = "/maps", consumes = {"application/freemind"})
@ResponseStatus(value = HttpStatus.CREATED)
public void createMapFromFreemind(@RequestBody byte[] freemindXml, @RequestParam(required = true) String title, @RequestParam(required = false) String description, @NotNull HttpServletResponse response) throws IOException, WiseMappingException, ImporterException {
// Convert map ...
final Importer importer = ImporterFactory.getInstance().getImporter(ImportFormat.FREEMIND);
final ByteArrayInputStream stream = new ByteArrayInputStream(freemindXml);
final MindMap mindMap = importer.importMap(title, description, stream);
// Save new map ...
final User user = Utils.getUser();
createMap(new RestMindmap(mindMap, user), response);
}
@RequestMapping(method = RequestMethod.POST, value = "/maps/{id}", consumes = {"application/xml", "application/json"}) @RequestMapping(method = RequestMethod.POST, value = "/maps/{id}", consumes = {"application/xml", "application/json"})
@ResponseStatus(value = HttpStatus.CREATED) @ResponseStatus(value = HttpStatus.CREATED)
public void createDuplicate(@RequestBody RestMindmapInfo restMindmap, @PathVariable int id, @NotNull HttpServletResponse response) throws IOException, WiseMappingException { public void createDuplicate(@RequestBody RestMindmapInfo restMindmap, @PathVariable int id, @NotNull HttpServletResponse response) throws IOException, WiseMappingException {

View File

@ -1,57 +0,0 @@
/*
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.validator;
import com.wisemapping.controller.Messages;
import com.wisemapping.importer.ImportFormat;
import com.wisemapping.importer.Importer;
import com.wisemapping.importer.ImporterException;
import com.wisemapping.importer.ImporterFactory;
import com.wisemapping.model.MindMap;
import com.wisemapping.view.ImportMapBean;
import org.jetbrains.annotations.NotNull;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import java.io.ByteArrayInputStream;
public class ImportMapValidator extends MapInfoValidator {
public boolean supports(final Class clazz) {
return clazz.equals(ImportMapBean.class);
}
public void validate(Object obj, @NotNull Errors errors) {
final ImportMapBean bean = (ImportMapBean) obj;
this.validateMapInfo(errors, bean.getTitle(), bean.getDescription());
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "mapFile", Messages.FIELD_REQUIRED);
try {
final Importer importer = ImporterFactory.getInstance().getImporter(ImportFormat.FREEMIND);
final ByteArrayInputStream stream = new ByteArrayInputStream(bean.getMapFile().getBytes());
final MindMap map = importer.importMap(bean.getTitle(), bean.getDescription(), stream);
bean.setImportedMap(map);
} catch (ImporterException e) {
Object[] errorArgs = new Object[]{e.getMessage()};
errors.rejectValue("mapFile", Messages.IMPORT_MAP_ERROR, errorArgs, "FreeMind could not be imported.");
}
}
}

View File

@ -1,45 +0,0 @@
/*
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.view;
import com.wisemapping.model.MindMap;
public class ImportMapBean extends MindMapInfoBean{
private String mapFile;
private MindMap importedMap;
public MindMap getImportedMap() {
return importedMap;
}
public void setMapFile(String mapFile) {
this.mapFile = mapFile;
}
public String getMapFile() {
return mapFile;
}
public void setImportedMap(MindMap map) {
this.importedMap = map;
}
}

View File

@ -1,6 +1,6 @@
NEW_MINDMAP=Create a new map
NAME=Name NAME=Name
DESCRIPTION=Description DESCRIPTION=Description
FILE_FORMAT=File Format
OK=Ok OK=Ok
WISEMAPPING=WiseMapping WISEMAPPING=WiseMapping
ADD=Add ADD=Add
@ -245,7 +245,6 @@ FREEMIND_EXPORT_IMPORT_MESSAGE=You can now easily import and export mind maps fr
EDITOR_TOOLBAR_IMPROVED=Usability Improvement: The editor toolbar has been redesign EDITOR_TOOLBAR_IMPROVED=Usability Improvement: The editor toolbar has been redesign
EDITOR_TOOLBAR_IMPROVED_MESSAGE= The toolbar has been redesign to improve its usability. EDITOR_TOOLBAR_IMPROVED_MESSAGE= The toolbar has been redesign to improve its usability.
COLLABORATE=Collaborate COLLABORATE=Collaborate
IMPORT-EXPORT_ISSUES_FIXED=Usability Improvement: Import-Export issues have been solved.
GO_TO= Go to my Wisemaps GO_TO= Go to my Wisemaps
NEWS_AND_ARTICLES=News & Articles NEWS_AND_ARTICLES=News & Articles

View File

@ -1,4 +1,3 @@
NEW_MINDMAP=Crear un nuevo mapa
NAME=Nombre NAME=Nombre
DESCRIPTION=Descripción DESCRIPTION=Descripción
OK=Ok OK=Ok

View File

@ -1,4 +1,3 @@
NEW_MINDMAP = Cr\u00e9er une nouvelle carte mentale
NAME = Nom NAME = Nom
DESCRIPTION = Description DESCRIPTION = Description
OK = Ok OK = Ok
@ -246,13 +245,6 @@ COLLABORATE = Contribuer
PRINT_FEATURE_IMPLEMENTED = Imprimer la carte maintenant. PRINT_FEATURE_IMPLEMENTED = Imprimer la carte maintenant.
PRINT_FEATURE_IMPLEMENTED_MESSAGE = Vous pouvez maintenant imprimer vos cartes \u00e0 partir de l\'\u00e9diteur et de la liste de cartes! PRINT_FEATURE_IMPLEMENTED_MESSAGE = Vous pouvez maintenant imprimer vos cartes \u00e0 partir de l\'\u00e9diteur et de la liste de cartes!
EMBEDDED_MAP_SIZE=* Note EMBEDDED_MAP_SIZE=* Note
USABILITY_EDITING_IMPROVED= Usability Improvement =
USABILITY_EDITING_IMPROVED_ESC= Usability Improvement =
USABILITY_EDITING_IMPROVED_TEXT=Now you have 3 different ways of editing a node text.</br><ul><li><b>Typing</b> Start typing to replace the focused node text.</li><li><b>F2</b> Pressing F2 key, will let you edit the node text</li><li><b>Double click
USABILITY_EDITING_IMPROVED_TEXT_ESC =
IMPORT-EXPORT_ISSUES_FIXED=Usability Improvement
USABILITY_EDITOR_IMPROVED= Usability Improvement
USABILITY_EDITOR_IMPROVED_SHRINK= Usability Improvement
EDITOR_LINKS=Mind Map feature EDITOR_LINKS=Mind Map feature
NEWS_ADD_ICON=Mind Map feature NEWS_ADD_ICON=Mind Map feature
EXPORT_FORMAT_RESTRICTIONS=Important: Exporting to Image, PDF or SVG is available only in the editor toolbar only.\ EXPORT_FORMAT_RESTRICTIONS=Important: Exporting to Image, PDF or SVG is available only in the editor toolbar only.\

View File

@ -166,7 +166,7 @@
<put name="body" value="/jsp/keyboard.jsp"/> <put name="body" value="/jsp/keyboard.jsp"/>
</definition> </definition>
<definition name="importMap" extends="pageTemplate"> <definition name="mindmapImport" extends="pageTemplate">
<put name="title" value="IMPORT_MINDMAP"/> <put name="title" value="IMPORT_MINDMAP"/>
<put name="details" value="IMPORT_MINDMAP_INFO"/> <put name="details" value="IMPORT_MINDMAP_INFO"/>
<put name="body" value="/jsp/mindmapImport.jsp"/> <put name="body" value="/jsp/mindmapImport.jsp"/>

View File

@ -114,28 +114,12 @@
<property name="userService" ref="userService"/> <property name="userService" ref="userService"/>
</bean> </bean>
<bean id="importMapValidator" class="com.wisemapping.validator.ImportMapValidator">
<property name="mindmapService" ref="mindmapService"/>
</bean>
<bean id="historyController" class="com.wisemapping.controller.HistoryController"> <bean id="historyController" class="com.wisemapping.controller.HistoryController">
<property name="methodNameResolver" ref="paramResolverByAction"/> <property name="methodNameResolver" ref="paramResolverByAction"/>
<property name="mindmapService" ref="mindmapService"/> <property name="mindmapService" ref="mindmapService"/>
<property name="userService" ref="userService"/> <property name="userService" ref="userService"/>
</bean> </bean>
<bean id="importMapController" class="com.wisemapping.controller.ImportController">
<property name="sessionForm" value="false"/>
<property name="commandName" value="importMap"/>
<property name="commandClass" value="com.wisemapping.view.ImportMapBean"/>
<property name="validator" ref="importMapValidator"/>
<property name="formView" value="importMap"/>
<property name="errorView" value="importMap"/>
<property name="mindmapService" ref="mindmapService"/>
<property name="userService" ref="userService"/>
</bean>
<bean id="multipartResolver" <bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
@ -166,8 +150,6 @@
</property> </property>
<property name="mappings"> <property name="mappings">
<props> <props>
<prop key="maps/import">importMapController</prop>
<!-- Review --> <!-- Review -->
<prop key="publicView">publicView</prop> <prop key="publicView">publicView</prop>
<prop key="embeddedView">embeddedView</prop> <prop key="embeddedView">embeddedView</prop>

View File

@ -260,7 +260,7 @@ function callbackOnTableInit() {
$(function() { $(function() {
$('#mindmapListTable').dataTable({ $('#mindmapListTable').dataTable({
bProcessing : true, bProcessing : true,
sAjaxSource : "../service/maps", sAjaxSource : "../service/maps/",
sAjaxDataProp: 'mindmapsInfo', sAjaxDataProp: 'mindmapsInfo',
fnInitComplete: function() { fnInitComplete: function() {
$('#mindmapListTable tbody').change(updateStatusToolbar); $('#mindmapListTable tbody').change(updateStatusToolbar);
@ -349,7 +349,7 @@ $(function() {
}); });
$("#importBtn").click(function() { $("#importBtn").click(function() {
window.open('c/maps/import'); window.location = 'c/maps/import';
}); });
$("#duplicateBtn").click(function() { $("#duplicateBtn").click(function() {
@ -483,7 +483,7 @@ $(function() {
$('#foldersContainer .active i').addClass('icon-white'); $('#foldersContainer .active i').addClass('icon-white');
// Reload the table data ... // Reload the table data ...
dataTable.fnReloadAjax("../service/maps?q=" + $(this).attr('data-filter'), callbackOnTableInit, true); dataTable.fnReloadAjax("../service/maps/?q=" + $(this).attr('data-filter'), callbackOnTableInit, true);
event.preventDefault(); event.preventDefault();
}); });
}); });

View File

@ -6,24 +6,63 @@
</h1> </h1>
<p><spring:message code="${requestScope.details}"/></p> <p><spring:message code="${requestScope.details}"/></p>
<form:form method="post" commandName="importMap" enctype="multipart/form-data">
<form method="post" enctype="multipart/form-data" action="#">
<fieldset> <fieldset>
<label for="title"><spring:message code="NAME"/></label> <label for="title"><spring:message code="NAME"/></label>
<form:input path="title" id="title" tabindex="1" required="required"/> <input type="text" id="title" required="required"/>
<form:errors path="title" cssClass="errorMsg"/>
<label for="title"><spring:message code="DESCRIPTION"/></label> <label for="description"><spring:message code="DESCRIPTION"/></label>
<form:input path="description" id="description" tabindex="2"/> <input type="text" name="description" id="description"/>
<form:errors path="description" cssClass="errorMsg"/>
<label><spring:message code="DESCRIPTION"/> </label>
<input type="radio" name="type" value="mm"/> Freemind (0.9)
<input type="radio" name="type" value="wxml"/> WiseMapping
<label for="mapFile"><spring:message code="FREE_MIND_FILE"/></label> <label for="mapFile"><spring:message code="FREE_MIND_FILE"/></label>
<input type="file" name="mapFile" id="mapFile"/> <input type="file" name="mapFile" id="mapFile"/>
<form:errors path="mapFile" cssClass="errorMsg"/>
</fieldset> </fieldset>
<input type="submit" value="<spring:message code="IMPORT"/>" class="btn btn-primary"/> <input type="button" id="acceptButton" value="<spring:message code="IMPORT"/>" class="btn btn-primary"/>
<input type="button" value="<spring:message code="CANCEL"/>" class="btn" <input type="button" id="cancelButton" value="<spring:message code="CANCEL"/>" class="btn">
onclick="window.location='/c/maps/'"> </form>
</form:form>
</div> </div>
<script type="text/javascript">
// Save status on click ...
$('#cancelButton').click(function() {
window.location = '/c/maps/';
});
$('#acceptButton').click(function(event) {
// http://www.html5rocks.com/en/tutorials/file/dndfiles/
var content;
if (window.FileReader) {
reader = new FileReader();
reader.onloadend = function (e) {
content = e.target.result;
};
reader.readAsDataURL(file);
}
jQuery.ajax("service/maps", {
async:false,
dataType: 'application/freemind',
data: "",
type: 'PUT',
contentType:"text/plain",
success : function(data, textStatus, jqXHR) {
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
});
// Hook for interaction with the main parent window ...
var submitDialogForm = function() {
$('#dialogMainForm').submit();
}
</script>