From 0acce28fd78e92028551eb5b5d07604780975a70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 12 May 2016 14:09:31 +0200 Subject: [PATCH] implemented business method generateRandomUserName() which uses getUserNameList() to get full list of available user names and checks that list. --- .../model/user/PizzaUserSessionBean.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java index c27e1bb..0124c40 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java @@ -95,7 +95,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS // Update cellphone, land-line and fax instance this.setAllContactPhoneEntriesCreated(user.getUserContact()); - // Persist it + // Persist it this.getEntityManager().persist(user); // Flush to get id back @@ -212,6 +212,9 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS @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 @@ -234,12 +237,39 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS 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 () { -- 2.39.5