181 lines
7.6 KiB
Java
Raw Normal View History

2012-06-09 22:55:55 -03:00
/*
2022-03-17 18:47:34 -03:00
* Copyright [2022] [wisemapping]
2022-01-27 19:06:51 -08:00
*
* 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.
*/
2012-06-09 22:55:55 -03:00
package com.wisemapping.webmvc;
import com.wisemapping.exceptions.AccessDeniedSecurityException;
2013-03-29 21:09:28 -03:00
import com.wisemapping.exceptions.MapCouldNotFoundException;
2023-07-30 22:31:24 -07:00
import com.wisemapping.exceptions.MapNotPublicSecurityException;
2012-06-17 19:16:39 -03:00
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.CollaborationRole;
2012-11-14 21:19:56 -03:00
import com.wisemapping.model.Mindmap;
2012-08-26 16:53:33 -03:00
import com.wisemapping.model.User;
import com.wisemapping.security.Utils;
2012-09-30 17:15:01 -03:00
import com.wisemapping.service.LockManager;
import com.wisemapping.service.MindmapService;
import com.wisemapping.view.MindMapBean;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
2012-06-09 22:49:54 -03:00
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.i18n.LocaleContextHolder;
2023-07-28 22:46:38 -07:00
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
2012-06-17 02:51:01 -03:00
import org.springframework.ui.Model;
2012-11-14 21:19:56 -03:00
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import java.util.Locale;
@Controller
2023-07-28 22:46:38 -07:00
public class MvcMindmapController {
2012-06-09 22:49:54 -03:00
@Qualifier("mindmapService")
@Autowired
private MindmapService mindmapService;
2012-06-17 02:51:01 -03:00
@RequestMapping(value = "maps/{id}/print")
public String showPrintPage(@PathVariable int id, @NotNull Model model) throws MapCouldNotFoundException, AccessDeniedSecurityException {
final MindMapBean mindmap = findMindmapBean(id);
model.addAttribute("principal", Utils.getUser());
2012-06-17 02:51:01 -03:00
model.addAttribute("mindmap", mindmap);
2012-07-06 00:46:54 -03:00
final Locale locale = LocaleContextHolder.getLocale();
model.addAttribute("locale", locale.toString().toLowerCase());
2023-07-28 22:46:38 -07:00
return "mindmapViewonly";
}
2012-06-17 02:51:01 -03:00
@RequestMapping(value = "maps/")
public String showListPage(@NotNull Model model) {
2023-07-28 22:46:38 -07:00
return "reactInclude";
2012-05-20 21:46:55 -03:00
}
@RequestMapping(value = "maps/{id}/edit", method = RequestMethod.GET)
2012-09-30 17:15:01 -03:00
public String showMindmapEditorPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
return showEditorPage(id, model, true);
}
private String showEditorPage(int id, @NotNull final Model model, boolean requiresLock) throws WiseMappingException {
final MindMapBean mindmapBean = findMindmapBean(id);
final Mindmap mindmap = mindmapBean.getDelegated();
2022-03-23 23:32:19 -03:00
final User user = Utils.getUser();
2012-09-30 17:15:01 -03:00
final Locale locale = LocaleContextHolder.getLocale();
2012-09-30 17:15:01 -03:00
// Is the mindmap locked ?.
2014-01-26 19:28:54 -03:00
boolean isLocked = false;
2022-03-23 23:32:19 -03:00
boolean readOnlyMode = !requiresLock || !mindmap.hasPermissions(user, CollaborationRole.EDITOR);
2012-09-30 17:15:01 -03:00
if (!readOnlyMode) {
final LockManager lockManager = this.mindmapService.getLockManager();
2022-03-23 23:32:19 -03:00
if (lockManager.isLocked(mindmap) && !lockManager.isLockedBy(mindmap, user)) {
2014-02-17 09:05:54 -03:00
isLocked = true;
2012-09-30 17:15:01 -03:00
}
model.addAttribute("lockInfo", lockManager.getLockInfo(mindmap));
2012-09-30 17:15:01 -03:00
}
// Set render attributes ...
model.addAttribute("mindmap", mindmapBean);
// Configure default locale for the editor ...
model.addAttribute("locale", locale.toString().toLowerCase());
2022-03-23 23:32:19 -03:00
model.addAttribute("principal", user);
2014-01-26 19:28:54 -03:00
model.addAttribute("mindmapLocked", isLocked);
return "mindmapEditor";
}
@RequestMapping(value = "maps/{id}/view", method = RequestMethod.GET)
public String showMindmapViewerPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
2022-01-27 19:06:51 -08:00
final String result = showPrintPage(id, model);
return result;
}
@RequestMapping(value = "maps/{id}/try", method = RequestMethod.GET)
2023-07-28 22:46:38 -07:00
@PreAuthorize("permitAll()")
public String showMindmapTryPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
2022-03-23 23:32:19 -03:00
return showEditorPage(id, model, false);
}
2012-06-17 19:16:39 -03:00
@RequestMapping(value = "maps/{id}/{hid}/view", method = RequestMethod.GET)
public String showMindmapViewerRevPage(@PathVariable int id, @PathVariable int hid, @NotNull Model model) throws WiseMappingException {
2022-01-27 19:06:51 -08:00
final String result = showPrintPage(id, model);
2013-03-29 21:09:28 -03:00
model.addAttribute("hid", String.valueOf(hid));
return result;
2012-06-17 19:16:39 -03:00
}
@RequestMapping(value = "maps/{id}/embed")
2023-07-28 22:46:38 -07:00
@PreAuthorize("permitAll()")
2023-07-30 22:31:24 -07:00
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) throws MapCouldNotFoundException, MapNotPublicSecurityException, AccessDeniedSecurityException {
if (!mindmapService.isMindmapPublic(id)) {
2023-07-30 22:31:24 -07:00
throw new MapNotPublicSecurityException("Map " + id + " is not public.");
}
final MindMapBean mindmap = findMindmapBean(id);
2023-07-28 22:46:38 -07:00
final ModelAndView view = new ModelAndView("mindmapViewonly", "mindmap", mindmap);
view.addObject("zoom", zoom == null ? 1 : zoom);
2012-07-06 00:46:54 -03:00
final Locale locale = LocaleContextHolder.getLocale();
view.addObject("locale", locale.toString().toLowerCase());
return view;
}
@RequestMapping(value = "maps/{id}/public", method = RequestMethod.GET)
2023-07-28 22:46:38 -07:00
@PreAuthorize("permitAll()")
public String showPublicViewPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
if (!mindmapService.isMindmapPublic(id)) {
2023-07-30 22:31:24 -07:00
throw new MapNotPublicSecurityException("Map " + id + " is not public.");
}
return this.showPrintPage(id, model);
}
@Deprecated
@RequestMapping(value = "publicView", method = RequestMethod.GET)
2023-07-28 22:46:38 -07:00
@PreAuthorize("permitAll()")
2012-06-18 01:15:46 -03:00
public String showPublicViewPageLegacy(@RequestParam(required = true) int mapId) {
return "redirect:maps/" + mapId + "/public";
}
@Deprecated
@RequestMapping(value = "embeddedView", method = RequestMethod.GET)
2023-07-28 22:46:38 -07:00
@PreAuthorize("permitAll()")
2012-06-18 01:15:46 -03:00
public String showPublicViewLegacyPage(@RequestParam(required = true) int mapId, @RequestParam(required = false) int zoom) {
return "redirect:maps/" + mapId + "/embed?zoom=" + zoom;
}
2013-03-29 20:32:52 -03:00
@NotNull
private Mindmap findMindmap(int mapId) throws MapCouldNotFoundException {
final Mindmap result = mindmapService.findMindmapById(mapId);
2013-03-29 21:09:28 -03:00
if (result == null) {
throw new MapCouldNotFoundException("Map could not be found " + mapId);
2013-03-29 20:32:52 -03:00
}
return result;
}
2013-03-29 20:32:52 -03:00
@NotNull
private MindMapBean findMindmapBean(int mapId) throws MapCouldNotFoundException, AccessDeniedSecurityException {
final User user = Utils.getUser();
if (!mindmapService.hasPermissions(user, mapId, CollaborationRole.VIEWER)) {
throw new AccessDeniedSecurityException(mapId, user);
}
2013-03-29 20:32:52 -03:00
final Mindmap mindmap = findMindmap(mapId);
return new MindMapBean(mindmap, Utils.getUser());
}
}