]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Wed, 24 Aug 2016 12:27:44 +0000 (14:27 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 24 Aug 2016 19:22:40 +0000 (21:22 +0200)
- added assert
- renamed variables to managed user/contact as this reflects the correct JPA state

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

index 9ee83eac19aad3c6f2730012943e16d8e22ab506..f660c50bbcfbe11e2608c720d9dd3c35db47f0a5 100644 (file)
@@ -139,10 +139,13 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
                }
 
                // 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());
@@ -213,7 +216,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
                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
@@ -221,7 +224,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
 
                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);
@@ -229,13 +232,13 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
 
                // 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
@@ -283,7 +286,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
                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
@@ -291,7 +294,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
 
                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);
@@ -299,13 +302,13 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
 
                // 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;
        }
 
 }