]> git.mxchange.org Git - jjobs-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:24:56 +0000 (21:24 +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/JobsAdminUserSessionBean.java

index c5a3fc7468161182d901a3d366a78246513c1c01..02b5d38f16560de5030128c78d9c3472d2bf4c00 100644 (file)
@@ -161,7 +161,7 @@ public class JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
        }
 
        @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 JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                // 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 JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                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 JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                // 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 JobsAdminUserSessionBean extends BaseJobsDatabaseBean implements Ad
                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;
        }
 
 }