Handle deleted maps propertly.

This commit is contained in:
Paulo Gustavo Veiga 2013-03-29 21:09:28 -03:00
parent bd80d95d22
commit 8e66c97aa3
11 changed files with 109 additions and 55 deletions

View File

@ -20,6 +20,7 @@ package com.wisemapping.dao;
import com.wisemapping.model.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.List;
@ -38,7 +39,7 @@ public interface MindmapManager {
List<Mindmap> getAllMindmaps();
@NotNull
@Nullable
Mindmap getMindmapById(int mindmapId);
Mindmap getMindmapByTitle(final String name, final User user);

View File

@ -21,6 +21,7 @@ package com.wisemapping.dao;
import com.wisemapping.model.*;
import com.wisemapping.util.ZipUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.SimpleExpression;
@ -195,7 +196,7 @@ public class MindmapManagerImpl
}
@Override
@NotNull
@Nullable
public Mindmap getMindmapById(int id) {
return getHibernateTemplate().get(Mindmap.class, id);
}

View File

@ -18,7 +18,11 @@ abstract public class ClientException extends WiseMappingException {
String getMsgBundleKey();
public String getMessage(@NotNull final MessageSource messageSource, final @NotNull Locale locale) {
return messageSource.getMessage(this.getMsgBundleKey(), this.getMsgBundleArgs(), locale);
String message = messageSource.getMessage(this.getMsgBundleKey(), this.getMsgBundleArgs(), locale);
if(message==null){
message = this.getMessage();
}
return message;
}
protected Object[] getMsgBundleArgs(){

View File

@ -0,0 +1,38 @@
/*
* Copyright [2012] [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.exceptions;
import org.jetbrains.annotations.NotNull;
public class MapCouldNotFoundException
extends ClientException
{
public static final String MSG_KEY = "MAP_CAN_NOT_BE_FOUND";
public MapCouldNotFoundException(@NotNull String msg)
{
super(msg,Severity.FATAL);
}
@NotNull
@Override
protected String getMsgBundleKey() {
return MSG_KEY;
}
}

View File

@ -154,12 +154,12 @@ final public class NotificationService {
// }
}
public void reportJavascriptException(@NotNull Mindmap mindmap, @Nullable User user, @Nullable String jsErrorMsg, @NotNull HttpServletRequest request) {
public void reportJavascriptException(@Nullable Mindmap mindmap, @Nullable User user, @Nullable String jsErrorMsg, @NotNull HttpServletRequest request) {
final Map<String, String> model = new HashMap<String, String>();
model.put("errorMsg", jsErrorMsg);
try {
model.put("mapXML", StringEscapeUtils.escapeXml(mindmap.getXmlStr()));
model.put("mapXML", StringEscapeUtils.escapeXml(mindmap == null ? "map not found" : mindmap.getXmlStr()));
} catch (UnsupportedEncodingException e) {
// Ignore ...
}

View File

@ -58,7 +58,7 @@ public class AccountController extends BaseController {
throw new IllegalArgumentException("Password can not be null");
}
final User user = Utils.getUser();
final User user = Utils.getUser(true);
user.setPassword(password);
userService.changePassword(user);
}
@ -95,7 +95,7 @@ public class AccountController extends BaseController {
}
final User user = Utils.getUser();
final User user = Utils.getUser(true);
user.setLocale(language);
userService.updateUser(user);
}

View File

@ -60,7 +60,7 @@ public class MindmapController extends BaseController {
@ResponseBody
public ModelAndView retrieve(@PathVariable int id) throws WiseMappingException {
final User user = Utils.getUser();
final Mindmap mindMap = mindmapService.findMindmapById(id);
final Mindmap mindMap = findMindmapById(id);
final RestMindmap map = new RestMindmap(mindMap, user);
return new ModelAndView("mapView", "map", map);
@ -69,7 +69,7 @@ public class MindmapController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/wisemapping+xml"}, params = {"download=wxml"})
@ResponseBody
public ModelAndView retrieveAsWise(@PathVariable int id) throws WiseMappingException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
final Mindmap mindMap = findMindmapById(id);
final Map<String, Object> values = new HashMap<String, Object>();
final User user = Utils.getUser();
@ -80,8 +80,8 @@ public class MindmapController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/freemind"}, params = {"download=mm"})
@ResponseBody
public ModelAndView retrieveDocumentAsFreemind(@PathVariable int id) throws IOException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
public ModelAndView retrieveDocumentAsFreemind(@PathVariable int id) throws IOException, MapCouldNotFoundException {
final Mindmap mindMap = findMindmapById(id);
final Map<String, Object> values = new HashMap<String, Object>();
values.put("content", mindMap.getXmlStr());
values.put("filename", mindMap.getTitle());
@ -91,8 +91,8 @@ public class MindmapController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"text/plain"}, params = {"download=txt"})
@ResponseBody
public ModelAndView retrieveDocumentAsText(@PathVariable int id) throws IOException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
public ModelAndView retrieveDocumentAsText(@PathVariable int id) throws IOException, MapCouldNotFoundException {
final Mindmap mindMap = findMindmapById(id);
final Map<String, Object> values = new HashMap<String, Object>();
values.put("content", mindMap.getXmlStr());
values.put("filename", mindMap.getTitle());
@ -101,8 +101,8 @@ public class MindmapController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/vnd.mindjet.mindmanager"}, params = {"download=mmap"})
@ResponseBody
public ModelAndView retrieveDocumentAsMindJet(@PathVariable int id) throws IOException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
public ModelAndView retrieveDocumentAsMindJet(@PathVariable int id) throws IOException, MapCouldNotFoundException {
final Mindmap mindMap = findMindmapById(id);
final Map<String, Object> values = new HashMap<String, Object>();
values.put("content", mindMap.getXmlStr());
values.put("filename", mindMap.getTitle());
@ -112,8 +112,8 @@ public class MindmapController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/vnd.ms-excel"}, params = {"download=xls"})
@ResponseBody
public ModelAndView retrieveDocumentAsExcel(@PathVariable int id) throws IOException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
public ModelAndView retrieveDocumentAsExcel(@PathVariable int id) throws IOException, MapCouldNotFoundException {
final Mindmap mindMap = findMindmapById(id);
final Map<String, Object> values = new HashMap<String, Object>();
values.put("content", mindMap.getXmlStr());
values.put("filename", mindMap.getTitle());
@ -122,8 +122,8 @@ public class MindmapController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/vnd.oasis.opendocument.text"}, params = {"download=odt"})
@ResponseBody
public ModelAndView retrieveDocumentAsOdt(@PathVariable int id) throws IOException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
public ModelAndView retrieveDocumentAsOdt(@PathVariable int id) throws IOException, MapCouldNotFoundException {
final Mindmap mindMap = findMindmapById(id);
final Map<String, Object> values = new HashMap<String, Object>();
values.put("content", mindMap.getXmlStr());
values.put("filename", mindMap.getTitle());
@ -164,7 +164,7 @@ public class MindmapController extends BaseController {
@RequestMapping(value = "maps/{id}/history/{hid}", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateRevertMindmap(@PathVariable int id, @PathVariable String hid) throws WiseMappingException, IOException {
final Mindmap mindmap = mindmapService.findMindmapById(id);
final Mindmap mindmap = findMindmapById(id);
final User user = Utils.getUser();
if (LATEST_HISTORY_REVISION.equals(hid)) {
@ -184,7 +184,7 @@ public class MindmapController extends BaseController {
@ResponseBody
public long updateDocument(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor, @RequestParam(required = false) Long timestamp, @RequestParam(required = false) Long session) throws WiseMappingException, IOException {
final Mindmap mindmap = mindmapService.findMindmapById(id);
final Mindmap mindmap = findMindmapById(id);
final User user = Utils.getUser();
// Validate arguments ...
@ -221,7 +221,7 @@ public class MindmapController extends BaseController {
public byte[] retrieveDocument(@PathVariable int id, @NotNull HttpServletResponse response) throws WiseMappingException, IOException {
// I should not return byte, but there is some encoding issue here. Further research needed.
response.setCharacterEncoding("UTF-8");
final Mindmap mindmap = mindmapService.findMindmapById(id);
final Mindmap mindmap = findMindmapById(id);
String xmlStr = mindmap.getXmlStr();
return xmlStr.getBytes("UTF-8");
@ -271,7 +271,7 @@ public class MindmapController extends BaseController {
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void update(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException {
final Mindmap mindmap = mindmapService.findMindmapById(id);
final Mindmap mindmap = findMindmapById(id);
final User user = Utils.getUser();
final String xml = restMindmap.getXml();
@ -310,12 +310,21 @@ public class MindmapController extends BaseController {
saveMindmapDocument(minor, mindmap, user);
}
@NotNull
private Mindmap findMindmapById(int id) throws MapCouldNotFoundException {
Mindmap result = mindmapService.findMindmapById(id);
if(result==null){
throw new MapCouldNotFoundException("Map could not be found. Id:" + id);
}
return result;
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/title", consumes = {"text/plain"}, produces = {"application/json", "text/html", "application/xml"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateTitle(@RequestBody String title, @PathVariable int id) throws WiseMappingException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
final Mindmap mindMap = findMindmapById(id);
final User user = Utils.getUser();
// Is there a map with the same name ?
@ -325,15 +334,15 @@ public class MindmapController extends BaseController {
}
// Update map ...
final Mindmap mindmap = mindmapService.findMindmapById(id);
final Mindmap mindmap = findMindmapById(id);
mindmap.setTitle(title);
mindmapService.updateMindmap(mindMap, !true);
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/collabs", consumes = {"application/json", "application/xml"}, produces = {"application/json", "text/html", "application/xml"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateCollabs(@PathVariable int id, @NotNull @RequestBody RestCollaborationList restCollabs) throws CollaborationException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
public void updateCollabs(@PathVariable int id, @NotNull @RequestBody RestCollaborationList restCollabs) throws CollaborationException, MapCouldNotFoundException {
final Mindmap mindMap = findMindmapById(id);
// Only owner can change collaborators...
final User user = Utils.getUser();
@ -372,8 +381,8 @@ public class MindmapController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/collabs", produces = {"application/json", "text/html", "application/xml"})
public ModelAndView retrieveList(@PathVariable int id) {
final Mindmap mindMap = mindmapService.findMindmapById(id);
public ModelAndView retrieveList(@PathVariable int id) throws MapCouldNotFoundException {
final Mindmap mindMap = findMindmapById(id);
final Set<Collaboration> collaborations = mindMap.getCollaborations();
final List<RestCollaboration> collabs = new ArrayList<RestCollaboration>();
@ -392,11 +401,11 @@ public class MindmapController extends BaseController {
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateDescription(@RequestBody String description, @PathVariable int id) throws WiseMappingException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
final Mindmap mindMap = findMindmapById(id);
final User user = Utils.getUser();
// Update map ...
final Mindmap mindmap = mindmapService.findMindmapById(id);
final Mindmap mindmap = findMindmapById(id);
mindmap.setDescription(description);
mindmapService.updateMindmap(mindMap, !true);
}
@ -405,7 +414,7 @@ public class MindmapController extends BaseController {
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updatePublishState(@RequestBody String value, @PathVariable int id) throws WiseMappingException {
final Mindmap mindMap = mindmapService.findMindmapById(id);
final Mindmap mindMap = findMindmapById(id);
final User user = Utils.getUser();
if (!mindMap.hasPermissions(user, CollaborationRole.OWNER)) {
@ -422,7 +431,7 @@ public class MindmapController extends BaseController {
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteMapById(@PathVariable int id) throws IOException, WiseMappingException {
final User user = Utils.getUser();
final Mindmap mindmap = mindmapService.findMindmapById(id);
final Mindmap mindmap = findMindmapById(id);
mindmapService.removeMindmap(mindmap, user);
}
@ -430,7 +439,7 @@ public class MindmapController extends BaseController {
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateStarredState(@RequestBody String value, @PathVariable int id) throws WiseMappingException {
final Mindmap mindmap = mindmapService.findMindmapById(id);
final Mindmap mindmap = findMindmapById(id);
final User user = Utils.getUser();
// Update map status ...
@ -448,7 +457,7 @@ public class MindmapController extends BaseController {
public void updateMapLock(@RequestBody String value, @PathVariable int id) throws IOException, WiseMappingException {
final User user = Utils.getUser();
final LockManager lockManager = mindmapService.getLockManager();
final Mindmap mindmap = mindmapService.findMindmapById(id);
final Mindmap mindmap = findMindmapById(id);
final boolean lock = Boolean.parseBoolean(value);
if (!lock) {
@ -464,7 +473,7 @@ public class MindmapController extends BaseController {
final User user = Utils.getUser();
final String[] mapsIds = ids.split(",");
for (final String mapId : mapsIds) {
final Mindmap mindmap = mindmapService.findMindmapById(Integer.parseInt(mapId));
final Mindmap mindmap = findMindmapById(Integer.parseInt(mapId));
mindmapService.removeMindmap(mindmap, user);
}
}
@ -540,7 +549,7 @@ public class MindmapController extends BaseController {
final User user = Utils.getUser();
// Create a shallowCopy of the map ...
final Mindmap mindMap = mindmapService.findMindmapById(id);
final Mindmap mindMap = findMindmapById(id);
final Mindmap clonedMap = mindMap.shallowClone();
clonedMap.setTitle(restMindmap.getTitle());
clonedMap.setDescription(restMindmap.getDescription());

View File

@ -30,7 +30,7 @@ public interface MindmapService {
static final String TAG_SEPARATOR = " ";
@NotNull
@Nullable
Mindmap findMindmapById(int id);
Mindmap getMindmapByTitle(String title, User user);

View File

@ -93,7 +93,7 @@ public class MindmapServiceImpl
}
@Override
@NotNull
@Nullable
public Mindmap findMindmapById(int id) {
return mindmapManager.getMindmapById(id);
}

View File

@ -20,6 +20,7 @@ package com.wisemapping.webmvc;
import com.wisemapping.exceptions.AccessDeniedSecurityException;
import com.wisemapping.exceptions.MapCouldNotFoundException;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.CollaborationRole;
import com.wisemapping.model.Mindmap;
@ -29,7 +30,6 @@ import com.wisemapping.service.LockManager;
import com.wisemapping.service.MindmapService;
import com.wisemapping.view.MindMapBean;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.i18n.LocaleContextHolder;
@ -59,7 +59,7 @@ public class MindmapController {
}
@RequestMapping(value = "maps/{id}/details")
public String showDetails(@PathVariable int id, @NotNull Model model,@NotNull HttpServletRequest request) throws AccessDeniedSecurityException {
public String showDetails(@PathVariable int id, @NotNull Model model, @NotNull HttpServletRequest request) throws MapCouldNotFoundException {
final MindMapBean mindmap = findMindmapBean(id);
model.addAttribute("mindmap", mindmap);
model.addAttribute("baseUrl", request.getAttribute("site.baseurl"));
@ -67,7 +67,7 @@ public class MindmapController {
}
@RequestMapping(value = "maps/{id}/print")
public String showPrintPage(@PathVariable int id, @NotNull Model model) throws AccessDeniedSecurityException {
public String showPrintPage(@PathVariable int id, @NotNull Model model) throws MapCouldNotFoundException {
final MindMapBean mindmap = findMindmapBean(id);
model.addAttribute("principal", Utils.getUser());
model.addAttribute("mindmap", mindmap);
@ -77,33 +77,33 @@ public class MindmapController {
}
@RequestMapping(value = "maps/{id}/export")
public String showExportPage(@PathVariable int id, @NotNull Model model) throws IOException, AccessDeniedSecurityException {
public String showExportPage(@PathVariable int id, @NotNull Model model) throws IOException, MapCouldNotFoundException {
final Mindmap mindmap = findMindmap(id);
model.addAttribute("mindmap", mindmap);
return "mindmapExport";
}
@RequestMapping(value = "maps/{id}/exportf")
public String showExportPageFull(@PathVariable int id, @NotNull Model model) throws IOException, AccessDeniedSecurityException {
public String showExportPageFull(@PathVariable int id, @NotNull Model model) throws IOException, MapCouldNotFoundException {
showExportPage(id, model);
return "mindmapExportFull";
}
@RequestMapping(value = "maps/{id}/share")
public String showSharePage(@PathVariable int id, @NotNull Model model) throws AccessDeniedSecurityException {
public String showSharePage(@PathVariable int id, @NotNull Model model) throws MapCouldNotFoundException {
final Mindmap mindmap = findMindmap(id);
model.addAttribute("mindmap", mindmap);
return "mindmapShare";
}
@RequestMapping(value = "maps/{id}/sharef")
public String showSharePageFull(@PathVariable int id, @NotNull Model model) throws AccessDeniedSecurityException {
public String showSharePageFull(@PathVariable int id, @NotNull Model model) throws MapCouldNotFoundException {
showSharePage(id, model);
return "mindmapShareFull";
}
@RequestMapping(value = "maps/{id}/publish")
public String showPublishPage(@PathVariable int id, @NotNull Model model,@NotNull HttpServletRequest request) throws AccessDeniedSecurityException {
public String showPublishPage(@PathVariable int id, @NotNull Model model, @NotNull HttpServletRequest request) throws MapCouldNotFoundException {
final Mindmap mindmap = findMindmap(id);
model.addAttribute("mindmap", mindmap);
model.addAttribute("baseUrl", request.getAttribute("site.baseurl"));
@ -111,7 +111,7 @@ public class MindmapController {
}
@RequestMapping(value = "maps/{id}/publishf")
public String showPublishPageFull(@PathVariable int id, @NotNull Model model,@NotNull HttpServletRequest request) throws AccessDeniedSecurityException {
public String showPublishPageFull(@PathVariable int id, @NotNull Model model, @NotNull HttpServletRequest request) throws MapCouldNotFoundException {
showPublishPage(id, model, request);
return "mindmapPublishFull";
}
@ -198,7 +198,7 @@ public class MindmapController {
}
@RequestMapping(value = "maps/{id}/embed")
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) throws AccessDeniedSecurityException {
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) throws MapCouldNotFoundException {
ModelAndView view;
final MindMapBean mindmap = findMindmapBean(id);
view = new ModelAndView("mindmapEmbedded", "mindmap", mindmap);
@ -226,17 +226,17 @@ public class MindmapController {
}
@NotNull
private Mindmap findMindmap(long mapId) throws AccessDeniedSecurityException {
private Mindmap findMindmap(long mapId) throws MapCouldNotFoundException {
final Mindmap result = mindmapService.findMindmapById((int) mapId);
if (result == null) {
throw new AccessDeniedSecurityException("Map could not be found " + mapId);
throw new MapCouldNotFoundException("Map could not be found " + mapId);
}
return result;
}
@NotNull
private MindMapBean findMindmapBean(long mapId) throws AccessDeniedSecurityException {
private MindMapBean findMindmapBean(long mapId) throws MapCouldNotFoundException {
final Mindmap mindmap = findMindmap(mapId);
return new MindMapBean(mindmap, Utils.getUser());
}

View File

@ -242,6 +242,7 @@ CONTACT_US=Contact Us
#Pending for translation ...
CAPTCHA_LOADING_ERROR=ReCaptcha could not be loaded. You must have access to Google ReCaptcha service.
ACCESS_HAS_BEEN_REVOKED= Upps. your access permissions to this map has been revoked. Contact map owner.
MAP_CAN_NOT_BE_FOUND= Upps. The map can not be found. It must have been deleted.
LICENSE=License
WELCOME_TO_WISEMAPPING=Welcome to WiseMapping
WELCOME_DETAILS=WiseMapping will enable you to create and read your mind maps everywhere. With WiseMapping you can: <ul><li>Embed mind map it in web pages and blogs</li><li>Link mind map and documents</li><li>Share your maps with friend and colleagues</li><li>Export your maps SVG,PNG,JPG and FreeMind</li></ul>.