From 704fb1a88019b3a004015b4b69a7ff709c8ed10d Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 24 Sep 2022 09:37:36 -0700 Subject: [PATCH] Workaround to solve maps visibility problem on missing COLLABORATION entry. --- .../com/wisemapping/dao/MindmapManager.java | 8 ---- .../wisemapping/dao/MindmapManagerImpl.java | 41 ++----------------- .../com/wisemapping/model/Collaborator.java | 37 ++++++++--------- .../wisemapping/rest/MindmapController.java | 2 +- 4 files changed, 22 insertions(+), 66 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java index abb9fa20..2d0b298d 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java @@ -29,16 +29,8 @@ public interface MindmapManager { Collaborator findCollaborator(@NotNull String email); - Collaborator findCollaborator(int id); - List findCollaboration(final int collaboratorId); - List findCollaboration(final CollaborationRole userRole); - - Collaboration findCollaboration(final int mindmapId, final User user); - - List getAllMindmaps(); - @Nullable Mindmap getMindmapById(int mindmapId); diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java index 42683d26..6f55f3b9 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java @@ -116,9 +116,11 @@ public class MindmapManagerImpl @Override public List findMindmapByUser(@NotNull User user) { + final Mindmap collaborator; + // Note: Inconsistency on the COLLABORATION table (m.creator.id=:collabId). Needs to review it. final Query query = currentSession() - .createQuery("from com.wisemapping.model.Mindmap m where m.id in (select c.mindMap.id from com.wisemapping.model.Collaboration as c where c.collaborator.id=:collabId )"); + .createQuery("from com.wisemapping.model.Mindmap m where m.creator.id=:collabId OR m.id in (select c.mindMap.id from com.wisemapping.model.Collaboration as c where c.collaborator.id=:collabId )"); query.setParameter("collabId", user.getId()); return query.getResultList(); @@ -159,11 +161,6 @@ public class MindmapManagerImpl return hibernateCriteria.list(); } - @Override - public Collaborator findCollaborator(int id) { - return getHibernateTemplate().get(Collaborator.class, id); - } - @Override public List findCollaboration(final int collaboratorId) { Query query = currentSession().createQuery("from com.wisemapping.model.Collaboration c where c.collaborator.id=:collaboratorId"); @@ -171,32 +168,6 @@ public class MindmapManagerImpl return query.getResultList(); } - @Override - public List findCollaboration(final CollaborationRole collaborationRole) { - Query query = currentSession().createQuery("from com.wisemapping.model.Collaboration c where c.role=:roleId"); - query.setParameter("roleId", collaborationRole.ordinal()); - return query.getResultList(); - } - - @Override - public Collaboration findCollaboration(final int mindmapId, final User user) { - final Collaboration result; - - Query query = currentSession().createQuery("from com.wisemapping.model.Collaboration c where c.mindMap.id=:mindmapId and c.id=:collaboratorId"); - query.setParameter("mindmapId", mindmapId); - query.setParameter("collaboratorId", user.getId()); - - final List mindMaps = query.getResultList(); - - if (mindMaps != null && !mindMaps.isEmpty()) { - result = mindMaps.get(0); - } else { - result = null; - } - - return result; - } - @Override public void addCollaborator(@NotNull Collaborator collaborator) { assert collaborator != null : "ADD MINDMAP COLLABORATOR: Collaborator is required!"; @@ -213,12 +184,6 @@ public class MindmapManagerImpl getHibernateTemplate().delete(collaborator); } - @Override - @SuppressWarnings("unchecked") - public List getAllMindmaps() { - return currentSession().createQuery("from com.wisemapping.model.Mindmap wisemapping").list(); - } - @Override @Nullable public Mindmap getMindmapById(int id) { diff --git a/wise-webapp/src/main/java/com/wisemapping/model/Collaborator.java b/wise-webapp/src/main/java/com/wisemapping/model/Collaborator.java index d9af2e99..a75db033 100755 --- a/wise-webapp/src/main/java/com/wisemapping/model/Collaborator.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Collaborator.java @@ -1,20 +1,20 @@ /* -* Copyright [2022] [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. -*/ + * Copyright [2022] [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. + */ package com.wisemapping.model; @@ -36,14 +36,14 @@ import java.util.Set; @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public class Collaborator implements Serializable { @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String email; @Column(name = "creation_date") private Calendar creationDate; - @OneToMany(mappedBy="collaborator") + @OneToMany(mappedBy = "collaborator") private Set collaborations = new HashSet<>(); public Collaborator() { @@ -117,7 +117,6 @@ public class Collaborator implements Serializable { if (id != that.getId()) return false; return email != null ? email.equals(that.getEmail()) : that.getEmail() == null; - } } 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 2d5739c3..da86633b 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -74,7 +74,7 @@ public class MindmapController extends BaseController { } @RequestMapping(method = RequestMethod.GET, value = "/maps/", produces = {"application/json"}) - public RestMindmapList retrieveList(@RequestParam(required = false) String q) throws IOException { + public RestMindmapList retrieveList(@RequestParam(required = false) String q) { final User user = Utils.getUser(); final MindmapFilter filter = MindmapFilter.parse(q);