From: Roland Häder Date: Thu, 12 May 2016 12:09:31 +0000 (+0200) Subject: implemented business method generateRandomUserName() which uses getUserNameList(... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=424ee5a906f4d355fb58e27a7d33bb34c078836b;p=jfinancials-mailer-ejb.git implemented business method generateRandomUserName() which uses getUserNameList() to get full list of available user names and checks that list. --- diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java index 52df172..a713d21 100644 --- a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java @@ -92,7 +92,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl // 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 AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl @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 AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl 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 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 getEmailAddressList () {