Improve registration code

This commit is contained in:
Paulo Gustavo Veiga 2022-09-27 21:46:42 -07:00
parent aa6ac9bf7f
commit e511d5e23d

View File

@ -109,27 +109,22 @@ public class UserManagerImpl
assert user != null : "Trying to store a null user"; assert user != null : "Trying to store a null user";
// Migrate from previous temporal collab to new user ... // Migrate from previous temporal collab to new user ...
List<Collaboration> newCollabs = new ArrayList<>();
final Set<Collaboration> 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(); final HibernateTemplate template = getHibernateTemplate();
collaborations.forEach(c -> template.delete(c)); collaborator.setEmail(collaborator.getEmail() + "_toRemove");
template.delete(collaborator); template.saveOrUpdate(collaborator);
template.flush();
// Save all new... // Save all new...
this.createUser(user); this.createUser(user);
newCollabs.forEach(c -> template.saveOrUpdate(c));
// Update mindmap ...
final Set<Collaboration> collaborations = collaborator.getCollaborations();
for (Collaboration collabs : collaborations) {
collabs.setCollaborator(user);
}
// Delete old user ...
template.delete(collaborator);
return user; return user;
} }