]> git.mxchange.org Git - jjobs-war.git/blob - src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java
Use other (new) exception
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / user / JobsUserWebSessionBean.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.jjobs.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.jjobs.beans.login.JobsUserLoginWebSessionController;
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.mobileprovider.MobileProvider;
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.exceptions.UserPasswordMismatchException;
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 JobsUserWebSessionBean implements JobsUserWebSessionController {
63
64         /**
65          * Serial number
66          */
67         private static final long serialVersionUID = 542_145_347_916L;
68
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 list
106          */
107         private List<String> emailAddressList;
108
109         /**
110          * Email address repeated
111          */
112         private String emailAddressRepeat;
113
114         /**
115          * Family name
116          */
117         private String familyName;
118
119         /**
120          * Fax number's area code
121          */
122         private Integer faxAreaCode;
123
124         /**
125          * Country instance for fax number
126          */
127         private Country faxCountry;
128
129         /**
130          * Fax number
131          */
132         private Long faxNumber;
133
134         /**
135          * First name
136          */
137         private String firstName;
138
139         /**
140          * Gender instance
141          */
142         private Gender gender;
143
144         /**
145          * House number
146          */
147         private Short houseNumber;
148
149         /**
150          * Login bean (controller)
151          */
152         @Inject
153         private JobsUserLoginWebSessionController loginController;
154
155         /**
156          * Phone number area code
157          */
158         private Integer phoneAreaCode;
159
160         /**
161          * Country instance for phone number
162          */
163         private Country phoneCountry;
164
165         /**
166          * Phone number
167          */
168         private Long phoneNumber;
169
170         /**
171          * Street
172          */
173         private String street;
174
175         /**
176          * Remote user bean
177          */
178         private final UserSessionBeanRemote userBean;
179
180         /**
181          * User id
182          */
183         private Long userId;
184
185         /**
186          * User name
187          */
188         private String userName;
189
190         /**
191          * User name list
192          */
193         private List<String> userNameList;
194
195         /**
196          * User password (unencrypted from web form)
197          */
198         private String userPassword;
199
200         /**
201          * User password repeated (unencrypted from web form)
202          */
203         private String userPasswordRepeat;
204
205         /**
206          * Whether the user wants a public profile
207          */
208         private ProfileMode userProfileMode;
209
210         /**
211          * A list of all public user profiles
212          */
213         private List<User> visibleUserList;
214
215         /**
216          * ZIP code
217          */
218         private Integer zipCode;
219
220         /**
221          * Default constructor
222          */
223         public JobsUserWebSessionBean () {
224                 // Set gender to UNKNOWN
225                 this.gender = Gender.UNKNOWN;
226
227                 // Try it
228                 try {
229                         // Get initial context
230                         Context context = new InitialContext();
231
232                         // Try to lookup
233                         this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
234                 } catch (final NamingException e) {
235                         // Throw again
236                         throw new FaceletException(e);
237                 }
238         }
239
240         @Override
241         public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) {
242                 // Trace message
243                 System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
244
245                 // event should not be null
246                 if (null == event) {
247                         // Throw NPE
248                         throw new NullPointerException("event is null"); //NOI18N
249                 } else if (event.getRegisteredUser() == null) {
250                         // Throw NPE again
251                         throw new NullPointerException("event.user is null"); //NOI18N
252                 } else if (event.getRegisteredUser().getUserId() == null) {
253                         // userId is null
254                         throw new NullPointerException("event.user.userId is null"); //NOI18N
255                 } else if (event.getRegisteredUser().getUserId() < 1) {
256                         // Not avalid id
257                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
258                 }
259
260                 // Get user instance
261                 User registeredUser = event.getRegisteredUser();
262
263                 // Debug message
264                 System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
265
266                 // Copy all data from registered->user
267                 this.copyUser(registeredUser);
268
269                 // Add user name and email address
270                 this.addUserNameEmailAddress(registeredUser);
271
272                 // Clear all data
273                 this.clear();
274
275                 // Set user id again
276                 this.setUserId(registeredUser.getUserId());
277
278                 // Is the account public?
279                 if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
280                         // Also add it to this list
281                         this.visibleUserList.add(registeredUser);
282                 }
283
284                 // Trace message
285                 System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
286         }
287
288         @Override
289         public void afterUserLogin (final @Observes UserLoggedInEvent event) {
290                 // Trace message
291                 System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
292
293                 // event should not be null
294                 if (null == event) {
295                         // Throw NPE
296                         throw new NullPointerException("event is null"); //NOI18N
297                 } else if (event.getLoggedInUser() == null) {
298                         // Throw NPE again
299                         throw new NullPointerException("event.user is null"); //NOI18N
300                 } else if (event.getLoggedInUser().getUserId() == null) {
301                         // userId is null
302                         throw new NullPointerException("event.user.userId is null"); //NOI18N
303                 } else if (event.getLoggedInUser().getUserId() < 1) {
304                         // Not avalid id
305                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
306                 }
307
308                 // Re-initialize list
309                 this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
310
311                 // Copy all data to this bean
312                 this.copyUser(event.getLoggedInUser());
313
314                 // Trace message
315                 System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
316         }
317
318         @Override
319         public List<User> allVisibleUsers () {
320                 // Return it
321                 return Collections.unmodifiableList(this.visibleUserList);
322         }
323
324         @Override
325         public User createUserInstance () {
326                 // User message
327                 //this.getLogger().logTrace("createUserInstance: CALLED!");
328
329                 // Required personal data must be set
330                 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
331
332                 // Create new user instance
333                 User localUser = new LoginUser();
334
335                 // Update all data ...
336                 localUser.setUserName(this.getUserName());
337                 localUser.setUserProfileMode(this.getUserProfileMode());
338
339                 // Generate phone number
340                 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
341                 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
342                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
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.setContactLandLineNumber(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 MobileProvider) && (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.setContactOwnContact(Boolean.TRUE);
415
416                 // Set contact in user
417                 localUser.setUserContact(contact);
418
419                 // Trace message
420                 //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user));
421
422                 // Return it
423                 return localUser;
424         }
425
426         @Override
427         public String doChangePersonalData () {
428                 // This method shall only be called if the user is logged-in
429                 if (!this.loginController.isUserLoggedIn()) {
430                         // Not logged-in
431                         throw new IllegalStateException("User is not logged-in"); //NOI18N
432                 } else if (!this.isRequiredChangePersonalDataSet()) {
433                         // Not all required fields are set
434                         throw new FaceletException("Not all required fields are set."); //NOI18N
435                 } else if (!this.loginController.ifCurrentPasswordMatches()) {
436                         // Password not matching
437                         throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
438                 }
439
440                 // Get user instance
441                 User user = this.loginController.getLoggedInUser();
442
443                 // It should be there, so run some tests on it
444                 assert (user instanceof User) : "Instance loginController.loggedInUser is null";
445                 assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null";
446                 assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId());
447                 assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null";
448                 assert (user.getUserContact().getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null";
449                 assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId());
450
451                 // Update all fields
452                 user.setUserProfileMode(this.getUserProfileMode());
453                 user.getUserContact().setContactGender(this.getGender());
454                 user.getUserContact().setContactFirstName(this.getFirstName());
455                 user.getUserContact().setContactFamilyName(this.getFamilyName());
456                 user.getUserContact().setContactStreet(this.getStreet());
457                 user.getUserContact().setContactHouseNumber(this.getHouseNumber());
458                 user.getUserContact().setContactZipCode(this.getZipCode());
459                 user.getUserContact().setContactCity(this.getCity());
460                 user.getUserContact().setContactCountry(this.getCountry());
461
462                 // Is there a phone number?
463                 if (user.getUserContact().getContactLandLineNumber() instanceof DialableLandLineNumber) {
464                         // Debug message
465                         System.out.println(MessageFormat.format("UserWebBean:doChangePersonalData: phoneId={0}", user.getUserContact().getContactLandLineNumber().getPhoneId())); //NOI18N
466
467                         // Yes, then update as well
468                         user.getUserContact().getContactLandLineNumber().setPhoneAreaCode(this.getPhoneAreaCode());
469                         user.getUserContact().getContactLandLineNumber().setPhoneNumber(this.getPhoneNumber());
470                 }
471
472                 // Is there a fax number?
473                 if (user.getUserContact().getContactFaxNumber() instanceof DialableFaxNumber) {
474                         // Debug message
475                         System.out.println(MessageFormat.format("UserWebBean:doChangePersonalData: faxId={0}", user.getUserContact().getContactFaxNumber().getPhoneId())); //NOI18N
476
477                         // Yes, then update as well
478                         user.getUserContact().getContactFaxNumber().setPhoneAreaCode(this.getFaxAreaCode());
479                         user.getUserContact().getContactFaxNumber().setPhoneNumber(this.getFaxNumber());
480                 }
481
482                 // Is there a cellphone number?
483                 if (user.getUserContact().getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
484                         // Debug message
485                         System.out.println(MessageFormat.format("UserWebBean:doChangePersonalData: cellPhoneId={0}", user.getUserContact().getContactCellphoneNumber().getPhoneId())); //NOI18N
486
487                         // Yes, then update as well
488                         user.getUserContact().getContactCellphoneNumber().setCellphoneProvider(this.getCellphoneCarrier());
489                         user.getUserContact().getContactCellphoneNumber().setPhoneNumber(this.getCellphoneNumber());
490                 }
491
492                 // Send it to the EJB
493                 this.userBean.updateUserPersonalData(user);
494
495                 // All fine
496                 return "login_data_saved"; //NOI18N
497         }
498
499         @Override
500         public Date getBirthday () {
501                 return this.birthday;
502         }
503
504         @Override
505         public void setBirthday (final Date birthday) {
506                 this.birthday = birthday;
507         }
508
509         @Override
510         public MobileProvider getCellphoneCarrier () {
511                 return this.cellphoneCarrier;
512         }
513
514         @Override
515         public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
516                 this.cellphoneCarrier = cellphoneCarrier;
517         }
518
519         @Override
520         public Long getCellphoneNumber () {
521                 return this.cellphoneNumber;
522         }
523
524         @Override
525         public void setCellphoneNumber (Long cellphoneNumber) {
526                 this.cellphoneNumber = cellphoneNumber;
527         }
528
529         @Override
530         public String getCity () {
531                 return this.city;
532         }
533
534         @Override
535         public void setCity (final String city) {
536                 this.city = city;
537         }
538
539         @Override
540         public String getComment () {
541                 return this.comment;
542         }
543
544         @Override
545         public void setComment (final String comment) {
546                 this.comment = comment;
547         }
548
549         @Override
550         public Country getCountry () {
551                 return this.country;
552         }
553
554         @Override
555         public void setCountry (final Country country) {
556                 this.country = country;
557         }
558
559         @Override
560         public String getEmailAddress () {
561                 return this.emailAddress;
562         }
563
564         @Override
565         public void setEmailAddress (final String emailAddress) {
566                 this.emailAddress = emailAddress;
567         }
568
569         @Override
570         public String getEmailAddressRepeat () {
571                 return this.emailAddressRepeat;
572         }
573
574         @Override
575         public void setEmailAddressRepeat (final String emailAddressRepeat) {
576                 this.emailAddressRepeat = emailAddressRepeat;
577         }
578
579         @Override
580         public String getFamilyName () {
581                 return this.familyName;
582         }
583
584         @Override
585         public void setFamilyName (final String familyName) {
586                 this.familyName = familyName;
587         }
588
589         @Override
590         public Integer getFaxAreaCode () {
591                 return this.faxAreaCode;
592         }
593
594         @Override
595         public void setFaxAreaCode (final Integer faxAreaCode) {
596                 this.faxAreaCode = faxAreaCode;
597         }
598
599         @Override
600         public Country getFaxCountry () {
601                 return this.faxCountry;
602         }
603
604         @Override
605         public void setFaxCountry (final Country faxCountry) {
606                 this.faxCountry = faxCountry;
607         }
608
609         @Override
610         public Long getFaxNumber () {
611                 return this.faxNumber;
612         }
613
614         @Override
615         public void setFaxNumber (final Long faxNumber) {
616                 this.faxNumber = faxNumber;
617         }
618
619         @Override
620         public String getFirstName () {
621                 return this.firstName;
622         }
623
624         @Override
625         public void setFirstName (final String firstName) {
626                 this.firstName = firstName;
627         }
628
629         @Override
630         public Gender getGender () {
631                 return this.gender;
632         }
633
634         @Override
635         public void setGender (final Gender gender) {
636                 this.gender = gender;
637         }
638
639         @Override
640         public Short getHouseNumber () {
641                 return this.houseNumber;
642         }
643
644         @Override
645         public void setHouseNumber (final Short houseNumber) {
646                 this.houseNumber = houseNumber;
647         }
648
649         @Override
650         public Integer getPhoneAreaCode () {
651                 return this.phoneAreaCode;
652         }
653
654         @Override
655         public void setPhoneAreaCode (final Integer phoneAreaCode) {
656                 this.phoneAreaCode = phoneAreaCode;
657         }
658
659         @Override
660         public Country getPhoneCountry () {
661                 return this.phoneCountry;
662         }
663
664         @Override
665         public void setPhoneCountry (final Country phoneCountry) {
666                 this.phoneCountry = phoneCountry;
667         }
668
669         @Override
670         public Long getPhoneNumber () {
671                 return this.phoneNumber;
672         }
673
674         @Override
675         public void setPhoneNumber (final Long phoneNumber) {
676                 this.phoneNumber = phoneNumber;
677         }
678
679         @Override
680         public String getStreet () {
681                 return this.street;
682         }
683
684         @Override
685         public void setStreet (final String street) {
686                 this.street = street;
687         }
688
689         @Override
690         public Long getUserId () {
691                 return this.userId;
692         }
693
694         @Override
695         public void setUserId (final Long userId) {
696                 this.userId = userId;
697         }
698
699         @Override
700         public String getUserName () {
701                 return this.userName;
702         }
703
704         @Override
705         public void setUserName (final String userName) {
706                 this.userName = userName;
707         }
708
709         @Override
710         public String getUserPassword () {
711                 return this.userPassword;
712         }
713
714         @Override
715         public void setUserPassword (final String userPassword) {
716                 this.userPassword = userPassword;
717         }
718
719         @Override
720         public String getUserPasswordRepeat () {
721                 return this.userPasswordRepeat;
722         }
723
724         @Override
725         public void setUserPasswordRepeat (final String userPasswordRepeat) {
726                 this.userPasswordRepeat = userPasswordRepeat;
727         }
728
729         @Override
730         public ProfileMode getUserProfileMode () {
731                 return this.userProfileMode;
732         }
733
734         @Override
735         public void setUserProfileMode (final ProfileMode userProfileMode) {
736                 this.userProfileMode = userProfileMode;
737         }
738
739         @Override
740         public Integer getZipCode () {
741                 return this.zipCode;
742         }
743
744         @Override
745         public void setZipCode (final Integer zipCode) {
746                 this.zipCode = zipCode;
747         }
748
749         /**
750          * Post-initialization of this class
751          */
752         @PostConstruct
753         public void init () {
754                 // Get full user name list for reducing EJB calls
755                 this.userNameList = this.userBean.getUserNameList();
756
757                 // Get full email address list for reducing EJB calls
758                 this.emailAddressList = this.userBean.getEmailAddressList();
759
760                 // Is the user logged-in?
761                 if (this.loginController.isUserLoggedIn()) {
762                         // Is logged-in, so load also users visible to memebers
763                         this.visibleUserList = this.userBean.allMemberPublicVisibleUsers();
764                 } else {
765                         // Initialize user list
766                         this.visibleUserList = this.userBean.allPublicUsers();
767                 }
768         }
769
770         @Override
771         public boolean isEmailAddressRegistered (final User user) {
772                 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(user.getUserContact().getContactEmailAddress())));
773         }
774
775         @Override
776         public boolean isRequiredChangePersonalDataSet () {
777                 return ((this.getUserProfileMode() != null) &&
778                                 (this.getGender() != null) &&
779                                 (this.getFirstName() != null) &&
780                                 (this.getFamilyName() != null) &&
781                                 (this.getStreet() != null) &&
782                                 (this.getHouseNumber() != null) &&
783                                 (this.getZipCode() != null) &&
784                                 (this.getCity() != null));
785         }
786
787         @Override
788         public boolean isRequiredPersonalDataSet () {
789                 return ((this.getUserName() != null) &&
790                                 (this.getUserProfileMode() != null) &&
791                                 (this.getGender() != null) &&
792                                 (this.getFirstName() != null) &&
793                                 (this.getFamilyName() != null) &&
794                                 (this.getStreet() != null) &&
795                                 (this.getHouseNumber() != null) &&
796                                 (this.getZipCode() != null) &&
797                                 (this.getCity() != null) &&
798                                 (this.getEmailAddress() != null) &&
799                                 (this.getEmailAddressRepeat() != null) &&
800                                 (this.getUserPassword() != null) &&
801                                 (this.getUserPasswordRepeat() != null));
802         }
803
804         @Override
805         public boolean isSameEmailAddressEntered () {
806                 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
807         }
808
809         @Override
810         public boolean isSamePasswordEntered () {
811                 return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
812         }
813
814         @Override
815         public boolean isUserIdEmpty () {
816                 return ((this.getUserId() == null) || (this.getUserId() == 0));
817         }
818
819         @Override
820         public boolean isUserNameRegistered (final User user) {
821                 return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
822         }
823
824         @Override
825         public boolean isVisibleUserFound () {
826                 return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
827         }
828
829         @Override
830         public User lookupUserById (final Long userId) throws UserNotFoundException {
831                 // Init variable
832                 User localUser = null;
833
834                 // Clear this bean
835                 this.clear();
836
837                 // Try to lookup it in visible user list
838                 for (final Iterator<User> iterator = this.visibleUserList.iterator(); iterator.hasNext();) {
839                         // Get next user
840                         User next = iterator.next();
841
842                         // Is the user id found?
843                         if (Objects.equals(next.getUserId(), userId)) {
844                                 // Copy to other variable
845                                 localUser = next;
846                                 break;
847                         }
848                 }
849
850                 // Is it still null?
851                 if (null == localUser) {
852                         // Not visible for the current user
853                         throw new UserNotFoundException(userId);
854                 }
855
856                 // Copy all data to this bean
857                 this.copyUser(localUser);
858
859                 // Return it
860                 return localUser;
861         }
862
863         /**
864          * Adds user's name and email address to bean's internal list. It also
865          * updates the public user list if the user has decided to ha   }
866          * <p>
867          * @param user User instance
868          */
869         private void addUserNameEmailAddress (final User user) {
870                 // Make sure the entry is not added yet
871                 if (this.userNameList.contains(user.getUserName())) {
872                         // Abort here
873                         throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
874                 } else if (this.emailAddressList.contains(user.getUserContact().getContactEmailAddress())) {
875                         // Already added
876                         throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
877                 }
878
879                 // Add user name
880                 this.userNameList.add(user.getUserName());
881
882                 // Add email addres
883                 this.emailAddressList.add(user.getUserContact().getContactEmailAddress());
884         }
885
886         /**
887          * Clears this bean
888          */
889         private void clear () {
890                 // Clear all data
891                 // - personal data
892                 this.setUserId(null);
893                 this.setGender(Gender.UNKNOWN);
894                 this.setUserProfileMode(null);
895                 this.setFirstName(null);
896                 this.setFamilyName(null);
897                 this.setStreet(null);
898                 this.setHouseNumber(null);
899                 this.setZipCode(null);
900                 this.setCity(null);
901                 this.setCountry(null);
902
903                 // - contact data
904                 this.setEmailAddress(null);
905                 this.setEmailAddressRepeat(null);
906                 this.setPhoneAreaCode(null);
907                 this.setCellphoneCarrier(null);
908                 this.setFaxAreaCode(null);
909
910                 // - other data
911                 this.setBirthday(null);
912                 this.setComment(null);
913                 this.setUserName(null);
914                 this.setUserPassword(null);
915                 this.setUserPasswordRepeat(null);
916         }
917
918         /**
919          * Copies given user into the controller
920          * <p>
921          * @param user User instance
922          */
923         private void copyUser (final User user) {
924                 // Copy all fields:
925                 // - base data
926                 this.setUserId(user.getUserId());
927                 this.setUserProfileMode(user.getUserProfileMode());
928                 this.setGender(user.getUserContact().getContactGender());
929                 this.setFirstName(user.getUserContact().getContactFirstName());
930                 this.setFamilyName(user.getUserContact().getContactFamilyName());
931                 this.setStreet(user.getUserContact().getContactStreet());
932                 this.setHouseNumber(user.getUserContact().getContactHouseNumber());
933                 this.setZipCode(user.getUserContact().getContactZipCode());
934                 this.setCity(user.getUserContact().getContactCity());
935                 this.setCountry(user.getUserContact().getContactCountry());
936
937                 // Get cellphone, phone and fax instance
938                 DialableCellphoneNumber cellphone = user.getUserContact().getContactCellphoneNumber();
939                 DialableFaxNumber fax = user.getUserContact().getContactFaxNumber();
940                 DialableLandLineNumber phone = user.getUserContact().getContactLandLineNumber();
941
942                 // - contact data
943                 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
944                         this.setPhoneCountry(phone.getPhoneCountry());
945                         this.setPhoneAreaCode(phone.getPhoneAreaCode());
946                         this.setPhoneNumber(phone.getPhoneNumber());
947                 }
948                 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
949                         this.setCellphoneCarrier(cellphone.getCellphoneProvider());
950                         this.setCellphoneNumber(cellphone.getPhoneNumber());
951                 }
952                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
953                         this.setFaxCountry(fax.getPhoneCountry());
954                         this.setFaxAreaCode(fax.getPhoneAreaCode());
955                         this.setFaxNumber(fax.getPhoneNumber());
956                 }
957                 this.setEmailAddress(user.getUserContact().getContactEmailAddress());
958
959                 // -- other data
960                 this.setBirthday(user.getUserContact().getContactBirthday());
961                 this.setComment(user.getUserContact().getContactComment());
962         }
963 }