From 400a827b510efda5f1c09087c857a4fc7652c815 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 13 May 2016 16:35:09 +0200 Subject: [PATCH] implemented lookupUserByEmailAddress() (this can be cherry-picked) --- .../beans/user/PizzaUserWebSessionBean.java | 47 +++++++++++++++++++ .../user/PizzaUserWebSessionController.java | 13 +++++ 2 files changed, 60 insertions(+) diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java index d82fc701..e9e7e7c6 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java @@ -42,6 +42,7 @@ import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent; import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent; +import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.jusercore.model.user.LoginUser; @@ -748,6 +749,52 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz return user; } + @Override + public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException { + // Parameter must be valid + if (null == emailAddress) { + // Throw NPE + throw new NullPointerException("emailAddress is null"); //NOI18N + } else if (emailAddress.isEmpty()) { + // Not valid + throw new IllegalArgumentException("emailAddress is empty"); //NOI18N + } + + // Init variable + User user = null; + + // Try to lookup it in visible user list + for (final Iterator iterator = this.userList.iterator(); iterator.hasNext();) { + // Get next user + User next = iterator.next(); + + // Contact should be set + if (next.getUserContact() == null) { + // Contact is null + throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", + next.getUserId())); + } else if (next.getUserContact().getContactEmailAddress() == null) { + // Email address should be set + throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); + } + + // Is the email address found? + if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) { + // Copy to other variable + user = next; + break; + } + } + + // Is it still null? + if (null == user) { + // Not visible for the current user + throw new UserEmailAddressNotFoundException(emailAddress); + } + + // Return it + return user; + } + @Override public List selectableContacts () { return Collections.unmodifiableList(this.selectableContacts); diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java index ff5d8b50..bb2d8ef3 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java @@ -25,6 +25,7 @@ import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent; import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; +import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; @@ -143,6 +144,18 @@ public interface PizzaUserWebSessionController extends Serializable { */ User lookupUserById (final Long userId) throws UserNotFoundException; + /** + * Tries to lookup user by given email address. If the user is not found a + * proper exceptions is thrown. + *

+ * @param emailAddress Email address + *

+ * @return User instance + *

+ * @throws UserEmailAddressNotFoundException If the user's email address is not found + */ + User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException; + /** * Returns a list of all selectable contacts for user creation. Contacts * from already existing users are excluded in this list. -- 2.39.5