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