From c73934aadf0230034800c6587aa7754874726a8e Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 17 Jun 2012 19:16:39 -0300 Subject: [PATCH] Add revert and view actions. --- .../controller/TagsController.java | 2 +- .../ncontroller/ExtensionsController.java | 2 +- .../ncontroller/MindmapController.java | 21 +++++++-- .../wisemapping/rest/MindmapController.java | 44 +++++++++++-------- .../security/aop/BaseSecurityAdvice.java | 4 ++ .../wisemapping/service/MindmapService.java | 12 ++--- .../service/MindmapServiceImpl.java | 36 ++++++++++----- .../main/webapp/WEB-INF/wisemapping-aop.xml | 5 ++- .../src/main/webapp/jsp/mindmapEditor.jsp | 8 ++-- .../src/main/webapp/jsp/mindmapHistory.jsp | 7 ++- 10 files changed, 95 insertions(+), 46 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/TagsController.java b/wise-webapp/src/main/java/com/wisemapping/controller/TagsController.java index 7d8587d8..90be67cb 100644 --- a/wise-webapp/src/main/java/com/wisemapping/controller/TagsController.java +++ b/wise-webapp/src/main/java/com/wisemapping/controller/TagsController.java @@ -53,7 +53,7 @@ public class TagsController throws ServletException, WiseMappingException, ImporterException { final TagBean bean = (TagBean) command; - final MindMap mindmap = getMindmapService().getMindmapById(bean.getMindmapId()); + final MindMap mindmap = getMindmapService().findMindmapById(bean.getMindmapId()); getMindmapService().addTags(mindmap, bean.getMindmapTags()); return new ModelAndView(getSuccessView()); } diff --git a/wise-webapp/src/main/java/com/wisemapping/ncontroller/ExtensionsController.java b/wise-webapp/src/main/java/com/wisemapping/ncontroller/ExtensionsController.java index 5475af8e..e85cbb05 100644 --- a/wise-webapp/src/main/java/com/wisemapping/ncontroller/ExtensionsController.java +++ b/wise-webapp/src/main/java/com/wisemapping/ncontroller/ExtensionsController.java @@ -37,7 +37,7 @@ public class ExtensionsController { @RequestMapping(value = "try") public ModelAndView tryEditor() throws IOException { - final MindMap mindmap = mindmapService.getMindmapById(TRY_EXAMPLE_MINDMAP_ID); + final MindMap mindmap = mindmapService.findMindmapById(TRY_EXAMPLE_MINDMAP_ID); ModelAndView view = new ModelAndView("mindmapEditor", "mindmap", mindmap); final String xmlMap = mindmap.getXmlAsJsLiteral(); diff --git a/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java index 8b4d8c7f..505f2b8c 100644 --- a/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java @@ -19,9 +19,10 @@ package com.wisemapping.ncontroller; -import com.wisemapping.filter.UserAgent; +import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.model.CollaborationRole; import com.wisemapping.model.MindMap; +import com.wisemapping.model.MindMapHistory; import com.wisemapping.security.Utils; import com.wisemapping.service.MindmapService; import com.wisemapping.view.MindMapBean; @@ -33,8 +34,8 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; -import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.util.List; @Controller public class MindmapController { @@ -141,10 +142,22 @@ public class MindmapController { return "mindmapEditor"; } + @RequestMapping(value = "maps/{id}/{hid}/view", method = RequestMethod.GET) + public String showMindmapViewerRevPage(@PathVariable int id, @PathVariable int hid, @NotNull Model model) throws WiseMappingException { + final MindMapBean mindmapBean = findMindmapBean(id); + + final MindMapHistory mindmapHistory = mindmapService.findMindmapHistory(id, hid); + mindmapBean.getDelegated().setXml(mindmapHistory.getXml()); + model.addAttribute("mindmap", mindmapBean); + model.addAttribute("readOnlyMode", true); + + return "mindmapEditor"; + } + @RequestMapping(value = "maps/{id}/embed") public ModelAndView embeddedView(@PathVariable int id, @RequestParam(required = false) Float zoom) { ModelAndView view; - final MindMap mindmap = mindmapService.getMindmapById(id); + final MindMap mindmap = mindmapService.findMindmapById(id); view = new ModelAndView("mindmapEmbedded", "mindmap", mindmap); view.addObject("user", Utils.getUser()); view.addObject("zoom", zoom == null ? 1 : zoom); @@ -153,7 +166,7 @@ public class MindmapController { private MindMap findMindmap(long mapId) { - final MindMap mindmap = mindmapService.getMindmapById((int) mapId); + final MindMap mindmap = mindmapService.findMindmapById((int) mapId); if (mindmap == null) { throw new IllegalArgumentException("Mindmap could not be found"); } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index 7d5ab6c7..f69b57d2 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -56,7 +56,7 @@ public class MindmapController extends BaseController { @ResponseBody public ModelAndView retrieve(@PathVariable int id) throws IOException { final User user = Utils.getUser(); - final MindMap mindMap = mindmapService.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final RestMindmap map = new RestMindmap(mindMap, user); return new ModelAndView("mapView", "map", map); @@ -65,7 +65,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 IOException { - final MindMap mindMap = mindmapService.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final Map values = new HashMap(); final User user = Utils.getUser(); @@ -77,7 +77,7 @@ 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.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final Map values = new HashMap(); values.put("content", mindMap.getXmlStr()); values.put("filename", mindMap.getTitle()); @@ -89,7 +89,7 @@ public class MindmapController extends BaseController { final User user = Utils.getUser(); final MindmapFilter filter = MindmapFilter.parse(q); - final List collaborations = mindmapService.getCollaborationsBy(user); + final List collaborations = mindmapService.findCollaborationsBy(user); final List mindmaps = new ArrayList(); for (Collaboration collaboration : collaborations) { @@ -105,7 +105,7 @@ public class MindmapController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/history", produces = {"application/json", "text/html", "application/xml"}) public ModelAndView retrieveHistory(@PathVariable int id) throws IOException { - final List histories = mindmapService.getMindMapHistory(id); + final List histories = mindmapService.findMindmapHistory(id); final RestMindmapHistoryList result = new RestMindmapHistoryList(); for (MindMapHistory history : histories) { result.addHistory(new RestMindmapHistory(history)); @@ -113,11 +113,19 @@ public class MindmapController extends BaseController { return new ModelAndView("historyView", "list", result); } + + @RequestMapping(value = "maps/{id}/history/{hid}", method = RequestMethod.POST) + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void updateRevertMindmap(@PathVariable int id, @PathVariable int hid) throws IOException, WiseMappingException { + final MindMap mindmap = mindmapService.findMindmapById(id); + mindmapService.revertChange(mindmap, hid); + } + @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/document", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"}) @ResponseStatus(value = HttpStatus.NO_CONTENT) public void updateDocument(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException { - final MindMap mindMap = mindmapService.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final User user = Utils.getUser(); // Validate arguments ... @@ -145,7 +153,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.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final User user = Utils.getUser(); // Update document properties ... @@ -187,7 +195,7 @@ public class MindmapController extends BaseController { @ResponseStatus(value = HttpStatus.NO_CONTENT) public void updateTitle(@RequestBody String title, @PathVariable int id) throws WiseMappingException { - final MindMap mindMap = mindmapService.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final User user = Utils.getUser(); // Is there a map with the same name ? @@ -197,7 +205,7 @@ public class MindmapController extends BaseController { } // Update map ... - final MindMap mindmap = mindmapService.getMindmapById(id); + final MindMap mindmap = mindmapService.findMindmapById(id); mindmap.setTitle(title); saveMindmap(true, mindMap, user); } @@ -205,7 +213,7 @@ public class MindmapController extends BaseController { @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.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); // Only owner can change collaborators... final User user = Utils.getUser(); @@ -245,7 +253,7 @@ 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.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final Set collaborations = mindMap.getCollaborations(); final List collabs = new ArrayList(); @@ -264,11 +272,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.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final User user = Utils.getUser(); // Update map ... - final MindMap mindmap = mindmapService.getMindmapById(id); + final MindMap mindmap = mindmapService.findMindmapById(id); mindmap.setDescription(description); saveMindmap(true, mindMap, user); } @@ -277,7 +285,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.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final User user = Utils.getUser(); if (!!mindMap.hasPermissions(user, CollaborationRole.OWNER)) { @@ -294,7 +302,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.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final User user = Utils.getUser(); // Update map status ... @@ -306,7 +314,7 @@ public class MindmapController extends BaseController { @ResponseStatus(value = HttpStatus.NO_CONTENT) public void updateMap(@PathVariable int id) throws IOException, WiseMappingException { final User user = Utils.getUser(); - final MindMap mindmap = mindmapService.getMindmapById(id); + final MindMap mindmap = mindmapService.findMindmapById(id); mindmapService.removeMindmap(mindmap, user); } @@ -316,7 +324,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.getMindmapById(Integer.parseInt(mapId)); + final MindMap mindmap = mindmapService.findMindmapById(Integer.parseInt(mapId)); mindmapService.removeMindmap(mindmap, user); } } @@ -391,7 +399,7 @@ public class MindmapController extends BaseController { final User user = Utils.getUser(); // Create a shallowCopy of the map ... - final MindMap mindMap = mindmapService.getMindmapById(id); + final MindMap mindMap = mindmapService.findMindmapById(id); final MindMap clonedMap = mindMap.shallowClone(); clonedMap.setTitle(restMindmap.getTitle()); clonedMap.setDescription(restMindmap.getDescription()); diff --git a/wise-webapp/src/main/java/com/wisemapping/security/aop/BaseSecurityAdvice.java b/wise-webapp/src/main/java/com/wisemapping/security/aop/BaseSecurityAdvice.java index 65d91af7..7330b8ec 100755 --- a/wise-webapp/src/main/java/com/wisemapping/security/aop/BaseSecurityAdvice.java +++ b/wise-webapp/src/main/java/com/wisemapping/security/aop/BaseSecurityAdvice.java @@ -18,6 +18,7 @@ package com.wisemapping.security.aop; +import com.wisemapping.model.Collaborator; import com.wisemapping.model.MindMap; import com.wisemapping.model.User; import com.wisemapping.exceptions.AccessDeniedSecurityException; @@ -40,6 +41,9 @@ public abstract class BaseSecurityAdvice { isAllowed = isAllowed(user, (MindMap) argument); } else if (argument instanceof Integer) { isAllowed = isAllowed(user, ((Integer) argument)); + } else if (argument instanceof Collaborator) { + // Read operation find on the user are allowed ... + isAllowed = user.equals(argument); } else { throw new UnexpectedArgumentException("Argument " + argument); } diff --git a/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java b/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java index 51ba0a5b..10e5feba 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java @@ -30,11 +30,11 @@ public interface MindmapService { public static final String TAG_SEPARATOR = " "; - public MindMap getMindmapById(int mindmapId); + public MindMap findMindmapById(int mindmapId); public MindMap getMindmapByTitle(String title, User user); - public List getCollaborationsBy(@NotNull User user); + public List findCollaborationsBy(@NotNull User user); public void updateMindmap(MindMap mindMap, boolean saveHistory) throws WiseMappingException; @@ -45,13 +45,13 @@ public interface MindmapService { public void removeCollaboration(@NotNull MindMap mindmap, @NotNull Collaboration collaboration) throws CollaborationException; - public void addTags(MindMap mindmap, String tags); + public void addTags(@NotNull MindMap mindmap, String tags); public void removeMindmap(@NotNull final MindMap mindmap, @NotNull final User user) throws WiseMappingException; public List search(MindMapCriteria criteria); - public List getMindMapHistory(int mindmapId); + public List findMindmapHistory(int mindmapId); public boolean hasPermissions(@Nullable User user, MindMap map, CollaborationRole allowedRole); @@ -59,5 +59,7 @@ public interface MindmapService { public void addWelcomeMindmap(User user) throws WiseMappingException; - public void revertMapToHistory(MindMap map, int historyId) throws IOException, WiseMappingException; + public void revertChange(@NotNull MindMap map, int historyId) throws WiseMappingException; + + MindMapHistory findMindmapHistory(int id, int hid) throws WiseMappingException; } diff --git a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java index 386f330c..03beb5f3 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java @@ -28,7 +28,6 @@ import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import java.io.IOException; import java.util.*; @@ -74,17 +73,17 @@ public class MindmapServiceImpl } @Override - public MindMap getMindmapById(int mindmapId) { + public MindMap findMindmapById(int mindmapId) { return mindmapManager.getMindmapById(mindmapId); } @Override - public List getCollaborationsBy(@NotNull User user) { + public List findCollaborationsBy(@NotNull User user) { return mindmapManager.getMindmapUserByCollaborator(user.getId()); } @Override - public void updateMindmap(MindMap mindMap, boolean saveHistory) throws WiseMappingException { + public void updateMindmap(@NotNull MindMap mindMap, boolean saveHistory) throws WiseMappingException { if (mindMap.getTitle() == null || mindMap.getTitle().length() == 0) { throw new WiseMappingException("The tile can not be empty"); } @@ -221,7 +220,7 @@ public class MindmapServiceImpl } public void addWelcomeMindmap(User user) throws WiseMappingException { - final MindMap savedWelcome = getMindmapById(Constants.WELCOME_MAP_ID); + final MindMap savedWelcome = findMindmapById(Constants.WELCOME_MAP_ID); // Is there a welcomed map configured ? if (savedWelcome != null) { @@ -234,15 +233,32 @@ public class MindmapServiceImpl } } - public List getMindMapHistory(int mindmapId) { + public List findMindmapHistory(int mindmapId) { return mindmapManager.getHistoryFrom(mindmapId); } - public void revertMapToHistory(MindMap map, int historyId) - throws IOException, WiseMappingException { + public void revertChange(@NotNull MindMap mindmap, int historyId) + throws WiseMappingException { final MindMapHistory history = mindmapManager.getHistory(historyId); - map.setXml(history.getXml()); - updateMindmap(map, false); + mindmap.setXml(history.getXml()); + updateMindmap(mindmap, true); + } + + @Override + public MindMapHistory findMindmapHistory(int id, int hid) throws WiseMappingException { + final List mindmapHistory = this.findMindmapHistory(id); + MindMapHistory result = null; + for (MindMapHistory history : mindmapHistory) { + if (history.getId() == hid) { + result = history; + break; + } + } + + if (result == null) { + throw new WiseMappingException("History could not be found for mapid=" + id + ",hid" + hid); + } + return result; } private Collaboration getCollaborationBy(String email, Set collaborations) { diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml index bdb3d236..68e4bb3e 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml @@ -11,7 +11,9 @@ getMindmapUserBy - getMindmapById + getMindmapById + find* + filter* @@ -27,6 +29,7 @@ update* add* remove* + revert* diff --git a/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp b/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp index 35f8468c..4285092c 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp @@ -8,7 +8,7 @@ <%@ include file="/jsp/init.jsp" %> - + <spring:message code="SITE.TITLE"/> - ${mindmap.title} @@ -63,10 +63,10 @@
, ${principal.firstname}| | - | + "> - | "> + | ">
diff --git a/wise-webapp/src/main/webapp/jsp/mindmapHistory.jsp b/wise-webapp/src/main/webapp/jsp/mindmapHistory.jsp index f5d3b515..c0a2370a 100755 --- a/wise-webapp/src/main/webapp/jsp/mindmapHistory.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapHistory.jsp @@ -43,13 +43,16 @@ tableElem.find('tr a.view').each(function() { $(this).click(function(event) { - window.open("/c/maps/${mindmapId}/view"); + window.open("/c/maps/${mindmapId}/" + $(this).closest("tr").attr("data-history-id") + "/view"); event.preventDefault(); }); }); tableElem.find('tr a.revert').each(function() { $(this).click(function(event) { - window.location = "/c/maps/${mindmapId}/edit"; + var url = "service/maps/${mindmapId}/history/" + $(this).closest("tr").attr("data-history-id"); + jQuery.post(url, function(data) { + window.parent.location = "c/maps/${mindmapId}/edit"; + }); event.preventDefault(); }); });