mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-12-23 03:43:48 +01:00
Working on a "REST" version of import.
This commit is contained in:
parent
b914bbb8a8
commit
3907e04ff6
@ -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
|
||||
}
|
||||
}
|
@ -32,6 +32,11 @@ public class MindmapController {
|
||||
return new ModelAndView("mindmapExport", "mindmap", modelObject);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/import")
|
||||
public ModelAndView showImportPAge() throws IOException {
|
||||
return new ModelAndView("mindmapImport");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/exportf")
|
||||
public ModelAndView showExportPageFull(@PathVariable int id) throws IOException {
|
||||
final MindMapBean modelObject = findMindmapBean(id);
|
||||
@ -76,7 +81,6 @@ public class MindmapController {
|
||||
return new ModelAndView("mindmapPublishFull", "mindmap", mindmap);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "maps/{id}/edit")
|
||||
public ModelAndView editMap(@PathVariable int id, @NotNull HttpServletRequest request) {
|
||||
ModelAndView view;
|
||||
|
@ -21,6 +21,10 @@ package com.wisemapping.rest;
|
||||
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
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.MindmapUser;
|
||||
import com.wisemapping.model.User;
|
||||
@ -29,6 +33,7 @@ import com.wisemapping.rest.model.RestMindmapInfo;
|
||||
import com.wisemapping.rest.model.RestMindmapList;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.MindmapService;
|
||||
import com.wisemapping.service.UserService;
|
||||
import com.wisemapping.validator.MapInfoValidator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -42,6 +47,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@ -85,8 +91,7 @@ public class MindmapController extends BaseController {
|
||||
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 {
|
||||
final User user = com.wisemapping.security.Utils.getUser();
|
||||
|
||||
@ -129,7 +134,6 @@ public class MindmapController extends BaseController {
|
||||
saveMindmap(minor, mindMap, user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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()));
|
||||
}
|
||||
|
||||
@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"})
|
||||
@ResponseStatus(value = HttpStatus.CREATED)
|
||||
public void createDuplicate(@RequestBody RestMindmapInfo restMindmap, @PathVariable int id, @NotNull HttpServletResponse response) throws IOException, WiseMappingException {
|
||||
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
NEW_MINDMAP=Create a new map
|
||||
NAME=Name
|
||||
DESCRIPTION=Description
|
||||
FILE_FORMAT=File Format
|
||||
OK=Ok
|
||||
WISEMAPPING=WiseMapping
|
||||
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_MESSAGE= The toolbar has been redesign to improve its usability.
|
||||
COLLABORATE=Collaborate
|
||||
IMPORT-EXPORT_ISSUES_FIXED=Usability Improvement: Import-Export issues have been solved.
|
||||
GO_TO= Go to my Wisemaps
|
||||
|
||||
NEWS_AND_ARTICLES=News & Articles
|
||||
|
@ -1,4 +1,3 @@
|
||||
NEW_MINDMAP=Crear un nuevo mapa
|
||||
NAME=Nombre
|
||||
DESCRIPTION=Descripción
|
||||
OK=Ok
|
||||
|
@ -1,4 +1,3 @@
|
||||
NEW_MINDMAP = Cr\u00e9er une nouvelle carte mentale
|
||||
NAME = Nom
|
||||
DESCRIPTION = Description
|
||||
OK = Ok
|
||||
@ -246,13 +245,6 @@ COLLABORATE = Contribuer
|
||||
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!
|
||||
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
|
||||
NEWS_ADD_ICON=Mind Map feature
|
||||
EXPORT_FORMAT_RESTRICTIONS=Important: Exporting to Image, PDF or SVG is available only in the editor toolbar only.\
|
||||
|
@ -166,7 +166,7 @@
|
||||
<put name="body" value="/jsp/keyboard.jsp"/>
|
||||
</definition>
|
||||
|
||||
<definition name="importMap" extends="pageTemplate">
|
||||
<definition name="mindmapImport" extends="pageTemplate">
|
||||
<put name="title" value="IMPORT_MINDMAP"/>
|
||||
<put name="details" value="IMPORT_MINDMAP_INFO"/>
|
||||
<put name="body" value="/jsp/mindmapImport.jsp"/>
|
||||
|
@ -114,28 +114,12 @@
|
||||
<property name="userService" ref="userService"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="importMapValidator" class="com.wisemapping.validator.ImportMapValidator">
|
||||
<property name="mindmapService" ref="mindmapService"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="historyController" class="com.wisemapping.controller.HistoryController">
|
||||
<property name="methodNameResolver" ref="paramResolverByAction"/>
|
||||
<property name="mindmapService" ref="mindmapService"/>
|
||||
<property name="userService" ref="userService"/>
|
||||
</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"
|
||||
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
||||
@ -166,8 +150,6 @@
|
||||
</property>
|
||||
<property name="mappings">
|
||||
<props>
|
||||
<prop key="maps/import">importMapController</prop>
|
||||
|
||||
<!-- Review -->
|
||||
<prop key="publicView">publicView</prop>
|
||||
<prop key="embeddedView">embeddedView</prop>
|
||||
|
@ -260,7 +260,7 @@ function callbackOnTableInit() {
|
||||
$(function() {
|
||||
$('#mindmapListTable').dataTable({
|
||||
bProcessing : true,
|
||||
sAjaxSource : "../service/maps",
|
||||
sAjaxSource : "../service/maps/",
|
||||
sAjaxDataProp: 'mindmapsInfo',
|
||||
fnInitComplete: function() {
|
||||
$('#mindmapListTable tbody').change(updateStatusToolbar);
|
||||
@ -349,7 +349,7 @@ $(function() {
|
||||
});
|
||||
|
||||
$("#importBtn").click(function() {
|
||||
window.open('c/maps/import');
|
||||
window.location = 'c/maps/import';
|
||||
});
|
||||
|
||||
$("#duplicateBtn").click(function() {
|
||||
@ -483,7 +483,7 @@ $(function() {
|
||||
$('#foldersContainer .active i').addClass('icon-white');
|
||||
|
||||
// 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();
|
||||
});
|
||||
});
|
||||
|
@ -6,24 +6,63 @@
|
||||
</h1>
|
||||
|
||||
<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>
|
||||
<label for="title"><spring:message code="NAME"/></label>
|
||||
<form:input path="title" id="title" tabindex="1" required="required"/>
|
||||
<form:errors path="title" cssClass="errorMsg"/>
|
||||
<input type="text" id="title" required="required"/>
|
||||
|
||||
<label for="title"><spring:message code="DESCRIPTION"/></label>
|
||||
<form:input path="description" id="description" tabindex="2"/>
|
||||
<form:errors path="description" cssClass="errorMsg"/>
|
||||
<label for="description"><spring:message code="DESCRIPTION"/></label>
|
||||
<input type="text" name="description" id="description"/>
|
||||
|
||||
<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>
|
||||
<input type="file" name="mapFile" id="mapFile"/>
|
||||
<form:errors path="mapFile" cssClass="errorMsg"/>
|
||||
</fieldset>
|
||||
|
||||
<input type="submit" value="<spring:message code="IMPORT"/>" class="btn btn-primary"/>
|
||||
<input type="button" value="<spring:message code="CANCEL"/>" class="btn"
|
||||
onclick="window.location='/c/maps/'">
|
||||
|
||||
</form:form>
|
||||
<input type="button" id="acceptButton" value="<spring:message code="IMPORT"/>" class="btn btn-primary"/>
|
||||
<input type="button" id="cancelButton" value="<spring:message code="CANCEL"/>" class="btn">
|
||||
</form>
|
||||
</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>
|
Loading…
Reference in New Issue
Block a user