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