]> git.mxchange.org Git - jjobs-war.git/blob - src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java
Continued a bit:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / user / JobsUserWebSessionBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jjobs.beans.user;
18
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.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.contact.JobsContactWebSessionController;
37 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
38 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
39 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
40 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
41 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
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.update.AdminUpdatedUserDataEvent;
46 import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
47 import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent;
48 import org.mxchange.jusercore.exceptions.UserNotFoundException;
49 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
50 import org.mxchange.jusercore.model.user.LoginUser;
51 import org.mxchange.jusercore.model.user.User;
52 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
53 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
54
55 /**
56  * A user bean (controller)
57  * <p>
58  * @author Roland Haeder<roland@mxchange.org>
59  */
60 @Named ("userController")
61 @SessionScoped
62 public class JobsUserWebSessionBean implements JobsUserWebSessionController {
63
64         /**
65          * Serial number
66          */
67         private static final long serialVersionUID = 542_145_347_916L;
68
69         /**
70          * General contact controller
71          */
72         @Inject
73         private JobsContactWebSessionController contactController;
74
75         /**
76          * A list of all selectable contacts
77          */
78         private List<Contact> selectableContacts;
79
80         /**
81          * Event being fired when user updated personal data
82          */
83         @Inject
84         @Any
85         private Event<UpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
86
87         /**
88          * Remote user bean
89          */
90         private final UserSessionBeanRemote userBean;
91
92         /**
93          * User id
94          */
95         private Long userId;
96
97         /**
98          * A list of all user profiles
99          */
100         private List<User> userList;
101
102         /**
103          * Login bean (controller)
104          */
105         @Inject
106         private JobsUserLoginWebSessionController userLoginController;
107
108         /**
109          * User name
110          */
111         private String userName;
112
113         /**
114          * User name list
115          */
116         private List<String> userNameList;
117
118         /**
119          * User password (unencrypted from web form)
120          */
121         private String userPassword;
122
123         /**
124          * User password repeated (unencrypted from web form)
125          */
126         private String userPasswordRepeat;
127
128         /**
129          * Whether the user wants a public profile
130          */
131         private ProfileMode userProfileMode;
132
133         /**
134          * A list of all public user profiles
135          */
136         private List<User> visibleUserList;
137
138         /**
139          * Default constructor
140          */
141         public JobsUserWebSessionBean () {
142                 // Try it
143                 try {
144                         // Get initial context
145                         Context context = new InitialContext();
146
147                         // Try to lookup
148                         this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
149                 } catch (final NamingException e) {
150                         // Throw again
151                         throw new FaceletException(e);
152                 }
153         }
154
155         @Override
156         public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
157                 // Trace message
158                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
159
160                 // event should not be null
161                 if (null == event) {
162                         // Throw NPE
163                         throw new NullPointerException("event is null"); //NOI18N
164                 } else if (event.getAddedUser() == null) {
165                         // Throw NPE again
166                         throw new NullPointerException("event.addedUser is null"); //NOI18N
167                 } else if (event.getAddedUser().getUserId() == null) {
168                         // userId is null
169                         throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
170                 } else if (event.getAddedUser().getUserId() < 1) {
171                         // Not avalid id
172                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
173                 }
174
175                 // Add user to local list
176                 this.userList.add(event.getAddedUser());
177
178                 // Clear all data
179                 this.clear();
180
181                 // Set user id again
182                 this.setUserId(event.getAddedUser().getUserId());
183
184                 // Trace message
185                 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
186         }
187
188         @Override
189         public void afterAdminUpdatedUserDataEvent (@Observes final AdminUpdatedUserDataEvent event) {
190                 // Trace message
191                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N
192
193                 // event should not be null
194                 if (null == event) {
195                         // Throw NPE
196                         throw new NullPointerException("event is null"); //NOI18N
197                 } else if (event.getUpdatedUser() == null) {
198                         // Throw NPE again
199                         throw new NullPointerException("event.updatedUser is null"); //NOI18N
200                 } else if (event.getUpdatedUser().getUserId() == null) {
201                         // userId is null
202                         throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
203                 } else if (event.getUpdatedUser().getUserId() < 1) {
204                         // Not avalid id
205                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
206                 }
207
208                 // Update list
209                 this.updateList(event.getUpdatedUser());
210
211                 // Clear all data
212                 this.clear();
213
214                 // Trace message
215                 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
216         }
217
218         @Override
219         public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
220                 // Trace message
221                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
222
223                 // event should not be null
224                 if (null == event) {
225                         // Throw NPE
226                         throw new NullPointerException("event is null"); //NOI18N
227                 } else if (event.getRegisteredUser() == null) {
228                         // Throw NPE again
229                         throw new NullPointerException("event.registeredUser is null"); //NOI18N
230                 } else if (event.getRegisteredUser().getUserId() == null) {
231                         // userId is null
232                         throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
233                 } else if (event.getRegisteredUser().getUserId() < 1) {
234                         // Not avalid id
235                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
236                 }
237
238                 // Get user instance
239                 User registeredUser = event.getRegisteredUser();
240
241                 // Debug message
242                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
243
244                 // Copy all data from registered->user
245                 this.copyUser(registeredUser);
246
247                 // Clear all data
248                 this.clear();
249
250                 // Add user to local list
251                 this.userList.add(registeredUser);
252
253                 // Add user name
254                 this.addUserName(registeredUser);
255
256                 // Is the account public?
257                 if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
258                         // Also add it to this list
259                         this.visibleUserList.add(registeredUser);
260                 }
261
262                 // Set user id again
263                 this.setUserId(registeredUser.getUserId());
264
265                 // Trace message
266                 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
267         }
268
269         @Override
270         public void afterUserLogin (final @Observes UserLoggedInEvent event) {
271                 // Trace message
272                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
273
274                 // event should not be null
275                 if (null == event) {
276                         // Throw NPE
277                         throw new NullPointerException("event is null"); //NOI18N
278                 } else if (event.getLoggedInUser() == null) {
279                         // Throw NPE again
280                         throw new NullPointerException("event.registeredUser is null"); //NOI18N
281                 } else if (event.getLoggedInUser().getUserId() == null) {
282                         // userId is null
283                         throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
284                 } else if (event.getLoggedInUser().getUserId() < 1) {
285                         // Not avalid id
286                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
287                 }
288
289                 // Copy all data to this bean
290                 this.copyUser(event.getLoggedInUser());
291
292                 // Re-initialize list
293                 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
294
295                 // Trace message
296                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
297         }
298
299         @Override
300         public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
301                 // Check parameter
302                 if (null == event) {
303                         // Throw NPE
304                         throw new NullPointerException("event is null"); //NOI18N
305                 } else if (event.getUpdatedUser() == null) {
306                         // Throw NPE again
307                         throw new NullPointerException("event.updatedUser is null"); //NOI18N
308                 } else if (event.getUpdatedUser().getUserId() == null) {
309                         // ... and again
310                         throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
311                 } else if (event.getUpdatedUser().getUserId() < 1) {
312                         // Invalid value
313                         throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
314                 }
315
316                 // All fine, so update list
317                 this.updateList(event.getUpdatedUser());
318         }
319
320         @Override
321         public List<User> allUsers () {
322                 // Return it
323                 return Collections.unmodifiableList(this.userList);
324         }
325
326         @Override
327         public List<User> allVisibleUsers () {
328                 // Return it
329                 return Collections.unmodifiableList(this.visibleUserList);
330         }
331
332         @Override
333         public User createUserInstance () {
334                 // Trace message
335                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: CALLED!", this.getClass().getSimpleName()));
336
337                 // Required personal data must be set
338                 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
339
340                 // Create new user instance
341                 User localUser = new LoginUser();
342
343                 // Update all data ...
344                 localUser.setUserName(this.getUserName());
345                 localUser.setUserProfileMode(this.getUserProfileMode());
346
347                 // Create contact instance
348                 Contact contact = this.contactController.createContactInstance();
349
350                 // Debug message
351                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact));
352
353                 // Set contact in user
354                 localUser.setUserContact(contact);
355
356                 // Trace message
357                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: user={1} - EXIT!", this.getClass().getSimpleName(), user));
358
359                 // Return it
360                 return localUser;
361         }
362
363         @Override
364         public User createUserLogin () {
365                 // Trace message
366                 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: CALLED!", this.getClass().getSimpleName()));
367
368                 // Is all data set?
369                 if (this.getUserName() == null) {
370                         // Throw NPE
371                         throw new NullPointerException("recruiterName is null"); //NOI18N
372                 } else if (this.getUserName().isEmpty()) {
373                         // Is empty
374                         throw new IllegalStateException("recruiterName is empty."); //NOI18N
375                 }
376
377                 // Create new recruiter instance
378                 User recruiter = new LoginUser();
379
380                 // Update all data ...
381                 recruiter.setUserName(this.getUserName());
382
383                 // Trace message
384                 //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: recruiter={1} - EXIT!", this.getClass().getSimpleName(), recruiter));
385
386                 // Return the new instance
387                 return recruiter;
388         }
389
390         @Override
391         public String doChangePersonalData () {
392                 // This method shall only be called if the user is logged-in
393                 if (!this.userLoginController.isUserLoggedIn()) {
394                         // Not logged-in
395                         throw new IllegalStateException("User is not logged-in"); //NOI18N
396                 } else if (!this.isRequiredChangePersonalDataSet()) {
397                         // Not all required fields are set
398                         throw new FaceletException("Not all required fields are set."); //NOI18N
399                 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
400                         // Password not matching
401                         throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
402                 }
403
404                 // Get user instance
405                 User user = this.userLoginController.getLoggedInUser();
406
407                 // Copy contact data to contact instance
408                 this.contactController.updateContactDataFromController(user.getUserContact());
409
410                 // It should be there, so run some tests on it
411                 assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N
412                 assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N
413                 assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N
414                 assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
415                 assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
416                 assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
417
418                 // Update all fields
419                 user.setUserProfileMode(this.getUserProfileMode());
420
421                 // Send it to the EJB
422                 User updatedUser = this.userBean.updateUserPersonalData(user);
423
424                 // Fire event
425                 this.updatedPersonalDataEvent.fire(new UserUpdatedPersonalDataEvent(updatedUser));
426
427                 // All fine
428                 return "user_data_saved"; //NOI18N
429         }
430
431         @Override
432         public Long getUserId () {
433                 return this.userId;
434         }
435
436         @Override
437         public void setUserId (final Long userId) {
438                 this.userId = userId;
439         }
440
441         @Override
442         public String getUserName () {
443                 return this.userName;
444         }
445
446         @Override
447         public void setUserName (final String userName) {
448                 this.userName = userName;
449         }
450
451         @Override
452         public String getUserPassword () {
453                 return this.userPassword;
454         }
455
456         @Override
457         public void setUserPassword (final String userPassword) {
458                 this.userPassword = userPassword;
459         }
460
461         @Override
462         public String getUserPasswordRepeat () {
463                 return this.userPasswordRepeat;
464         }
465
466         @Override
467         public void setUserPasswordRepeat (final String userPasswordRepeat) {
468                 this.userPasswordRepeat = userPasswordRepeat;
469         }
470
471         @Override
472         public ProfileMode getUserProfileMode () {
473                 return this.userProfileMode;
474         }
475
476         @Override
477         public void setUserProfileMode (final ProfileMode userProfileMode) {
478                 this.userProfileMode = userProfileMode;
479         }
480
481         @Override
482         public boolean hasUsers () {
483                 return (!this.allUsers().isEmpty());
484         }
485
486         /**
487          * Post-initialization of this class
488          */
489         @PostConstruct
490         public void init () {
491                 // Initialize user list
492                 this.userList = this.userBean.allUsers();
493
494                 // Get full user name list for reducing EJB calls
495                 this.userNameList = this.userBean.getUserNameList();
496
497                 // Is the user logged-in?
498                 if (this.userLoginController.isUserLoggedIn()) {
499                         // Is logged-in, so load also users visible to memebers
500                         this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
501                 } else {
502                         // Initialize user list
503                         this.visibleUserList = this.userBean.allPublicUsers();
504                 }
505
506                 // Get all users
507                 List<User> allUsers = this.allUsers();
508
509                 // Get all contacts
510                 List<Contact> allContacts = this.contactController.allContacts();
511
512                 // Get iterator
513                 Iterator<Contact> iterator = allContacts.iterator();
514
515                 // Loop through it
516                 while (iterator.hasNext()) {
517                         // Get next element
518                         Contact next = iterator.next();
519
520                         // Get iterator
521                         Iterator<User> userIterator = allUsers.iterator();
522
523                         // Loop through all users
524                         while (userIterator.hasNext()) {
525                                 // Get user instance
526                                 User nextUser = userIterator.next();
527
528                                 // Is contact same?
529                                 if (Objects.equals(next, nextUser.getUserContact())) {
530                                         // Found same
531                                         iterator.remove();
532                                         break;
533                                 }
534                         }
535                 }
536
537                 // Set contact list
538                 this.selectableContacts = allContacts;
539         }
540
541         @Override
542         public boolean isContactFound (final Contact contact) {
543                 // The contact must be valid
544                 if (null == contact) {
545                         // Throw NPE
546                         throw new NullPointerException("contact is null"); //NOI18N
547                 } else if (contact.getContactId() == null) {
548                         // Throw again ...
549                         throw new NullPointerException("contact.contactId is null"); //NOI18N
550                 } else if (contact.getContactId() < 1) {
551                         // Not valid
552                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
553                 }
554
555                 // Default is not found
556                 boolean isFound = false;
557
558                 // Get iterator
559                 Iterator<User> iterator = this.allUsers().iterator();
560
561                 // Loop through all entries
562                 while (iterator.hasNext()) {
563                         // Get user
564                         User next = iterator.next();
565
566                         // Compare both objects
567                         if (Objects.equals(contact, next.getUserContact())) {
568                                 // Found it
569                                 isFound = true;
570                                 break;
571                         }
572                 }
573
574                 // Return status
575                 return isFound;
576         }
577
578         @Override
579         public boolean isRequiredChangePersonalDataSet () {
580                 return ((this.getUserProfileMode() != null) &&
581                                 (this.getUserName() != null) && (!this.getUserName().isEmpty()) &&
582                                 (this.contactController.isRequiredChangePersonalDataSet()));
583         }
584
585         @Override
586         public boolean isRequiredPersonalDataSet () {
587                 return ((this.getUserName() != null) &&
588                                 (this.getUserProfileMode() != null) &&
589                                 (this.contactController.isRequiredPersonalDataSet()) &&
590                                 (this.getUserPassword() != null) &&
591                                 (this.getUserPasswordRepeat() != null));
592         }
593
594         @Override
595         public boolean isSamePasswordEntered () {
596                 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
597         }
598
599         @Override
600         public boolean isUserIdEmpty () {
601                 return ((this.getUserId() == null) || (this.getUserId() == 0));
602         }
603
604         @Override
605         public boolean isUserNameRegistered (final User user) {
606                 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
607         }
608
609         @Override
610         public boolean isVisibleUserFound () {
611                 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
612         }
613
614         @Override
615         public User lookupUserById (final Long userId) throws UserNotFoundException {
616                 // Parameter must be valid
617                 if (null == userId) {
618                         // Throw NPE
619                         throw new NullPointerException("userId is null"); //NOI18N
620                 } else if (userId < 1) {
621                         // Not valid
622                         throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
623                 }
624
625                 // Init variable
626                 User user = null;
627
628                 // Try to lookup it in visible user list
629                 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
630                         // Get next user
631                         User next = iterator.next();
632
633                         // Is the user id found?
634                         if (Objects.equals(next.getUserId(), userId)) {
635                                 // Copy to other variable
636                                 user = next;
637                                 break;
638                         }
639                 }
640
641                 // Is it still null?
642                 if (null == user) {
643                         // Not visible for the current user
644                         throw new UserNotFoundException(userId);
645                 }
646
647                 // Return it
648                 return user;
649         }
650
651         @Override
652         public List<Contact> selectableContacts () {
653                 return Collections.unmodifiableList(this.selectableContacts);
654         }
655
656         /**
657          * Adds user's name to bean's internal list. It also updates the public user
658          * list if the user has decided to have a public account,
659          * <p>
660          * @param user User instance
661          */
662         private void addUserName (final User user) {
663                 // Make sure the entry is not added yet
664                 if (this.userNameList.contains(user.getUserName())) {
665                         // Abort here
666                         throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
667                 } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
668                         // Already added
669                         throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
670                 }
671
672                 // Add user name
673                 this.userNameList.add(user.getUserName());
674         }
675
676         /**
677          * Clears this bean
678          */
679         private void clear () {
680                 // Clear all data
681                 // - personal data
682                 this.setUserId(null);
683                 this.setUserProfileMode(null);
684
685                 // - other data
686                 this.setUserName(null);
687                 this.setUserPassword(null);
688                 this.setUserPasswordRepeat(null);
689         }
690
691         /**
692          * Copies given user into the controller
693          * <p>
694          * @param user User instance
695          */
696         private void copyUser (final User user) {
697                 // Make sure the instance is valid
698                 if (null == user) {
699                         // Throw NPE
700                         throw new NullPointerException("user is null"); //NOI18N
701                 } else if (user.getUserContact() == null) {
702                         // Throw again ...
703                         throw new NullPointerException("user.userContact is null"); //NOI18N
704                 }
705
706                 // Copy all fields:
707                 // - base data
708                 this.setUserId(user.getUserId());
709                 this.setUserProfileMode(user.getUserProfileMode());
710         }
711
712         /**
713          * Updates list with given user instance
714          * <p>
715          * @param user User instance
716          */
717         private void updateList (final User user) {
718                 // The user should be valid
719                 if (null == user) {
720                         // Throw NPE
721                         throw new NullPointerException("user is null"); //NOI18N
722                 } else if (user.getUserId() == null) {
723                         // ... again NPE
724                         throw new NullPointerException("user.userId is null"); //NOI18N
725                 } else if (user.getUserId() < 1) {
726                         // Invalid id
727                         throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
728                 }
729
730                 // Get iterator
731                 Iterator<User> iterator = this.userList.iterator();
732
733                 // Look whole list
734                 while (iterator.hasNext()) {
735                         // Get next element
736                         User next = iterator.next();
737
738                         // Is the same user id?
739                         if (Objects.equals(user.getUserId(), next.getUserId())) {
740                                 // Found it, so remove it
741                                 this.userList.remove(next);
742                                 break;
743                         }
744                 }
745
746                 // Re-add item
747                 this.userList.add(user);
748         }
749
750 }