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.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.jjobs.beans.BaseJobsController;
40 import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
41 import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
42 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
43 import org.mxchange.jjobs.beans.register.JobsUserRegisterWebSessionController;
44 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
45 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
46 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
47 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
48 import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
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 bean (controller)
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;
78 private ContactSessionBeanRemote contactBean;
81 * General contact controller
84 private JobsContactWebSessionController contactController;
87 * Localization controller
90 private JobsLocalizationSessionController localizationController;
93 * Login bean (controller)
96 private JobsUserLoginWebSessionController loginController;
99 * Registration controller
102 private JobsUserRegisterWebSessionController registerController;
105 * A list of all selectable contacts
107 private List<Contact> selectableContacts;
110 * Event being fired when user updated personal data
114 private Event<UpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
119 private final UserSessionBeanRemote userBean;
127 * A list of all user profiles
129 private List<User> userList;
132 * Login bean (controller)
135 private JobsUserLoginWebSessionController userLoginController;
140 private String userName;
145 private List<String> userNameList;
148 * User password (unencrypted from web form)
150 private String userPassword;
153 * User password repeated (unencrypted from web form)
155 private String userPasswordRepeat;
158 * Whether the user wants a public profile
160 private ProfileMode userProfileMode;
163 * A list of all public user profiles
165 * @TODO Hmm, makes that sense? Having visible user list in current
166 * (session-scoped) user's visible user list?
168 private List<User> visibleUserList;
171 * Default constructor
173 public JobsUserWebSessionBean () {
176 // Get initial context
177 Context context = new InitialContext();
180 this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
183 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
184 } catch (final NamingException e) {
186 throw new FaceletException(e);
191 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
192 // The event must be valid
195 throw new NullPointerException("event is null"); //NOI18N
196 } else if (event.getAddedContact() == null) {
198 throw new NullPointerException("event.addedContact is null"); //NOI18N
199 } else if (event.getAddedContact().getContactId() == null) {
201 throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
202 } else if (event.getAddedContact().getContactId() < 1) {
204 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
208 this.selectableContacts.add(event.getAddedContact());
212 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
214 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
216 // event should not be null
219 throw new NullPointerException("event is null"); //NOI18N
220 } else if (event.getAddedUser() == null) {
222 throw new NullPointerException("event.addedUser is null"); //NOI18N
223 } else if (event.getAddedUser().getUserId() == null) {
225 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
226 } else if (event.getAddedUser().getUserId() < 1) {
228 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
232 this.uniqueAddUser(event.getAddedUser());
238 this.setUserId(event.getAddedUser().getUserId());
241 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
245 public void afterAdminUpdatedUserDataEvent (@Observes final AdminUpdatedUserDataEvent event) {
247 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N
249 // event should not be null
252 throw new NullPointerException("event is null"); //NOI18N
253 } else if (event.getUpdatedUser() == null) {
255 throw new NullPointerException("event.updatedUser is null"); //NOI18N
256 } else if (event.getUpdatedUser().getUserId() == null) {
258 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
259 } else if (event.getUpdatedUser().getUserId() < 1) {
261 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
265 this.updateList(event.getUpdatedUser());
271 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
275 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
277 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
279 // event should not be null
282 throw new NullPointerException("event is null"); //NOI18N
283 } else if (event.getRegisteredUser() == null) {
285 throw new NullPointerException("event.registeredUser is null"); //NOI18N
286 } else if (event.getRegisteredUser().getUserId() == null) {
288 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
289 } else if (event.getRegisteredUser().getUserId() < 1) {
291 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
295 User registeredUser = event.getRegisteredUser();
298 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
300 // Copy all data from registered->user
301 this.copyUser(registeredUser);
307 this.uniqueAddUser(registeredUser);
310 this.addUserName(registeredUser);
312 // Is the account public?
313 if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
314 // Also add it to this list
315 this.visibleUserList.add(registeredUser);
319 this.setUserId(registeredUser.getUserId());
322 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
326 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
328 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
330 // event should not be null
333 throw new NullPointerException("event is null"); //NOI18N
334 } else if (event.getConfirmedUser() == null) {
336 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
337 } else if (event.getConfirmedUser().getUserId() == null) {
339 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
340 } else if (event.getConfirmedUser().getUserId() < 1) {
342 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
346 this.uniqueAddUser(event.getConfirmedUser());
350 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
352 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
354 // event should not be null
357 throw new NullPointerException("event is null"); //NOI18N
358 } else if (event.getLoggedInUser() == null) {
360 throw new NullPointerException("event.registeredUser is null"); //NOI18N
361 } else if (event.getLoggedInUser().getUserId() == null) {
363 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
364 } else if (event.getLoggedInUser().getUserId() < 1) {
366 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
369 // "Cache" user instance
370 User loggedInUser = event.getLoggedInUser();
372 // Copy all data to this bean
373 this.copyUser(loggedInUser);
375 // Is the user visible?
376 if (Objects.equals(loggedInUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
377 // Yes, then add user
378 this.visibleUserList.add(loggedInUser);
383 public void afterUserUpdatedPasswordEvent (@Observes final UpdatedUserPasswordEvent event) {
387 throw new NullPointerException("event is null"); //NOI18N
388 } else if (event.getPasswordHistory() == null) {
390 throw new NullPointerException("event.passwordHistory is null"); //NOI18N
391 } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
393 throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
394 } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
396 throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
399 // All fine, so update list
400 this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
404 public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
408 throw new NullPointerException("event is null"); //NOI18N
409 } else if (event.getUpdatedUser() == null) {
411 throw new NullPointerException("event.updatedUser is null"); //NOI18N
412 } else if (event.getUpdatedUser().getUserId() == null) {
414 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
415 } else if (event.getUpdatedUser().getUserId() < 1) {
417 throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
420 // All fine, so update list
421 this.updateList(event.getUpdatedUser());
425 public List<User> allUsers () {
427 return Collections.unmodifiableList(this.userList);
431 public List<User> allVisibleUsers () {
433 return Collections.unmodifiableList(this.visibleUserList);
437 public User createUserInstance () {
439 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: CALLED!", this.getClass().getSimpleName()));
441 // Required personal data must be set
442 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
444 // Create new user instance
445 User user = new LoginUser();
447 // Is user name required?
448 if (!this.isUserNameRequired()) {
449 // Generate pseudo-random user name
450 String randomName = this.userBean.generateRandomUserName();
452 // Set it and inivisible profile
453 this.setUserName(randomName);
454 this.setUserProfileMode(ProfileMode.INVISIBLE);
456 // Generate random password
457 String randomPassword = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
459 // Set random password
460 this.setUserPassword(randomPassword);
461 this.setUserPasswordRepeat(randomPassword);
464 // Set local, user name and mode
465 user.setUserLocale(this.localizationController.getLocale());
466 user.setUserName(this.getUserName());
467 user.setUserProfileMode(this.getUserProfileMode());
469 // Is multiple registration page
470 if (!this.registerController.isMultiplePageEnabled()) {
471 // Create contact instance
472 Contact contact = this.contactController.createContactInstance();
475 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact));
477 // Set contact in user
478 user.setUserContact(contact);
482 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: user={1} - EXIT!", this.getClass().getSimpleName(), user));
489 public User createUserLogin () {
491 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: CALLED!", this.getClass().getSimpleName()));
494 if (this.getUserName() == null) {
496 throw new NullPointerException("recruiterName is null"); //NOI18N
497 } else if (this.getUserName().isEmpty()) {
499 throw new IllegalStateException("recruiterName is empty."); //NOI18N
502 // Create new recruiter instance
503 User recruiter = new LoginUser();
505 // Update all data ...
506 recruiter.setUserName(this.getUserName());
509 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: recruiter={1} - EXIT!", this.getClass().getSimpleName(), recruiter));
511 // Return the new instance
516 public String doChangePersonalData () {
517 // This method shall only be called if the user is logged-in
518 if (!this.userLoginController.isUserLoggedIn()) {
520 throw new IllegalStateException("User is not logged-in"); //NOI18N
521 } else if (!this.isRequiredChangePersonalDataSet()) {
522 // Not all required fields are set
523 throw new FaceletException("Not all required fields are set."); //NOI18N
524 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
525 // Password not matching
526 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
527 } else if (!this.featureController.isFeatureEnabled("edit_user_data")) {
528 // Editing is not allowed
529 throw new IllegalStateException("User tried to edit personal data."); //NOI18N
533 User user = this.userLoginController.getLoggedInUser();
535 // Copy contact data to contact instance
536 this.contactController.updateContactDataFromController(user.getUserContact());
538 // It should be there, so run some tests on it
539 assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N
540 assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N
541 assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
542 assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
543 assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
544 assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
547 user.setUserProfileMode(this.getUserProfileMode());
549 // Send it to the EJB
550 User updatedUser = this.userBean.updateUserPersonalData(user);
553 this.updatedPersonalDataEvent.fire(new UserUpdatedPersonalDataEvent(updatedUser));
556 return "contact_data_saved"; //NOI18N
560 public Long getUserId () {
565 public void setUserId (final Long userId) {
566 this.userId = userId;
570 public String getUserName () {
571 return this.userName;
575 public void setUserName (final String userName) {
576 this.userName = userName;
580 public String getUserPassword () {
581 return this.userPassword;
585 public void setUserPassword (final String userPassword) {
586 this.userPassword = userPassword;
590 public String getUserPasswordRepeat () {
591 return this.userPasswordRepeat;
595 public void setUserPasswordRepeat (final String userPasswordRepeat) {
596 this.userPasswordRepeat = userPasswordRepeat;
600 public ProfileMode getUserProfileMode () {
601 return this.userProfileMode;
605 public void setUserProfileMode (final ProfileMode userProfileMode) {
606 this.userProfileMode = userProfileMode;
610 public boolean hasUsers () {
611 return (!this.allUsers().isEmpty());
615 * Post-initialization of this class
618 public void init () {
619 // Initialize user list
620 this.userList = this.userBean.allUsers();
622 // Get full user name list for reducing EJB calls
623 this.userNameList = this.userBean.getUserNameList();
625 // Is the user logged-in?
626 if (this.userLoginController.isUserLoggedIn()) {
627 // Is logged-in, so load also users visible to memebers
628 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
630 // Initialize user list
631 this.visibleUserList = this.userBean.allPublicUsers();
635 List<User> allUsers = this.allUsers();
638 List<Contact> allContacts = this.contactBean.getAllContacts();
641 Iterator<Contact> iterator = allContacts.iterator();
644 while (iterator.hasNext()) {
646 Contact next = iterator.next();
649 Iterator<User> userIterator = allUsers.iterator();
651 // Loop through all users
652 while (userIterator.hasNext()) {
654 User nextUser = userIterator.next();
657 if (Objects.equals(next, nextUser.getUserContact())) {
666 this.selectableContacts = allContacts;
670 public boolean isContactFound (final Contact contact) {
671 // The contact must be valid
672 if (null == contact) {
674 throw new NullPointerException("contact is null"); //NOI18N
675 } else if (contact.getContactId() == null) {
677 throw new NullPointerException("contact.contactId is null"); //NOI18N
678 } else if (contact.getContactId() < 1) {
680 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
683 // Default is not found
684 boolean isFound = false;
687 Iterator<User> iterator = this.allUsers().iterator();
689 // Loop through all entries
690 while (iterator.hasNext()) {
692 User next = iterator.next();
694 // Compare both objects
695 if (Objects.equals(contact, next.getUserContact())) {
707 public boolean isPublicUserProfileEnabled () {
708 // Get context parameter
709 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N
712 boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
714 // This requires user names being enabled, too.
715 if ((isEnabled) && (!this.isUserNameRequired())) {
716 // Not valid state, users must be able to modify their profile, especially when it is public
717 throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
725 public boolean isRequiredChangePersonalDataSet () {
726 return ((this.getUserProfileMode() != null) &&
727 (this.getUserName() != null) && (!this.getUserName().isEmpty()) &&
728 (this.contactController.isRequiredChangePersonalDataSet()));
732 public boolean isRequiredPersonalDataSet () {
733 if (this.registerController.isMultiplePageEnabled()) {
734 // Multiple registration page
735 return this.contactController.isRequiredPersonalDataSet();
737 // Single registration page
738 return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
739 (this.getUserProfileMode() != null) &&
740 (this.contactController.isRequiredPersonalDataSet()) &&
741 (this.getUserPassword() != null) &&
742 (this.getUserPasswordRepeat() != null));
747 public boolean isSamePasswordEntered () {
748 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
752 public boolean isUserIdEmpty () {
753 return ((this.getUserId() == null) || (this.getUserId() == 0));
757 public boolean isUserNameRegistered (final User user) {
758 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
762 public boolean isUserNameRequired () {
763 // Get context parameter
764 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N
767 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
774 public boolean isVisibleUserFound () {
775 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
779 public User lookupUserById (final Long userId) throws UserNotFoundException {
780 // Parameter must be valid
781 if (null == userId) {
783 throw new NullPointerException("userId is null"); //NOI18N
784 } else if (userId < 1) {
786 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
792 // Try to lookup it in visible user list
793 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
795 User next = iterator.next();
797 // Is the user id found?
798 if (Objects.equals(next.getUserId(), userId)) {
799 // Copy to other variable
807 // Not visible for the current user
808 throw new UserNotFoundException(userId);
816 public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
817 // Parameter must be valid
818 if (null == emailAddress) {
820 throw new NullPointerException("emailAddress is null"); //NOI18N
821 } else if (emailAddress.isEmpty()) {
823 throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
829 // Try to lookup it in visible user list
830 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
832 User next = iterator.next();
834 // Contact should be set
835 if (next.getUserContact() == null) {
837 throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
838 } else if (next.getUserContact().getContactEmailAddress() == null) {
839 // Email address should be set
840 throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N //NOI18N
843 // Is the email address found?
844 if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) {
845 // Copy to other variable
853 // Not visible for the current user
854 throw new UserEmailAddressNotFoundException(emailAddress);
862 public List<Contact> selectableContacts () {
863 return Collections.unmodifiableList(this.selectableContacts);
867 * Adds user's name to bean's internal list. It also updates the public user
868 * list if the user has decided to have a public account,
870 * @param user User instance
872 private void addUserName (final User user) {
873 // Make sure the entry is not added yet
874 if (this.userNameList.contains(user.getUserName())) {
876 throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
877 } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
879 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
883 this.userNameList.add(user.getUserName());
889 private void clear () {
892 this.setUserId(null);
893 this.setUserProfileMode(null);
896 this.setUserName(null);
897 this.setUserPassword(null);
898 this.setUserPasswordRepeat(null);
902 * Copies given user into the controller
904 * @param user User instance
906 private void copyUser (final User user) {
907 // Make sure the instance is valid
910 throw new NullPointerException("user is null"); //NOI18N
911 } else if (user.getUserContact() == null) {
913 throw new NullPointerException("user.userContact is null"); //NOI18N
918 this.setUserId(user.getUserId());
919 this.setUserProfileMode(user.getUserProfileMode());
923 * Uniquely adds given user instance to user list. First an existing
924 * instance will be removed, then the given instance is being added.
926 * @param user User instance to add
928 private void uniqueAddUser (final User user) {
929 // Make sure the instance is valid
932 throw new NullPointerException("user is null"); //NOI18N
933 } else if (user.getUserContact() == null) {
935 throw new NullPointerException("user.userContact is null"); //NOI18N
938 // Get iterator from list
939 Iterator<User> iterator = this.userList.iterator();
941 // "Walk" through all entries
942 while (iterator.hasNext()) {
944 User next = iterator.next();
946 // Is id number the same?
947 if (Objects.equals(user.getUserId(), next.getUserId())) {
948 // Found entry, so remove it and abort
949 this.userList.remove(next);
954 // Add contact to list
955 this.userList.add(user);
959 * Updates list with given user instance
961 * @param user User instance
963 private void updateList (final User user) {
964 // The user should be valid
967 throw new NullPointerException("user is null"); //NOI18N
968 } else if (user.getUserId() == null) {
970 throw new NullPointerException("user.userId is null"); //NOI18N
971 } else if (user.getUserId() < 1) {
973 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
977 Iterator<User> iterator = this.userList.iterator();
980 while (iterator.hasNext()) {
982 User next = iterator.next();
984 // Is the same user id?
985 if (Objects.equals(user.getUserId(), next.getUserId())) {
986 // Found it, so remove it
987 this.userList.remove(next);
993 this.userList.add(user);