2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.beans.user;
19 import java.text.MessageFormat;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Objects;
23 import javax.annotation.PostConstruct;
24 import javax.enterprise.context.SessionScoped;
25 import javax.enterprise.event.Event;
26 import javax.enterprise.event.Observes;
27 import javax.enterprise.inject.Any;
28 import javax.faces.context.FacesContext;
29 import javax.faces.view.facelets.FaceletException;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import javax.naming.Context;
33 import javax.naming.InitialContext;
34 import javax.naming.NamingException;
35 import org.mxchange.jcontacts.contact.Contact;
36 import org.mxchange.jjobs.beans.BaseJobsController;
37 import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
38 import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController;
39 import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
40 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
41 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
42 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
43 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
44 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
45 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
46 import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
47 import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
48 import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent;
49 import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
50 import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
51 import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent;
52 import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
53 import org.mxchange.jusercore.exceptions.UserNotFoundException;
54 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
55 import org.mxchange.jusercore.model.user.LoginUser;
56 import org.mxchange.jusercore.model.user.User;
57 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
58 import org.mxchange.jusercore.model.user.UserUtils;
59 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
62 * A user controller (bean)
64 * @author Roland Haeder<roland@mxchange.org>
66 @Named ("userController")
68 public class JobsUserWebSessionBean extends BaseJobsController implements JobsUserWebSessionController {
73 private static final long serialVersionUID = 542_145_347_916L;
76 * General contact controller
79 private JobsContactWebSessionController contactController;
85 private JobsFeaturesWebApplicationController featureController;
88 * Localization controller
91 private JobsLocalizationSessionController localizationController;
94 * Event being fired when user updated personal data
98 private Event<UpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
103 private final UserSessionBeanRemote userBean;
111 * A list of all user profiles
113 private List<User> userList;
116 * Login controller (bean)
119 private JobsUserLoginWebSessionController userLoginController;
124 private String userName;
129 private List<String> userNameList;
132 * User password (unencrypted from web form)
134 private String userPassword;
137 * User password repeated (unencrypted from web form)
139 private String userPasswordRepeat;
142 * Whether the user wants a public profile
144 private ProfileMode userProfileMode;
147 * A list of all public user profiles
149 * @TODO Hmm, makes that sense? Having visible user list in current
150 * (session-scoped) user's visible user list?
152 private List<User> visibleUserList;
155 * Default constructor
157 public JobsUserWebSessionBean () {
160 // Get initial context
161 Context context = new InitialContext();
164 this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
165 } catch (final NamingException e) {
167 throw new FaceletException(e);
172 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
174 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
176 // event should not be null
179 throw new NullPointerException("event is null"); //NOI18N
180 } else if (event.getAddedUser() == null) {
182 throw new NullPointerException("event.addedUser is null"); //NOI18N
183 } else if (event.getAddedUser().getUserId() == null) {
185 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
186 } else if (event.getAddedUser().getUserId() < 1) {
188 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
192 this.updateList(event.getAddedUser());
198 this.setUserId(event.getAddedUser().getUserId());
202 public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) {
203 // event should not be null
206 throw new NullPointerException("event is null"); //NOI18N
207 } else if (event.getLinkedUser() == null) {
209 throw new NullPointerException("event.linkedUser is null"); //NOI18N
210 } else if (event.getLinkedUser().getUserId() == null) {
212 throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
213 } else if (event.getLinkedUser().getUserId() < 1) {
215 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
219 this.updateList(event.getLinkedUser());
225 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
229 public void afterAdminLockedUserEvent (@Observes final AdminLockedUserEvent event) {
230 // event should not be null
233 throw new NullPointerException("event is null"); //NOI18N
234 } else if (event.getLockedUser() == null) {
236 throw new NullPointerException("event.lockedUser is null"); //NOI18N
237 } else if (event.getLockedUser().getUserId() == null) {
239 throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
240 } else if (event.getLockedUser().getUserId() < 1) {
242 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
246 this.updateList(event.getLockedUser());
250 public void afterAdminUnlockedUserEvent (@Observes final AdminUnlockedUserEvent event) {
251 // event should not be null
254 throw new NullPointerException("event is null"); //NOI18N
255 } else if (event.getUnlockedUser() == null) {
257 throw new NullPointerException("event.unlockedUser is null"); //NOI18N
258 } else if (event.getUnlockedUser().getUserId() == null) {
260 throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
261 } else if (event.getUnlockedUser().getUserId() < 1) {
263 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
267 this.updateList(event.getUnlockedUser());
271 public void afterAdminUpdatedUserDataEvent (@Observes final AdminUpdatedUserDataEvent event) {
273 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N
275 // event should not be null
278 throw new NullPointerException("event is null"); //NOI18N
279 } else if (event.getUpdatedUser() == null) {
281 throw new NullPointerException("event.updatedUser is null"); //NOI18N
282 } else if (event.getUpdatedUser().getUserId() == null) {
284 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
285 } else if (event.getUpdatedUser().getUserId() < 1) {
287 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
291 this.updateList(event.getUpdatedUser());
297 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
301 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
303 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
305 // event should not be null
308 throw new NullPointerException("event is null"); //NOI18N
309 } else if (event.getRegisteredUser() == null) {
311 throw new NullPointerException("event.registeredUser is null"); //NOI18N
312 } else if (event.getRegisteredUser().getUserId() == null) {
314 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
315 } else if (event.getRegisteredUser().getUserId() < 1) {
317 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
321 User registeredUser = event.getRegisteredUser();
324 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
326 // Copy all data from registered->user
327 this.copyUser(registeredUser);
333 this.updateList(registeredUser);
336 this.addUserName(registeredUser);
338 // Is the account public?
339 if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
340 // Also add it to this list
341 this.visibleUserList.add(registeredUser);
345 this.setUserId(registeredUser.getUserId());
348 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
352 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
354 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
356 // event should not be null
359 throw new NullPointerException("event is null"); //NOI18N
360 } else if (event.getConfirmedUser() == null) {
362 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
363 } else if (event.getConfirmedUser().getUserId() == null) {
365 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
366 } else if (event.getConfirmedUser().getUserId() < 1) {
368 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
372 this.updateList(event.getConfirmedUser());
376 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
378 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
380 // event should not be null
383 throw new NullPointerException("event is null"); //NOI18N
384 } else if (event.getLoggedInUser() == null) {
386 throw new NullPointerException("event.registeredUser is null"); //NOI18N
387 } else if (event.getLoggedInUser().getUserId() == null) {
389 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
390 } else if (event.getLoggedInUser().getUserId() < 1) {
392 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
395 // "Cache" user instance
396 User loggedInUser = event.getLoggedInUser();
398 // Copy all data to this bean
399 this.copyUser(loggedInUser);
401 // Is the user visible?
402 if (Objects.equals(loggedInUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
403 // Yes, then add user
404 this.visibleUserList.add(loggedInUser);
409 public void afterUserUpdatedPasswordEvent (@Observes final UpdatedUserPasswordEvent event) {
413 throw new NullPointerException("event is null"); //NOI18N
414 } else if (event.getPasswordHistory() == null) {
416 throw new NullPointerException("event.passwordHistory is null"); //NOI18N
417 } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
419 throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
420 } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
422 throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
426 this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
430 public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
434 throw new NullPointerException("event is null"); //NOI18N
435 } else if (event.getUpdatedUser() == null) {
437 throw new NullPointerException("event.updatedUser is null"); //NOI18N
438 } else if (event.getUpdatedUser().getUserId() == null) {
440 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
441 } else if (event.getUpdatedUser().getUserId() < 1) {
443 throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
447 this.updateList(event.getUpdatedUser());
451 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
452 public List<User> allUsers () {
454 return this.userList;
458 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
459 public List<User> allVisibleUsers () {
461 return this.visibleUserList;
465 public User createUserInstance (final boolean createContactData) {
467 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: CALLED!", this.getClass().getSimpleName()));
469 // Required personal data must be set
470 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
472 // Create new user instance
473 User user = new LoginUser();
475 // Is user name required?
476 if (!this.isUserNameRequired()) {
477 // Generate pseudo-random user name
478 String randomName = this.userBean.generateRandomUserName();
480 // Set it and inivisible profile
481 this.setUserName(randomName);
482 this.setUserProfileMode(ProfileMode.INVISIBLE);
484 // Generate random password
485 String randomPassword = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
487 // Set random password
488 this.setUserPassword(randomPassword);
489 this.setUserPasswordRepeat(randomPassword);
492 // Set local, user name and mode
493 user.setUserLocale(this.localizationController.getLocale());
494 user.setUserName(this.getUserName());
495 user.setUserProfileMode(this.getUserProfileMode());
497 // Is multiple registration page
498 if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N
499 // Create contact instance
500 Contact contact = this.contactController.createContactInstance();
503 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact));
505 // Set contact in user
506 user.setUserContact(contact);
510 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: user={1} - EXIT!", this.getClass().getSimpleName(), user));
517 public User createUserLogin () {
519 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: CALLED!", this.getClass().getSimpleName()));
522 if (this.getUserName() == null) {
524 throw new NullPointerException("recruiterName is null"); //NOI18N
525 } else if (this.getUserName().isEmpty()) {
527 throw new IllegalStateException("recruiterName is empty."); //NOI18N
530 // Create new recruiter instance
531 User recruiter = new LoginUser();
533 // Update all data ...
534 recruiter.setUserName(this.getUserName());
537 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: recruiter={1} - EXIT!", this.getClass().getSimpleName(), recruiter));
539 // Return the new instance
544 public String doChangePersonalData () {
545 // This method shall only be called if the user is logged-in
546 if (!this.userLoginController.isUserLoggedIn()) {
548 throw new IllegalStateException("User is not logged-in"); //NOI18N
549 } else if (!this.isRequiredChangePersonalDataSet()) {
550 // Not all required fields are set
551 throw new FaceletException("Not all required fields are set."); //NOI18N
552 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
553 // Password not matching
554 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
555 } else if (!this.featureController.isFeatureEnabled("edit_user_data")) {
556 // Editing is not allowed
557 throw new IllegalStateException("User tried to edit personal data."); //NOI18N
561 User user = this.userLoginController.getLoggedInUser();
563 // Copy contact data to contact instance
564 this.contactController.updateContactDataFromController(user.getUserContact());
566 // It should be there, so run some tests on it
567 assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N
568 assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N
569 assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
570 assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
571 assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
572 assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
575 user.setUserProfileMode(this.getUserProfileMode());
577 // Send it to the EJB
578 User updatedUser = this.userBean.updateUserPersonalData(user);
581 this.updatedPersonalDataEvent.fire(new UserUpdatedPersonalDataEvent(updatedUser));
584 return "contact_data_saved"; //NOI18N
588 public Long getUserId () {
593 public void setUserId (final Long userId) {
594 this.userId = userId;
598 public String getUserName () {
599 return this.userName;
603 public void setUserName (final String userName) {
604 this.userName = userName;
608 public String getUserPassword () {
609 return this.userPassword;
613 public void setUserPassword (final String userPassword) {
614 this.userPassword = userPassword;
618 public String getUserPasswordRepeat () {
619 return this.userPasswordRepeat;
623 public void setUserPasswordRepeat (final String userPasswordRepeat) {
624 this.userPasswordRepeat = userPasswordRepeat;
628 public ProfileMode getUserProfileMode () {
629 return this.userProfileMode;
633 public void setUserProfileMode (final ProfileMode userProfileMode) {
634 this.userProfileMode = userProfileMode;
638 * Post-initialization of this class
641 public void init () {
642 // Initialize user list
643 this.userList = this.userBean.allUsers();
645 // Get full user name list for reducing EJB calls
646 this.userNameList = this.userBean.getUserNameList();
648 // Is the user logged-in?
649 if (this.userLoginController.isUserLoggedIn()) {
650 // Is logged-in, so load also users visible to memebers
651 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
653 // Initialize user list
654 this.visibleUserList = this.userBean.allPublicUsers();
659 public boolean isContactFound (final Contact contact) {
660 // The contact must be valid
661 if (null == contact) {
663 throw new NullPointerException("contact is null"); //NOI18N
664 } else if (contact.getContactId() == null) {
666 throw new NullPointerException("contact.contactId is null"); //NOI18N
667 } else if (contact.getContactId() < 1) {
669 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
672 // Default is not found
673 boolean isFound = false;
676 Iterator<User> iterator = this.allUsers().iterator();
678 // Loop through all entries
679 while (iterator.hasNext()) {
681 User next = iterator.next();
683 // Compare both objects
684 if (Objects.equals(contact, next.getUserContact())) {
696 public boolean isPublicUserProfileEnabled () {
697 // Get context parameter
698 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N
701 boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
703 // This requires user names being enabled, too.
704 if ((isEnabled) && (!this.isUserNameRequired())) {
705 // Not valid state, users must be able to modify their profile, especially when it is public
706 throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
714 public boolean isRequiredChangePersonalDataSet () {
715 return ((this.getUserProfileMode() != null) &&
716 (this.getUserName() != null) && (!this.getUserName().isEmpty()) &&
717 (this.contactController.isRequiredChangePersonalDataSet()));
721 public boolean isRequiredPersonalDataSet () {
722 if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
723 // Multiple registration page
724 return this.contactController.isRequiredPersonalDataSet();
726 // Single registration page
727 return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
728 (this.getUserProfileMode() != null) &&
729 (this.contactController.isRequiredPersonalDataSet()) &&
730 (this.getUserPassword() != null) &&
731 (this.getUserPasswordRepeat() != null));
736 public boolean isSamePasswordEntered () {
737 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
741 public boolean isUserIdEmpty () {
742 return ((this.getUserId() == null) || (this.getUserId() == 0));
746 public boolean isUserNameRegistered (final User user) {
747 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
751 public boolean isUserNameRequired () {
752 // Get context parameter
753 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N
756 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
763 public boolean isVisibleUserFound () {
764 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
768 public User lookupUserById (final Long userId) throws UserNotFoundException {
769 // Parameter must be valid
770 if (null == userId) {
772 throw new NullPointerException("userId is null"); //NOI18N
773 } else if (userId < 1) {
775 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
781 // Try to lookup it in visible user list
782 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
784 User next = iterator.next();
786 // Is the user id found?
787 if (Objects.equals(next.getUserId(), userId)) {
788 // Copy to other variable
796 // Not visible for the current user
797 throw new UserNotFoundException(userId);
805 public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
806 // Parameter must be valid
807 if (null == emailAddress) {
809 throw new NullPointerException("emailAddress is null"); //NOI18N
810 } else if (emailAddress.isEmpty()) {
812 throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
818 // Try to lookup it in visible user list
819 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
821 User next = iterator.next();
823 // Contact should be set
824 if (next.getUserContact() == null) {
826 throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
827 } else if (next.getUserContact().getContactEmailAddress() == null) {
828 // Email address should be set
829 throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N //NOI18N
832 // Is the email address found?
833 if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) {
834 // Copy to other variable
842 // Not visible for the current user
843 throw new UserEmailAddressNotFoundException(emailAddress);
851 * Adds user's name to bean's internal list. It also updates the public user
852 * list if the user has decided to have a public account,
854 * @param user User instance
856 private void addUserName (final User user) {
857 // Make sure the entry is not added yet
858 if (this.userNameList.contains(user.getUserName())) {
860 throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
861 } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
863 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
867 this.userNameList.add(user.getUserName());
873 private void clear () {
876 this.setUserId(null);
877 this.setUserProfileMode(null);
880 this.setUserName(null);
881 this.setUserPassword(null);
882 this.setUserPasswordRepeat(null);
886 * Copies given user into the controller
888 * @param user User instance
890 private void copyUser (final User user) {
891 // Make sure the instance is valid
894 throw new NullPointerException("user is null"); //NOI18N
895 } else if (user.getUserContact() == null) {
897 throw new NullPointerException("user.userContact is null"); //NOI18N
902 this.setUserId(user.getUserId());
903 this.setUserProfileMode(user.getUserProfileMode());
907 * Updates list with given user instance
909 * @param user User instance
911 private void updateList (final User user) {
912 // The user should be valid
915 throw new NullPointerException("user is null"); //NOI18N
916 } else if (user.getUserId() == null) {
918 throw new NullPointerException("user.userId is null"); //NOI18N
919 } else if (user.getUserId() < 1) {
921 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
922 } else if (user.getUserContact() == null) {
924 throw new NullPointerException("user.userContact is null"); //NOI18N
925 } else if (user.getUserContact().getContactId() == null) {
927 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
928 } else if (user.getUserContact().getContactId() < 1) {
930 throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N
933 // Get iterator from list
934 Iterator<User> iterator = this.userList.iterator();
936 // "Walk" through all entries
937 while (iterator.hasNext()) {
939 User next = iterator.next();
941 // Is user id number the same?
942 if (Objects.equals(user.getUserId(), next.getUserId())) {
943 // Found entry, so remove it and abort
944 this.userList.remove(next);
950 this.userList.add(user);