From: Roland Häder Date: Thu, 11 Aug 2016 10:30:39 +0000 (+0200) Subject: Continued with lock/unlock user accounts: (please cherry-pick) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=30888cb20c80c9bd53f6f4ecfb05def9dd071705;p=pizzaservice-ejb.git Continued with lock/unlock user accounts: (please cherry-pick) - return detached and updated user instance on locking/unlocking - update data in found instance and then merge it? A bit confusing ... --- diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java index e93cae5..129afcb 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java @@ -161,7 +161,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements } @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 PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements // 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 PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements 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 PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements // 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 PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements 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; } }