Working on a "REST" version of import.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user