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