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.login.JobsUserLoginWebSessionController;
42 import org.mxchange.jjobs.beans.register.JobsUserRegisterWebSessionController;
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 JobsUserWebSessionBean extends BaseJobsController implements JobsUserWebSessionController {
71 private static final long serialVersionUID = 542_145_347_916L;
76 private ContactSessionBeanRemote contactBean;
79 * General contact controller
82 private JobsContactWebSessionController contactController;
85 * Registration controller
88 private JobsUserRegisterWebSessionController registerController;
91 * A list of all selectable contacts
93 private List<Contact> selectableContacts;
96 * Event being fired when user updated personal data
100 private Event<UpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
105 private final UserSessionBeanRemote userBean;
113 * A list of all user profiles
115 private List<User> userList;
118 * Login bean (controller)
121 private JobsUserLoginWebSessionController userLoginController;
126 private String userName;
131 private List<String> userNameList;
134 * User password (unencrypted from web form)
136 private String userPassword;
139 * User password repeated (unencrypted from web form)
141 private String userPasswordRepeat;
144 * Whether the user wants a public profile
146 private ProfileMode userProfileMode;
149 * A list of all public user profiles
151 private List<User> visibleUserList;
154 * Default constructor
156 public JobsUserWebSessionBean () {
159 // Get initial context
160 Context context = new InitialContext();
163 this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
166 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
167 } catch (final NamingException e) {
169 throw new FaceletException(e);
174 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
175 // The event must be valid
178 throw new NullPointerException("event is null"); //NOI18N
179 } else if (event.getAddedContact() == null) {
181 throw new NullPointerException("event.addedContact is null"); //NOI18N
182 } else if (event.getAddedContact().getContactId() == null) {
184 throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
185 } else if (event.getAddedContact().getContactId() < 1) {
187 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
191 this.selectableContacts.add(event.getAddedContact());
195 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
197 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
199 // event should not be null
202 throw new NullPointerException("event is null"); //NOI18N
203 } else if (event.getAddedUser() == null) {
205 throw new NullPointerException("event.addedUser is null"); //NOI18N
206 } else if (event.getAddedUser().getUserId() == null) {
208 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
209 } else if (event.getAddedUser().getUserId() < 1) {
211 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
214 // Add user to local list
215 this.userList.add(event.getAddedUser());
221 this.setUserId(event.getAddedUser().getUserId());
224 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
228 public void afterAdminUpdatedUserDataEvent (@Observes final AdminUpdatedUserDataEvent event) {
230 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N
232 // event should not be null
235 throw new NullPointerException("event is null"); //NOI18N
236 } else if (event.getUpdatedUser() == null) {
238 throw new NullPointerException("event.updatedUser is null"); //NOI18N
239 } else if (event.getUpdatedUser().getUserId() == null) {
241 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
242 } else if (event.getUpdatedUser().getUserId() < 1) {
244 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
248 this.updateList(event.getUpdatedUser());
254 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
258 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
260 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
262 // event should not be null
265 throw new NullPointerException("event is null"); //NOI18N
266 } else if (event.getRegisteredUser() == null) {
268 throw new NullPointerException("event.registeredUser is null"); //NOI18N
269 } else if (event.getRegisteredUser().getUserId() == null) {
271 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
272 } else if (event.getRegisteredUser().getUserId() < 1) {
274 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
278 User registeredUser = event.getRegisteredUser();
281 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
283 // Copy all data from registered->user
284 this.copyUser(registeredUser);
289 // Add user to local list
290 this.userList.add(registeredUser);
293 this.addUserName(registeredUser);
295 // Is the account public?
296 if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
297 // Also add it to this list
298 this.visibleUserList.add(registeredUser);
302 this.setUserId(registeredUser.getUserId());
305 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
309 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
311 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
313 // event should not be null
316 throw new NullPointerException("event is null"); //NOI18N
317 } else if (event.getConfirmedUser() == null) {
319 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
320 } else if (event.getConfirmedUser().getUserId() == null) {
322 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
323 } else if (event.getConfirmedUser().getUserId() < 1) {
325 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
328 // Get iterator from list
329 Iterator<User> iterator = this.userList.iterator();
331 // "Walk" through all entries
332 while (iterator.hasNext()) {
334 User next = iterator.next();
336 // Is id number the same?
337 if (Objects.equals(event.getConfirmedUser().getUserId(), next.getUserId())) {
338 // Found entry, so remove it and abort
339 this.userList.remove(next);
344 // Add contact to list
345 this.userList.add(event.getConfirmedUser());
349 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
351 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
353 // event should not be null
356 throw new NullPointerException("event is null"); //NOI18N
357 } else if (event.getLoggedInUser() == null) {
359 throw new NullPointerException("event.registeredUser is null"); //NOI18N
360 } else if (event.getLoggedInUser().getUserId() == null) {
362 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
363 } else if (event.getLoggedInUser().getUserId() < 1) {
365 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
368 // Copy all data to this bean
369 this.copyUser(event.getLoggedInUser());
371 // Re-initialize list
372 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
375 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
379 public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
383 throw new NullPointerException("event is null"); //NOI18N
384 } else if (event.getUpdatedUser() == null) {
386 throw new NullPointerException("event.updatedUser is null"); //NOI18N
387 } else if (event.getUpdatedUser().getUserId() == null) {
389 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
390 } else if (event.getUpdatedUser().getUserId() < 1) {
392 throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
395 // All fine, so update list
396 this.updateList(event.getUpdatedUser());
400 public List<User> allUsers () {
402 return Collections.unmodifiableList(this.userList);
406 public List<User> allVisibleUsers () {
408 return Collections.unmodifiableList(this.visibleUserList);
412 public User createUserInstance () {
414 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: CALLED!", this.getClass().getSimpleName()));
416 // Required personal data must be set
417 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
419 // Create new user instance
420 User user = new LoginUser();
422 // Is user name required?
423 if (!this.isUserNameRequired()) {
424 // Generate pseudo-random user name
425 String randomName = this.userBean.generateRandomUserName();
427 // Set it and inivisible profile
428 this.setUserName(randomName);
429 this.setUserProfileMode(ProfileMode.INVISIBLE);
431 // Generate random password
432 String randomPassword = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
434 // Set random password
435 this.setUserPassword(randomPassword);
436 this.setUserPasswordRepeat(randomPassword);
439 // Set user name and mode
440 user.setUserName(this.getUserName());
441 user.setUserProfileMode(this.getUserProfileMode());
443 // Is multiple registration page
444 if (!this.registerController.isMultiplePageEnabled()) {
445 // Create contact instance
446 Contact contact = this.contactController.createContactInstance();
449 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact));
451 // Set contact in user
452 user.setUserContact(contact);
456 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: user={1} - EXIT!", this.getClass().getSimpleName(), user));
463 public User createUserLogin () {
465 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: CALLED!", this.getClass().getSimpleName()));
468 if (this.getUserName() == null) {
470 throw new NullPointerException("recruiterName is null"); //NOI18N
471 } else if (this.getUserName().isEmpty()) {
473 throw new IllegalStateException("recruiterName is empty."); //NOI18N
476 // Create new recruiter instance
477 User recruiter = new LoginUser();
479 // Update all data ...
480 recruiter.setUserName(this.getUserName());
483 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: recruiter={1} - EXIT!", this.getClass().getSimpleName(), recruiter));
485 // Return the new instance
490 public String doChangePersonalData () {
491 // This method shall only be called if the user is logged-in
492 if (!this.userLoginController.isUserLoggedIn()) {
494 throw new IllegalStateException("User is not logged-in"); //NOI18N
495 } else if (!this.isRequiredChangePersonalDataSet()) {
496 // Not all required fields are set
497 throw new FaceletException("Not all required fields are set."); //NOI18N
498 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
499 // Password not matching
500 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
504 User user = this.userLoginController.getLoggedInUser();
506 // Copy contact data to contact instance
507 this.contactController.updateContactDataFromController(user.getUserContact());
509 // It should be there, so run some tests on it
510 assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N
511 assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N
512 assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
513 assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
514 assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
515 assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
518 user.setUserProfileMode(this.getUserProfileMode());
520 // Send it to the EJB
521 User updatedUser = this.userBean.updateUserPersonalData(user);
524 this.updatedPersonalDataEvent.fire(new UserUpdatedPersonalDataEvent(updatedUser));
527 return "user_data_saved"; //NOI18N
531 public Long getUserId () {
536 public void setUserId (final Long userId) {
537 this.userId = userId;
541 public String getUserName () {
542 return this.userName;
546 public void setUserName (final String userName) {
547 this.userName = userName;
551 public String getUserPassword () {
552 return this.userPassword;
556 public void setUserPassword (final String userPassword) {
557 this.userPassword = userPassword;
561 public String getUserPasswordRepeat () {
562 return this.userPasswordRepeat;
566 public void setUserPasswordRepeat (final String userPasswordRepeat) {
567 this.userPasswordRepeat = userPasswordRepeat;
571 public ProfileMode getUserProfileMode () {
572 return this.userProfileMode;
576 public void setUserProfileMode (final ProfileMode userProfileMode) {
577 this.userProfileMode = userProfileMode;
581 public boolean hasUsers () {
582 return (!this.allUsers().isEmpty());
586 * Post-initialization of this class
589 public void init () {
590 // Initialize user list
591 this.userList = this.userBean.allUsers();
593 // Get full user name list for reducing EJB calls
594 this.userNameList = this.userBean.getUserNameList();
596 // Is the user logged-in?
597 if (this.userLoginController.isUserLoggedIn()) {
598 // Is logged-in, so load also users visible to memebers
599 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
601 // Initialize user list
602 this.visibleUserList = this.userBean.allPublicUsers();
606 List<User> allUsers = this.allUsers();
609 List<Contact> allContacts = this.contactBean.getAllContacts();
612 Iterator<Contact> iterator = allContacts.iterator();
615 while (iterator.hasNext()) {
617 Contact next = iterator.next();
620 Iterator<User> userIterator = allUsers.iterator();
622 // Loop through all users
623 while (userIterator.hasNext()) {
625 User nextUser = userIterator.next();
628 if (Objects.equals(next, nextUser.getUserContact())) {
637 this.selectableContacts = allContacts;
641 public boolean isContactFound (final Contact contact) {
642 // The contact must be valid
643 if (null == contact) {
645 throw new NullPointerException("contact is null"); //NOI18N
646 } else if (contact.getContactId() == null) {
648 throw new NullPointerException("contact.contactId is null"); //NOI18N
649 } else if (contact.getContactId() < 1) {
651 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
654 // Default is not found
655 boolean isFound = false;
658 Iterator<User> iterator = this.allUsers().iterator();
660 // Loop through all entries
661 while (iterator.hasNext()) {
663 User next = iterator.next();
665 // Compare both objects
666 if (Objects.equals(contact, next.getUserContact())) {
678 public boolean isPublicUserProfileEnabled () {
679 // Get context parameter
680 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N
683 boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
685 // This requires user names being enabled, too.
686 if ((isEnabled) && (!this.isUserNameRequired())) {
687 // Not valid state, users must be able to modify their profile, especially when it is public
688 throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
696 public boolean isRequiredChangePersonalDataSet () {
697 return ((this.getUserProfileMode() != null) &&
698 (this.getUserName() != null) && (!this.getUserName().isEmpty()) &&
699 (this.contactController.isRequiredChangePersonalDataSet()));
703 public boolean isRequiredPersonalDataSet () {
704 if (this.registerController.isMultiplePageEnabled()) {
705 // Multiple registration page
706 return this.contactController.isRequiredPersonalDataSet();
708 // Single registration page
709 return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
710 (this.getUserProfileMode() != null) &&
711 (this.contactController.isRequiredPersonalDataSet()) &&
712 (this.getUserPassword() != null) &&
713 (this.getUserPasswordRepeat() != null));
718 public boolean isSamePasswordEntered () {
719 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
723 public boolean isUserIdEmpty () {
724 return ((this.getUserId() == null) || (this.getUserId() == 0));
728 public boolean isUserNameRegistered (final User user) {
729 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
733 public boolean isUserNameRequired () {
734 // Get context parameter
735 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N
738 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
745 public boolean isVisibleUserFound () {
746 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
750 public User lookupUserById (final Long userId) throws UserNotFoundException {
751 // Parameter must be valid
752 if (null == userId) {
754 throw new NullPointerException("userId is null"); //NOI18N
755 } else if (userId < 1) {
757 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
763 // Try to lookup it in visible user list
764 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
766 User next = iterator.next();
768 // Is the user id found?
769 if (Objects.equals(next.getUserId(), userId)) {
770 // Copy to other variable
778 // Not visible for the current user
779 throw new UserNotFoundException(userId);
787 public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
788 // Parameter must be valid
789 if (null == emailAddress) {
791 throw new NullPointerException("emailAddress is null"); //NOI18N
792 } else if (emailAddress.isEmpty()) {
794 throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
800 // Try to lookup it in visible user list
801 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
803 User next = iterator.next();
805 // Contact should be set
806 if (next.getUserContact() == null) {
808 throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
809 } else if (next.getUserContact().getContactEmailAddress() == null) {
810 // Email address should be set
811 throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N //NOI18N
814 // Is the email address found?
815 if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) {
816 // Copy to other variable
824 // Not visible for the current user
825 throw new UserEmailAddressNotFoundException(emailAddress);
833 public List<Contact> selectableContacts () {
834 return Collections.unmodifiableList(this.selectableContacts);
838 * Adds user's name to bean's internal list. It also updates the public user
839 * list if the user has decided to have a public account,
841 * @param user User instance
843 private void addUserName (final User user) {
844 // Make sure the entry is not added yet
845 if (this.userNameList.contains(user.getUserName())) {
847 throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
848 } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
850 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
854 this.userNameList.add(user.getUserName());
860 private void clear () {
863 this.setUserId(null);
864 this.setUserProfileMode(null);
867 this.setUserName(null);
868 this.setUserPassword(null);
869 this.setUserPasswordRepeat(null);
873 * Copies given user into the controller
875 * @param user User instance
877 private void copyUser (final User user) {
878 // Make sure the instance is valid
881 throw new NullPointerException("user is null"); //NOI18N
882 } else if (user.getUserContact() == null) {
884 throw new NullPointerException("user.userContact is null"); //NOI18N
889 this.setUserId(user.getUserId());
890 this.setUserProfileMode(user.getUserProfileMode());
894 * Updates list with given user instance
896 * @param user User instance
898 private void updateList (final User user) {
899 // The user should be valid
902 throw new NullPointerException("user is null"); //NOI18N
903 } else if (user.getUserId() == null) {
905 throw new NullPointerException("user.userId is null"); //NOI18N
906 } else if (user.getUserId() < 1) {
908 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
912 Iterator<User> iterator = this.userList.iterator();
915 while (iterator.hasNext()) {
917 User next = iterator.next();
919 // Is the same user id?
920 if (Objects.equals(user.getUserId(), next.getUserId())) {
921 // Found it, so remove it
922 this.userList.remove(next);
928 this.userList.add(user);