2012-06-09 22:55:55 -03:00
|
|
|
/*
|
2022-01-27 19:06:51 -08:00
|
|
|
* Copyright [2015] [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.
|
|
|
|
*/
|
2012-06-09 22:55:55 -03:00
|
|
|
|
2012-11-10 17:19:28 -03:00
|
|
|
package com.wisemapping.webmvc;
|
2012-04-02 14:11:28 -03:00
|
|
|
|
|
|
|
|
2013-03-29 21:09:28 -03:00
|
|
|
import com.wisemapping.exceptions.MapCouldNotFoundException;
|
2022-02-21 09:43:04 -08:00
|
|
|
import com.wisemapping.exceptions.MapNonPublicException;
|
2012-06-17 19:16:39 -03:00
|
|
|
import com.wisemapping.exceptions.WiseMappingException;
|
2012-06-17 12:24:09 -03:00
|
|
|
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;
|
2012-04-02 14:11:28 -03:00
|
|
|
import com.wisemapping.security.Utils;
|
2012-09-30 17:15:01 -03:00
|
|
|
import com.wisemapping.service.LockManager;
|
2012-04-02 14:11:28 -03:00
|
|
|
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;
|
2012-07-01 17:54:46 -03:00
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
2012-04-02 14:11:28 -03:00
|
|
|
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;
|
2012-04-02 14:11:28 -03:00
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
2012-07-01 17:54:46 -03:00
|
|
|
import java.util.Locale;
|
2012-04-02 14:11:28 -03:00
|
|
|
|
|
|
|
@Controller
|
|
|
|
public class MindmapController {
|
2012-06-03 20:23:31 -03:00
|
|
|
|
2012-11-13 21:01:04 -03:00
|
|
|
public static final String LOCK_SESSION_ATTRIBUTE = "lockSession";
|
2012-06-09 22:49:54 -03:00
|
|
|
@Qualifier("mindmapService")
|
2012-04-02 14:11:28 -03:00
|
|
|
@Autowired
|
|
|
|
private MindmapService mindmapService;
|
|
|
|
|
2012-06-17 02:51:01 -03:00
|
|
|
@RequestMapping(value = "maps/{id}/print")
|
2013-03-29 21:09:28 -03:00
|
|
|
public String showPrintPage(@PathVariable int id, @NotNull Model model) throws MapCouldNotFoundException {
|
2012-06-18 00:40:42 -03:00
|
|
|
final MindMapBean mindmap = findMindmapBean(id);
|
2012-07-01 17:56:31 -03:00
|
|
|
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());
|
2012-06-17 02:51:01 -03:00
|
|
|
return "mindmapPrint";
|
2012-06-03 11:16:38 -03:00
|
|
|
}
|
|
|
|
|
2012-06-17 02:51:01 -03:00
|
|
|
@RequestMapping(value = "maps/")
|
2012-07-01 17:56:31 -03:00
|
|
|
public String showListPage(@NotNull Model model) {
|
2012-06-17 02:51:01 -03:00
|
|
|
return "mindmapList";
|
2012-05-20 21:46:55 -03:00
|
|
|
}
|
|
|
|
|
2012-06-17 12:24:09 -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);
|
|
|
|
}
|
|
|
|
|
2012-10-04 20:28:59 -03:00
|
|
|
private String showEditorPage(int id, @NotNull final Model model, boolean requiresLock) throws WiseMappingException {
|
2012-06-17 12:24:09 -03:00
|
|
|
final MindMapBean mindmapBean = findMindmapBean(id);
|
2012-08-15 21:28:51 -03:00
|
|
|
final Mindmap mindmap = mindmapBean.getDelegated();
|
2012-09-30 17:15:01 -03:00
|
|
|
final User collaborator = Utils.getUser();
|
|
|
|
final Locale locale = LocaleContextHolder.getLocale();
|
2012-04-14 18:46:07 -03:00
|
|
|
|
2012-09-30 17:15:01 -03:00
|
|
|
// Is the mindmap locked ?.
|
2014-01-26 19:28:54 -03:00
|
|
|
boolean isLocked = false;
|
2012-09-30 17:15:01 -03:00
|
|
|
boolean readOnlyMode = !requiresLock || !mindmap.hasPermissions(collaborator, CollaborationRole.EDITOR);
|
|
|
|
if (!readOnlyMode) {
|
|
|
|
final LockManager lockManager = this.mindmapService.getLockManager();
|
|
|
|
if (lockManager.isLocked(mindmap) && !lockManager.isLockedBy(mindmap, collaborator)) {
|
2014-02-17 09:05:54 -03:00
|
|
|
isLocked = true;
|
2012-09-30 17:15:01 -03:00
|
|
|
} else {
|
2012-11-14 20:53:59 -03:00
|
|
|
model.addAttribute("lockTimestamp", mindmap.getLastModificationTime().getTimeInMillis());
|
2012-11-14 20:44:59 -03:00
|
|
|
model.addAttribute(LOCK_SESSION_ATTRIBUTE, lockManager.generateSession());
|
2012-09-30 17:15:01 -03:00
|
|
|
}
|
2012-10-04 20:28:59 -03:00
|
|
|
model.addAttribute("lockInfo", lockManager.getLockInfo(mindmap));
|
2012-09-30 17:15:01 -03:00
|
|
|
}
|
|
|
|
// Set render attributes ...
|
2012-08-23 22:07:37 -03:00
|
|
|
model.addAttribute("mindmap", mindmapBean);
|
|
|
|
|
|
|
|
// Configure default locale for the editor ...
|
|
|
|
model.addAttribute("locale", locale.toString().toLowerCase());
|
2012-08-26 16:53:33 -03:00
|
|
|
model.addAttribute("principal", collaborator);
|
2014-01-26 19:28:54 -03:00
|
|
|
model.addAttribute("memoryPersistence", false);
|
|
|
|
model.addAttribute("mindmapLocked", isLocked);
|
|
|
|
|
2012-08-23 22:07:37 -03:00
|
|
|
return "mindmapEditor";
|
2012-06-17 12:24:09 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "maps/{id}/view", method = RequestMethod.GET)
|
2012-10-04 20:28:59 -03:00
|
|
|
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);
|
|
|
|
model.addAttribute("readOnlyMode", true);
|
2022-02-21 09:43:04 -08:00
|
|
|
return result;
|
|
|
|
}
|
2012-08-23 22:07:37 -03:00
|
|
|
|
|
|
|
@RequestMapping(value = "maps/{id}/try", method = RequestMethod.GET)
|
2012-10-04 20:28:59 -03:00
|
|
|
public String showMindmapTryPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
2012-09-30 17:15:01 -03:00
|
|
|
final String result = showEditorPage(id, model, false);
|
2012-08-23 22:07:37 -03:00
|
|
|
model.addAttribute("memoryPersistence", true);
|
2012-11-10 20:22:26 -03:00
|
|
|
model.addAttribute("readOnlyMode", false);
|
2012-08-23 22:07:37 -03:00
|
|
|
return result;
|
2012-04-14 18:46:07 -03:00
|
|
|
}
|
|
|
|
|
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);
|
2012-08-23 22:07:37 -03:00
|
|
|
model.addAttribute("readOnlyMode", true);
|
2013-03-29 21:09:28 -03:00
|
|
|
model.addAttribute("hid", String.valueOf(hid));
|
2012-08-23 22:07:37 -03:00
|
|
|
return result;
|
2012-06-17 19:16:39 -03:00
|
|
|
}
|
|
|
|
|
2012-06-03 20:23:31 -03:00
|
|
|
@RequestMapping(value = "maps/{id}/embed")
|
2022-02-21 09:43:04 -08:00
|
|
|
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) throws MapCouldNotFoundException, MapNonPublicException {
|
|
|
|
if (!mindmapService.isMindmapPublic(id)) {
|
|
|
|
throw new MapNonPublicException("Map " + id + " is not public.");
|
|
|
|
}
|
|
|
|
|
2012-06-18 00:40:42 -03:00
|
|
|
final MindMapBean mindmap = findMindmapBean(id);
|
2022-02-21 09:43:04 -08:00
|
|
|
final ModelAndView view = new ModelAndView("mindmapEmbedded", "mindmap", mindmap);
|
2012-06-03 20:23:31 -03:00
|
|
|
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());
|
2012-06-03 20:23:31 -03:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2012-06-18 00:40:42 -03:00
|
|
|
@RequestMapping(value = "maps/{id}/public", method = RequestMethod.GET)
|
|
|
|
public String showPublicViewPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
2022-02-21 09:43:04 -08:00
|
|
|
if (!mindmapService.isMindmapPublic(id)) {
|
|
|
|
throw new MapNonPublicException("Map " + id + " is not public.");
|
|
|
|
}
|
2012-06-18 00:40:42 -03:00
|
|
|
return this.showPrintPage(id, model);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
@RequestMapping(value = "publicView", method = RequestMethod.GET)
|
2012-06-18 01:15:46 -03:00
|
|
|
public String showPublicViewPageLegacy(@RequestParam(required = true) int mapId) {
|
2012-06-18 00:40:42 -03:00
|
|
|
return "redirect:maps/" + mapId + "/public";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
@RequestMapping(value = "embeddedView", method = RequestMethod.GET)
|
2012-06-18 01:15:46 -03:00
|
|
|
public String showPublicViewLegacyPage(@RequestParam(required = true) int mapId, @RequestParam(required = false) int zoom) {
|
2012-06-18 00:40:42 -03:00
|
|
|
return "redirect:maps/" + mapId + "/embed?zoom=" + zoom;
|
|
|
|
}
|
2012-04-02 14:11:28 -03:00
|
|
|
|
2013-03-29 20:32:52 -03:00
|
|
|
@NotNull
|
2022-01-16 20:01:56 -08:00
|
|
|
private Mindmap findMindmap(int mapId) throws MapCouldNotFoundException {
|
2022-02-21 09:43:04 -08:00
|
|
|
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;
|
|
|
|
|
2012-04-02 14:11:28 -03:00
|
|
|
}
|
|
|
|
|
2013-03-29 20:32:52 -03:00
|
|
|
@NotNull
|
2022-01-16 20:01:56 -08:00
|
|
|
private MindMapBean findMindmapBean(int mapId) throws MapCouldNotFoundException {
|
2013-03-29 20:32:52 -03:00
|
|
|
final Mindmap mindmap = findMindmap(mapId);
|
|
|
|
return new MindMapBean(mindmap, Utils.getUser());
|
2012-04-02 14:11:28 -03:00
|
|
|
}
|
|
|
|
}
|