]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java
ea5cb658e89176e1613a6b788978ca50ed3fee77
[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.Date;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Objects;
25 import javax.annotation.PostConstruct;
26 import javax.enterprise.context.SessionScoped;
27 import javax.enterprise.event.Observes;
28 import javax.faces.view.facelets.FaceletException;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33 import javax.naming.NamingException;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.UserContact;
36 import org.mxchange.jcontacts.contact.gender.Gender;
37 import org.mxchange.jcountry.data.Country;
38 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
39 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
40 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
41 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
42 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
43 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
44 import org.mxchange.jphone.phonenumbers.smsprovider.MobileProvider;
45 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
46 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
47 import org.mxchange.jusercore.exceptions.UserNotFoundException;
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.addressbook.beans.login.AddressbookUserLoginWebSessionController;
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         /////////////////////// Properties /////////////////////
69         /**
70          * Birth day
71          */
72         private Date birthday;
73
74         /**
75          * Cellphone number's carrier
76          */
77         private MobileProvider cellphoneCarrier;
78
79         /**
80          * Cellphone number
81          */
82         private Long cellphoneNumber;
83
84         /**
85          * City
86          */
87         private String city;
88
89         /**
90          * Optional comments
91          */
92         private String comment;
93
94         /**
95          * Country instance
96          */
97         private Country country;
98
99         /**
100          * Email address
101          */
102         private String emailAddress;
103
104         /**
105          * Email address 1 (changing)
106          */
107         private String emailAddress1;
108
109         /**
110          * Email address 2 (repeat in changing)
111          */
112         private String emailAddress2;
113
114         /**
115          * Email address list
116          */
117         private List<String> emailAddressList;
118
119         /**
120          * Email address repeated
121          */
122         private String emailAddressRepeat;
123
124         /**
125          * Family name
126          */
127         private String familyName;
128
129         /**
130          * Fax number's area code
131          */
132         private Integer faxAreaCode;
133
134         /**
135          * Country instance for fax number
136          */
137         private Country faxCountry;
138
139         /**
140          * Fax number
141          */
142         private Long faxNumber;
143
144         /**
145          * First name
146          */
147         private String firstName;
148
149         /**
150          * Gender instance
151          */
152         private Gender gender;
153
154         /**
155          * House number
156          */
157         private Short houseNumber;
158
159         /**
160          * Login bean (controller)
161          */
162         @Inject
163         private AddressbookUserLoginWebSessionController loginController;
164
165         /**
166          * Phone number area code
167          */
168         private Integer phoneAreaCode;
169
170         /**
171          * Country instance for phone number
172          */
173         private Country phoneCountry;
174
175         /**
176          * Phone number
177          */
178         private Long phoneNumber;
179
180         /**
181          * Street
182          */
183         private String street;
184
185         /**
186          * Remote user bean
187          */
188         private final UserSessionBeanRemote userBean;
189
190         /**
191          * User id
192          */
193         private Long userId;
194
195         /**
196          * User name
197          */
198         private String userName;
199
200         /**
201          * User name list
202          */
203         private List<String> userNameList;
204
205         /**
206          * User password (unencrypted from web form)
207          */
208         private String userPassword;
209
210         /**
211          * User password repeated (unencrypted from web form)
212          */
213         private String userPasswordRepeat;
214
215         /**
216          * Whether the user wants a public profile
217          */
218         private ProfileMode userProfileMode;
219
220         /**
221          * A list of all public user profiles
222          */
223         private List<User> visibleUserList;
224
225         /**
226          * ZIP code
227          */
228         private Integer zipCode;
229
230         /**
231          * Default constructor
232          */
233         public AddressbookUserWebSessionBean () {
234                 // Set gender to UNKNOWN
235                 this.gender = Gender.UNKNOWN;
236
237                 // Try it
238                 try {
239                         // Get initial context
240                         Context context = new InitialContext();
241
242                         // Try to lookup
243                         this.userBean = (UserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
244                 } catch (final NamingException e) {
245                         // Throw again
246                         throw new FaceletException(e);
247                 }
248         }
249
250         @Override
251         public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) {
252                 // Trace message
253                 System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
254
255                 // event should not be null
256                 if (null == event) {
257                         // Throw NPE
258                         throw new NullPointerException("event is null"); //NOI18N
259                 } else if (event.getUser() == null) {
260                         // Throw NPE again
261                         throw new NullPointerException("event.user is null"); //NOI18N
262                 } else if (event.getUser().getUserId() == null) {
263                         // userId is null
264                         throw new NullPointerException("event.user.userId is null"); //NOI18N
265                 } else if (event.getUser().getUserId() < 1) {
266                         // Not avalid id
267                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUser(), event.getUser().getUserId())); //NOI18N
268                 }
269
270                 // Get user instance
271                 User registeredUser = event.getUser();
272
273                 // Debug message
274                 System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
275
276                 // Copy all data from registered->user
277                 this.copyUser(registeredUser);
278
279                 // Add user name and email address
280                 this.addUserNameEmailAddress(registeredUser);
281
282                 // Clear all data
283                 this.clearData();
284
285                 // Set user id again
286                 this.setUserId(registeredUser.getUserId());
287
288                 // Is the account public?
289                 if (registeredUser.getUserProfileMode().equals(ProfileMode.PUBLIC)) {
290                         // Also add it to this list
291                         this.visibleUserList.add(registeredUser);
292                 }
293
294                 // Trace message
295                 System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
296         }
297
298         @Override
299         public void afterUserLogin (final @Observes UserLoggedInEvent event) {
300                 // Trace message
301                 System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
302
303                 // event should not be null
304                 if (null == event) {
305                         // Throw NPE
306                         throw new NullPointerException("event is null"); //NOI18N
307                 } else if (event.getUser() == null) {
308                         // Throw NPE again
309                         throw new NullPointerException("event.user is null"); //NOI18N
310                 } else if (event.getUser().getUserId() == null) {
311                         // userId is null
312                         throw new NullPointerException("event.user.userId is null"); //NOI18N
313                 } else if (event.getUser().getUserId() < 1) {
314                         // Not avalid id
315                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUser(), event.getUser().getUserId())); //NOI18N
316                 }
317
318                 // Re-initialize list
319                 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
320
321                 // Copy all data to this bean
322                 this.copyUser(event.getUser());
323
324                 // Trace message
325                 System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
326         }
327
328         @Override
329         public List<User> allVisibleUsers () {
330                 // Return it
331                 return Collections.unmodifiableList(this.visibleUserList);
332         }
333
334         @Override
335         public User createUserInstance () {
336                 // User message
337                 //this.getLogger().logTrace("createUserInstance: CALLED!");
338
339                 // Required personal data must be set
340                 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
341
342                 // Create new user instance
343                 User user = new LoginUser();
344                 user.setUserName(this.getUserName());
345                 user.setUserProfileMode(this.getUserProfileMode());
346
347                 // Generate phone number
348                 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
349                 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
350                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
351
352                 // Create new contact
353                 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
354                 contact.setContactStreet(this.getStreet());
355                 contact.setContactHouseNumber(this.getHouseNumber());
356                 contact.setContactZipCode(this.getZipCode());
357                 contact.setContactCity(this.getCity());
358                 contact.setContactCountry(this.getCountry());
359                 contact.setContactEmailAddress(this.getEmailAddress());
360
361                 // Don't set null or wrong references
362                 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
363                         // Now the number must be given
364                         if (phone.getPhoneAreaCode() == null) {
365                                 // Is null
366                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
367                         } else if (phone.getPhoneAreaCode() < 1) {
368                                 // Abort here
369                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
370                         } else if (phone.getPhoneNumber() == null) {
371                                 // Is null
372                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
373                         } else if (phone.getPhoneNumber() < 1) {
374                                 // Abort here
375                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
376                         }
377
378                         // Set phone number
379                         contact.setContactLandLineNumber(phone);
380                 }
381
382                 // Don't set null or wrong references
383                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
384                         // Now the number must be given
385                         if (fax.getPhoneAreaCode() == null) {
386                                 // Is null
387                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
388                         } else if (fax.getPhoneAreaCode() < 1) {
389                                 // Abort here
390                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
391                         } else if (fax.getPhoneNumber() == null) {
392                                 // Is null
393                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
394                         } else if (fax.getPhoneNumber() < 1) {
395                                 // Abort here
396                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
397                         }
398
399                         // Set fax number
400                         contact.setContactFaxNumber(fax);
401                 }
402
403                 // Is the provider set?
404                 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
405                         // Is the number set?
406                         if (cellphone.getPhoneNumber() == null) {
407                                 // Is null
408                                 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
409                         } else if (cellphone.getPhoneNumber() < 1) {
410                                 // Abort here
411                                 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
412                         }
413
414                         // Set cellphone number
415                         contact.setContactCellphoneNumber(cellphone);
416                 }
417
418                 contact.setContactBirthday(this.getBirthday());
419                 contact.setContactComment(this.getComment());
420
421                 // Created timestamp and ownContact
422                 contact.setContactOwnContact(Boolean.TRUE);
423
424                 // Set contact in user
425                 user.setUserContact(contact);
426
427                 // Trace message
428                 //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user));
429
430                 // Return it
431                 return user;
432         }
433
434         @Override
435         public Date getBirthday () {
436                 return this.birthday;
437         }
438
439         @Override
440         public void setBirthday (final Date birthday) {
441                 this.birthday = birthday;
442         }
443
444         @Override
445         public MobileProvider getCellphoneCarrier () {
446                 return this.cellphoneCarrier;
447         }
448
449         @Override
450         public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
451                 this.cellphoneCarrier = cellphoneCarrier;
452         }
453
454         @Override
455         public Long getCellphoneNumber () {
456                 return this.cellphoneNumber;
457         }
458
459         @Override
460         public void setCellphoneNumber (Long cellphoneNumber) {
461                 this.cellphoneNumber = cellphoneNumber;
462         }
463
464         @Override
465         public String getCity () {
466                 return this.city;
467         }
468
469         @Override
470         public void setCity (final String city) {
471                 this.city = city;
472         }
473
474         @Override
475         public String getComment () {
476                 return this.comment;
477         }
478
479         @Override
480         public void setComment (final String comment) {
481                 this.comment = comment;
482         }
483
484         @Override
485         public Country getCountry () {
486                 return this.country;
487         }
488
489         @Override
490         public void setCountry (final Country country) {
491                 this.country = country;
492         }
493
494         @Override
495         public String getEmailAddress () {
496                 return this.emailAddress;
497         }
498
499         @Override
500         public void setEmailAddress (final String emailAddress) {
501                 this.emailAddress = emailAddress;
502         }
503
504         @Override
505         public String getEmailAddress1 () {
506                 return this.emailAddress1;
507         }
508
509         @Override
510         public void setEmailAddress1 (final String emailAddress1) {
511                 this.emailAddress1 = emailAddress1;
512         }
513
514         @Override
515         public String getEmailAddress2 () {
516                 return this.emailAddress2;
517         }
518
519         @Override
520         public void setEmailAddress2 (final String emailAddress2) {
521                 this.emailAddress2 = emailAddress2;
522         }
523
524         @Override
525         public String getEmailAddressRepeat () {
526                 return this.emailAddressRepeat;
527         }
528
529         @Override
530         public void setEmailAddressRepeat (final String emailAddressRepeat) {
531                 this.emailAddressRepeat = emailAddressRepeat;
532         }
533
534         @Override
535         public String getFamilyName () {
536                 return this.familyName;
537         }
538
539         @Override
540         public void setFamilyName (final String familyName) {
541                 this.familyName = familyName;
542         }
543
544         @Override
545         public Integer getFaxAreaCode () {
546                 return this.faxAreaCode;
547         }
548
549         @Override
550         public void setFaxAreaCode (final Integer faxAreaCode) {
551                 this.faxAreaCode = faxAreaCode;
552         }
553
554         @Override
555         public Country getFaxCountry () {
556                 return this.faxCountry;
557         }
558
559         @Override
560         public void setFaxCountry (final Country faxCountry) {
561                 this.faxCountry = faxCountry;
562         }
563
564         @Override
565         public Long getFaxNumber () {
566                 return this.faxNumber;
567         }
568
569         @Override
570         public void setFaxNumber (final Long faxNumber) {
571                 this.faxNumber = faxNumber;
572         }
573
574         @Override
575         public String getFirstName () {
576                 return this.firstName;
577         }
578
579         @Override
580         public void setFirstName (final String firstName) {
581                 this.firstName = firstName;
582         }
583
584         @Override
585         public Gender getGender () {
586                 return this.gender;
587         }
588
589         @Override
590         public void setGender (final Gender gender) {
591                 this.gender = gender;
592         }
593
594         @Override
595         public Short getHouseNumber () {
596                 return this.houseNumber;
597         }
598
599         @Override
600         public void setHouseNumber (final Short houseNumber) {
601                 this.houseNumber = houseNumber;
602         }
603
604         @Override
605         public Integer getPhoneAreaCode () {
606                 return this.phoneAreaCode;
607         }
608
609         @Override
610         public void setPhoneAreaCode (final Integer phoneAreaCode) {
611                 this.phoneAreaCode = phoneAreaCode;
612         }
613
614         @Override
615         public Country getPhoneCountry () {
616                 return this.phoneCountry;
617         }
618
619         @Override
620         public void setPhoneCountry (final Country phoneCountry) {
621                 this.phoneCountry = phoneCountry;
622         }
623
624         @Override
625         public Long getPhoneNumber () {
626                 return this.phoneNumber;
627         }
628
629         @Override
630         public void setPhoneNumber (final Long phoneNumber) {
631                 this.phoneNumber = phoneNumber;
632         }
633
634         @Override
635         public String getStreet () {
636                 return this.street;
637         }
638
639         @Override
640         public void setStreet (final String street) {
641                 this.street = street;
642         }
643
644         @Override
645         public Long getUserId () {
646                 return this.userId;
647         }
648
649         @Override
650         public void setUserId (final Long userId) {
651                 this.userId = userId;
652         }
653
654         @Override
655         public String getUserName () {
656                 return this.userName;
657         }
658
659         @Override
660         public void setUserName (final String userName) {
661                 this.userName = userName;
662         }
663
664         @Override
665         public String getUserPassword () {
666                 return this.userPassword;
667         }
668
669         @Override
670         public void setUserPassword (final String userPassword) {
671                 this.userPassword = userPassword;
672         }
673
674         @Override
675         public String getUserPasswordRepeat () {
676                 return this.userPasswordRepeat;
677         }
678
679         @Override
680         public void setUserPasswordRepeat (final String userPasswordRepeat) {
681                 this.userPasswordRepeat = userPasswordRepeat;
682         }
683
684         @Override
685         public ProfileMode getUserProfileMode () {
686                 return this.userProfileMode;
687         }
688
689         @Override
690         public void setUserProfileMode (final ProfileMode userProfileMode) {
691                 this.userProfileMode = userProfileMode;
692         }
693
694         @Override
695         public Integer getZipCode () {
696                 return this.zipCode;
697         }
698
699         @Override
700         public void setZipCode (final Integer zipCode) {
701                 this.zipCode = zipCode;
702         }
703
704         /**
705          * Post-initialization of this class
706          */
707         @PostConstruct
708         public void init () {
709                 // Get full user name list for reducing EJB calls
710                 this.userNameList = this.userBean.getUserNameList();
711
712                 // Get full email address list for reducing EJB calls
713                 this.emailAddressList = this.userBean.getEmailAddressList();
714
715                 // Is the user logged-in?
716                 if (this.loginController.isUserLoggedIn()) {
717                         // Is logged-in, so load also users visible to memebers
718                         this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
719                 } else {
720                         // Initialize user list
721                         this.visibleUserList = this.userBean.allPublicUsers();
722                 }
723         }
724
725         @Override
726         public boolean isEmailAddressRegistered (final User user) {
727                 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(user.getUserContact().getContactEmailAddress())));
728         }
729
730         @Override
731         public boolean isRequiredChangePersonalDataSet () {
732                 return ((this.getUserProfileMode() != null) &&
733                                 (this.getGender() != null) &&
734                                 (this.getFirstName() != null) &&
735                                 (this.getFamilyName() != null) &&
736                                 (this.getStreet() != null) &&
737                                 (this.getHouseNumber() != null) &&
738                                 (this.getZipCode() != null) &&
739                                 (this.getCity() != null));
740         }
741
742         @Override
743         public boolean isRequiredPersonalDataSet () {
744                 return ((this.getUserName() != null) &&
745                                 (this.getUserProfileMode() != null) &&
746                                 (this.getGender() != null) &&
747                                 (this.getFirstName() != null) &&
748                                 (this.getFamilyName() != null) &&
749                                 (this.getStreet() != null) &&
750                                 (this.getHouseNumber() != null) &&
751                                 (this.getZipCode() != null) &&
752                                 (this.getCity() != null) &&
753                                 (this.getEmailAddress() != null) &&
754                                 (this.getEmailAddressRepeat() != null) &&
755                                 (this.getUserPassword() != null) &&
756                                 (this.getUserPasswordRepeat() != null));
757         }
758
759         @Override
760         public boolean isSameEmailAddressEntered () {
761                 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
762         }
763
764         @Override
765         public boolean isSamePasswordEntered () {
766                 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
767         }
768
769         @Override
770         public boolean isUserIdEmpty () {
771                 return ((this.getUserId() == null) || (this.getUserId() == 0));
772         }
773
774         @Override
775         public boolean isUserNameRegistered (final User user) {
776                 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
777         }
778
779         @Override
780         public boolean isVisibleUserFound () {
781                 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
782         }
783
784         @Override
785         public User lookupUserById (final Long userId) throws UserNotFoundException {
786                 // Init variable
787                 User user = null;
788
789                 // Try to lookup it in visible user list
790                 for (final Iterator<User> iterator = this.visibleUserList.iterator(); iterator.hasNext();) {
791                         // Get next user
792                         User next = iterator.next();
793
794                         // Is the user id found?
795                         if (Objects.equals(next.getUserId(), userId)) {
796                                 // Copy to other variable
797                                 user = next;
798                                 break;
799                         }
800                 }
801
802                 // Is it still null?
803                 if (null == user) {
804                         // Not visible for the current user
805                         throw new UserNotFoundException(userId);
806                 }
807
808                 // Return it
809                 return user;
810         }
811
812         /**
813          * Adds user's name and email address to bean's internal list. It also
814          * updates the public user list if the user has decided to ha   }
815          * <p>
816          * @param user User instance
817          */
818         private void addUserNameEmailAddress (final User user) {
819                 // Make sure the entry is not added yet
820                 if (this.userNameList.contains(user.getUserName())) {
821                         // Abort here
822                         throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
823                 } else if (this.emailAddressList.contains(user.getUserContact().getContactEmailAddress())) {
824                         // Already added
825                         throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
826                 }
827
828                 // Add user name
829                 this.userNameList.add(user.getUserName());
830
831                 // Add email addres
832                 this.emailAddressList.add(user.getUserContact().getContactEmailAddress());
833         }
834
835         /**
836          * Clears all data in this bean
837          */
838         private void clearData () {
839                 // Clear all data
840                 // - personal data
841                 this.setUserId(null);
842                 this.setGender(Gender.UNKNOWN);
843                 this.setUserProfileMode(null);
844                 this.setFirstName(null);
845                 this.setFamilyName(null);
846                 this.setStreet(null);
847                 this.setHouseNumber(null);
848                 this.setZipCode(null);
849                 this.setCity(null);
850                 this.setCountry(null);
851
852                 // - contact data
853                 this.setEmailAddress(null);
854                 this.setEmailAddressRepeat(null);
855                 this.setPhoneAreaCode(null);
856                 this.setCellphoneCarrier(null);
857                 this.setFaxAreaCode(null);
858
859                 // - other data
860                 this.setBirthday(null);
861                 this.setComment(null);
862                 this.setUserName(null);
863                 this.setUserPassword(null);
864                 this.setUserPasswordRepeat(null);
865         }
866
867         /**
868          * Copies given user into the controller
869          * <p>
870          * @param user User instance
871          */
872         private void copyUser (final User user) {
873                 // Copy all fields:
874                 // - base data
875                 this.setUserId(user.getUserId());
876                 this.setUserProfileMode(user.getUserProfileMode());
877                 this.setGender(user.getUserContact().getContactGender());
878                 this.setFirstName(user.getUserContact().getContactFirstName());
879                 this.setFamilyName(user.getUserContact().getContactFamilyName());
880                 this.setStreet(user.getUserContact().getContactStreet());
881                 this.setHouseNumber(user.getUserContact().getContactHouseNumber());
882                 this.setZipCode(user.getUserContact().getContactZipCode());
883                 this.setCity(user.getUserContact().getContactCity());
884                 this.setCountry(user.getUserContact().getContactCountry());
885
886                 // Get cellphone, phone and fax instance
887                 DialableCellphoneNumber cellphone = user.getUserContact().getContactCellphoneNumber();
888                 DialableFaxNumber fax = user.getUserContact().getContactFaxNumber();
889                 DialableLandLineNumber phone = user.getUserContact().getContactLandLineNumber();
890
891                 // - contact data
892                 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
893                         this.setPhoneCountry(phone.getPhoneCountry());
894                         this.setPhoneAreaCode(phone.getPhoneAreaCode());
895                         this.setPhoneNumber(phone.getPhoneNumber());
896                 }
897                 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
898                         this.setCellphoneCarrier(cellphone.getCellphoneProvider());
899                         this.setCellphoneNumber(cellphone.getPhoneNumber());
900                 }
901                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
902                         this.setFaxCountry(fax.getPhoneCountry());
903                         this.setFaxAreaCode(fax.getPhoneAreaCode());
904                         this.setFaxNumber(fax.getPhoneNumber());
905                 }
906                 this.setEmailAddress(user.getUserContact().getContactEmailAddress());
907
908                 // -- other data
909                 this.setBirthday(user.getUserContact().getContactBirthday());
910                 this.setComment(user.getUserContact().getContactComment());
911         }
912 }