]> git.mxchange.org Git - jjobs-ejb.git/commitdiff
implemented business method generateRandomUserName() which uses getUserNameList(...
authorRoland Häder <roland@mxchange.org>
Thu, 12 May 2016 12:09:31 +0000 (14:09 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 14 May 2016 12:44:07 +0000 (14:44 +0200)
src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java

index 63c5ecb6f7f1b1b6f110887f650c9b60c2e93ccf..f89ad9ca23b7a14d592d07896e9249bded73a81b 100644 (file)
@@ -92,7 +92,7 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                // Update cellphone, land-line and fax instance
                this.setAllContactPhoneEntriesCreated(user.getUserContact());
 
-                       // Persist it
+               // Persist it
                this.getEntityManager().persist(user);
 
                // Flush to get id back
@@ -209,6 +209,9 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
 
        @Override
        public User findUserById (final Long userId) throws UserNotFoundException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("findUserById: userId={0} - CALLED!", userId)); //NOI18N
+
                // Is the parameter valid?
                if (null == userId) {
                        // Throw NPE
@@ -231,12 +234,39 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes
                User user = (User) query.getSingleResult();
 
                // Should be there
-               assert(user instanceof User) : "user is null"; //NOI18N
+               assert (user instanceof User) : "user is null"; //NOI18N
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("findUserById: user={0} - EXIT!!", user)); //NOI18N
 
                // Return found user
                return user;
        }
 
+       @Override
+       public String generateRandomUserName () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("generateRandomUserName - CALLED!"); //NOI18N
+
+               // Get full list
+               List<String> userList = this.getUserNameList();
+
+               // 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("generateRandomUserName: userName={0} - EXIT!", userName)); //NOI18N
+
+               // Found one, so return it
+               return userName;
+       }
+
        @Override
        @SuppressWarnings ("unchecked")
        public List<String> getEmailAddressList () {