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