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