]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/beans/user/UserWebSessionBean.java
Some improvements:
[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                 // Copy all data to this bean
313                 this.copyUser(event.getUser());
314
315                 // Trace message
316                 System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
317         }
318
319         @Override
320         public List<User> allVisibleUsers () {
321                 // Return it
322                 return Collections.unmodifiableList(this.visibleUserList);
323         }
324
325         @Override
326         public User createUserInstance () {
327                 // User message
328                 //this.getLogger().logTrace("createUserInstance: CALLED!");
329
330                 // Required personal data must be set
331                 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
332
333                 // Create new user instance
334                 User user = new LoginUser();
335                 user.setUserName(this.getUserName());
336                 user.setUserProfileMode(this.getUserProfileMode());
337                 user.setUserCreated(new GregorianCalendar());
338
339                 // Generate phone number
340                 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber(), new GregorianCalendar());
341                 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber(), new GregorianCalendar());
342                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber(), new GregorianCalendar());
343
344                 // Create new contact
345                 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
346                 contact.setContactStreet(this.getStreet());
347                 contact.setContactHouseNumber(this.getHouseNumber());
348                 contact.setContactZipCode(this.getZipCode());
349                 contact.setContactCity(this.getCity());
350                 contact.setContactCountry(this.getCountry());
351                 contact.setContactEmailAddress(this.getEmailAddress());
352
353                 // Don't set null or wrong references
354                 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
355                         // Now the number must be given
356                         if (phone.getPhoneAreaCode() == null) {
357                                 // Is null
358                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
359                         } else if (phone.getPhoneAreaCode() < 1) {
360                                 // Abort here
361                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
362                         } else if (phone.getPhoneNumber() == null) {
363                                 // Is null
364                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
365                         } else if (phone.getPhoneNumber() < 1) {
366                                 // Abort here
367                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
368                         }
369
370                         // Set phone number
371                         contact.setContactPhoneNumber(phone);
372                 }
373
374                 // Don't set null or wrong references
375                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
376                         // Now the number must be given
377                         if (fax.getPhoneAreaCode() == null) {
378                                 // Is null
379                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
380                         } else if (fax.getPhoneAreaCode() < 1) {
381                                 // Abort here
382                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
383                         } else if (fax.getPhoneNumber() == null) {
384                                 // Is null
385                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
386                         } else if (fax.getPhoneNumber() < 1) {
387                                 // Abort here
388                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
389                         }
390
391                         // Set fax number
392                         contact.setContactFaxNumber(fax);
393                 }
394
395                 // Is the provider set?
396                 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof SmsProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
397                         // Is the number set?
398                         if (cellphone.getPhoneNumber() == null) {
399                                 // Is null
400                                 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
401                         } else if (cellphone.getPhoneNumber() < 1) {
402                                 // Abort here
403                                 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
404                         }
405
406                         // Set cellphone number
407                         contact.setContactCellphoneNumber(cellphone);
408                 }
409
410                 contact.setContactBirthday(this.getBirthday());
411                 contact.setContactComment(this.getComment());
412
413                 // Created timestamp and ownContact
414                 contact.setContactCreated(new GregorianCalendar());
415                 contact.setContactOwnContact(Boolean.TRUE);
416
417                 // Set contact in user
418                 user.setUserContact(contact);
419
420                 // Trace message
421                 //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user));
422                 // Return it
423                 return user;
424         }
425
426         @Override
427         public Date getBirthday () {
428                 return this.birthday;
429         }
430
431         @Override
432         public void setBirthday (final Date birthday) {
433                 this.birthday = birthday;
434         }
435
436         @Override
437         public SmsProvider getCellphoneCarrier () {
438                 return this.cellphoneCarrier;
439         }
440
441         @Override
442         public void setCellphoneCarrier (final SmsProvider cellphoneCarrier) {
443                 this.cellphoneCarrier = cellphoneCarrier;
444         }
445
446         @Override
447         public Long getCellphoneNumber () {
448                 return this.cellphoneNumber;
449         }
450
451         @Override
452         public void setCellphoneNumber (Long cellphoneNumber) {
453                 this.cellphoneNumber = cellphoneNumber;
454         }
455
456         @Override
457         public String getCity () {
458                 return this.city;
459         }
460
461         @Override
462         public void setCity (final String city) {
463                 this.city = city;
464         }
465
466         @Override
467         public String getComment () {
468                 return this.comment;
469         }
470
471         @Override
472         public void setComment (final String comment) {
473                 this.comment = comment;
474         }
475
476         @Override
477         public Country getCountry () {
478                 return this.country;
479         }
480
481         @Override
482         public void setCountry (final Country country) {
483                 this.country = country;
484         }
485
486         @Override
487         public String getEmailAddress () {
488                 return this.emailAddress;
489         }
490
491         @Override
492         public void setEmailAddress (final String emailAddress) {
493                 this.emailAddress = emailAddress;
494         }
495
496         @Override
497         public String getEmailAddressRepeat () {
498                 return this.emailAddressRepeat;
499         }
500
501         @Override
502         public void setEmailAddressRepeat (final String emailAddressRepeat) {
503                 this.emailAddressRepeat = emailAddressRepeat;
504         }
505
506         @Override
507         public String getFamilyName () {
508                 return this.familyName;
509         }
510
511         @Override
512         public void setFamilyName (final String familyName) {
513                 this.familyName = familyName;
514         }
515
516         @Override
517         public Integer getFaxAreaCode () {
518                 return this.faxAreaCode;
519         }
520
521         @Override
522         public void setFaxAreaCode (final Integer faxAreaCode) {
523                 this.faxAreaCode = faxAreaCode;
524         }
525
526         @Override
527         public Country getFaxCountry () {
528                 return this.faxCountry;
529         }
530
531         @Override
532         public void setFaxCountry (final Country faxCountry) {
533                 this.faxCountry = faxCountry;
534         }
535
536         @Override
537         public Long getFaxNumber () {
538                 return this.faxNumber;
539         }
540
541         @Override
542         public void setFaxNumber (final Long faxNumber) {
543                 this.faxNumber = faxNumber;
544         }
545
546         @Override
547         public String getFirstName () {
548                 return this.firstName;
549         }
550
551         @Override
552         public void setFirstName (final String firstName) {
553                 this.firstName = firstName;
554         }
555
556         @Override
557         public Gender getGender () {
558                 return this.gender;
559         }
560
561         @Override
562         public void setGender (final Gender gender) {
563                 this.gender = gender;
564         }
565
566         @Override
567         public Short getHouseNumber () {
568                 return this.houseNumber;
569         }
570
571         @Override
572         public void setHouseNumber (final Short houseNumber) {
573                 this.houseNumber = houseNumber;
574         }
575
576         @Override
577         public Integer getPhoneAreaCode () {
578                 return this.phoneAreaCode;
579         }
580
581         @Override
582         public void setPhoneAreaCode (final Integer phoneAreaCode) {
583                 this.phoneAreaCode = phoneAreaCode;
584         }
585
586         @Override
587         public Country getPhoneCountry () {
588                 return this.phoneCountry;
589         }
590
591         @Override
592         public void setPhoneCountry (final Country phoneCountry) {
593                 this.phoneCountry = phoneCountry;
594         }
595
596         @Override
597         public Long getPhoneNumber () {
598                 return this.phoneNumber;
599         }
600
601         @Override
602         public void setPhoneNumber (final Long phoneNumber) {
603                 this.phoneNumber = phoneNumber;
604         }
605
606         @Override
607         public String getStreet () {
608                 return this.street;
609         }
610
611         @Override
612         public void setStreet (final String street) {
613                 this.street = street;
614         }
615
616         @Override
617         public Long getUserId () {
618                 return this.userId;
619         }
620
621         @Override
622         public void setUserId (final Long userId) {
623                 this.userId = userId;
624         }
625
626         @Override
627         public String getUserName () {
628                 return this.userName;
629         }
630
631         @Override
632         public void setUserName (final String userName) {
633                 this.userName = userName;
634         }
635
636         @Override
637         public String getUserPassword () {
638                 return this.userPassword;
639         }
640
641         @Override
642         public void setUserPassword (final String userPassword) {
643                 this.userPassword = userPassword;
644         }
645
646         @Override
647         public String getUserPasswordRepeat () {
648                 return this.userPasswordRepeat;
649         }
650
651         @Override
652         public void setUserPasswordRepeat (final String userPasswordRepeat) {
653                 this.userPasswordRepeat = userPasswordRepeat;
654         }
655
656         @Override
657         public ProfileMode getUserProfileMode () {
658                 return this.userProfileMode;
659         }
660
661         @Override
662         public void setUserProfileMode (final ProfileMode userProfileMode) {
663                 this.userProfileMode = userProfileMode;
664         }
665
666         @Override
667         public Integer getZipCode () {
668                 return this.zipCode;
669         }
670
671         @Override
672         public void setZipCode (final Integer zipCode) {
673                 this.zipCode = zipCode;
674         }
675
676         /**
677          * Post-initialization of this class
678          */
679         @PostConstruct
680         public void init () {
681                 // Get full user name list for reducing EJB calls
682                 this.userNameList = this.userBean.getUserNameList();
683
684                 // Get full email address list for reducing EJB calls
685                 this.emailAddressList = this.userBean.getEmailAddressList();
686
687                 // Is the user logged-in?
688                 if (this.loginController.isUserLoggedIn()) {
689                         // Is logged-in, so load also users visible to memebers
690                         this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
691                 } else {
692                         // Initialize user list
693                         this.visibleUserList = this.userBean.allPublicUsers();
694                 }
695         }
696
697         @Override
698         public boolean isEmailAddressRegistered (final User user) {
699                 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(user.getUserContact().getContactEmailAddress())));
700         }
701
702         @Override
703         public boolean isRequiredPersonalDataSet () {
704                 return ((this.getUserName() != null) &&
705                                 (this.getUserProfileMode() != null) &&
706                                 (this.getGender() != null) &&
707                                 (this.getFirstName() != null) &&
708                                 (this.getFamilyName() != null) &&
709                                 (this.getStreet() != null) &&
710                                 (this.getHouseNumber() != null) &&
711                                 (this.getZipCode() != null) &&
712                                 (this.getCity() != null) &&
713                                 (this.getEmailAddress() != null) &&
714                                 (this.getEmailAddressRepeat() != null) &&
715                                 (this.getUserPassword() != null) &&
716                                 (this.getUserPasswordRepeat() != null));
717         }
718
719         @Override
720         public boolean isSameEmailAddressEntered () {
721                 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
722         }
723
724         @Override
725         public boolean isSamePasswordEntered () {
726                 return (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat()));
727         }
728
729         @Override
730         public boolean isUserIdEmpty () {
731                 return ((this.getUserId() == null) || (this.getUserId() == 0));
732         }
733
734         @Override
735         public boolean isUserNameRegistered (final User user) {
736                 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
737         }
738
739         @Override
740         public boolean isVisibleUserFound () {
741                 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
742         }
743
744         @Override
745         public User lookupUserById (final Long userId) throws UserNotFoundException {
746                 // Init variable
747                 User user = null;
748
749                 // Try to lookup it in visible user list
750                 for (final Iterator<User> iterator = this.visibleUserList.iterator(); iterator.hasNext();) {
751                         // Get next user
752                         User next = iterator.next();
753
754                         // Is the user id found?
755                         if (Objects.equals(next.getUserId(), userId)) {
756                                 // Copy to other variable
757                                 user = next;
758                                 break;
759                         }
760                 }
761
762                 // Is it still null?
763                 if (null == user) {
764                         // Not visible for the current user
765                         throw new UserNotFoundException(userId);
766                 }
767
768                 // Return it
769                 return user;
770         }
771
772         /**
773          * Adds user's name and email address to bean's internal list. It also
774          * updates the public user list if the user has decided to ha   }
775          * <p>
776          * @param user User instance
777          */
778         private void addUserNameEmailAddress (final User user) {
779                 // Make sure the entry is not added yet
780                 if (this.userNameList.contains(user.getUserName())) {
781                         // Abort here
782                         throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
783                 } else if (this.emailAddressList.contains(user.getUserContact().getContactEmailAddress())) {
784                         // Already added
785                         throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
786                 }
787
788                 // Add user name
789                 this.userNameList.add(user.getUserName());
790
791                 // Add email addres
792                 this.emailAddressList.add(user.getUserContact().getContactEmailAddress());
793         }
794
795         /**
796          * Clears all data in this bean
797          */
798         private void clearData () {
799                 // Clear all data
800                 // - personal data
801                 this.setUserId(null);
802                 this.setGender(Gender.UNKNOWN);
803                 this.setUserProfileMode(null);
804                 this.setFirstName(null);
805                 this.setFamilyName(null);
806                 this.setStreet(null);
807                 this.setHouseNumber(null);
808                 this.setZipCode(null);
809                 this.setCity(null);
810                 this.setCountry(null);
811
812                 // - contact data
813                 this.setEmailAddress(null);
814                 this.setEmailAddressRepeat(null);
815                 this.setPhoneAreaCode(null);
816                 this.setCellphoneCarrier(null);
817                 this.setFaxAreaCode(null);
818
819                 // - other data
820                 this.setBirthday(null);
821                 this.setComment(null);
822                 this.setUserName(null);
823                 this.setUserPassword(null);
824                 this.setUserPasswordRepeat(null);
825         }
826
827         /**
828          * Copies given user into the controller
829          * <p>
830          * @param user User instance
831          */
832         private void copyUser (final User user) {
833                 // Copy all fields:
834                 // - base data
835                 this.setUserId(user.getUserId());
836                 this.setUserProfileMode(user.getUserProfileMode());
837                 this.setGender(user.getUserContact().getContactGender());
838                 this.setFirstName(user.getUserContact().getContactFirstName());
839                 this.setFamilyName(user.getUserContact().getContactFamilyName());
840                 this.setStreet(user.getUserContact().getContactStreet());
841                 this.setHouseNumber(user.getUserContact().getContactHouseNumber());
842                 this.setZipCode(user.getUserContact().getContactZipCode());
843                 this.setCity(user.getUserContact().getContactCity());
844                 this.setCountry(user.getUserContact().getContactCountry());
845
846                 // Get cellphone, phone and fax instance
847                 DialableCellphoneNumber cellphone = user.getUserContact().getContactCellphoneNumber();
848                 DialableFaxNumber fax = user.getUserContact().getContactFaxNumber();
849                 DialableLandLineNumber phone = user.getUserContact().getContactPhoneNumber();
850
851                 // - contact data
852                 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
853                         this.setPhoneCountry(phone.getPhoneCountry());
854                         this.setPhoneAreaCode(phone.getPhoneAreaCode());
855                         this.setPhoneNumber(phone.getPhoneNumber());
856                 }
857                 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof SmsProvider)) {
858                         this.setCellphoneCarrier(cellphone.getCellphoneProvider());
859                         this.setCellphoneNumber(cellphone.getPhoneNumber());
860                 }
861                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
862                         this.setFaxCountry(fax.getPhoneCountry());
863                         this.setFaxAreaCode(fax.getPhoneAreaCode());
864                         this.setFaxNumber(fax.getPhoneNumber());
865                 }
866                 this.setEmailAddress(user.getUserContact().getContactEmailAddress());
867
868                 // -- other data
869                 this.setBirthday(user.getUserContact().getContactBirthday());
870                 this.setComment(user.getUserContact().getContactComment());
871         }
872 }