wisemapping-open-source/wise-webapp/src/main/java/com/wisemapping/webmvc/MindmapController.java

244 lines
9.8 KiB
Java
Raw Normal View History

2012-06-10 03:55:55 +02:00
/*
2012-10-05 01:48:01 +02:00
* Copyright [2012] [wisemapping]
2012-06-10 03:55:55 +02: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.
*/
package com.wisemapping.webmvc;
2012-06-18 00:16:39 +02:00
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.CollaborationRole;
import com.wisemapping.model.Mindmap;
2012-06-18 00:16:39 +02:00
import com.wisemapping.model.MindMapHistory;
2012-08-26 21:53:33 +02:00
import com.wisemapping.model.User;
import com.wisemapping.security.Utils;
import com.wisemapping.service.LockInfo;
2012-09-30 22:15:01 +02: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-10 03:49:54 +02:00
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Controller;
2012-06-17 07:51:01 +02:00
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.io.IOException;
import java.util.Locale;
@Controller
public class MindmapController {
2012-11-14 01:01:04 +01:00
public static final String LOCK_SESSION_ATTRIBUTE = "lockSession";
2012-06-10 03:49:54 +02:00
@Qualifier("mindmapService")
@Autowired
private MindmapService mindmapService;
@Value("${site.baseurl}")
String siteBaseUrl;
2012-06-17 07:51:01 +02:00
@RequestMapping(value = "maps/import")
public String showImportPage() {
return "mindmapImport";
}
2012-06-17 07:51:01 +02:00
@RequestMapping(value = "maps/{id}/details")
public String showDetails(@PathVariable int id, @NotNull Model model) {
final MindMapBean mindmap = findMindmapBean(id);
model.addAttribute("mindmap", mindmap);
2012-06-20 18:28:45 +02:00
model.addAttribute("baseUrl", siteBaseUrl);
2012-06-17 07:51:01 +02:00
return "mindmapDetail";
2012-06-04 00:19:48 +02:00
}
2012-06-17 07:51:01 +02:00
@RequestMapping(value = "maps/{id}/print")
public String showPrintPage(@PathVariable int id, @NotNull Model model) {
final MindMapBean mindmap = findMindmapBean(id);
model.addAttribute("principal", Utils.getUser());
2012-06-17 07:51:01 +02:00
model.addAttribute("mindmap", mindmap);
2012-07-06 05:46:54 +02:00
final Locale locale = LocaleContextHolder.getLocale();
model.addAttribute("locale", locale.toString().toLowerCase());
2012-06-17 07:51:01 +02:00
return "mindmapPrint";
}
2012-06-17 07:51:01 +02:00
@RequestMapping(value = "maps/{id}/export")
public String showExportPage(@PathVariable int id, @NotNull Model model) throws IOException {
final Mindmap mindmap = findMindmap(id);
2012-06-17 07:51:01 +02:00
model.addAttribute("mindmap", mindmap);
return "mindmapExport";
}
@RequestMapping(value = "maps/{id}/exportf")
public String showExportPageFull(@PathVariable int id, @NotNull Model model) throws IOException {
showExportPage(id, model);
return "mindmapExportFull";
}
@RequestMapping(value = "maps/{id}/share")
2012-06-17 07:51:01 +02:00
public String showSharePage(@PathVariable int id, @NotNull Model model) {
final Mindmap mindmap = findMindmap(id);
2012-06-17 07:51:01 +02:00
model.addAttribute("mindmap", mindmap);
return "mindmapShare";
}
@RequestMapping(value = "maps/{id}/sharef")
2012-06-17 07:51:01 +02:00
public String showSharePageFull(@PathVariable int id, @NotNull Model model) {
showSharePage(id, model);
return "mindmapShareFull";
}
2012-05-27 23:15:46 +02:00
@RequestMapping(value = "maps/{id}/publish")
2012-06-17 07:51:01 +02:00
public String showPublishPage(@PathVariable int id, @NotNull Model model) {
final Mindmap mindmap = findMindmap(id);
2012-06-17 07:51:01 +02:00
model.addAttribute("mindmap", mindmap);
model.addAttribute("baseUrl", siteBaseUrl);
2012-06-17 07:51:01 +02:00
return "mindmapPublish";
2012-05-27 23:15:46 +02:00
}
@RequestMapping(value = "maps/{id}/publishf")
2012-06-17 07:51:01 +02:00
public String showPublishPageFull(@PathVariable int id, @NotNull Model model) {
showPublishPage(id, model);
return "mindmapPublishFull";
}
@RequestMapping(value = "maps/{id}/history", method = RequestMethod.GET)
public String showHistoryPage(@PathVariable int id, @NotNull Model model) {
model.addAttribute("mindmapId", id);
return "mindmapHistory";
}
@RequestMapping(value = "maps/{id}/historyf", method = RequestMethod.GET)
public String showHistoryPageFull(@PathVariable int id, @NotNull Model model) {
showHistoryPage(id, model);
return "mindmapHistoryFull";
}
@RequestMapping(value = "maps/")
public String showListPage(@NotNull Model model) {
final Locale locale = LocaleContextHolder.getLocale();
// @Todo: This should be more flexible ...
String localeStr = locale.toString().toLowerCase();
if ("es".equals(locale.getLanguage()) || "pt".equals(locale.getLanguage())) {
localeStr = locale.getLanguage();
}
model.addAttribute("locale", localeStr);
2012-06-17 07:51:01 +02:00
return "mindmapList";
2012-05-21 02:46:55 +02:00
}
@RequestMapping(value = "maps/{id}/edit", method = RequestMethod.GET)
2012-09-30 22:15:01 +02: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();
2012-09-30 22:15:01 +02:00
final User collaborator = Utils.getUser();
final Locale locale = LocaleContextHolder.getLocale();
2012-09-30 22:15:01 +02:00
// Is the mindmap locked ?.
boolean readOnlyMode = !requiresLock || !mindmap.hasPermissions(collaborator, CollaborationRole.EDITOR);
if (!readOnlyMode) {
final LockManager lockManager = this.mindmapService.getLockManager();
if (lockManager.isLocked(mindmap) && !lockManager.isLockedBy(mindmap, collaborator)) {
readOnlyMode = true;
2012-11-08 00:14:07 +01:00
model.addAttribute("mindmapLocked",true);
2012-09-30 22:15:01 +02:00
} else {
2012-11-14 01:01:04 +01:00
final LockInfo lock = lockManager.lock(mindmap, collaborator);
model.addAttribute("lockTimestamp", lock.getTimestamp());
2012-11-14 01:01:04 +01:00
model.addAttribute(LOCK_SESSION_ATTRIBUTE, lock.getSession());
2012-09-30 22:15:01 +02:00
}
model.addAttribute("lockInfo", lockManager.getLockInfo(mindmap));
2012-09-30 22:15:01 +02:00
}
// Set render attributes ...
model.addAttribute("mindmap", mindmapBean);
// Configure default locale for the editor ...
model.addAttribute("locale", locale.toString().toLowerCase());
2012-08-26 21:53:33 +02:00
model.addAttribute("principal", collaborator);
2012-09-30 22:15:01 +02:00
model.addAttribute("readOnlyMode", readOnlyMode);
return "mindmapEditor";
}
@RequestMapping(value = "maps/{id}/view", method = RequestMethod.GET)
public String showMindmapViewerPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
2012-09-30 22:15:01 +02:00
return showEditorPage(id, model, false);
}
@RequestMapping(value = "maps/{id}/try", method = RequestMethod.GET)
public String showMindmapTryPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
2012-09-30 22:15:01 +02:00
final String result = showEditorPage(id, model, false);
model.addAttribute("memoryPersistence", true);
2012-11-11 00:22:26 +01:00
model.addAttribute("readOnlyMode", false);
return result;
}
2012-06-18 00:16:39 +02:00
@RequestMapping(value = "maps/{id}/{hid}/view", method = RequestMethod.GET)
public String showMindmapViewerRevPage(@PathVariable int id, @PathVariable int hid, @NotNull Model model) throws WiseMappingException {
final String result = showMindmapEditorPage(id, model);
model.addAttribute("readOnlyMode", true);
// Change map XML ....
final MindMapBean mindmapBean = (MindMapBean) model.asMap().get("mindmap");
2012-06-18 00:16:39 +02:00
final MindMapHistory mindmapHistory = mindmapService.findMindmapHistory(id, hid);
mindmapBean.getDelegated().setXml(mindmapHistory.getXml());
return result;
2012-06-18 00:16:39 +02:00
}
@RequestMapping(value = "maps/{id}/embed")
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) {
ModelAndView view;
final MindMapBean mindmap = findMindmapBean(id);
view = new ModelAndView("mindmapEmbedded", "mindmap", mindmap);
view.addObject("zoom", zoom == null ? 1 : zoom);
2012-07-06 05:46:54 +02:00
final Locale locale = LocaleContextHolder.getLocale();
view.addObject("locale", locale.toString().toLowerCase());
return view;
}
@RequestMapping(value = "maps/{id}/public", method = RequestMethod.GET)
public String showPublicViewPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
return this.showPrintPage(id, model);
}
@Deprecated
@RequestMapping(value = "publicView", method = RequestMethod.GET)
2012-06-18 06:15:46 +02:00
public String showPublicViewPageLegacy(@RequestParam(required = true) int mapId) {
return "redirect:maps/" + mapId + "/public";
}
@Deprecated
@RequestMapping(value = "embeddedView", method = RequestMethod.GET)
2012-06-18 06:15:46 +02:00
public String showPublicViewLegacyPage(@RequestParam(required = true) int mapId, @RequestParam(required = false) int zoom) {
return "redirect:maps/" + mapId + "/embed?zoom=" + zoom;
}
private Mindmap findMindmap(long mapId) {
2012-09-30 22:15:01 +02:00
return mindmapService.findMindmapById((int) mapId);
}
private MindMapBean findMindmapBean(long mapId) {
return new MindMapBean(findMindmap(mapId), Utils.getUser());
}
}