]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java
Updated copyright year
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / contact / AddressbookContactWebRequestBean.java
1 /*
2  * Copyright (C) 2016 - 2024 Free Software Foundation
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.addressbook.beans.contact;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.Objects;
22 import javax.ejb.EJB;
23 import javax.enterprise.context.RequestScoped;
24 import javax.enterprise.event.Event;
25 import javax.enterprise.event.Observes;
26 import javax.enterprise.inject.Any;
27 import javax.faces.FacesException;
28 import javax.faces.application.FacesMessage;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import org.mxchange.addressbook.beans.BaseAddressbookBean;
32 import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
33 import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
34 import org.mxchange.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
35 import org.mxchange.jcontacts.events.contact.update.UpdatedContactEvent;
36 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
37 import org.mxchange.jcontacts.model.contact.Contact;
38 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
39 import org.mxchange.jcontacts.model.contact.UserContact;
40 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
41 import org.mxchange.jcontacts.model.utils.ContactUtils;
42 import org.mxchange.jcountry.model.data.Country;
43 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
44 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
45 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
46 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
47 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
48 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
49 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
50 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
51 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
52 import org.mxchange.jusercore.events.user.update.pre.ObservablePreUserPersonalDataUpdatedEvent;
53 import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
54 import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
55
56 /**
57  * A general contact bean (controller)
58  * <p>
59  * @author Roland Häder<roland@mxchange.org>
60  */
61 @Named ("contactController")
62 @RequestScoped
63 public class AddressbookContactWebRequestBean extends BaseAddressbookBean implements AddressbookContactWebRequestController {
64
65         /**
66          * Serial number
67          */
68         private static final long serialVersionUID = 542_145_352_001L;
69
70         /**
71          * Academic academicTitle
72          */
73         private String academicTitle;
74
75         /**
76          * Birth day
77          */
78         private Date birthday;
79
80         /**
81          * City
82          */
83         private String city;
84
85         /**
86          * Optional comments
87          */
88         private String comment;
89
90         /**
91          * EJB for general contact purposes
92          */
93         @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
94         private ContactSessionBeanRemote contactBean;
95
96         /**
97          * An instance of a contact-list backing bean
98          */
99         private AddressbookContactListWebViewController contactListController;
100
101         /**
102          * Event being fired when a user has updated his contact data
103          */
104         @Any
105         @Inject
106         private Event<ObservableUpdatedContactEvent> contactUpdatedEvent;
107
108         /**
109          * Country instance
110          */
111         private Country country;
112
113         /**
114          * Email address
115          */
116         private String emailAddress;
117
118         /**
119          * Email address repeated
120          */
121         private String emailAddressRepeat;
122
123         /**
124          * Family name
125          */
126         private String familyName;
127
128         /**
129          * Fax number's area code
130          */
131         private Integer faxAreaCode;
132
133         /**
134          * Country instance for fax number
135          */
136         private Country faxCountry;
137
138         /**
139          * Fax number
140          */
141         private Long faxNumber;
142
143         /**
144          * First name
145          */
146         private String firstName;
147
148         /**
149          * House number
150          */
151         private Short houseNumber;
152
153         /**
154          * House number extension
155          */
156         private String houseNumberExtension;
157
158         /**
159          * Phone number area code
160          */
161         private Integer landLineAreaCode;
162
163         /**
164          * Country instance for phone number
165          */
166         private Country landLineCountry;
167
168         /**
169          * Phone number
170          */
171         private Long landLineNumber;
172
173         /**
174          * Mobile number
175          */
176         private Long mobileNumber;
177
178         /**
179          * Mobile number's carrier
180          */
181         private MobileProvider mobileProvider;
182
183         /**
184          * Personal academicTitle
185          */
186         private PersonalTitle personalTitle;
187
188         /**
189          * Street
190          */
191         private String street;
192
193         /**
194          * Login bean (controller)
195          */
196         @Inject
197         private AddressbookUserLoginWebSessionController userLoginController;
198
199         /**
200          * ZIP code
201          */
202         private Integer zipCode;
203
204         /**
205          * Default constructor
206          */
207         public AddressbookContactWebRequestBean () {
208                 // Call super constructor
209                 super();
210         }
211
212         /**
213          * Event observer for newly added users by administrator
214          * <p>
215          * @param event Event being fired
216          */
217         public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
218                 // Event and contained entity instance should not be null
219                 if (null == event) {
220                         // Throw NPE
221                         throw new NullPointerException("event is null"); //NOI18N
222                 } else if (event.getAddedUser() == null) {
223                         // Throw NPE again
224                         throw new NullPointerException("event.addedUser is null"); //NOI18N
225                 } else if (event.getAddedUser().getUserId() == null) {
226                         // userId is null
227                         throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
228                 } else if (event.getAddedUser().getUserId() < 1) {
229                         // Not avalid id
230                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
231                 }
232
233                 // Clear all data
234                 this.clear();
235         }
236
237         /**
238          * Observes events being fired when an administrator has linked a new user
239          * with existing contact data.
240          * <p>
241          * @param event Event being fired
242          */
243         public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
244                 // Event and contained entity instance should not be null
245                 if (null == event) {
246                         // Throw NPE
247                         throw new NullPointerException("event is null"); //NOI18N
248                 } else if (event.getLinkedUser() == null) {
249                         // Throw NPE again
250                         throw new NullPointerException("event.linkedUser is null"); //NOI18N
251                 } else if (event.getLinkedUser().getUserContact() == null) {
252                         // Throw NPE again
253                         throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
254                 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
255                         // userId is null
256                         throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
257                 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
258                         // Not avalid id
259                         throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
260                 }
261
262                 // Clear all data
263                 this.clear();
264         }
265
266         /**
267          * Event observer for logged-in user
268          * <p>
269          * @param event Event instance
270          */
271         public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
272                 // Event and contained entity instance should not be null
273                 if (null == event) {
274                         // Throw NPE
275                         throw new NullPointerException("event is null"); //NOI18N
276                 } else if (event.getLoggedInUser() == null) {
277                         // Throw NPE again
278                         throw new NullPointerException("event.loggedInUser is null"); //NOI18N
279                 } else if (event.getLoggedInUser().getUserId() == null) {
280                         // userId is null
281                         throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
282                 } else if (event.getLoggedInUser().getUserId() < 1) {
283                         // Not avalid id
284                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
285                 }
286
287                 // Copy all data to this bean
288                 this.copyFromContact(event.getLoggedInUser().getUserContact());
289         }
290
291         /**
292          * Observes events being fired before an updated of personal data done by a
293          * user has started.
294          * <p>
295          * @param event Event being observed
296          */
297         public void beforeUserUpdatedPersonalDataEvent (@Observes final ObservablePreUserPersonalDataUpdatedEvent event) {
298                 // Is the instance valid?
299                 if (null == event) {
300                         // Throw NPE
301                         throw new NullPointerException("event is null"); //NOI18N
302                 } else if (event.getUpdatedUser() == null) {
303                         // Throw NPE
304                         throw new NullPointerException("event.updatedUser is null"); //NOI18N
305                 }
306
307                 // Set all
308                 this.copyToContact(event.getUpdatedUser().getUserContact());
309         }
310
311         @Override
312         public void clearEmailAddresses () {
313                 // Clear both
314                 this.setEmailAddress(null);
315                 this.setEmailAddressRepeat(null);
316         }
317
318         @Override
319         public Contact createContactInstance () {
320                 // Is all required data set?
321                 if (!this.isRequiredPersonalDataSet()) {
322                         // No, then abort here
323                         throw new FacesException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
324                 }
325
326                 // Create new contact
327                 final Contact contact = new UserContact(
328                                           this.getPersonalTitle(),
329                                           this.getFirstName(),
330                                           this.getFamilyName(),
331                                           this.getCountry(),
332                                           Boolean.FALSE
333                           );
334
335                 // Return instance
336                 return contact;
337         }
338
339         @Override
340         public String doChangePersonalContactData () {
341                 // This method shall only be called if the user is logged-in
342                 if (!this.userLoginController.isUserLoggedIn()) {
343                         // Not logged-in
344                         throw new IllegalStateException("User is not logged-in"); //NOI18N
345                 } else if (!this.isRequiredChangePersonalDataSet()) {
346                         // Not all required fields are set
347                         throw new FacesException("Not all required fields are set."); //NOI18N
348                 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
349                         // Password not matching
350                         this.showFacesException("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()), FacesMessage.SEVERITY_ERROR); //NOI18N
351                         return ""; //NOI18N
352                 }
353
354                 // Get contact instance
355                 final Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
356
357                 // It should be there, so run some tests on it
358                 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
359                 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
360                 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
361
362                 // Update all fields
363                 contact.setContactPersonalTitle(this.getPersonalTitle());
364                 contact.setContactFirstName(this.getFirstName());
365                 contact.setContactFamilyName(this.getFamilyName());
366                 contact.setContactStreet(this.getStreet());
367                 contact.setContactHouseNumber(this.getHouseNumber());
368                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
369                 contact.setContactZipCode(this.getZipCode());
370                 contact.setContactCity(this.getCity());
371                 contact.setContactCountry(this.getCountry());
372
373                 // Update contact's mobile number
374                 final boolean isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
375
376                 // Update contact's land-line number
377                 final boolean isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
378
379                 // Update contact's fax number
380                 final boolean isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
381
382                 // Init updated contact instance
383                 final Contact updatedContact;
384
385                 try {
386                         // Send it to the EJB
387                         updatedContact = this.contactBean.updateContactData(contact, isMobileUnlinked, isLandLineUnlinked, isFaxUnlinked);
388                 } catch (final ContactNotFoundException ex) {
389                         // Throw as cause
390                         throw new FacesException(ex);
391                 }
392
393                 // Fire event
394                 this.contactUpdatedEvent.fire(new UpdatedContactEvent(updatedContact));
395
396                 // All fine
397                 return "contact_data_saved"; //NOI18N
398         }
399
400         /**
401          * Getter for academic title
402          * <p>
403          * @return Academic title
404          */
405         public String getAcademicTitle () {
406                 return this.academicTitle;
407         }
408
409         /**
410          * Setter for academic title
411          * <p>
412          * @param academicTitle Academic title
413          */
414         public void setAcademicTitle (final String academicTitle) {
415                 this.academicTitle = academicTitle;
416         }
417
418         /**
419          * Getter for birth day
420          * <p>
421          * @return Birth day
422          */
423         @SuppressWarnings ("ReturnOfDateField")
424         public Date getBirthday () {
425                 return this.birthday;
426         }
427
428         /**
429          * Setter for birth day
430          * <p>
431          * @param birthday Birth day
432          */
433         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
434         public void setBirthday (final Date birthday) {
435                 this.birthday = birthday;
436         }
437
438         /**
439          * Getter for city name
440          * <p>
441          * @return City name
442          */
443         public String getCity () {
444                 return this.city;
445         }
446
447         /**
448          * Setter for city name
449          * <p>
450          * @param city City name
451          */
452         public void setCity (final String city) {
453                 this.city = city;
454         }
455
456         /**
457          * Getter for comments
458          * <p>
459          * @return Comments
460          */
461         public String getComment () {
462                 return this.comment;
463         }
464
465         /**
466          * Setter for comment
467          * <p>
468          * @param comment Comments
469          */
470         public void setComment (final String comment) {
471                 this.comment = comment;
472         }
473
474         /**
475          * Getter for country instance
476          * <p>
477          * @return Country instance
478          */
479         public Country getCountry () {
480                 return this.country;
481         }
482
483         /**
484          * Setter for country instance
485          * <p>
486          * @param country Country instance
487          */
488         public void setCountry (final Country country) {
489                 this.country = country;
490         }
491
492         @Override
493         public String getEmailAddress () {
494                 return this.emailAddress;
495         }
496
497         /**
498          * Setter for email address
499          * <p>
500          * @param emailAddress Email address
501          */
502         public void setEmailAddress (final String emailAddress) {
503                 this.emailAddress = emailAddress;
504         }
505
506         /**
507          * Getter for email address, repeated
508          * <p>
509          * @return the emailAddress, repeated
510          */
511         public String getEmailAddressRepeat () {
512                 return this.emailAddressRepeat;
513         }
514
515         /**
516          * Setter for email address repeated
517          * <p>
518          * @param emailAddressRepeat the emailAddress to set
519          */
520         public void setEmailAddressRepeat (final String emailAddressRepeat) {
521                 this.emailAddressRepeat = emailAddressRepeat;
522         }
523
524         /**
525          * Family name
526          * <p>
527          * @return the familyName
528          */
529         public String getFamilyName () {
530                 return this.familyName;
531         }
532
533         /**
534          * Family name
535          * <p>
536          * @param familyName the familyName to set
537          */
538         public void setFamilyName (final String familyName) {
539                 this.familyName = familyName;
540         }
541
542         /**
543          * Getter for fax number's area code
544          * <p>
545          * @return Fax number's area code
546          */
547         public Integer getFaxAreaCode () {
548                 return this.faxAreaCode;
549         }
550
551         /**
552          * Setter for fax number's area code
553          * <p>
554          * @param faxAreaCode Fax number's area code
555          */
556         public void setFaxAreaCode (final Integer faxAreaCode) {
557                 this.faxAreaCode = faxAreaCode;
558         }
559
560         /**
561          * Getter for fax's country instance
562          * <p>
563          * @return Fax' country instance
564          */
565         public Country getFaxCountry () {
566                 return this.faxCountry;
567         }
568
569         /**
570          * Setter for fax's country instance
571          * <p>
572          * @param faxCountry Fax' country instance
573          */
574         public void setFaxCountry (final Country faxCountry) {
575                 this.faxCountry = faxCountry;
576         }
577
578         /**
579          * Getter for fax number
580          * <p>
581          * @return Fax number
582          */
583         public Long getFaxNumber () {
584                 return this.faxNumber;
585         }
586
587         /**
588          * Setter for fax number
589          * <p>
590          * @param faxNumber Fax number
591          */
592         public void setFaxNumber (final Long faxNumber) {
593                 this.faxNumber = faxNumber;
594         }
595
596         /**
597          * First name
598          * <p>
599          * @return the first name
600          */
601         public String getFirstName () {
602                 return this.firstName;
603         }
604
605         /**
606          * First name
607          * <p>
608          * @param firstName the first name to set
609          */
610         public void setFirstName (final String firstName) {
611                 this.firstName = firstName;
612         }
613
614         /**
615          * House number
616          * <p>
617          * @return the houseNumber
618          */
619         public Short getHouseNumber () {
620                 return this.houseNumber;
621         }
622
623         /**
624          * House number
625          * <p>
626          * @param houseNumber the houseNumber to set
627          */
628         public void setHouseNumber (final Short houseNumber) {
629                 this.houseNumber = houseNumber;
630         }
631
632         /**
633          * Getter for house number extension, example: 123a 'a' is then the
634          * extension and 123 is the house number.
635          * <p>
636          * @return House number extension
637          */
638         public String getHouseNumberExtension () {
639                 return this.houseNumberExtension;
640         }
641
642         /**
643          * Setter for house number extension
644          * <p>
645          * @param houseNumberExtension House number extension
646          */
647         public void setHouseNumberExtension (final String houseNumberExtension) {
648                 this.houseNumberExtension = houseNumberExtension;
649         }
650
651         /**
652          * Getter for land-line number's area code
653          * <p>
654          * @return Land-line number's area code
655          */
656         public Integer getLandLineAreaCode () {
657                 return this.landLineAreaCode;
658         }
659
660         /**
661          * Setter for land-line number's area code
662          * <p>
663          * @param landLineAreaCode Land-line number's area code
664          */
665         public void setLandLineAreaCode (final Integer landLineAreaCode) {
666                 this.landLineAreaCode = landLineAreaCode;
667         }
668
669         /**
670          * Getter for land-line number's country instance
671          * <p>
672          * @return Land-line number's country instance
673          */
674         public Country getLandLineCountry () {
675                 return this.landLineCountry;
676         }
677
678         /**
679          * Setter for land-line number's country instance
680          * <p>
681          * @param landLineCountry Land-line number's country instance
682          */
683         public void setLandLineCountry (final Country landLineCountry) {
684                 this.landLineCountry = landLineCountry;
685         }
686
687         /**
688          * Getter for land-line number
689          * <p>
690          * @return Land-line number
691          */
692         public Long getLandLineNumber () {
693                 return this.landLineNumber;
694         }
695
696         /**
697          * Setter for land-line number
698          * <p>
699          * @param landLineNumber Land-line number
700          */
701         public void setLandLineNumber (final Long landLineNumber) {
702                 this.landLineNumber = landLineNumber;
703         }
704
705         /**
706          * Getter for mobile number
707          * <p>
708          * @return Mobile number
709          */
710         public Long getMobileNumber () {
711                 return this.mobileNumber;
712         }
713
714         /**
715          * Setter for mobile number
716          * <p>
717          * @param mobileNumber Mobile number
718          */
719         public void setMobileNumber (final Long mobileNumber) {
720                 this.mobileNumber = mobileNumber;
721         }
722
723         /**
724          * Getter for mobile number's carrier
725          * <p>
726          * @return Mobile number's carrier
727          */
728         public MobileProvider getMobileProvider () {
729                 return this.mobileProvider;
730         }
731
732         /**
733          * Setter for mobile number's provider
734          * <p>
735          * @param mobileProvider Mobile number's provider
736          */
737         public void setMobileProvider (final MobileProvider mobileProvider) {
738                 this.mobileProvider = mobileProvider;
739         }
740
741         /**
742          * Getter for personal title
743          * <p>
744          * @return Personal title
745          */
746         public PersonalTitle getPersonalTitle () {
747                 return this.personalTitle;
748         }
749
750         /**
751          * Setter for personal title
752          * <p>
753          * @param personalTitle Personal title
754          */
755         public void setPersonalTitle (final PersonalTitle personalTitle) {
756                 this.personalTitle = personalTitle;
757         }
758
759         /**
760          * Getter for street
761          * <p>
762          * @return Street
763          */
764         public String getStreet () {
765                 return this.street;
766         }
767
768         /**
769          * Setter for street
770          * <p>
771          * @param street Street
772          */
773         public void setStreet (final String street) {
774                 this.street = street;
775         }
776
777         /**
778          * Getter for ZIP code
779          * <p>
780          * @return ZIP code
781          */
782         public Integer getZipCode () {
783                 return this.zipCode;
784         }
785
786         /**
787          * Setter for ZIP code
788          * <p>
789          * @param zipCode ZIP code
790          */
791         public void setZipCode (final Integer zipCode) {
792                 this.zipCode = zipCode;
793         }
794
795         @Override
796         public boolean isEmailAddressRegistered (final Contact contact) {
797                 // Cherck parameter
798                 if (null == contact) {
799                         // Throw NPE
800                         throw new NullPointerException("contact is null"); //NOI18N
801                 } else if (contact.getContactEmailAddress() == null) {
802                         // Throw again
803                         throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
804                 } else if (contact.getContactEmailAddress().isEmpty()) {
805                         // Is empty
806                         throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
807                 }
808
809                 // Default is not registered
810                 boolean isRegistered = false;
811
812                 // Determine it
813                 for (final Contact currentContact : this.contactListController.getAllContacts()) {
814                         // Is same contact found?
815                         if (currentContact.getContactEmailAddress().equals(contact.getContactEmailAddress())) {
816                                 // Found same email address
817                                 isRegistered = true;
818
819                                 // Skipp further iterations
820                                 break;
821                         }
822                 }
823
824                 // Return status
825                 return isRegistered;
826         }
827
828         @Override
829         public boolean isEmailAddressRegistered (final String emailAddress) {
830                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
831         }
832
833         @Override
834         public boolean isRequiredChangePersonalDataSet () {
835                 return ((this.getPersonalTitle() != null) &&
836                                 (this.getFirstName() != null) &&
837                                 (this.getFamilyName() != null) &&
838                                 (this.getStreet() != null) &&
839                                 (this.getHouseNumber() != null) &&
840                                 (this.getZipCode() != null) &&
841                                 (this.getCity() != null));
842         }
843
844         @Override
845         public boolean isRequiredPersonalDataSet () {
846                 return ((this.getPersonalTitle() != null) &&
847                                 (this.getFirstName() != null) &&
848                                 (this.getFamilyName() != null) &&
849                                 (this.getStreet() != null) &&
850                                 (this.getHouseNumber() != null) &&
851                                 (this.getZipCode() != null) &&
852                                 (this.getCity() != null) &&
853                                 (this.getEmailAddress() != null) &&
854                                 (this.getEmailAddressRepeat() != null));
855         }
856
857         @Override
858         public boolean isSameEmailAddressEntered () {
859                 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
860         }
861
862         /**
863          * Clears this bean
864          */
865         private void clear () {
866                 // Clear all data
867                 // - personal data
868                 this.setPersonalTitle(null);
869                 this.setAcademicTitle(null);
870                 this.setFirstName(null);
871                 this.setFamilyName(null);
872                 this.setStreet(null);
873                 this.setHouseNumber(null);
874                 this.setHouseNumberExtension(null);
875                 this.setZipCode(null);
876                 this.setCity(null);
877                 this.setCountry(null);
878
879                 // - contact data
880                 this.clearEmailAddresses();
881                 this.setLandLineAreaCode(null);
882                 this.setLandLineCountry(null);
883                 this.setLandLineNumber(null);
884                 this.setMobileProvider(null);
885                 this.setMobileNumber(null);
886                 this.setFaxAreaCode(null);
887                 this.setFaxCountry(null);
888                 this.setFaxNumber(null);
889
890                 // - other data
891                 this.setBirthday(null);
892                 this.setComment(null);
893         }
894
895         /**
896          * Copies given contact data into the controller
897          * <p>
898          * @param contact Contact instance
899          */
900         private void copyFromContact (final Contact contact) {
901                 // Copy all fields:
902                 // - base data
903                 this.setPersonalTitle(contact.getContactPersonalTitle());
904                 this.setAcademicTitle(contact.getContactTitle());
905                 this.setFirstName(contact.getContactFirstName());
906                 this.setFamilyName(contact.getContactFamilyName());
907                 this.setStreet(contact.getContactStreet());
908                 this.setHouseNumber(contact.getContactHouseNumber());
909                 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
910                 this.setZipCode(contact.getContactZipCode());
911                 this.setCity(contact.getContactCity());
912                 this.setCountry(contact.getContactCountry());
913                 this.setEmailAddress(contact.getContactEmailAddress());
914                 this.setBirthday(contact.getContactBirthday());
915                 this.setComment(contact.getContactComment());
916
917                 // Get mobile, phone and fax instance
918                 final DialableFaxNumber fax = contact.getContactFaxNumber();
919                 final DialableLandLineNumber landLine = contact.getContactLandLineNumber();
920                 final DialableMobileNumber mobile = contact.getContactMobileNumber();
921
922                 // Is a fax number set?
923                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
924                         // Copy elements
925                         this.setFaxCountry(fax.getPhoneCountry());
926                         this.setFaxAreaCode(fax.getPhoneAreaCode());
927                         this.setFaxNumber(fax.getPhoneNumber());
928                 }
929
930                 // Is a land-line number set?
931                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneAreaCode() > 0)) {
932                         // Copy elements
933                         this.setLandLineCountry(landLine.getPhoneCountry());
934                         this.setLandLineAreaCode(landLine.getPhoneAreaCode());
935                         this.setLandLineNumber(landLine.getPhoneNumber());
936                 }
937
938                 // Is a mobile number set?
939                 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
940                         // Copy elements
941                         this.setMobileProvider(mobile.getMobileProvider());
942                         this.setMobileNumber(mobile.getMobileNumber());
943                 }
944         }
945
946         /**
947          * Copies all fields from this backing bean into given instance.
948          * <p>
949          * @param contact An instance of a Contact class
950          */
951         private void copyToContact (final Contact contact) {
952                 // Set other elements
953                 contact.setContactStreet(this.getStreet());
954                 contact.setContactHouseNumber(this.getHouseNumber());
955                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
956                 contact.setContactZipCode(this.getZipCode());
957                 contact.setContactCity(this.getCity());
958                 contact.setContactCountry(this.getCountry());
959                 contact.setContactEmailAddress(this.getEmailAddress());
960                 contact.setContactBirthday(this.getBirthday());
961                 contact.setContactComment(this.getComment());
962
963                 // Generate phone number
964                 final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
965                 final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
966                 final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
967
968                 // Don't set null or wrong references
969                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
970                         // Now the number must be given
971                         if (landLine.getPhoneAreaCode() == null) {
972                                 // Is null
973                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
974                         } else if (landLine.getPhoneAreaCode() < 1) {
975                                 // Abort here
976                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
977                         } else if (landLine.getPhoneNumber() == null) {
978                                 // Is null
979                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
980                         } else if (landLine.getPhoneNumber() < 1) {
981                                 // Abort here
982                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
983                         }
984
985                         // Set phone number
986                         contact.setContactLandLineNumber(landLine);
987                 }
988
989                 // Don't set null or wrong references
990                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
991                         // Now the number must be given
992                         if (fax.getPhoneAreaCode() == null) {
993                                 // Is null
994                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
995                         } else if (fax.getPhoneAreaCode() < 1) {
996                                 // Abort here
997                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
998                         } else if (fax.getPhoneNumber() == null) {
999                                 // Is null
1000                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
1001                         } else if (fax.getPhoneNumber() < 1) {
1002                                 // Abort here
1003                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
1004                         }
1005
1006                         // Set fax number
1007                         contact.setContactFaxNumber(fax);
1008                 }
1009
1010                 // Is the provider set?
1011                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
1012                         // Is the number set?
1013                         if (mobile.getMobileNumber() == null) {
1014                                 // Is null
1015                                 throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
1016                         } else if (mobile.getMobileNumber() < 1) {
1017                                 // Abort here
1018                                 throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
1019                         }
1020
1021                         // Set mobile number
1022                         contact.setContactMobileNumber(mobile);
1023                 }
1024         }
1025
1026 }