2 * Copyright (C) 2016 Roland Häder
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.user.update.UpdatedUserPersonalDataEvent;
42 import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
43 import org.mxchange.jusercore.exceptions.UserNotFoundException;
44 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
45 import org.mxchange.jusercore.model.user.LoginUser;
46 import org.mxchange.jusercore.model.user.User;
47 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
48 import org.mxchange.jusercore.model.user.UserUtils;
49 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
50 import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
51 import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
52 import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
53 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
54 import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
55 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
56 import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
57 import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
58 import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
59 import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
60 import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
63 * A user controller (bean)
65 * @author Roland Häder<roland@mxchange.org>
67 @Named ("userController")
69 public class JobsUserWebSessionBean extends BaseJobsController implements JobsUserWebSessionController {
74 private static final long serialVersionUID = 542_145_347_916L;
77 * General contact controller
80 private JobsContactWebSessionController contactController;
86 private JobsFeaturesWebApplicationController featureController;
89 * Localization controller
92 private JobsLocalizationSessionController localizationController;
95 * Event being fired when user updated personal data
99 private Event<ObservableUpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
104 private final UserSessionBeanRemote userBean;
112 * A list of all user profiles
114 private List<User> userList;
117 * Login controller (bean)
120 private JobsUserLoginWebSessionController userLoginController;
125 private String userName;
130 private List<String> userNameList;
133 * User password (unencrypted from web form)
135 private String userPassword;
138 * User password repeated (unencrypted from web form)
140 private String userPasswordRepeat;
143 * Whether the user wants a public profile
145 private ProfileMode userProfileMode;
148 * A list of all public user profiles
150 * @TODO Hmm, makes that sense? Having visible user list in current
151 * (session-scoped) user's visible user list?
153 private List<User> visibleUserList;
156 * Default constructor
158 public JobsUserWebSessionBean () {
161 // Get initial context
162 Context context = new InitialContext();
165 this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
166 } catch (final NamingException e) {
168 throw new FaceletException(e);
173 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
174 // event should not be null
177 throw new NullPointerException("event is null"); //NOI18N
178 } else if (event.getAddedUser() == null) {
180 throw new NullPointerException("event.addedUser is null"); //NOI18N
181 } else if (event.getAddedUser().getUserId() == null) {
183 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
184 } else if (event.getAddedUser().getUserId() < 1) {
186 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
190 this.updateList(event.getAddedUser());
196 this.setUserId(event.getAddedUser().getUserId());
200 public void afterAdminDeletedUserEvent (final ObservableAdminDeletedUserEvent event) {
201 // event should not be null
204 throw new NullPointerException("event is null"); //NOI18N
205 } else if (event.getDeletedUser() == null) {
207 throw new NullPointerException("event.deletedUser is null"); //NOI18N
208 } else if (event.getDeletedUser().getUserId() == null) {
210 throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
211 } else if (event.getDeletedUser().getUserId() < 1) {
213 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
217 this.removeFromList(event.getDeletedUser());
224 public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
225 // event should not be null
228 throw new NullPointerException("event is null"); //NOI18N
229 } else if (event.getLinkedUser() == null) {
231 throw new NullPointerException("event.linkedUser is null"); //NOI18N
232 } else if (event.getLinkedUser().getUserId() == null) {
234 throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
235 } else if (event.getLinkedUser().getUserId() < 1) {
237 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
241 this.updateList(event.getLinkedUser());
247 this.setUserId(event.getLinkedUser().getUserId());
251 public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent event) {
252 // event should not be null
255 throw new NullPointerException("event is null"); //NOI18N
256 } else if (event.getLockedUser() == null) {
258 throw new NullPointerException("event.lockedUser is null"); //NOI18N
259 } else if (event.getLockedUser().getUserId() == null) {
261 throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
262 } else if (event.getLockedUser().getUserId() < 1) {
264 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
268 this.updateList(event.getLockedUser());
272 public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent event) {
273 // event should not be null
276 throw new NullPointerException("event is null"); //NOI18N
277 } else if (event.getUnlockedUser() == null) {
279 throw new NullPointerException("event.unlockedUser is null"); //NOI18N
280 } else if (event.getUnlockedUser().getUserId() == null) {
282 throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
283 } else if (event.getUnlockedUser().getUserId() < 1) {
285 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
289 this.updateList(event.getUnlockedUser());
293 public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
294 // event should not be null
297 throw new NullPointerException("event is null"); //NOI18N
298 } else if (event.getUpdatedUser() == null) {
300 throw new NullPointerException("event.updatedUser is null"); //NOI18N
301 } else if (event.getUpdatedUser().getUserId() == null) {
303 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
304 } else if (event.getUpdatedUser().getUserId() < 1) {
306 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
310 this.updateList(event.getUpdatedUser());
317 public void afterUserConfirmedAccountEvent (@Observes final ObservableUserConfirmedAccountEvent event) {
318 // event should not be null
321 throw new NullPointerException("event is null"); //NOI18N
322 } else if (event.getConfirmedUser() == null) {
324 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
325 } else if (event.getConfirmedUser().getUserId() == null) {
327 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
328 } else if (event.getConfirmedUser().getUserId() < 1) {
330 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
334 this.updateList(event.getConfirmedUser());
338 public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
339 // event should not be null
342 throw new NullPointerException("event is null"); //NOI18N
343 } else if (event.getLoggedInUser() == null) {
345 throw new NullPointerException("event.registeredUser is null"); //NOI18N
346 } else if (event.getLoggedInUser().getUserId() == null) {
348 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
349 } else if (event.getLoggedInUser().getUserId() < 1) {
351 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
354 // "Cache" user instance
355 User loggedInUser = event.getLoggedInUser();
357 // Copy all data to this bean
358 this.copyUser(loggedInUser);
360 // Is the user visible?
361 if (Objects.equals(loggedInUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
362 // Yes, then add user
363 this.visibleUserList.add(loggedInUser);
368 public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
369 // event should not be null
372 throw new NullPointerException("event is null"); //NOI18N
373 } else if (event.getRegisteredUser() == null) {
375 throw new NullPointerException("event.registeredUser is null"); //NOI18N
376 } else if (event.getRegisteredUser().getUserId() == null) {
378 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
379 } else if (event.getRegisteredUser().getUserId() < 1) {
381 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
385 User registeredUser = event.getRegisteredUser();
387 // Copy all data from registered->user
388 this.copyUser(registeredUser);
394 this.updateList(registeredUser);
397 this.addUserName(registeredUser);
399 // Is the account public?
400 if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
401 // Also add it to this list
402 this.visibleUserList.add(registeredUser);
406 this.setUserId(registeredUser.getUserId());
410 public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
414 throw new NullPointerException("event is null"); //NOI18N
415 } else if (event.getPasswordHistory() == null) {
417 throw new NullPointerException("event.passwordHistory is null"); //NOI18N
418 } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
420 throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
421 } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
423 throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
427 this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
431 public void afterUserUpdatedPersonalDataEvent (@Observes final ObservableUpdatedUserPersonalDataEvent event) {
435 throw new NullPointerException("event is null"); //NOI18N
436 } else if (event.getUpdatedUser() == null) {
438 throw new NullPointerException("event.updatedUser is null"); //NOI18N
439 } else if (event.getUpdatedUser().getUserId() == null) {
441 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
442 } else if (event.getUpdatedUser().getUserId() < 1) {
444 throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
448 this.updateList(event.getUpdatedUser());
452 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
453 public List<User> allUsers () {
455 return this.userList;
459 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
460 public List<User> allVisibleUsers () {
462 return this.visibleUserList;
466 public User createUserInstance (final boolean createContactData) {
467 // Required personal data must be set
468 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
470 // Create new user instance
471 User user = new LoginUser();
473 // Is user name required?
474 if (!this.isUserNameRequired()) {
475 // Generate pseudo-random user name
476 String randomName = this.userBean.generateRandomUserName();
478 // Set it and inivisible profile
479 this.setUserName(randomName);
480 this.setUserProfileMode(ProfileMode.INVISIBLE);
482 // Generate random password
483 String randomPassword = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
485 // Set random password
486 this.setUserPassword(randomPassword);
487 this.setUserPasswordRepeat(randomPassword);
490 // Set local, user name and mode
491 user.setUserLocale(this.localizationController.getLocale());
492 user.setUserName(this.getUserName());
493 user.setUserProfileMode(this.getUserProfileMode());
495 // Is multiple registration page
496 if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N
497 // Create contact instance
498 Contact contact = this.contactController.createContactInstance();
500 // Set contact in user
501 user.setUserContact(contact);
509 public User createUserLogin () {
511 if (this.getUserName() == null) {
513 throw new NullPointerException("recruiterName is null"); //NOI18N
514 } else if (this.getUserName().isEmpty()) {
516 throw new IllegalStateException("recruiterName is empty."); //NOI18N
519 // Create new recruiter instance
520 User recruiter = new LoginUser();
522 // Update all data ...
523 recruiter.setUserName(this.getUserName());
525 // Return the new instance
530 public String doChangePersonalData () {
531 // This method shall only be called if the user is logged-in
532 if (!this.userLoginController.isUserLoggedIn()) {
534 throw new IllegalStateException("User is not logged-in"); //NOI18N
535 } else if (!this.isRequiredChangePersonalDataSet()) {
536 // Not all required fields are set
537 throw new FaceletException("Not all required fields are set."); //NOI18N
538 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
539 // Password not matching
540 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
541 } else if (!this.featureController.isFeatureEnabled("change_user_personal_data")) {
542 // Editing is not allowed
543 throw new IllegalStateException("User tried to edit personal data."); //NOI18N
547 User user = this.userLoginController.getLoggedInUser();
549 // Copy contact data to contact instance
550 this.contactController.updateContactDataFromController(user.getUserContact());
552 // It should be there, so run some tests on it
553 assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N
554 assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N
555 assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
556 assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
557 assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
558 assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
561 user.setUserProfileMode(this.getUserProfileMode());
563 // Send it to the EJB
564 User updatedUser = this.userBean.updateUserPersonalData(user);
567 this.updatedPersonalDataEvent.fire(new UpdatedUserPersonalDataEvent(updatedUser));
570 return "user_contact_data_saved"; //NOI18N
574 public Long getUserId () {
579 public void setUserId (final Long userId) {
580 this.userId = userId;
584 public String getUserName () {
585 return this.userName;
589 public void setUserName (final String userName) {
590 this.userName = userName;
594 public String getUserPassword () {
595 return this.userPassword;
599 public void setUserPassword (final String userPassword) {
600 this.userPassword = userPassword;
604 public String getUserPasswordRepeat () {
605 return this.userPasswordRepeat;
609 public void setUserPasswordRepeat (final String userPasswordRepeat) {
610 this.userPasswordRepeat = userPasswordRepeat;
614 public ProfileMode getUserProfileMode () {
615 return this.userProfileMode;
619 public void setUserProfileMode (final ProfileMode userProfileMode) {
620 this.userProfileMode = userProfileMode;
624 * Post-initialization of this class
627 public void init () {
628 // Initialize user list
629 this.userList = this.userBean.allUsers();
631 // Get full user name list for reducing EJB calls
632 this.userNameList = this.userBean.getUserNameList();
634 // Is the user logged-in?
635 if (this.userLoginController.isUserLoggedIn()) {
636 // Is logged-in, so load also users visible to memebers
637 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
639 // Initialize user list
640 this.visibleUserList = this.userBean.allPublicUsers();
645 public boolean isContactFound (final Contact contact) {
646 // The contact must be valid
647 if (null == contact) {
649 throw new NullPointerException("contact is null"); //NOI18N
650 } else if (contact.getContactId() == null) {
652 throw new NullPointerException("contact.contactId is null"); //NOI18N
653 } else if (contact.getContactId() < 1) {
655 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
658 // Default is not found
659 boolean isFound = false;
662 Iterator<User> iterator = this.allUsers().iterator();
664 // Loop through all entries
665 while (iterator.hasNext()) {
667 User next = iterator.next();
669 // Compare both objects
670 if (Objects.equals(contact, next.getUserContact())) {
682 public boolean isPublicUserProfileEnabled () {
683 // Get context parameter
684 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N
687 boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
689 // This requires user names being enabled, too.
690 if ((isEnabled) && (!this.isUserNameRequired())) {
691 // Not valid state, users must be able to modify their profile, especially when it is public
692 throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
700 public boolean isRequiredChangePersonalDataSet () {
701 return ((this.getUserProfileMode() != null) &&
702 (this.getUserName() != null) && (!this.getUserName().isEmpty()) &&
703 (this.contactController.isRequiredChangePersonalDataSet()));
707 public boolean isRequiredPersonalDataSet () {
708 if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
709 // Multiple registration page
710 return this.contactController.isRequiredPersonalDataSet();
712 // Single registration page
713 return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
714 (this.getUserProfileMode() != null) &&
715 (this.contactController.isRequiredPersonalDataSet()) &&
716 (this.getUserPassword() != null) &&
717 (this.getUserPasswordRepeat() != null));
722 public boolean isSamePasswordEntered () {
723 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
727 public boolean isUserIdEmpty () {
728 return ((this.getUserId() == null) || (this.getUserId() == 0));
732 public boolean isUserNameRegistered (final User user) {
733 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
737 public boolean isUserNameRequired () {
738 // Get context parameter
739 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N
742 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
749 public boolean isVisibleUserFound () {
750 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
754 public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
755 // Parameter must be valid
756 if (null == emailAddress) {
758 throw new NullPointerException("emailAddress is null"); //NOI18N
759 } else if (emailAddress.isEmpty()) {
761 throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
767 // Try to lookup it in visible user list
768 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
770 User next = iterator.next();
772 // Contact should be set
773 if (next.getUserContact() == null) {
775 throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
776 } else if (next.getUserContact().getContactEmailAddress() == null) {
777 // Email address should be set
778 throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N
781 // Is the email address found?
782 if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) {
783 // Copy to other variable
791 // Not visible for the current user
792 throw new UserEmailAddressNotFoundException(emailAddress);
800 public User lookupUserById (final Long userId) throws UserNotFoundException {
801 // Parameter must be valid
802 if (null == userId) {
804 throw new NullPointerException("userId is null"); //NOI18N
805 } else if (userId < 1) {
807 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
813 // Try to lookup it in visible user list
814 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
816 User next = iterator.next();
818 // Is the user id found?
819 if (Objects.equals(next.getUserId(), userId)) {
820 // Copy to other variable
828 // Not visible for the current user
829 throw new UserNotFoundException(userId);
837 * Adds user's name to bean's internal list. It also updates the public user
838 * list if the user has decided to have a public account,
840 * @param user User instance
842 private void addUserName (final User user) {
843 // Make sure the entry is not added yet
844 if (this.userNameList.contains(user.getUserName())) {
846 throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
850 this.userNameList.add(user.getUserName());
856 private void clear () {
859 this.setUserId(null);
860 this.setUserProfileMode(null);
863 this.setUserName(null);
864 this.setUserPassword(null);
865 this.setUserPasswordRepeat(null);
869 * Copies given user into the controller
871 * @param user User instance
873 private void copyUser (final User user) {
874 // Make sure the instance is valid
877 throw new NullPointerException("user is null"); //NOI18N
878 } else if (user.getUserContact() == null) {
880 throw new NullPointerException("user.userContact is null"); //NOI18N
885 this.setUserId(user.getUserId());
886 this.setUserProfileMode(user.getUserProfileMode());
890 * Removes user from all lists
892 * @param user User to remove
894 private void removeFromList (final User user) {
895 // The user should be valid
898 throw new NullPointerException("user is null"); //NOI18N
899 } else if (user.getUserId() == null) {
901 throw new NullPointerException("user.userId is null"); //NOI18N
902 } else if (user.getUserId() < 1) {
904 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
907 // Remove it from lists
908 this.userList.remove(user);
909 this.visibleUserList.remove(user);
911 // Remove name from list
912 this.userNameList.remove(user.getUserName());
916 * Updates list with given user instance
918 * @param user User instance
920 private void updateList (final User user) {
921 // The user should be valid
924 throw new NullPointerException("user is null"); //NOI18N
925 } else if (user.getUserId() == null) {
927 throw new NullPointerException("user.userId is null"); //NOI18N
928 } else if (user.getUserId() < 1) {
930 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
931 } else if (user.getUserContact() == null) {
933 throw new NullPointerException("user.userContact is null"); //NOI18N
934 } else if (user.getUserContact().getContactId() == null) {
936 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
937 } else if (user.getUserContact().getContactId() < 1) {
939 throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N
942 // Get iterator from list
943 Iterator<User> iterator = this.userList.iterator();
945 // "Walk" through all entries
946 while (iterator.hasNext()) {
948 User next = iterator.next();
950 // Is user id number the same?
951 if (Objects.equals(user.getUserId(), next.getUserId())) {
952 // Found entry, so remove it and abort
953 this.userList.remove(next);
959 this.userList.add(user);