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.pizzaapplication.beans.user;
19 import java.text.MessageFormat;
20 import java.util.Collections;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Objects;
24 import javax.annotation.PostConstruct;
25 import javax.enterprise.context.SessionScoped;
26 import javax.enterprise.event.Event;
27 import javax.enterprise.event.Observes;
28 import javax.enterprise.inject.Any;
29 import javax.faces.context.FacesContext;
30 import javax.faces.view.facelets.FaceletException;
31 import javax.inject.Inject;
32 import javax.inject.Named;
33 import javax.naming.Context;
34 import javax.naming.InitialContext;
35 import javax.naming.NamingException;
36 import org.mxchange.jcontacts.contact.Contact;
37 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
38 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
39 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
40 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
41 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
42 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
43 import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
44 import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
45 import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent;
46 import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
47 import org.mxchange.jusercore.exceptions.UserNotFoundException;
48 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
49 import org.mxchange.jusercore.model.user.LoginUser;
50 import org.mxchange.jusercore.model.user.User;
51 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
52 import org.mxchange.jusercore.model.user.UserUtils;
53 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
54 import org.mxchange.pizzaapplication.beans.BasePizzaController;
55 import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
56 import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
57 import org.mxchange.pizzaapplication.beans.register.PizzaUserRegisterWebSessionController;
60 * A user bean (controller)
62 * @author Roland Haeder<roland@mxchange.org>
64 @Named ("userController")
66 public class PizzaUserWebSessionBean extends BasePizzaController implements PizzaUserWebSessionController {
71 private static final long serialVersionUID = 542_145_347_916L;
76 private ContactSessionBeanRemote contactBean;
79 * General contact controller
82 private PizzaContactWebSessionController contactController;
85 * Login bean (controller)
88 private PizzaUserLoginWebSessionController loginController;
91 * Registration controller
94 private PizzaUserRegisterWebSessionController
98 * A list of all selectable contacts
100 private List<Contact> selectableContacts;
103 * Event being fired when user updated personal data
107 private Event<UpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
112 private final UserSessionBeanRemote userBean;
120 * A list of all user profiles
122 private List<User> userList;
125 * Login bean (controller)
128 private PizzaUserLoginWebSessionController userLoginController;
133 private String userName;
138 private List<String> userNameList;
141 * User password (unencrypted from web form)
143 private String userPassword;
146 * User password repeated (unencrypted from web form)
148 private String userPasswordRepeat;
151 * Whether the user wants a public profile
153 private ProfileMode userProfileMode;
156 * A list of all public user profiles
158 private List<User> visibleUserList;
161 * Default constructor
163 public PizzaUserWebSessionBean () {
166 // Get initial context
167 Context context = new InitialContext();
170 this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
173 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
174 } catch (final NamingException e) {
176 throw new FaceletException(e);
181 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
182 // The event must be valid
185 throw new NullPointerException("event is null"); //NOI18N
186 } else if (event.getAddedContact() == null) {
188 throw new NullPointerException("event.addedContact is null"); //NOI18N
189 } else if (event.getAddedContact().getContactId() == null) {
191 throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
192 } else if (event.getAddedContact().getContactId() < 1) {
194 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
198 this.selectableContacts.add(event.getAddedContact());
202 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
204 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
206 // event should not be null
209 throw new NullPointerException("event is null"); //NOI18N
210 } else if (event.getAddedUser() == null) {
212 throw new NullPointerException("event.addedUser is null"); //NOI18N
213 } else if (event.getAddedUser().getUserId() == null) {
215 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
216 } else if (event.getAddedUser().getUserId() < 1) {
218 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
221 // Add user to local list
222 this.userList.add(event.getAddedUser());
228 this.setUserId(event.getAddedUser().getUserId());
231 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
235 public void afterAdminUpdatedUserDataEvent (@Observes final AdminUpdatedUserDataEvent event) {
237 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N
239 // event should not be null
242 throw new NullPointerException("event is null"); //NOI18N
243 } else if (event.getUpdatedUser() == null) {
245 throw new NullPointerException("event.updatedUser is null"); //NOI18N
246 } else if (event.getUpdatedUser().getUserId() == null) {
248 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
249 } else if (event.getUpdatedUser().getUserId() < 1) {
251 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
255 this.updateList(event.getUpdatedUser());
261 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
265 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
267 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
269 // event should not be null
272 throw new NullPointerException("event is null"); //NOI18N
273 } else if (event.getRegisteredUser() == null) {
275 throw new NullPointerException("event.registeredUser is null"); //NOI18N
276 } else if (event.getRegisteredUser().getUserId() == null) {
278 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
279 } else if (event.getRegisteredUser().getUserId() < 1) {
281 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
285 User registeredUser = event.getRegisteredUser();
288 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
290 // Copy all data from registered->user
291 this.copyUser(registeredUser);
296 // Add user to local list
297 this.userList.add(registeredUser);
300 this.addUserName(registeredUser);
302 // Is the account public?
303 if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
304 // Also add it to this list
305 this.visibleUserList.add(registeredUser);
309 this.setUserId(registeredUser.getUserId());
312 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
316 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
318 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
320 // event should not be null
323 throw new NullPointerException("event is null"); //NOI18N
324 } else if (event.getConfirmedUser() == null) {
326 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
327 } else if (event.getConfirmedUser().getUserId() == null) {
329 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
330 } else if (event.getConfirmedUser().getUserId() < 1) {
332 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
335 // Get iterator from list
336 Iterator<User> iterator = this.userList.iterator();
338 // "Walk" through all entries
339 while (iterator.hasNext()) {
341 User next = iterator.next();
343 // Is id number the same?
344 if (Objects.equals(event.getConfirmedUser().getUserId(), next.getUserId())) {
345 // Found entry, so remove it and abort
346 this.userList.remove(next);
351 // Add contact to list
352 this.userList.add(event.getConfirmedUser());
356 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
358 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
360 // event should not be null
363 throw new NullPointerException("event is null"); //NOI18N
364 } else if (event.getLoggedInUser() == null) {
366 throw new NullPointerException("event.registeredUser is null"); //NOI18N
367 } else if (event.getLoggedInUser().getUserId() == null) {
369 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
370 } else if (event.getLoggedInUser().getUserId() < 1) {
372 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
375 // Copy all data to this bean
376 this.copyUser(event.getLoggedInUser());
378 // Re-initialize list
379 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
382 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
386 public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
390 throw new NullPointerException("event is null"); //NOI18N
391 } else if (event.getUpdatedUser() == null) {
393 throw new NullPointerException("event.updatedUser is null"); //NOI18N
394 } else if (event.getUpdatedUser().getUserId() == null) {
396 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
397 } else if (event.getUpdatedUser().getUserId() < 1) {
399 throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
402 // All fine, so update list
403 this.updateList(event.getUpdatedUser());
407 public List<User> allUsers () {
409 return Collections.unmodifiableList(this.userList);
413 public List<User> allVisibleUsers () {
415 return Collections.unmodifiableList(this.visibleUserList);
419 public User createUserInstance () {
421 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: CALLED!", this.getClass().getSimpleName()));
423 // Required personal data must be set
424 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
426 // Create new user instance
427 User user = new LoginUser();
429 // Is user name required?
430 if (!this.isUserNameRequired()) {
431 // Generate pseudo-random user name
432 String randomName = this.userBean.generateRandomUserName();
434 // Set it and inivisible profile
435 this.setUserName(randomName);
436 this.setUserProfileMode(ProfileMode.INVISIBLE);
438 // Generate random password
439 String randomPassword = UserUtils.createRandomPassword(PizzaUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
441 // Set random password
442 this.setUserPassword(randomPassword);
443 this.setUserPasswordRepeat(randomPassword);
446 // Set user name and mode
447 user.setUserName(this.getUserName());
448 user.setUserProfileMode(this.getUserProfileMode());
450 // Is multiple registration page
451 if (!this.registerController.isMultiplePageEnabled()) {
452 // Create contact instance
453 Contact contact = this.contactController.createContactInstance();
456 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact));
458 // Set contact in user
459 user.setUserContact(contact);
463 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: user={1} - EXIT!", this.getClass().getSimpleName(), user));
470 public User createUserLogin () {
472 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: CALLED!", this.getClass().getSimpleName()));
475 if (this.getUserName() == null) {
477 throw new NullPointerException("recruiterName is null"); //NOI18N
478 } else if (this.getUserName().isEmpty()) {
480 throw new IllegalStateException("recruiterName is empty."); //NOI18N
483 // Create new recruiter instance
484 User recruiter = new LoginUser();
486 // Update all data ...
487 recruiter.setUserName(this.getUserName());
490 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: recruiter={1} - EXIT!", this.getClass().getSimpleName(), recruiter));
492 // Return the new instance
497 public String doChangePersonalData () {
498 // This method shall only be called if the user is logged-in
499 if (!this.loginController.isUserLoggedIn()) {
501 throw new IllegalStateException("User is not logged-in"); //NOI18N
502 } else if (!this.isRequiredChangePersonalDataSet()) {
503 // Not all required fields are set
504 throw new FaceletException("Not all required fields are set."); //NOI18N
505 } else if (!this.loginController.ifCurrentPasswordMatches()) {
506 // Password not matching
507 throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
511 User user = this.loginController.getLoggedInUser();
513 // Copy contact data to contact instance
514 this.contactController.updateContactDataFromController(user.getUserContact());
516 // It should be there, so run some tests on it
517 assert (user instanceof User) : "Instance loginController.loggedInUser is null"; //NOI18N
518 assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null"; //NOI18N
519 assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
520 assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N
521 assert (user.getUserContact().getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N
522 assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
525 user.setUserProfileMode(this.getUserProfileMode());
527 // Send it to the EJB
528 User updatedUser = this.userBean.updateUserPersonalData(user);
531 this.updatedPersonalDataEvent.fire(new UserUpdatedPersonalDataEvent(updatedUser));
534 return "user_data_saved"; //NOI18N
538 public Long getUserId () {
543 public void setUserId (final Long userId) {
544 this.userId = userId;
548 public String getUserName () {
549 return this.userName;
553 public void setUserName (final String userName) {
554 this.userName = userName;
558 public String getUserPassword () {
559 return this.userPassword;
563 public void setUserPassword (final String userPassword) {
564 this.userPassword = userPassword;
568 public String getUserPasswordRepeat () {
569 return this.userPasswordRepeat;
573 public void setUserPasswordRepeat (final String userPasswordRepeat) {
574 this.userPasswordRepeat = userPasswordRepeat;
578 public ProfileMode getUserProfileMode () {
579 return this.userProfileMode;
583 public void setUserProfileMode (final ProfileMode userProfileMode) {
584 this.userProfileMode = userProfileMode;
588 public boolean hasUsers () {
589 return (!this.allUsers().isEmpty());
593 * Post-initialization of this class
596 public void init () {
597 // Initialize user list
598 this.userList = this.userBean.allUsers();
600 // Get full user name list for reducing EJB calls
601 this.userNameList = this.userBean.getUserNameList();
603 // Is the user logged-in?
604 if (this.userLoginController.isUserLoggedIn()) {
605 // Is logged-in, so load also users visible to memebers
606 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
608 // Initialize user list
609 this.visibleUserList = this.userBean.allPublicUsers();
613 List<User> allUsers = this.allUsers();
616 List<Contact> allContacts = this.contactBean.getAllContacts();
619 Iterator<Contact> iterator = allContacts.iterator();
622 while (iterator.hasNext()) {
624 Contact next = iterator.next();
627 Iterator<User> userIterator = allUsers.iterator();
629 // Loop through all users
630 while (userIterator.hasNext()) {
632 User nextUser = userIterator.next();
635 if (Objects.equals(next, nextUser.getUserContact())) {
644 this.selectableContacts = allContacts;
648 public boolean isContactFound (final Contact contact) {
649 // The contact must be valid
650 if (null == contact) {
652 throw new NullPointerException("contact is null"); //NOI18N
653 } else if (contact.getContactId() == null) {
655 throw new NullPointerException("contact.contactId is null"); //NOI18N
656 } else if (contact.getContactId() < 1) {
658 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
661 // Default is not found
662 boolean isFound = false;
665 Iterator<User> iterator = this.allUsers().iterator();
667 // Loop through all entries
668 while (iterator.hasNext()) {
670 User next = iterator.next();
672 // Compare both objects
673 if (Objects.equals(contact, next.getUserContact())) {
685 public boolean isPublicUserProfileEnabled () {
686 // Get context parameter
687 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N
690 boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
692 // This requires user names being enabled, too.
693 if ((isEnabled) && (!this.isUserNameRequired())) {
694 // Not valid state, users must be able to modify their profile, especially when it is public
695 throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
703 public boolean isRequiredChangePersonalDataSet () {
704 return ((this.getUserProfileMode() != null) &&
705 (this.getUserName() != null) && (!this.getUserName().isEmpty()) &&
706 (this.contactController.isRequiredChangePersonalDataSet()));
710 public boolean isRequiredPersonalDataSet () {
711 if (this.registerController.isMultiplePageEnabled()) {
712 // Multiple registration page
713 return this.contactController.isRequiredPersonalDataSet();
715 // Single registration page
716 return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
717 (this.getUserProfileMode() != null) &&
718 (this.contactController.isRequiredPersonalDataSet()) &&
719 (this.getUserPassword() != null) &&
720 (this.getUserPasswordRepeat() != null));
725 public boolean isSamePasswordEntered () {
726 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
730 public boolean isUserIdEmpty () {
731 return ((this.getUserId() == null) || (this.getUserId() == 0));
735 public boolean isUserNameRegistered (final User user) {
736 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
740 public boolean isUserNameRequired () {
741 // Get context parameter
742 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N
745 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
752 public boolean isVisibleUserFound () {
753 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
757 public User lookupUserById (final Long userId) throws UserNotFoundException {
758 // Parameter must be valid
759 if (null == userId) {
761 throw new NullPointerException("userId is null"); //NOI18N
762 } else if (userId < 1) {
764 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
770 // Try to lookup it in visible user list
771 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
773 User next = iterator.next();
775 // Is the user id found?
776 if (Objects.equals(next.getUserId(), userId)) {
777 // Copy to other variable
785 // Not visible for the current user
786 throw new UserNotFoundException(userId);
794 public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
795 // Parameter must be valid
796 if (null == emailAddress) {
798 throw new NullPointerException("emailAddress is null"); //NOI18N
799 } else if (emailAddress.isEmpty()) {
801 throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
807 // Try to lookup it in visible user list
808 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
810 User next = iterator.next();
812 // Contact should be set
813 if (next.getUserContact() == null) {
815 throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
816 } else if (next.getUserContact().getContactEmailAddress() == null) {
817 // Email address should be set
818 throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N //NOI18N
821 // Is the email address found?
822 if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) {
823 // Copy to other variable
831 // Not visible for the current user
832 throw new UserEmailAddressNotFoundException(emailAddress);
840 public List<Contact> selectableContacts () {
841 return Collections.unmodifiableList(this.selectableContacts);
845 * Adds user's name to bean's internal list. It also updates the public user
846 * list if the user has decided to have a public account,
848 * @param user User instance
850 private void addUserName (final User user) {
851 // Make sure the entry is not added yet
852 if (this.userNameList.contains(user.getUserName())) {
854 throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
855 } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
857 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
861 this.userNameList.add(user.getUserName());
867 private void clear () {
870 this.setUserId(null);
871 this.setUserProfileMode(null);
874 this.setUserName(null);
875 this.setUserPassword(null);
876 this.setUserPasswordRepeat(null);
880 * Copies given user into the controller
882 * @param user User instance
884 private void copyUser (final User user) {
885 // Make sure the instance is valid
888 throw new NullPointerException("user is null"); //NOI18N
889 } else if (user.getUserContact() == null) {
891 throw new NullPointerException("user.userContact is null"); //NOI18N
896 this.setUserId(user.getUserId());
897 this.setUserProfileMode(user.getUserProfileMode());
901 * Updates list with given user instance
903 * @param user User instance
905 private void updateList (final User user) {
906 // The user should be valid
909 throw new NullPointerException("user is null"); //NOI18N
910 } else if (user.getUserId() == null) {
912 throw new NullPointerException("user.userId is null"); //NOI18N
913 } else if (user.getUserId() < 1) {
915 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
919 Iterator<User> iterator = this.userList.iterator();
922 while (iterator.hasNext()) {
924 User next = iterator.next();
926 // Is the same user id?
927 if (Objects.equals(user.getUserId(), next.getUserId())) {
928 // Found it, so remove it
929 this.userList.remove(next);
935 this.userList.add(user);