From: Roland Häder Date: Wed, 24 Aug 2016 12:27:44 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=53e18720737c7df756c9ef4d18b8ab82bfe39343;p=jjobs-mailer-ejb.git Please cherry-pick: - added assert - renamed variables to managed user/contact as this reflects the correct JPA state --- diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java index 5406727..fff9620 100644 --- a/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java @@ -184,10 +184,13 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean } // Try to find the contact - Contact foundContact = this.getEntityManager().getReference(user.getUserContact().getClass(), user.getUserContact().getContactId()); + Contact managedContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId()); + + // Should be found! + assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", managedContact.getContactId()); //NOI18N // Set detached object in rexcruiter instance - user.setUserContact(foundContact); + user.setUserContact(managedContact); // Set timestamp user.setUserCreated(new GregorianCalendar()); @@ -258,7 +261,7 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean user.setUserLastLockedReason(userLockReason); // Update user - User updatedUser = this.userBean.updateUserData(user); + User managedUser = this.userBean.updateUserData(user); // @TODO Create user lock history entry // Init variable @@ -266,7 +269,7 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean try { // Create email address and set - emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress()); + emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress()); } catch (final AddressException ex) { // Throw again throw new EJBException(ex); @@ -274,13 +277,13 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean // Send out email // @TODO externalize subject line - this.sendEmail("Account locked", "account_locked", emailAddress, updatedUser, baseUrl); //NOI18N + this.sendEmail("Account locked", "account_locked", emailAddress, managedUser, baseUrl); //NOI18N // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N // Return detached (and updated) user - return updatedUser; + return managedUser; } @Override @@ -328,7 +331,7 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean user.setUserAccountStatus(UserAccountStatus.CONFIRMED); // Update user - User updatedUser = this.userBean.updateUserData(user); + User managedUser = this.userBean.updateUserData(user); // @TODO Create user lock history entry // Init variable @@ -336,7 +339,7 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean try { // Create email address and set - emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress()); + emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress()); } catch (final AddressException ex) { // Throw again throw new EJBException(ex); @@ -344,13 +347,13 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean // Send out email // @TODO externalize subject line - this.sendEmail("Account unlocked", "account_unlocked", emailAddress, updatedUser, baseUrl); //NOI18N + this.sendEmail("Account unlocked", "account_unlocked", emailAddress, managedUser, baseUrl); //NOI18N // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N // Return changed account - return updatedUser; + return managedUser; } }