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/jlandingpage-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) {
173 // event should not be null
176 throw new NullPointerException("event is null"); //NOI18N
177 } else if (event.getAddedUser() == null) {
179 throw new NullPointerException("event.addedUser is null"); //NOI18N
180 } else if (event.getAddedUser().getUserId() == null) {
182 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
183 } else if (event.getAddedUser().getUserId() < 1) {
185 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
189 this.updateList(event.getAddedUser());
195 this.setUserId(event.getAddedUser().getUserId());
199 public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) {
200 // event should not be null
203 throw new NullPointerException("event is null"); //NOI18N
204 } else if (event.getLinkedUser() == null) {
206 throw new NullPointerException("event.linkedUser is null"); //NOI18N
207 } else if (event.getLinkedUser().getUserId() == null) {
209 throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
210 } else if (event.getLinkedUser().getUserId() < 1) {
212 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
216 this.updateList(event.getLinkedUser());
222 this.setUserId(event.getLinkedUser().getUserId());
226 public void afterAdminLockedUserEvent (@Observes final AdminLockedUserEvent event) {
227 // event should not be null
230 throw new NullPointerException("event is null"); //NOI18N
231 } else if (event.getLockedUser() == null) {
233 throw new NullPointerException("event.lockedUser is null"); //NOI18N
234 } else if (event.getLockedUser().getUserId() == null) {
236 throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
237 } else if (event.getLockedUser().getUserId() < 1) {
239 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
243 this.updateList(event.getLockedUser());
247 public void afterAdminUnlockedUserEvent (@Observes final AdminUnlockedUserEvent event) {
248 // event should not be null
251 throw new NullPointerException("event is null"); //NOI18N
252 } else if (event.getUnlockedUser() == null) {
254 throw new NullPointerException("event.unlockedUser is null"); //NOI18N
255 } else if (event.getUnlockedUser().getUserId() == null) {
257 throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
258 } else if (event.getUnlockedUser().getUserId() < 1) {
260 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
264 this.updateList(event.getUnlockedUser());
268 public void afterAdminUpdatedUserDataEvent (@Observes final AdminUpdatedUserDataEvent event) {
269 // event should not be null
272 throw new NullPointerException("event is null"); //NOI18N
273 } else if (event.getUpdatedUser() == null) {
275 throw new NullPointerException("event.updatedUser is null"); //NOI18N
276 } else if (event.getUpdatedUser().getUserId() == null) {
278 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
279 } else if (event.getUpdatedUser().getUserId() < 1) {
281 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
285 this.updateList(event.getUpdatedUser());
292 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
293 // event should not be null
296 throw new NullPointerException("event is null"); //NOI18N
297 } else if (event.getRegisteredUser() == null) {
299 throw new NullPointerException("event.registeredUser is null"); //NOI18N
300 } else if (event.getRegisteredUser().getUserId() == null) {
302 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
303 } else if (event.getRegisteredUser().getUserId() < 1) {
305 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
309 User registeredUser = event.getRegisteredUser();
311 // Copy all data from registered->user
312 this.copyUser(registeredUser);
318 this.updateList(registeredUser);
321 this.addUserName(registeredUser);
323 // Is the account public?
324 if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
325 // Also add it to this list
326 this.visibleUserList.add(registeredUser);
330 this.setUserId(registeredUser.getUserId());
334 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
335 // event should not be null
338 throw new NullPointerException("event is null"); //NOI18N
339 } else if (event.getConfirmedUser() == null) {
341 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
342 } else if (event.getConfirmedUser().getUserId() == null) {
344 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
345 } else if (event.getConfirmedUser().getUserId() < 1) {
347 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
351 this.updateList(event.getConfirmedUser());
355 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
356 // event should not be null
359 throw new NullPointerException("event is null"); //NOI18N
360 } else if (event.getLoggedInUser() == null) {
362 throw new NullPointerException("event.registeredUser is null"); //NOI18N
363 } else if (event.getLoggedInUser().getUserId() == null) {
365 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
366 } else if (event.getLoggedInUser().getUserId() < 1) {
368 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
371 // "Cache" user instance
372 User loggedInUser = event.getLoggedInUser();
374 // Copy all data to this bean
375 this.copyUser(loggedInUser);
377 // Is the user visible?
378 if (Objects.equals(loggedInUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
379 // Yes, then add user
380 this.visibleUserList.add(loggedInUser);
385 public void afterUserUpdatedPasswordEvent (@Observes final UpdatedUserPasswordEvent event) {
389 throw new NullPointerException("event is null"); //NOI18N
390 } else if (event.getPasswordHistory() == null) {
392 throw new NullPointerException("event.passwordHistory is null"); //NOI18N
393 } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
395 throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
396 } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
398 throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
402 this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
406 public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
410 throw new NullPointerException("event is null"); //NOI18N
411 } else if (event.getUpdatedUser() == null) {
413 throw new NullPointerException("event.updatedUser is null"); //NOI18N
414 } else if (event.getUpdatedUser().getUserId() == null) {
416 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
417 } else if (event.getUpdatedUser().getUserId() < 1) {
419 throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
423 this.updateList(event.getUpdatedUser());
427 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
428 public List<User> allUsers () {
430 return this.userList;
434 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
435 public List<User> allVisibleUsers () {
437 return this.visibleUserList;
441 public User createUserInstance (final boolean createContactData) {
442 // Required personal data must be set
443 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
445 // Create new user instance
446 User user = new LoginUser();
448 // Is user name required?
449 if (!this.isUserNameRequired()) {
450 // Generate pseudo-random user name
451 String randomName = this.userBean.generateRandomUserName();
453 // Set it and inivisible profile
454 this.setUserName(randomName);
455 this.setUserProfileMode(ProfileMode.INVISIBLE);
457 // Generate random password
458 String randomPassword = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
460 // Set random password
461 this.setUserPassword(randomPassword);
462 this.setUserPasswordRepeat(randomPassword);
465 // Set local, user name and mode
466 user.setUserLocale(this.localizationController.getLocale());
467 user.setUserName(this.getUserName());
468 user.setUserProfileMode(this.getUserProfileMode());
470 // Is multiple registration page
471 if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N
472 // Create contact instance
473 Contact contact = this.contactController.createContactInstance();
475 // Set contact in user
476 user.setUserContact(contact);
484 public User createUserLogin () {
486 if (this.getUserName() == null) {
488 throw new NullPointerException("recruiterName is null"); //NOI18N
489 } else if (this.getUserName().isEmpty()) {
491 throw new IllegalStateException("recruiterName is empty."); //NOI18N
494 // Create new recruiter instance
495 User recruiter = new LoginUser();
497 // Update all data ...
498 recruiter.setUserName(this.getUserName());
500 // Return the new instance
505 public String doChangePersonalData () {
506 // This method shall only be called if the user is logged-in
507 if (!this.userLoginController.isUserLoggedIn()) {
509 throw new IllegalStateException("User is not logged-in"); //NOI18N
510 } else if (!this.isRequiredChangePersonalDataSet()) {
511 // Not all required fields are set
512 throw new FaceletException("Not all required fields are set."); //NOI18N
513 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
514 // Password not matching
515 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
516 } else if (!this.featureController.isFeatureEnabled("edit_user_data")) {
517 // Editing is not allowed
518 throw new IllegalStateException("User tried to edit personal data."); //NOI18N
522 User user = this.userLoginController.getLoggedInUser();
524 // Copy contact data to contact instance
525 this.contactController.updateContactDataFromController(user.getUserContact());
527 // It should be there, so run some tests on it
528 assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N
529 assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N
530 assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
531 assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
532 assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
533 assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
536 user.setUserProfileMode(this.getUserProfileMode());
538 // Send it to the EJB
539 User updatedUser = this.userBean.updateUserPersonalData(user);
542 this.updatedPersonalDataEvent.fire(new UserUpdatedPersonalDataEvent(updatedUser));
545 return "contact_data_saved"; //NOI18N
549 public Long getUserId () {
554 public void setUserId (final Long userId) {
555 this.userId = userId;
559 public String getUserName () {
560 return this.userName;
564 public void setUserName (final String userName) {
565 this.userName = userName;
569 public String getUserPassword () {
570 return this.userPassword;
574 public void setUserPassword (final String userPassword) {
575 this.userPassword = userPassword;
579 public String getUserPasswordRepeat () {
580 return this.userPasswordRepeat;
584 public void setUserPasswordRepeat (final String userPasswordRepeat) {
585 this.userPasswordRepeat = userPasswordRepeat;
589 public ProfileMode getUserProfileMode () {
590 return this.userProfileMode;
594 public void setUserProfileMode (final ProfileMode userProfileMode) {
595 this.userProfileMode = userProfileMode;
599 * Post-initialization of this class
602 public void init () {
603 // Initialize user list
604 this.userList = this.userBean.allUsers();
606 // Get full user name list for reducing EJB calls
607 this.userNameList = this.userBean.getUserNameList();
609 // Is the user logged-in?
610 if (this.userLoginController.isUserLoggedIn()) {
611 // Is logged-in, so load also users visible to memebers
612 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
614 // Initialize user list
615 this.visibleUserList = this.userBean.allPublicUsers();
620 public boolean isContactFound (final Contact contact) {
621 // The contact must be valid
622 if (null == contact) {
624 throw new NullPointerException("contact is null"); //NOI18N
625 } else if (contact.getContactId() == null) {
627 throw new NullPointerException("contact.contactId is null"); //NOI18N
628 } else if (contact.getContactId() < 1) {
630 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
633 // Default is not found
634 boolean isFound = false;
637 Iterator<User> iterator = this.allUsers().iterator();
639 // Loop through all entries
640 while (iterator.hasNext()) {
642 User next = iterator.next();
644 // Compare both objects
645 if (Objects.equals(contact, next.getUserContact())) {
657 public boolean isPublicUserProfileEnabled () {
658 // Get context parameter
659 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N
662 boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
664 // This requires user names being enabled, too.
665 if ((isEnabled) && (!this.isUserNameRequired())) {
666 // Not valid state, users must be able to modify their profile, especially when it is public
667 throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
675 public boolean isRequiredChangePersonalDataSet () {
676 return ((this.getUserProfileMode() != null) &&
677 (this.getUserName() != null) && (!this.getUserName().isEmpty()) &&
678 (this.contactController.isRequiredChangePersonalDataSet()));
682 public boolean isRequiredPersonalDataSet () {
683 if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
684 // Multiple registration page
685 return this.contactController.isRequiredPersonalDataSet();
687 // Single registration page
688 return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
689 (this.getUserProfileMode() != null) &&
690 (this.contactController.isRequiredPersonalDataSet()) &&
691 (this.getUserPassword() != null) &&
692 (this.getUserPasswordRepeat() != null));
697 public boolean isSamePasswordEntered () {
698 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
702 public boolean isUserIdEmpty () {
703 return ((this.getUserId() == null) || (this.getUserId() == 0));
707 public boolean isUserNameRegistered (final User user) {
708 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
712 public boolean isUserNameRequired () {
713 // Get context parameter
714 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N
717 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
724 public boolean isVisibleUserFound () {
725 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
729 public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
730 // Parameter must be valid
731 if (null == emailAddress) {
733 throw new NullPointerException("emailAddress is null"); //NOI18N
734 } else if (emailAddress.isEmpty()) {
736 throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
742 // Try to lookup it in visible user list
743 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
745 User next = iterator.next();
747 // Contact should be set
748 if (next.getUserContact() == null) {
750 throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
751 } else if (next.getUserContact().getContactEmailAddress() == null) {
752 // Email address should be set
753 throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N
756 // Is the email address found?
757 if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) {
758 // Copy to other variable
766 // Not visible for the current user
767 throw new UserEmailAddressNotFoundException(emailAddress);
775 public User lookupUserById (final Long userId) throws UserNotFoundException {
776 // Parameter must be valid
777 if (null == userId) {
779 throw new NullPointerException("userId is null"); //NOI18N
780 } else if (userId < 1) {
782 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
788 // Try to lookup it in visible user list
789 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
791 User next = iterator.next();
793 // Is the user id found?
794 if (Objects.equals(next.getUserId(), userId)) {
795 // Copy to other variable
803 // Not visible for the current user
804 throw new UserNotFoundException(userId);
812 * Adds user's name to bean's internal list. It also updates the public user
813 * list if the user has decided to have a public account,
815 * @param user User instance
817 private void addUserName (final User user) {
818 // Make sure the entry is not added yet
819 if (this.userNameList.contains(user.getUserName())) {
821 throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
825 this.userNameList.add(user.getUserName());
831 private void clear () {
834 this.setUserId(null);
835 this.setUserProfileMode(null);
838 this.setUserName(null);
839 this.setUserPassword(null);
840 this.setUserPasswordRepeat(null);
844 * Copies given user into the controller
846 * @param user User instance
848 private void copyUser (final User user) {
849 // Make sure the instance is valid
852 throw new NullPointerException("user is null"); //NOI18N
853 } else if (user.getUserContact() == null) {
855 throw new NullPointerException("user.userContact is null"); //NOI18N
860 this.setUserId(user.getUserId());
861 this.setUserProfileMode(user.getUserProfileMode());
865 * Updates list with given user instance
867 * @param user User instance
869 private void updateList (final User user) {
870 // The user should be valid
873 throw new NullPointerException("user is null"); //NOI18N
874 } else if (user.getUserId() == null) {
876 throw new NullPointerException("user.userId is null"); //NOI18N
877 } else if (user.getUserId() < 1) {
879 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
880 } else if (user.getUserContact() == null) {
882 throw new NullPointerException("user.userContact is null"); //NOI18N
883 } else if (user.getUserContact().getContactId() == null) {
885 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
886 } else if (user.getUserContact().getContactId() < 1) {
888 throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N
891 // Get iterator from list
892 Iterator<User> iterator = this.userList.iterator();
894 // "Walk" through all entries
895 while (iterator.hasNext()) {
897 User next = iterator.next();
899 // Is user id number the same?
900 if (Objects.equals(user.getUserId(), next.getUserId())) {
901 // Found entry, so remove it and abort
902 this.userList.remove(next);
908 this.userList.add(user);