]> git.mxchange.org Git - jjobs-ejb.git/blobdiff - src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java
Don't cherry-pick:
[jjobs-ejb.git] / src / java / org / mxchange / jusercore / model / user / JobsUserSessionBean.java
index 9d29a403d2400737c5045069e46f36bd8052d845..7a4339379b74f79d265a486dbe738ee1b2f5e2d5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2022 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -19,30 +19,26 @@ package org.mxchange.jusercore.model.user;
 import java.text.MessageFormat;
 import java.util.Date;
 import java.util.List;
-import javax.ejb.EJB;
+import java.util.Objects;
 import javax.ejb.EJBException;
 import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
-import javax.persistence.PersistenceException;
 import javax.persistence.Query;
 import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jcontacts.model.contact.ContactUtils;
-import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
+import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers;
 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers;
 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers;
+import org.mxchange.jphone.model.utils.FaxNumberUtils;
+import org.mxchange.jphone.model.utils.LandLineNumberUtils;
+import org.mxchange.jphone.model.utils.MobileNumberUtils;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
 import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
 import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
 import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.utils.UserUtils;
 
 /**
  * A user EJB
@@ -50,19 +46,13 @@ import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBe
  * @author Roland Häder<roland@mxchange.org>
  */
 @Stateless (name = "user", description = "A bean handling the user data")
-public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSessionBeanRemote {
+public class JobsUserSessionBean extends BaseJobsEnterpriseBean implements UserSessionBeanRemote {
 
        /**
         * Serial number
         */
        private static final long serialVersionUID = 542_145_347_916L;
 
-       /**
-        * Registration EJB
-        */
-       @EJB
-       private UserRegistrationSessionBeanRemote registerBean;
-
        /**
         * Default constructor
         */
@@ -72,92 +62,7 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
        }
 
        @Override
-       @SuppressWarnings ("unchecked")
-       public List<User> allMemberPublicVisibleUsers () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get named query
-               final Query query = this.getEntityManager().createNamedQuery("AllMemberPublicUsers", LoginUser.class); //NOI18N
-
-               // Set parameters
-               query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
-               query.setParameter("members", ProfileMode.MEMBERS); //NOI18N
-               query.setParameter("public", ProfileMode.PUBLIC); //NOI18N
-
-               // Get result
-               final List<User> users = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
-
-               // Return full list
-               return users;
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<User> allPublicUsers () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get named query
-               final Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", LoginUser.class); //NOI18N
-
-               // Set parameters
-               query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
-               query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N
-
-               // Get result
-               final List<User> users = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
-
-               // Return full list
-               return users;
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<String> allUserNames () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get query
-               final Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N
-
-               // Get result list
-               final List<String> userNameList = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: userNameList.size()={1} - EXIT!", this.getClass().getSimpleName(), userNameList.size())); //NOI18N
-
-               // Return it
-               return userNameList;
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<User> allUsers () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get named query
-               final Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N
-
-               // Get result
-               final List<User> users = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
-
-               // Return full list
-               return users;
-       }
-
-       @Override
-       public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
+       public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException, UserNotFoundException {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
 
@@ -184,7 +89,7 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                        // Throw it again
                        throw new NullPointerException("baseUrl is null"); //NOI18N
                } else if (baseUrl.isEmpty()) {
-                       // Invalid parameter
+                       // Throw IAE
                        throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
                }
 
@@ -194,7 +99,7 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                // Update user status and remove confirmation key
                managedUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
                managedUser.setUserConfirmKey(null);
-               managedUser.setUserUpdated(new Date());
+               managedUser.setUserEntryUpdated(new Date());
 
                // Send out email
                this.sendEmail("User account confirmed", "user_account_confirmed", managedUser, baseUrl, null); //NOI18N
@@ -206,126 +111,23 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                return managedUser;
        }
 
-       @Override
-       public User fillUserData (final User user) throws UserNotFoundException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
-
-               // user should not be null
-               if (null == user) {
-                       // Abort here
-                       throw new NullPointerException("user is null"); //NOI18N
-               } else if (user.getUserName() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("user.userName is null");
-               } else if (user.getUserName().isEmpty()) {
-                       // Throw IAE
-                       throw new IllegalArgumentException("user.userName is empty");
-               } else if (!this.ifUserExists(user)) {
-                       // User does not exist
-                       throw new UserNotFoundException(user);
-               }
-
-               // Try to locate it
-               final Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
-
-               // Set parameter
-               query.setParameter("param", user.getUserName()); //NOI18N
-
-               // Initialize variable
-               final User foundUser;
-
-               // Try it
-               try {
-                       // Try to get single result
-                       foundUser = (User) query.getSingleResult();
-               } catch (final NoResultException ex) {
-                       // Log it
-                       this.getLoggerBeanLocal().logException(ex);
-                       return null;
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: foundUser={1} - EXIT!", this.getClass().getSimpleName(), foundUser)); //NOI18N
-
-               // Return prepared instance
-               return foundUser;
-       }
-
-       @Override
-       public User findUserById (final Long userId) throws UserNotFoundException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
-
-               // Is the parameter valid?
-               if (null == userId) {
-                       // Throw NPE
-                       throw new NullPointerException("userId is null"); //NOI18N
-               } else if (userId < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
-               } else if (!this.ifUserIdExists(userId)) {
-                       // Does not exist
-                       throw new UserNotFoundException(userId);
-               }
-
-               // Create query instance
-               final Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
-
-               // Set user id
-               query.setParameter("id", userId); //NOI18N
-
-               // Fetch the result, it should be there by now
-               final User user = (User) query.getSingleResult();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
-
-               // Return found user
-               return user;
-       }
-
-       @Override
-       public String generateRandomUserName () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get full list
-               final List<String> userList = this.allUserNames();
-
-               // Init variable
-               String userName = null;
-
-               // Loop until a user name is found
-               while ((userName == null) || (userList.contains(userName))) {
-                       // Generate random name
-                       userName = UserUtils.generateRandomUserName();
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName: userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
-
-               // Found one, so return it
-               return userName;
-       }
-
        @Override
        @SuppressWarnings ("unchecked")
-       public List<String> getEmailAddressList () {
+       public List<User> fetchAllUsers () {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: CALLED!", this.getClass().getSimpleName())); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
-               // Get query
-               final Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N
+               // Get named query
+               final Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N
 
-               // Get result list
-               final List<String> emailAddressList = query.getResultList();
+               // Get result
+               final List<User> users = query.getResultList();
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddressList.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddressList.size())); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
 
-               // Return it
-               return emailAddressList;
+               // Return full list
+               return users;
        }
 
        @Override
@@ -345,86 +147,31 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                        throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
                }
 
-               // Generate query
-               final Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
-
-               // Set parameter
-               query.setParameter("id", user.getUserId()); //NOI18N
-
-               // Try this
-               try {
-                       // Try to get single result
-                       final User dummy = (User) query.getSingleResult();
-
-                       // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
-               } catch (final NoResultException ex) {
-                       // Log it
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
-
-                       // User name does not exist
-                       return false;
-               } catch (final PersistenceException ex) {
-                       // Something bad happened
-                       this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user {0} found.", user, ex)); //NOI18N
-
-                       // Throw again
-                       throw ex;
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: Found user {1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
-
-               // Found it
-               return true;
-       }
-
-       @Override
-       public boolean ifUserIdExists (final Long userId) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
-
-               // userId should not be null
-               if (null == userId) {
-                       // Abort here
-                       throw new NullPointerException("userId is null"); //NOI18N
-               } else if (userId < 1) {
-                       // Invalid number
-                       throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", userId)); //NOI18N
-               }
-
-               // Generate query
-               final Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
-
-               // Set parameter
-               query.setParameter("id", userId); //NOI18N
-
-               // Try this
-               try {
-                       // Try to get single result
-                       final User dummy = (User) query.getSingleResult();
-
-                       // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
-               } catch (final NoResultException ex) {
-                       // Log it
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
-
-                       // User name does not exist
-                       return false;
-               } catch (final PersistenceException ex) {
-                       // Something bad happened
-                       this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user id {0} found.", userId, ex)); //NOI18N
-
-                       // Throw again
-                       throw ex;
+               // Default is not found
+               boolean isFound = false;
+
+               // Fetch whole list
+               for (final User currentUser : this.fetchAllUsers()) {
+                       /*
+                        * E.g. userAccountStatus can be fifferent because lockUserAccount
+                        * is setting it BEFORE this method is invoked. So this is enough
+                        * for us in this case. But otherwise e.g. when a new user is
+                        * created with same data, then this method must return FALSE even
+                        * when userId is currently NULL.
+                        */
+                       //* NOISY-DEBUG: */ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserExists: currentUser={1},currentUser.userId={2}", this.getClass(), currentUser, currentUser.getUserId())); //NOI18N
+                       if ((Objects.equals(user.getUserId(), currentUser.getUserId()) && user.getUserId() != null) || Objects.equals(user, currentUser)) {
+                               // Yes, then set flag and exit iteration
+                               isFound = true;
+                               break;
+                       }
                }
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: Found userId={1} - EXIT!", this.getClass().getSimpleName(), userId)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N
 
-               // Found it
-               return true;
+               // Return flag
+               return isFound;
        }
 
        @Override
@@ -441,29 +188,21 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                        throw new NullPointerException("userName is empty"); //NOI18N
                }
 
-               // Generate query
-               final Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
-
-               // Set parameter
-               query.setParameter("param", userName); //NOI18N
-
-               // Try this
-               try {
-                       // Try to get single result
-                       final User dummy = (User) query.getSingleResult();
-
-                       // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
-               } catch (final NoResultException ex) {
-                       // Log it
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
-
-                       // User name does not exist
-                       return false;
+               // Default is not registered
+               boolean isRegistered = false;
+
+               // Iterate over all records
+               for (final User currentUser : this.fetchAllUsers()) {
+                       // Does the username match?
+                       if (userName.equals(currentUser.getUserName())) {
+                               // Yes, then set flag and exit iteration
+                               isRegistered = true;
+                               break;
+                       }
                }
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: Found userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: isRegistered={1} - EXIT!", this.getClass().getSimpleName(), isRegistered)); //NOI18N
 
                // Found it
                return true;
@@ -480,38 +219,24 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                        throw new NullPointerException("user is null"); //NOI18N
                }
 
-               // Generate query
-               final Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", LoginUser.class); //NOI18N
-
-               // Set parameter
-               query.setParameter("param", user.getUserContact().getContactEmailAddress()); //NOI18N
-
-               // Search for it
-               try {
-                       // Try to get single result
-                       final User dummy = (User) query.getSingleResult();
-
-                       // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
-               } catch (final NoResultException ex) {
-                       // Log it
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
-
-                       // Email address does not exist
-                       return false;
-               } catch (final PersistenceException ex) {
-                       // Something bad happened
-                       this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
-
-                       // Throw again
-                       throw ex;
+               // Default is not registered
+               boolean isRegistered = false;
+
+               // Iterate over all records
+               for (final User currentUser : this.fetchAllUsers()) {
+                       // Does the email address match?
+                       if (user.getUserContact().getContactEmailAddress().equals(currentUser.getUserContact().getContactEmailAddress())) {
+                               // Yes, then set flag and exit iteration
+                               isRegistered = true;
+                               break;
+                       }
                }
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: isRegistered={1} - EXIT!", this.getClass().getSimpleName(), isRegistered)); //NOI18N
 
                // Found it
-               return true;
+               return isRegistered;
        }
 
        @Override
@@ -525,42 +250,18 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                        throw new NullPointerException("user is null"); //NOI18N
                }
 
-               // Generate query
-               final Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
-
-               // Set parameter
-               query.setParameter("param", user.getUserName()); //NOI18N
-
-               // Try this
-               try {
-                       // Try to get single result
-                       final User dummy = (User) query.getSingleResult();
-
-                       // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
-               } catch (final NoResultException ex) {
-                       // Log it
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
-
-                       // User name does not exist
-                       return false;
-               } catch (final PersistenceException ex) {
-                       // Something bad happened
-                       this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
-
-                       // Throw again
-                       throw ex;
-               }
+               // Ask other method
+               final boolean isRegistered = this.ifUserNameExists(user.getUserName());
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: isRegistered={1} - EXIT!", this.getClass().getSimpleName(), isRegistered)); //NOI18N
 
-               // Found it
-               return true;
+               // Return flag
+               return isRegistered;
        }
 
        @Override
-       public User updateUserData (final User user) {
+       public User updateUserData (final User user) throws UserNotFoundException {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
 
@@ -579,7 +280,7 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                        throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
                } else if (!this.ifUserExists(user)) {
                        // User does not exist
-                       throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
+                       throw new UserNotFoundException(user.getUserId());
                }
 
                // Find the instance
@@ -588,17 +289,17 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                // Should be found!
                assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
 
+               // Copy all data
+               UserUtils.copyUserData(user, foundUser);
+
                // Merge user
                final User managedUser = this.getEntityManager().merge(foundUser);
 
                // Should be found!
                assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
 
-               // Copy all data
-               UserUtils.copyAll(user, managedUser);
-
                // Set as updated
-               managedUser.setUserUpdated(new Date());
+               managedUser.setUserEntryUpdated(new Date());
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
@@ -658,10 +359,10 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                final User managedUser = this.updateUserData(user);
 
                // Update user account
-               managedUser.setUserUpdated(new Date());
+               managedUser.setUserEntryUpdated(new Date());
 
                // Create history entry
-               PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), managedUser);
+               final PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), managedUser);
 
                // Set created timestamp
                entry.setUserPasswordHistoryCreated(new Date());
@@ -713,32 +414,19 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
 
                // Copy all data
-               UserUtils.copyAll(user, managedUser);
+               UserUtils.copyUserData(user, managedUser);
 
                // Set as updated
-               managedUser.setUserUpdated(new Date());
-               managedUser.getUserContact().setContactUpdated(new Date());
-
-               // Get contact from it and find it
-               final Contact foundContact = this.getEntityManager().find(managedUser.getUserContact().getClass(), managedUser.getUserContact().getContactId());
-
-               // Should be found
-               assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
+               managedUser.setUserEntryUpdated(new Date());
 
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N
-
-               // Merge contact instance
-               final Contact managedContact = this.getEntityManager().merge(foundContact);
-
-               // Copy all
-               ContactUtils.copyAll(user.getUserContact(), managedContact);
+               // Update user data
+               final Contact managedContact = this.mergeContactData(managedUser.getUserContact());
 
                // Set it back in user
-               user.setUserContact(managedContact);
+               managedUser.setUserContact(managedContact);
 
                // Should be found!
-               assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N
+               assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", managedUser.getUserContact().getContactId()); //NOI18N
 
                // Get mobile instance
                final DialableMobileNumber mobileNumber = managedContact.getContactMobileNumber();
@@ -746,25 +434,25 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                // Is there a  mobile instance set?
                if (mobileNumber instanceof DialableMobileNumber) {
                        // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getPhoneId())); //NOI18N
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getMobileId())); //NOI18N
 
                        // Then find it, too
-                       final DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId());
+                       final DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getMobileId());
 
                        // Should be there
-                       assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
+                       assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getMobileId()); //NOI18N
+
+                       // Copy all
+                       MobileNumberUtils.copyMobileNumberData(managedUser.getUserContact().getContactMobileNumber(), foundMobile);
 
                        // Then merge it, too
                        final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
 
                        // Should be there
-                       assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
-
-                       // Copy all
-                       MobileNumbers.copyAll(managedUser.getUserContact().getContactMobileNumber(), managedMobile);
+                       assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getMobileId()); //NOI18N
 
                        // Set it back
-                       managedContact.setContactMobileNumber(this.getManaged(mobileNumber, mobileNumber));
+                       managedContact.setContactMobileNumber(managedMobile);
                }
 
                // Get mobile instance
@@ -773,7 +461,7 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                // Is there a  fax instance set?
                if (faxNumber instanceof DialableFaxNumber) {
                        // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: faxNumber.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
 
                        // Then find it, too
                        final DialableFaxNumber foundFax = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
@@ -781,15 +469,15 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                        // Should be there
                        assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
 
+                       // Copy all
+                       FaxNumberUtils.copyFaxNumberData(managedUser.getUserContact().getContactFaxNumber(), foundFax);
+
                        // Then merge it, too
                        final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
 
                        // Should be there
                        assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
 
-                       // Copy all
-                       FaxNumbers.copyAll(managedUser.getUserContact().getContactFaxNumber(), managedFax);
-
                        // Set it back
                        managedContact.setContactFaxNumber(managedFax);
                }
@@ -800,7 +488,7 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                // Is there a  fax instance set?
                if (landLineNumber instanceof DialableLandLineNumber) {
                        // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLineNumber.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
 
                        // Then find it, too
                        final DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
@@ -808,15 +496,15 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                        // Should be there
                        assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
 
+                       // Copy all
+                       LandLineNumberUtils.copyLandLineNumberData(managedUser.getUserContact().getContactLandLineNumber(), foundLandLine);
+
                        // Then merge it, too
                        final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
 
                        // Should be there
                        assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
 
-                       // Copy all
-                       LandLineNumbers.copyAll(managedUser.getUserContact().getContactLandLineNumber(), managedLandLine);
-
                        // Set it back
                        managedContact.setContactLandLineNumber(managedLandLine);
                }