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.addressbook.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.addressbook.beans.BaseAddressbookController;
37 import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
38 import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
39 import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
40 import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
41 import org.mxchange.jcontacts.contact.Contact;
42 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
43 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
44 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
45 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
46 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
47 import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
48 import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
49 import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent;
50 import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
51 import org.mxchange.jusercore.exceptions.UserNotFoundException;
52 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
53 import org.mxchange.jusercore.model.user.LoginUser;
54 import org.mxchange.jusercore.model.user.User;
55 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
56 import org.mxchange.jusercore.model.user.UserUtils;
57 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
60 * A user bean (controller)
62 * @author Roland Haeder<roland@mxchange.org>
64 @Named ("userController")
66 public class AddressbookUserWebSessionBean extends BaseAddressbookController implements AddressbookUserWebSessionController {
71 private static final long serialVersionUID = 542_145_347_916L;
76 private ContactSessionBeanRemote contactBean;
79 * General contact controller
82 private AddressbookContactWebSessionController contactController;
88 private AddressbookFeaturesWebApplicationController featureController;
91 * Localization controller
94 private AddressbookLocalizationSessionController localizationController;
97 * Event being fired when user updated personal data
101 private Event<UpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
106 private final UserSessionBeanRemote userBean;
114 * A list of all user profiles
116 private List<User> userList;
119 * Login bean (controller)
122 private AddressbookUserLoginWebSessionController userLoginController;
127 private String userName;
132 private List<String> userNameList;
135 * User password (unencrypted from web form)
137 private String userPassword;
140 * User password repeated (unencrypted from web form)
142 private String userPasswordRepeat;
145 * Whether the user wants a public profile
147 private ProfileMode userProfileMode;
150 * A list of all public user profiles
152 private List<User> visibleUserList;
155 * Default constructor
157 public AddressbookUserWebSessionBean () {
160 // Get initial context
161 Context context = new InitialContext();
164 this.userBean = (UserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
167 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
168 } catch (final NamingException e) {
170 throw new FaceletException(e);
175 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
177 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
179 // event should not be null
182 throw new NullPointerException("event is null"); //NOI18N
183 } else if (event.getAddedUser() == null) {
185 throw new NullPointerException("event.addedUser is null"); //NOI18N
186 } else if (event.getAddedUser().getUserId() == null) {
188 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
189 } else if (event.getAddedUser().getUserId() < 1) {
191 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
195 this.uniqueAddUser(event.getAddedUser());
201 this.setUserId(event.getAddedUser().getUserId());
204 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
208 public void afterAdminUpdatedUserDataEvent (@Observes final AdminUpdatedUserDataEvent event) {
210 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N
212 // event should not be null
215 throw new NullPointerException("event is null"); //NOI18N
216 } else if (event.getUpdatedUser() == null) {
218 throw new NullPointerException("event.updatedUser is null"); //NOI18N
219 } else if (event.getUpdatedUser().getUserId() == null) {
221 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
222 } else if (event.getUpdatedUser().getUserId() < 1) {
224 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
228 this.updateList(event.getUpdatedUser());
234 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
238 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
240 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
242 // event should not be null
245 throw new NullPointerException("event is null"); //NOI18N
246 } else if (event.getRegisteredUser() == null) {
248 throw new NullPointerException("event.registeredUser is null"); //NOI18N
249 } else if (event.getRegisteredUser().getUserId() == null) {
251 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
252 } else if (event.getRegisteredUser().getUserId() < 1) {
254 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
258 User registeredUser = event.getRegisteredUser();
261 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
263 // Copy all data from registered->user
264 this.copyUser(registeredUser);
270 this.uniqueAddUser(registeredUser);
273 this.addUserName(registeredUser);
275 // Is the account public?
276 if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
277 // Also add it to this list
278 this.visibleUserList.add(registeredUser);
282 this.setUserId(registeredUser.getUserId());
285 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
289 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
291 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
293 // event should not be null
296 throw new NullPointerException("event is null"); //NOI18N
297 } else if (event.getConfirmedUser() == null) {
299 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
300 } else if (event.getConfirmedUser().getUserId() == null) {
302 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
303 } else if (event.getConfirmedUser().getUserId() < 1) {
305 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
309 this.uniqueAddUser(event.getConfirmedUser());
313 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
315 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
317 // event should not be null
320 throw new NullPointerException("event is null"); //NOI18N
321 } else if (event.getLoggedInUser() == null) {
323 throw new NullPointerException("event.registeredUser is null"); //NOI18N
324 } else if (event.getLoggedInUser().getUserId() == null) {
326 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
327 } else if (event.getLoggedInUser().getUserId() < 1) {
329 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
332 // Copy all data to this bean
333 this.copyUser(event.getLoggedInUser());
335 // Re-initialize list
336 // @TODO This calls the EJB again, after a user logs in which can cause lots of calls on it.
337 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
343 public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
347 throw new NullPointerException("event is null"); //NOI18N
348 } else if (event.getUpdatedUser() == null) {
350 throw new NullPointerException("event.updatedUser is null"); //NOI18N
351 } else if (event.getUpdatedUser().getUserId() == null) {
353 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
354 } else if (event.getUpdatedUser().getUserId() < 1) {
356 throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
359 // All fine, so update list
360 this.updateList(event.getUpdatedUser());
364 public List<User> allUsers () {
366 return Collections.unmodifiableList(this.userList);
370 public List<User> allVisibleUsers () {
372 return Collections.unmodifiableList(this.visibleUserList);
376 public User createUserInstance (final boolean createContactData) {
378 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: CALLED!", this.getClass().getSimpleName()));
380 // Required personal data must be set
381 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
383 // Create new user instance
384 User user = new LoginUser();
386 // Is user name required?
387 if (!this.isUserNameRequired()) {
388 // Generate pseudo-random user name
389 String randomName = this.userBean.generateRandomUserName();
391 // Set it and inivisible profile
392 this.setUserName(randomName);
393 this.setUserProfileMode(ProfileMode.INVISIBLE);
395 // Generate random password
396 String randomPassword = UserUtils.createRandomPassword(AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
398 // Set random password
399 this.setUserPassword(randomPassword);
400 this.setUserPasswordRepeat(randomPassword);
403 // Set local, user name and mode
404 user.setUserLocale(this.localizationController.getLocale());
405 user.setUserName(this.getUserName());
406 user.setUserProfileMode(this.getUserProfileMode());
408 // Is multiple registration page
409 if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N
410 // Create contact instance
411 Contact contact = this.contactController.createContactInstance();
414 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact));
416 // Set contact in user
417 user.setUserContact(contact);
421 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: user={1} - EXIT!", this.getClass().getSimpleName(), user));
428 public User createUserLogin () {
430 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: CALLED!", this.getClass().getSimpleName()));
433 if (this.getUserName() == null) {
435 throw new NullPointerException("recruiterName is null"); //NOI18N
436 } else if (this.getUserName().isEmpty()) {
438 throw new IllegalStateException("recruiterName is empty."); //NOI18N
441 // Create new recruiter instance
442 User recruiter = new LoginUser();
444 // Update all data ...
445 recruiter.setUserName(this.getUserName());
448 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: recruiter={1} - EXIT!", this.getClass().getSimpleName(), recruiter));
450 // Return the new instance
455 public String doChangePersonalData () {
456 // This method shall only be called if the user is logged-in
457 if (!this.userLoginController.isUserLoggedIn()) {
459 throw new IllegalStateException("User is not logged-in"); //NOI18N
460 } else if (!this.isRequiredChangePersonalDataSet()) {
461 // Not all required fields are set
462 throw new FaceletException("Not all required fields are set."); //NOI18N
463 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
464 // Password not matching
465 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
466 } else if (!this.featureController.isFeatureEnabled("edit_user_data")) {
467 // Editing is not allowed
468 throw new IllegalStateException("User tried to edit personal data"); //NOI18N
472 User user = this.userLoginController.getLoggedInUser();
474 // Copy contact data to contact instance
475 this.contactController.updateContactDataFromController(user.getUserContact());
477 // It should be there, so run some tests on it
478 assert (user instanceof User) : "Instance loginController.loggedInUser is null";
479 assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null";
480 assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId());
481 assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null";
482 assert (user.getUserContact().getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null";
483 assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId());
486 user.setUserProfileMode(this.getUserProfileMode());
488 // Send it to the EJB
489 User updatedUser = this.userBean.updateUserPersonalData(user);
492 this.updatedPersonalDataEvent.fire(new UserUpdatedPersonalDataEvent(updatedUser));
495 return "user_data_saved"; //NOI18N
499 public Long getUserId () {
504 public void setUserId (final Long userId) {
505 this.userId = userId;
509 public String getUserName () {
510 return this.userName;
514 public void setUserName (final String userName) {
515 this.userName = userName;
519 public String getUserPassword () {
520 return this.userPassword;
524 public void setUserPassword (final String userPassword) {
525 this.userPassword = userPassword;
529 public String getUserPasswordRepeat () {
530 return this.userPasswordRepeat;
534 public void setUserPasswordRepeat (final String userPasswordRepeat) {
535 this.userPasswordRepeat = userPasswordRepeat;
539 public ProfileMode getUserProfileMode () {
540 return this.userProfileMode;
544 public void setUserProfileMode (final ProfileMode userProfileMode) {
545 this.userProfileMode = userProfileMode;
549 public boolean hasUsers () {
550 return (!this.allUsers().isEmpty());
554 * Post-initialization of this class
557 public void init () {
558 // Initialize user list
559 this.userList = this.userBean.allUsers();
561 // Get full user name list for reducing EJB calls
562 this.userNameList = this.userBean.getUserNameList();
564 // Is the user logged-in?
565 if (this.userLoginController.isUserLoggedIn()) {
566 // Is logged-in, so load also users visible to memebers
567 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
569 // Initialize user list
570 this.visibleUserList = this.userBean.allPublicUsers();
575 public boolean isContactFound (final Contact contact) {
576 // The contact must be valid
577 if (null == contact) {
579 throw new NullPointerException("contact is null"); //NOI18N
580 } else if (contact.getContactId() == null) {
582 throw new NullPointerException("contact.contactId is null"); //NOI18N
583 } else if (contact.getContactId() < 1) {
585 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
588 // Default is not found
589 boolean isFound = false;
592 Iterator<User> iterator = this.allUsers().iterator();
594 // Loop through all entries
595 while (iterator.hasNext()) {
597 User next = iterator.next();
599 // Compare both objects
600 if (Objects.equals(contact, next.getUserContact())) {
612 public boolean isPublicUserProfileEnabled () {
613 // Get context parameter
614 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N
617 boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
619 // This requires user names being enabled, too.
620 if ((isEnabled) && (!this.isUserNameRequired())) {
621 // Not valid state, users must be able to modify their profile, especially when it is public
622 throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
630 public boolean isRequiredChangePersonalDataSet () {
631 return ((this.getUserProfileMode() != null) &&
632 (this.getUserName() != null) && (!this.getUserName().isEmpty()) &&
633 (this.contactController.isRequiredChangePersonalDataSet()));
637 public boolean isRequiredPersonalDataSet () {
638 if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
639 // Multiple registration page
640 return this.contactController.isRequiredPersonalDataSet();
642 // Single registration page
643 return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
644 (this.getUserProfileMode() != null) &&
645 (this.contactController.isRequiredPersonalDataSet()) &&
646 (this.getUserPassword() != null) &&
647 (this.getUserPasswordRepeat() != null));
652 public boolean isSamePasswordEntered () {
653 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
657 public boolean isUserIdEmpty () {
658 return ((this.getUserId() == null) || (this.getUserId() == 0));
662 public boolean isUserNameRegistered (final User user) {
663 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
667 public boolean isUserNameRequired () {
668 // Get context parameter
669 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N
672 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
679 public boolean isVisibleUserFound () {
680 return ((this.visibleUserList instanceof List) && (!this.visibleUserList.isEmpty()));
684 public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
685 // Parameter must be valid
686 if (null == emailAddress) {
688 throw new NullPointerException("emailAddress is null"); //NOI18N
689 } else if (emailAddress.isEmpty()) {
691 throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
697 // Try to lookup it in visible user list
698 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
700 User next = iterator.next();
702 // Contact should be set
703 if (next.getUserContact() == null) {
705 throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
706 } else if (next.getUserContact().getContactEmailAddress() == null) {
707 // Email address should be set
708 throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N //NOI18N
711 // Is the email address found?
712 if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) {
713 // Copy to other variable
721 // Not visible for the current user
722 throw new UserEmailAddressNotFoundException(emailAddress);
730 public User lookupUserById (final Long userId) throws UserNotFoundException {
731 // Parameter must be valid
732 if (null == userId) {
734 throw new NullPointerException("userId is null"); //NOI18N
735 } else if (userId < 1) {
737 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
743 // Try to lookup it in visible user list
744 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
746 User next = iterator.next();
748 // Is the user id found?
749 if (Objects.equals(next.getUserId(), userId)) {
750 // Copy to other variable
758 // Not visible for the current user
759 throw new UserNotFoundException(userId);
767 * Adds user's name to bean's internal list. It also updates the public user
768 * list if the user has decided to have a public account,
770 * @param user User instance
772 private void addUserName (final User user) {
773 // Make sure the entry is not added yet
774 if (this.userNameList.contains(user.getUserName())) {
776 throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
777 } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
779 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
783 this.userNameList.add(user.getUserName());
789 private void clear () {
792 this.setUserId(null);
793 this.setUserProfileMode(null);
796 this.setUserName(null);
797 this.setUserPassword(null);
798 this.setUserPasswordRepeat(null);
802 * Copies given user into the controller
804 * @param user User instance
806 private void copyUser (final User user) {
807 // Make sure the instance is valid
810 throw new NullPointerException("user is null"); //NOI18N
811 } else if (user.getUserContact() == null) {
813 throw new NullPointerException("user.userContact is null"); //NOI18N
818 this.setUserId(user.getUserId());
819 this.setUserProfileMode(user.getUserProfileMode());
823 * Uniquely adds given user instance to user list. First an existing
824 * instance will be removed, then the given instance is being added.
826 * @param user User instance to add
828 private void uniqueAddUser (final User user) {
829 // Make sure the instance is valid
832 throw new NullPointerException("user is null"); //NOI18N
833 } else if (user.getUserContact() == null) {
835 throw new NullPointerException("user.userContact is null"); //NOI18N
838 // Get iterator from list
839 Iterator<User> iterator = this.userList.iterator();
841 // "Walk" through all entries
842 while (iterator.hasNext()) {
844 User next = iterator.next();
846 // Is id number the same?
847 if (Objects.equals(user.getUserId(), next.getUserId())) {
848 // Found entry, so remove it and abort
849 this.userList.remove(next);
854 // Add contact to list
855 this.userList.add(user);
859 * Updates list with given user instance
861 * @param user User instance
863 private void updateList (final User user) {
864 // The user should be valid
867 throw new NullPointerException("user is null"); //NOI18N
868 } else if (user.getUserId() == null) {
870 throw new NullPointerException("user.userId is null"); //NOI18N
871 } else if (user.getUserId() < 1) {
873 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
877 Iterator<User> iterator = this.userList.iterator();
880 while (iterator.hasNext()) {
882 User next = iterator.next();
884 // Is the same user id?
885 if (Objects.equals(user.getUserId(), next.getUserId())) {
886 // Found it, so remove it
887 this.userList.remove(next);
893 this.userList.add(user);