]> git.mxchange.org Git - addressbook-mailer-ejb.git/commitdiff
Continued with lock/unlock user accounts: (please cherry-pick)
authorRoland Häder <roland@mxchange.org>
Thu, 11 Aug 2016 10:30:39 +0000 (12:30 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 16 Aug 2016 19:42:51 +0000 (21:42 +0200)
- return detached and updated user instance on locking/unlocking
- update data in found instance and then merge it? A bit confusing ...

src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java

index 54f3b754d1e14e5ec5178d7ba7d5b6d247106071..5b2e102c51e25484333a70f44b7a030b7ae50d6d 100644 (file)
@@ -161,7 +161,7 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean
        }
 
        @Override
-       public void lockUserAccount (final User user, final String userLockReason, final String baseUrl) throws UserStatusLockedException, UserStatusUnconfirmedException, UserNotFoundException {
+       public User lockUserAccount (final User user, final String userLockReason, final String baseUrl) throws UserStatusLockedException, UserStatusUnconfirmedException, UserNotFoundException {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: user={1},userLockReason={2},baseUrl={3} - CALLED!", this.getClass().getSimpleName(), user, userLockReason, baseUrl)); //NOI18N
 
@@ -213,20 +213,20 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean
                // Should be found!
                assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
 
+               // Copy all data
+               foundUser.copyAll(user);
+
+               // Set as locked
+               foundUser.setUserAccountStatus(UserAccountStatus.LOCKED);
+               foundUser.setUserLastLocked(new GregorianCalendar());
+               foundUser.setUserLastLockedReason(userLockReason);
+
                // Merge user
                User detachedUser = this.getEntityManager().merge(foundUser);
 
                // Should be found!
                assert (detachedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", user.getUserId()); //NOI18N
 
-               // Copy all data
-               detachedUser.copyAll(user);
-
-               // Set as locked
-               detachedUser.setUserAccountStatus(UserAccountStatus.LOCKED);
-               detachedUser.setUserLastLocked(new GregorianCalendar());
-               detachedUser.setUserLastLockedReason(userLockReason);
-
                // Update user
                User updatedUser = this.userBean.updateUserData(user);
 
@@ -247,11 +247,14 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean
                this.sendEmail("Account locked", "account_locked", emailAddress, updatedUser, baseUrl); //NOI18N
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount - EXIT!", this.getClass().getSimpleName())); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: detachedUser={1} - EXIT!", this.getClass().getSimpleName(), detachedUser)); //NOI18N
+
+               // Return detached (and updated) user
+               return detachedUser;
        }
 
        @Override
-       public void unlockUserAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusUnconfirmedException, UserNotFoundException {
+       public User unlockUserAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusUnconfirmedException, UserNotFoundException {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
 
@@ -297,18 +300,18 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean
                // Should be found!
                assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
 
+               // Copy all data
+               foundUser.copyAll(user);
+
+               // Unlock account
+               foundUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
+
                // Merge user
                User detachedUser = this.getEntityManager().merge(foundUser);
 
                // Should be found!
                assert (detachedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", user.getUserId()); //NOI18N
 
-               // Copy all data
-               detachedUser.copyAll(user);
-
-               // Unlock account
-               detachedUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
-
                // Update user
                User updatedUser = this.userBean.updateUserData(user);
 
@@ -329,7 +332,10 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean
                this.sendEmail("Account unlocked", "account_unlocked", emailAddress, updatedUser, baseUrl); //NOI18N
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount - EXIT!", this.getClass().getSimpleName())); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: detachedUser={1} - EXIT!", this.getClass().getSimpleName(), detachedUser)); //NOI18N
+
+               // Return changed account
+               return detachedUser;
        }
 
 }