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