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