From e511d5e23daf164a489b11667a470a978810b6eb Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Tue, 27 Sep 2022 21:46:42 -0700 Subject: [PATCH] Improve registration code --- .../com/wisemapping/dao/UserManagerImpl.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/UserManagerImpl.java b/wise-webapp/src/main/java/com/wisemapping/dao/UserManagerImpl.java index bea65dcd..6e3028be 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/UserManagerImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/UserManagerImpl.java @@ -109,27 +109,22 @@ public class UserManagerImpl assert user != null : "Trying to store a null user"; // Migrate from previous temporal collab to new user ... - List newCollabs = new ArrayList<>(); - final Set collaborations = collaborator.getCollaborations(); - for (Collaboration oldCollab : collaborations) { - Collaboration newCollab = new Collaboration(); - newCollab.setRoleId(oldCollab.getRole().ordinal()); - newCollab.setMindMap(oldCollab.getMindMap()); - oldCollab.getMindMap().removedCollaboration(oldCollab); - newCollab.setCollaborator(user); - user.addCollaboration(newCollab); - newCollabs.add(newCollab); - } - - // Delete old collaboration final HibernateTemplate template = getHibernateTemplate(); - collaborations.forEach(c -> template.delete(c)); - template.delete(collaborator); + collaborator.setEmail(collaborator.getEmail() + "_toRemove"); + template.saveOrUpdate(collaborator); + template.flush(); // Save all new... this.createUser(user); - newCollabs.forEach(c -> template.saveOrUpdate(c)); + // Update mindmap ... + final Set collaborations = collaborator.getCollaborations(); + for (Collaboration collabs : collaborations) { + collabs.setCollaborator(user); + } + + // Delete old user ... + template.delete(collaborator); return user; }