]> git.mxchange.org Git - jjobs-war.git/commitdiff
implemented lookupUserByEmailAddress() (this can be cherry-picked)
authorRoland Häder <roland@mxchange.org>
Fri, 13 May 2016 14:35:09 +0000 (16:35 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 14 May 2016 13:13:47 +0000 (15:13 +0200)
src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java
src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java

index 34eaf3705a1b4926b02f03c0dd0c15a6faada5a0..3acd67283e77499c1b7657319b57eb0b0fcfc722 100644 (file)
@@ -46,6 +46,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;
@@ -741,6 +742,52 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                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<User> 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<Contact> selectableContacts () {
                return Collections.unmodifiableList(this.selectableContacts);
index 8f5168eda00af0ee1f0fc72b8aab2311980c68ef..92d7d3482f87d41a9a38a1a2327cf2b7ce333e4c 100644 (file)
@@ -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;
@@ -151,6 +152,18 @@ public interface JobsUserWebSessionController 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.
+        * <p>
+        * @param emailAddress Email address
+        * <p>
+        * @return User instance
+        * <p>
+        * @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.