Workaround to solve maps visibility problem on missing COLLABORATION entry.

main
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(int id);
List<Collaboration> findCollaboration(final int collaboratorId);
List<Collaboration> findCollaboration(final CollaborationRole userRole);
Collaboration findCollaboration(final int mindmapId, final User user);
List<Mindmap> getAllMindmaps();
@Nullable
Mindmap getMindmapById(int mindmapId);

View File

@ -116,9 +116,11 @@ public class MindmapManagerImpl
@Override
public List<Mindmap> 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<Collaboration> 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<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
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<Mindmap> getAllMindmaps() {
return currentSession().createQuery("from com.wisemapping.model.Mindmap wisemapping").list();
}
@Override
@Nullable
public Mindmap getMindmapById(int id) {

View File

@ -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;
}
}

View File

@ -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);