From 63cfe44d506e8a7d01f52fbc584116e9698205fa Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 16 Feb 2022 18:05:26 -0800 Subject: [PATCH] Remove orphan collabs on registration --- .../java/com/wisemapping/dao/UserManagerImpl.java | 15 +++++++++++---- .../java/com/wisemapping/model/Collaboration.java | 4 +++- .../com/wisemapping/rest/AccountController.java | 2 -- .../com/wisemapping/service/UserServiceImpl.java | 4 +--- 4 files changed, 15 insertions(+), 10 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 1729aea8..25ed8db3 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/UserManagerImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/UserManagerImpl.java @@ -102,22 +102,29 @@ public class UserManagerImpl } @Override - public User createUser(@NotNull User user, @NotNull Collaborator col) { + public User createUser(@NotNull User user, @NotNull Collaborator collaborator) { user.setPassword(passwordEncoder.encode(user.getPassword())); assert user != null : "Trying to store a null user"; - final Set set = col.getCollaborations(); - for (Collaboration collaboration : set) { + final Set collaborations = collaborator.getCollaborations(); + for (Collaboration collaboration : collaborations) { + // Move maps to the new ... Collaboration newMapUser = new Collaboration(); newMapUser.setRoleId(collaboration.getRole().ordinal()); newMapUser.setMindMap(collaboration.getMindMap()); newMapUser.setCollaborator(user); user.addCollaboration(newMapUser); + + // Delete collaborations on this collaborator ... + getHibernateTemplate().delete(collaboration); + getHibernateTemplate().flush(); } - getHibernateTemplate().delete(col); + // Delete collaboration ... + getHibernateTemplate().delete(collaborator); getHibernateTemplate().flush(); getHibernateTemplate().saveOrUpdate(user); + return user; } diff --git a/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java b/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java index 42395542..81c690b9 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java @@ -19,6 +19,9 @@ package com.wisemapping.model; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; @@ -46,7 +49,6 @@ public class Collaboration implements Serializable { @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "properties_id", nullable = false, unique = true) private CollaborationProperties collaborationProperties = new CollaborationProperties(); - ; public Collaboration() { } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/AccountController.java b/wise-webapp/src/main/java/com/wisemapping/rest/AccountController.java index 630f274c..1cb040be 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/AccountController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/AccountController.java @@ -55,8 +55,6 @@ public class AccountController extends BaseController { @Autowired private NotificationService notificationService; - final Logger logger = Logger.getLogger(AccountController.class); - @RequestMapping(method = RequestMethod.PUT, value = "account/password", consumes = {"text/plain"}) @ResponseStatus(value = HttpStatus.NO_CONTENT) diff --git a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java index ad17c2b9..b55a2a69 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java @@ -119,13 +119,11 @@ public class UserServiceImpl if (emailConfirmEnabled) { user.setActivationDate(null); - } else { user.setActivationDate(Calendar.getInstance()); } - Collaborator col = userManager.getCollaboratorBy(user.getEmail()); - + final Collaborator col = userManager.getCollaboratorBy(user.getEmail()); if (col != null) { userManager.createUser(user, col); } else {