Workaround to solve maps visibility problem on missing COLLABORATION entry.

This commit is contained in:
Paulo Gustavo Veiga 2022-09-24 09:37:36 -07:00
parent b5e7389e41
commit 704fb1a880
4 changed files with 22 additions and 66 deletions

View File

@ -29,16 +29,8 @@ public interface MindmapManager {
Collaborator findCollaborator(@NotNull String email); Collaborator findCollaborator(@NotNull String email);
Collaborator findCollaborator(int id);
List<Collaboration> findCollaboration(final int collaboratorId); List<Collaboration> findCollaboration(final int collaboratorId);
List<Collaboration> findCollaboration(final CollaborationRole userRole);
Collaboration findCollaboration(final int mindmapId, final User user);
List<Mindmap> getAllMindmaps();
@Nullable @Nullable
Mindmap getMindmapById(int mindmapId); Mindmap getMindmapById(int mindmapId);

View File

@ -116,9 +116,11 @@ public class MindmapManagerImpl
@Override @Override
public List<Mindmap> findMindmapByUser(@NotNull User user) { public List<Mindmap> findMindmapByUser(@NotNull User user) {
final Mindmap collaborator; final Mindmap collaborator;
// Note: Inconsistency on the COLLABORATION table (m.creator.id=:collabId). Needs to review it.
final Query query = currentSession() 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()); query.setParameter("collabId", user.getId());
return query.getResultList(); return query.getResultList();
@ -159,11 +161,6 @@ public class MindmapManagerImpl
return hibernateCriteria.list(); return hibernateCriteria.list();
} }
@Override
public Collaborator findCollaborator(int id) {
return getHibernateTemplate().get(Collaborator.class, id);
}
@Override @Override
public List<Collaboration> findCollaboration(final int collaboratorId) { public List<Collaboration> findCollaboration(final int collaboratorId) {
Query query = currentSession().createQuery("from com.wisemapping.model.Collaboration c where c.collaborator.id=: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(); return query.getResultList();
} }
@Override
public List<Collaboration> 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<Collaboration> mindMaps = query.getResultList();
if (mindMaps != null && !mindMaps.isEmpty()) {
result = mindMaps.get(0);
} else {
result = null;
}
return result;
}
@Override @Override
public void addCollaborator(@NotNull Collaborator collaborator) { public void addCollaborator(@NotNull Collaborator collaborator) {
assert collaborator != null : "ADD MINDMAP COLLABORATOR: Collaborator is required!"; assert collaborator != null : "ADD MINDMAP COLLABORATOR: Collaborator is required!";
@ -213,12 +184,6 @@ public class MindmapManagerImpl
getHibernateTemplate().delete(collaborator); getHibernateTemplate().delete(collaborator);
} }
@Override
@SuppressWarnings("unchecked")
public List<Mindmap> getAllMindmaps() {
return currentSession().createQuery("from com.wisemapping.model.Mindmap wisemapping").list();
}
@Override @Override
@Nullable @Nullable
public Mindmap getMindmapById(int id) { public Mindmap getMindmapById(int id) {

View File

@ -117,7 +117,6 @@ public class Collaborator implements Serializable {
if (id != that.getId()) return false; if (id != that.getId()) return false;
return email != null ? email.equals(that.getEmail()) : that.getEmail() == null; return email != null ? email.equals(that.getEmail()) : that.getEmail() == null;
} }
} }

View File

@ -74,7 +74,7 @@ public class MindmapController extends BaseController {
} }
@RequestMapping(method = RequestMethod.GET, value = "/maps/", produces = {"application/json"}) @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 User user = Utils.getUser();
final MindmapFilter filter = MindmapFilter.parse(q); final MindmapFilter filter = MindmapFilter.parse(q);