Clean up lock implementation

This commit is contained in:
Paulo Gustavo Veiga
2022-03-23 23:32:19 -03:00
parent b8eadb7533
commit d380b97938
9 changed files with 68 additions and 183 deletions

View File

@@ -47,7 +47,6 @@ import java.util.Locale;
@Controller
public class MindmapController {
public static final String LOCK_SESSION_ATTRIBUTE = "lockSession";
@Qualifier("mindmapService")
@Autowired
private MindmapService mindmapService;
@@ -76,19 +75,16 @@ public class MindmapController {
private String showEditorPage(int id, @NotNull final Model model, boolean requiresLock) throws WiseMappingException {
final MindMapBean mindmapBean = findMindmapBean(id);
final Mindmap mindmap = mindmapBean.getDelegated();
final User collaborator = Utils.getUser();
final User user = Utils.getUser();
final Locale locale = LocaleContextHolder.getLocale();
// Is the mindmap locked ?.
boolean isLocked = false;
boolean readOnlyMode = !requiresLock || !mindmap.hasPermissions(collaborator, CollaborationRole.EDITOR);
boolean readOnlyMode = !requiresLock || !mindmap.hasPermissions(user, CollaborationRole.EDITOR);
if (!readOnlyMode) {
final LockManager lockManager = this.mindmapService.getLockManager();
if (lockManager.isLocked(mindmap) && !lockManager.isLockedBy(mindmap, collaborator)) {
if (lockManager.isLocked(mindmap) && !lockManager.isLockedBy(mindmap, user)) {
isLocked = true;
} else {
model.addAttribute("lockTimestamp", mindmap.getLastModificationTime().getTimeInMillis());
model.addAttribute(LOCK_SESSION_ATTRIBUTE, lockManager.generateSession());
}
model.addAttribute("lockInfo", lockManager.getLockInfo(mindmap));
}
@@ -97,8 +93,7 @@ public class MindmapController {
// Configure default locale for the editor ...
model.addAttribute("locale", locale.toString().toLowerCase());
model.addAttribute("principal", collaborator);
model.addAttribute("memoryPersistence", false);
model.addAttribute("principal", user);
model.addAttribute("mindmapLocked", isLocked);
return "mindmapEditor";
@@ -107,23 +102,17 @@ public class MindmapController {
@RequestMapping(value = "maps/{id}/view", method = RequestMethod.GET)
public String showMindmapViewerPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
final String result = showPrintPage(id, model);
model.addAttribute("readOnlyMode", true);
return result;
}
@RequestMapping(value = "maps/{id}/try", method = RequestMethod.GET)
public String showMindmapTryPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
final String result = showEditorPage(id, model, false);
model.addAttribute("memoryPersistence", true);
model.addAttribute("readOnlyMode", false);
return result;
return showEditorPage(id, model, false);
}
@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 = showPrintPage(id, model);
model.addAttribute("readOnlyMode", true);
model.addAttribute("hid", String.valueOf(hid));
return result;
}