]> 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 - 2022 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.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.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
32 import org.mxchange.jcontacts.events.contact.update.UpdatedContactEvent;
33 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
34 import org.mxchange.jcontacts.model.contact.Contact;
35 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
36 import org.mxchange.jcontacts.model.utils.ContactUtils;
37 import org.mxchange.jcontacts.model.contact.UserContact;
38 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
39 import org.mxchange.jcountry.model.data.Country;
40 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
41 import org.mxchange.jfinancials.beans.contact.list.FinancialsContactListWebViewController;
42 import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController;
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 FinancialsContactWebRequestBean extends BaseFinancialsBean implements FinancialsContactWebRequestController {
64
65         /**
66          * Serial number
67          */
68         private static final long serialVersionUID = 542_145_347_916L;
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/jfinancials-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 FinancialsContactListWebViewController 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 FinancialsUserLoginWebSessionController userLoginController;
198
199         /**
200          * ZIP code
201          */
202         private Integer zipCode;
203
204         /**
205          * Default constructor
206          */
207         public FinancialsContactWebRequestBean () {
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                 // Required personal data must be set
327                 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
328
329                 // Create new contact
330                 final Contact contact = new UserContact(
331                                           this.getPersonalTitle(),
332                                           this.getFirstName(),
333                                           this.getFamilyName()
334                           );
335
336                 // Return instance
337                 return contact;
338         }
339
340         @Override
341         public String doChangePersonalContactData () {
342                 // This method shall only be called if the user is logged-in
343                 if (!this.userLoginController.isUserLoggedIn()) {
344                         // Not logged-in
345                         throw new IllegalStateException("User is not logged-in"); //NOI18N
346                 } else if (!this.isRequiredChangePersonalDataSet()) {
347                         // Not all required fields are set
348                         throw new FacesException("Not all required fields are set."); //NOI18N
349                 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
350                         // Password not matching
351                         this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()), FacesMessage.SEVERITY_ERROR); //NOI18N
352                         return ""; //NOI18N
353                 }
354
355                 // Get contact instance
356                 final Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
357
358                 // It should be there, so run some tests on it
359                 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
360                 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
361                 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
362
363                 // Update all fields
364                 contact.setContactPersonalTitle(this.getPersonalTitle());
365                 contact.setContactFirstName(this.getFirstName());
366                 contact.setContactFamilyName(this.getFamilyName());
367                 contact.setContactStreet(this.getStreet());
368                 contact.setContactHouseNumber(this.getHouseNumber());
369                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
370                 contact.setContactZipCode(this.getZipCode());
371                 contact.setContactCity(this.getCity());
372                 contact.setContactCountry(this.getCountry());
373
374                 // Update contact's mobile number
375                 final boolean isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
376
377                 // Update contact's land-line number
378                 final boolean isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
379
380                 // Update contact's fax number
381                 final boolean isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
382
383                 // Init updated contact instance
384                 final Contact updatedContact;
385
386                 try {
387                         // Send it to the EJB
388                         updatedContact = this.contactBean.updateContactData(contact, isMobileUnlinked, isLandLineUnlinked, isFaxUnlinked);
389                 } catch (final ContactNotFoundException ex) {
390                         // Throw as cause
391                         throw new FacesException(ex);
392                 }
393
394                 // Fire event
395                 this.contactUpdatedEvent.fire(new UpdatedContactEvent(updatedContact));
396
397                 // All fine
398                 return "contact_data_saved"; //NOI18N
399         }
400
401         /**
402          * Getter for academic title
403          * <p>
404          * @return Academic title
405          */
406         public String getAcademicTitle () {
407                 return this.academicTitle;
408         }
409
410         /**
411          * Setter for academic title
412          * <p>
413          * @param academicTitle Academic title
414          */
415         public void setAcademicTitle (final String academicTitle) {
416                 this.academicTitle = academicTitle;
417         }
418
419         /**
420          * Getter for birth day
421          * <p>
422          * @return Birth day
423          */
424         @SuppressWarnings ("ReturnOfDateField")
425         public Date getBirthday () {
426                 return this.birthday;
427         }
428
429         /**
430          * Setter for birth day
431          * <p>
432          * @param birthday Birth day
433          */
434         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
435         public void setBirthday (final Date birthday) {
436                 this.birthday = birthday;
437         }
438
439         /**
440          * Getter for city name
441          * <p>
442          * @return City name
443          */
444         public String getCity () {
445                 return this.city;
446         }
447
448         /**
449          * Setter for city name
450          * <p>
451          * @param city City name
452          */
453         public void setCity (final String city) {
454                 this.city = city;
455         }
456
457         /**
458          * Getter for comments
459          * <p>
460          * @return Comments
461          */
462         public String getComment () {
463                 return this.comment;
464         }
465
466         /**
467          * Setter for comment
468          * <p>
469          * @param comment Comments
470          */
471         public void setComment (final String comment) {
472                 this.comment = comment;
473         }
474
475         /**
476          * Getter for country instance
477          * <p>
478          * @return Country instance
479          */
480         public Country getCountry () {
481                 return this.country;
482         }
483
484         /**
485          * Setter for country instance
486          * <p>
487          * @param country Country instance
488          */
489         public void setCountry (final Country country) {
490                 this.country = country;
491         }
492
493         @Override
494         public String getEmailAddress () {
495                 return this.emailAddress;
496         }
497
498         /**
499          * Setter for email address
500          * <p>
501          * @param emailAddress Email address
502          */
503         public void setEmailAddress (final String emailAddress) {
504                 this.emailAddress = emailAddress;
505         }
506
507         /**
508          * Getter for email address, repeated
509          * <p>
510          * @return the emailAddress, repeated
511          */
512         public String getEmailAddressRepeat () {
513                 return this.emailAddressRepeat;
514         }
515
516         /**
517          * Setter for email address repeated
518          * <p>
519          * @param emailAddressRepeat the emailAddress to set
520          */
521         public void setEmailAddressRepeat (final String emailAddressRepeat) {
522                 this.emailAddressRepeat = emailAddressRepeat;
523         }
524
525         /**
526          * Family name
527          * <p>
528          * @return the familyName
529          */
530         public String getFamilyName () {
531                 return this.familyName;
532         }
533
534         /**
535          * Family name
536          * <p>
537          * @param familyName the familyName to set
538          */
539         public void setFamilyName (final String familyName) {
540                 this.familyName = familyName;
541         }
542
543         /**
544          * Getter for fax number's area code
545          * <p>
546          * @return Fax number's area code
547          */
548         public Integer getFaxAreaCode () {
549                 return this.faxAreaCode;
550         }
551
552         /**
553          * Setter for fax number's area code
554          * <p>
555          * @param faxAreaCode Fax number's area code
556          */
557         public void setFaxAreaCode (final Integer faxAreaCode) {
558                 this.faxAreaCode = faxAreaCode;
559         }
560
561         /**
562          * Getter for fax's country instance
563          * <p>
564          * @return Fax' country instance
565          */
566         public Country getFaxCountry () {
567                 return this.faxCountry;
568         }
569
570         /**
571          * Setter for fax's country instance
572          * <p>
573          * @param faxCountry Fax' country instance
574          */
575         public void setFaxCountry (final Country faxCountry) {
576                 this.faxCountry = faxCountry;
577         }
578
579         /**
580          * Getter for fax number
581          * <p>
582          * @return Fax number
583          */
584         public Long getFaxNumber () {
585                 return this.faxNumber;
586         }
587
588         /**
589          * Setter for fax number
590          * <p>
591          * @param faxNumber Fax number
592          */
593         public void setFaxNumber (final Long faxNumber) {
594                 this.faxNumber = faxNumber;
595         }
596
597         /**
598          * First name
599          * <p>
600          * @return the first name
601          */
602         public String getFirstName () {
603                 return this.firstName;
604         }
605
606         /**
607          * First name
608          * <p>
609          * @param firstName the first name to set
610          */
611         public void setFirstName (final String firstName) {
612                 this.firstName = firstName;
613         }
614
615         /**
616          * House number
617          * <p>
618          * @return the houseNumber
619          */
620         public Short getHouseNumber () {
621                 return this.houseNumber;
622         }
623
624         /**
625          * House number
626          * <p>
627          * @param houseNumber the houseNumber to set
628          */
629         public void setHouseNumber (final Short houseNumber) {
630                 this.houseNumber = houseNumber;
631         }
632
633         /**
634          * Getter for house number extension, example: 123a 'a' is then the
635          * extension and 123 is the house number.
636          * <p>
637          * @return House number extension
638          */
639         public String getHouseNumberExtension () {
640                 return this.houseNumberExtension;
641         }
642
643         /**
644          * Setter for house number extension
645          * <p>
646          * @param houseNumberExtension House number extension
647          */
648         public void setHouseNumberExtension (final String houseNumberExtension) {
649                 this.houseNumberExtension = houseNumberExtension;
650         }
651
652         /**
653          * Getter for land-line number's area code
654          * <p>
655          * @return Land-line number's area code
656          */
657         public Integer getLandLineAreaCode () {
658                 return this.landLineAreaCode;
659         }
660
661         /**
662          * Setter for land-line number's area code
663          * <p>
664          * @param landLineAreaCode Land-line number's area code
665          */
666         public void setLandLineAreaCode (final Integer landLineAreaCode) {
667                 this.landLineAreaCode = landLineAreaCode;
668         }
669
670         /**
671          * Getter for land-line number's country instance
672          * <p>
673          * @return Land-line number's country instance
674          */
675         public Country getLandLineCountry () {
676                 return this.landLineCountry;
677         }
678
679         /**
680          * Setter for land-line number's country instance
681          * <p>
682          * @param landLineCountry Land-line number's country instance
683          */
684         public void setLandLineCountry (final Country landLineCountry) {
685                 this.landLineCountry = landLineCountry;
686         }
687
688         /**
689          * Getter for land-line number
690          * <p>
691          * @return Land-line number
692          */
693         public Long getLandLineNumber () {
694                 return this.landLineNumber;
695         }
696
697         /**
698          * Setter for land-line number
699          * <p>
700          * @param landLineNumber Land-line number
701          */
702         public void setLandLineNumber (final Long landLineNumber) {
703                 this.landLineNumber = landLineNumber;
704         }
705
706         /**
707          * Getter for mobile number
708          * <p>
709          * @return Mobile number
710          */
711         public Long getMobileNumber () {
712                 return this.mobileNumber;
713         }
714
715         /**
716          * Setter for mobile number
717          * <p>
718          * @param mobileNumber Mobile number
719          */
720         public void setMobileNumber (final Long mobileNumber) {
721                 this.mobileNumber = mobileNumber;
722         }
723
724         /**
725          * Getter for mobile number's carrier
726          * <p>
727          * @return Mobile number's carrier
728          */
729         public MobileProvider getMobileProvider () {
730                 return this.mobileProvider;
731         }
732
733         /**
734          * Setter for mobile number's provider
735          * <p>
736          * @param mobileProvider Mobile number's provider
737          */
738         public void setMobileProvider (final MobileProvider mobileProvider) {
739                 this.mobileProvider = mobileProvider;
740         }
741
742         /**
743          * Getter for personal title
744          * <p>
745          * @return Personal title
746          */
747         public PersonalTitle getPersonalTitle () {
748                 return this.personalTitle;
749         }
750
751         /**
752          * Setter for personal title
753          * <p>
754          * @param personalTitle Personal title
755          */
756         public void setPersonalTitle (final PersonalTitle personalTitle) {
757                 this.personalTitle = personalTitle;
758         }
759
760         /**
761          * Getter for street
762          * <p>
763          * @return Street
764          */
765         public String getStreet () {
766                 return this.street;
767         }
768
769         /**
770          * Setter for street
771          * <p>
772          * @param street Street
773          */
774         public void setStreet (final String street) {
775                 this.street = street;
776         }
777
778         /**
779          * Getter for ZIP code
780          * <p>
781          * @return ZIP code
782          */
783         public Integer getZipCode () {
784                 return this.zipCode;
785         }
786
787         /**
788          * Setter for ZIP code
789          * <p>
790          * @param zipCode ZIP code
791          */
792         public void setZipCode (final Integer zipCode) {
793                 this.zipCode = zipCode;
794         }
795
796         @Override
797         public boolean isEmailAddressRegistered (final Contact contact) {
798                 // Cherck parameter
799                 if (null == contact) {
800                         // Throw NPE
801                         throw new NullPointerException("contact is null"); //NOI18N
802                 } else if (contact.getContactEmailAddress() == null) {
803                         // Throw again
804                         throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
805                 } else if (contact.getContactEmailAddress().isEmpty()) {
806                         // Is empty
807                         throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
808                 }
809
810                 // Default is not registered
811                 boolean isRegistered = false;
812
813                 // Determine it
814                 for (final Contact currentContact : this.contactListController.getAllContacts()) {
815                         // Is same contact found?
816                         if (currentContact.getContactEmailAddress().equals(contact.getContactEmailAddress())) {
817                                 // Found same email address
818                                 isRegistered = true;
819
820                                 // Skipp further iterations
821                                 break;
822                         }
823                 }
824
825                 // Return status
826                 return isRegistered;
827         }
828
829         @Override
830         public boolean isEmailAddressRegistered (final String emailAddress) {
831                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
832         }
833
834         @Override
835         public boolean isRequiredChangePersonalDataSet () {
836                 return ((this.getPersonalTitle() != null) &&
837                                 (this.getFirstName() != null) &&
838                                 (this.getFamilyName() != null) &&
839                                 (this.getStreet() != null) &&
840                                 (this.getHouseNumber() != null) &&
841                                 (this.getZipCode() != null) &&
842                                 (this.getCity() != null));
843         }
844
845         @Override
846         public boolean isRequiredPersonalDataSet () {
847                 return ((this.getPersonalTitle() != null) &&
848                                 (this.getFirstName() != null) &&
849                                 (this.getFamilyName() != null) &&
850                                 (this.getStreet() != null) &&
851                                 (this.getHouseNumber() != null) &&
852                                 (this.getZipCode() != null) &&
853                                 (this.getCity() != null) &&
854                                 (this.getEmailAddress() != null) &&
855                                 (this.getEmailAddressRepeat() != null));
856         }
857
858         @Override
859         public boolean isSameEmailAddressEntered () {
860                 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
861         }
862
863         /**
864          * Clears this bean
865          */
866         private void clear () {
867                 // Clear all data
868                 // - personal data
869                 this.setPersonalTitle(null);
870                 this.setAcademicTitle(null);
871                 this.setFirstName(null);
872                 this.setFamilyName(null);
873                 this.setStreet(null);
874                 this.setHouseNumber(null);
875                 this.setHouseNumberExtension(null);
876                 this.setZipCode(null);
877                 this.setCity(null);
878                 this.setCountry(null);
879
880                 // - contact data
881                 this.clearEmailAddresses();
882                 this.setLandLineAreaCode(null);
883                 this.setLandLineCountry(null);
884                 this.setLandLineNumber(null);
885                 this.setMobileProvider(null);
886                 this.setMobileNumber(null);
887                 this.setFaxAreaCode(null);
888                 this.setFaxCountry(null);
889                 this.setFaxNumber(null);
890
891                 // - other data
892                 this.setBirthday(null);
893                 this.setComment(null);
894         }
895
896         /**
897          * Copies given contact data into the controller
898          * <p>
899          * @param contact Contact instance
900          */
901         private void copyFromContact (final Contact contact) {
902                 // Copy all fields:
903                 // - base data
904                 this.setPersonalTitle(contact.getContactPersonalTitle());
905                 this.setAcademicTitle(contact.getContactTitle());
906                 this.setFirstName(contact.getContactFirstName());
907                 this.setFamilyName(contact.getContactFamilyName());
908                 this.setStreet(contact.getContactStreet());
909                 this.setHouseNumber(contact.getContactHouseNumber());
910                 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
911                 this.setZipCode(contact.getContactZipCode());
912                 this.setCity(contact.getContactCity());
913                 this.setCountry(contact.getContactCountry());
914                 this.setEmailAddress(contact.getContactEmailAddress());
915                 this.setBirthday(contact.getContactBirthday());
916                 this.setComment(contact.getContactComment());
917
918                 // Get mobile, phone and fax instance
919                 final DialableFaxNumber fax = contact.getContactFaxNumber();
920                 final DialableLandLineNumber landLine = contact.getContactLandLineNumber();
921                 final DialableMobileNumber mobile = contact.getContactMobileNumber();
922
923                 // Is a fax number set?
924                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
925                         // Copy elements
926                         this.setFaxCountry(fax.getPhoneCountry());
927                         this.setFaxAreaCode(fax.getPhoneAreaCode());
928                         this.setFaxNumber(fax.getPhoneNumber());
929                 }
930
931                 // Is a land-line number set?
932                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneAreaCode() > 0)) {
933                         // Copy elements
934                         this.setLandLineCountry(landLine.getPhoneCountry());
935                         this.setLandLineAreaCode(landLine.getPhoneAreaCode());
936                         this.setLandLineNumber(landLine.getPhoneNumber());
937                 }
938
939                 // Is a mobile number set?
940                 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
941                         // Copy elements
942                         this.setMobileProvider(mobile.getMobileProvider());
943                         this.setMobileNumber(mobile.getMobileNumber());
944                 }
945         }
946
947         /**
948          * Copies all fields from this backing bean into given instance.
949          * <p>
950          * @param contact An instance of a Contact class
951          */
952         private void copyToContact (final Contact contact) {
953                 // Set other elements
954                 contact.setContactStreet(this.getStreet());
955                 contact.setContactHouseNumber(this.getHouseNumber());
956                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
957                 contact.setContactZipCode(this.getZipCode());
958                 contact.setContactCity(this.getCity());
959                 contact.setContactCountry(this.getCountry());
960                 contact.setContactEmailAddress(this.getEmailAddress());
961                 contact.setContactBirthday(this.getBirthday());
962                 contact.setContactComment(this.getComment());
963
964                 // Generate phone number
965                 final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
966                 final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
967                 final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
968
969                 // Don't set null or wrong references
970                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
971                         // Now the number must be given
972                         if (landLine.getPhoneAreaCode() == null) {
973                                 // Is null
974                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
975                         } else if (landLine.getPhoneAreaCode() < 1) {
976                                 // Abort here
977                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
978                         } else if (landLine.getPhoneNumber() == null) {
979                                 // Is null
980                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
981                         } else if (landLine.getPhoneNumber() < 1) {
982                                 // Abort here
983                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
984                         }
985
986                         // Set phone number
987                         contact.setContactLandLineNumber(landLine);
988                 }
989
990                 // Don't set null or wrong references
991                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
992                         // Now the number must be given
993                         if (fax.getPhoneAreaCode() == null) {
994                                 // Is null
995                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
996                         } else if (fax.getPhoneAreaCode() < 1) {
997                                 // Abort here
998                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
999                         } else if (fax.getPhoneNumber() == null) {
1000                                 // Is null
1001                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
1002                         } else if (fax.getPhoneNumber() < 1) {
1003                                 // Abort here
1004                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
1005                         }
1006
1007                         // Set fax number
1008                         contact.setContactFaxNumber(fax);
1009                 }
1010
1011                 // Is the provider set?
1012                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
1013                         // Is the number set?
1014                         if (mobile.getMobileNumber() == null) {
1015                                 // Is null
1016                                 throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
1017                         } else if (mobile.getMobileNumber() < 1) {
1018                                 // Abort here
1019                                 throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
1020                         }
1021
1022                         // Set mobile number
1023                         contact.setContactMobileNumber(mobile);
1024                 }
1025         }
1026
1027 }