]> 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.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.contact.Contacts;
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 = Contacts.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
376
377                 // Update contact's land-line number
378                 final boolean isLandLineUnlinked = Contacts.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
379
380                 // Update contact's fax number
381                 final boolean isFaxUnlinked = Contacts.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         @Override
476         public String getControllerType () {
477                 return "general"; //NOI18N
478         }
479
480         @Override
481         @Deprecated
482         public void setControllerType (final String controllerType) {
483                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
484         }
485
486         /**
487          * Getter for country instance
488          * <p>
489          * @return Country instance
490          */
491         public Country getCountry () {
492                 return this.country;
493         }
494
495         /**
496          * Setter for country instance
497          * <p>
498          * @param country Country instance
499          */
500         public void setCountry (final Country country) {
501                 this.country = country;
502         }
503
504         @Override
505         public String getEmailAddress () {
506                 return this.emailAddress;
507         }
508
509         /**
510          * Setter for email address
511          * <p>
512          * @param emailAddress Email address
513          */
514         public void setEmailAddress (final String emailAddress) {
515                 this.emailAddress = emailAddress;
516         }
517
518         /**
519          * Getter for email address, repeated
520          * <p>
521          * @return the emailAddress, repeated
522          */
523         public String getEmailAddressRepeat () {
524                 return this.emailAddressRepeat;
525         }
526
527         /**
528          * Setter for email address repeated
529          * <p>
530          * @param emailAddressRepeat the emailAddress to set
531          */
532         public void setEmailAddressRepeat (final String emailAddressRepeat) {
533                 this.emailAddressRepeat = emailAddressRepeat;
534         }
535
536         /**
537          * Family name
538          * <p>
539          * @return the familyName
540          */
541         public String getFamilyName () {
542                 return this.familyName;
543         }
544
545         /**
546          * Family name
547          * <p>
548          * @param familyName the familyName to set
549          */
550         public void setFamilyName (final String familyName) {
551                 this.familyName = familyName;
552         }
553
554         /**
555          * Getter for fax number's area code
556          * <p>
557          * @return Fax number's area code
558          */
559         public Integer getFaxAreaCode () {
560                 return this.faxAreaCode;
561         }
562
563         /**
564          * Setter for fax number's area code
565          * <p>
566          * @param faxAreaCode Fax number's area code
567          */
568         public void setFaxAreaCode (final Integer faxAreaCode) {
569                 this.faxAreaCode = faxAreaCode;
570         }
571
572         /**
573          * Getter for fax's country instance
574          * <p>
575          * @return Fax' country instance
576          */
577         public Country getFaxCountry () {
578                 return this.faxCountry;
579         }
580
581         /**
582          * Setter for fax's country instance
583          * <p>
584          * @param faxCountry Fax' country instance
585          */
586         public void setFaxCountry (final Country faxCountry) {
587                 this.faxCountry = faxCountry;
588         }
589
590         /**
591          * Getter for fax number
592          * <p>
593          * @return Fax number
594          */
595         public Long getFaxNumber () {
596                 return this.faxNumber;
597         }
598
599         /**
600          * Setter for fax number
601          * <p>
602          * @param faxNumber Fax number
603          */
604         public void setFaxNumber (final Long faxNumber) {
605                 this.faxNumber = faxNumber;
606         }
607
608         /**
609          * First name
610          * <p>
611          * @return the first name
612          */
613         public String getFirstName () {
614                 return this.firstName;
615         }
616
617         /**
618          * First name
619          * <p>
620          * @param firstName the first name to set
621          */
622         public void setFirstName (final String firstName) {
623                 this.firstName = firstName;
624         }
625
626         /**
627          * House number
628          * <p>
629          * @return the houseNumber
630          */
631         public Short getHouseNumber () {
632                 return this.houseNumber;
633         }
634
635         /**
636          * House number
637          * <p>
638          * @param houseNumber the houseNumber to set
639          */
640         public void setHouseNumber (final Short houseNumber) {
641                 this.houseNumber = houseNumber;
642         }
643
644         /**
645          * Getter for house number extension, example: 123a 'a' is then the
646          * extension and 123 is the house number.
647          * <p>
648          * @return House number extension
649          */
650         public String getHouseNumberExtension () {
651                 return this.houseNumberExtension;
652         }
653
654         /**
655          * Setter for house number extension
656          * <p>
657          * @param houseNumberExtension House number extension
658          */
659         public void setHouseNumberExtension (final String houseNumberExtension) {
660                 this.houseNumberExtension = houseNumberExtension;
661         }
662
663         /**
664          * Getter for land-line number's area code
665          * <p>
666          * @return Land-line number's area code
667          */
668         public Integer getLandLineAreaCode () {
669                 return this.landLineAreaCode;
670         }
671
672         /**
673          * Setter for land-line number's area code
674          * <p>
675          * @param landLineAreaCode Land-line number's area code
676          */
677         public void setLandLineAreaCode (final Integer landLineAreaCode) {
678                 this.landLineAreaCode = landLineAreaCode;
679         }
680
681         /**
682          * Getter for land-line number's country instance
683          * <p>
684          * @return Land-line number's country instance
685          */
686         public Country getLandLineCountry () {
687                 return this.landLineCountry;
688         }
689
690         /**
691          * Setter for land-line number's country instance
692          * <p>
693          * @param landLineCountry Land-line number's country instance
694          */
695         public void setLandLineCountry (final Country landLineCountry) {
696                 this.landLineCountry = landLineCountry;
697         }
698
699         /**
700          * Getter for land-line number
701          * <p>
702          * @return Land-line number
703          */
704         public Long getLandLineNumber () {
705                 return this.landLineNumber;
706         }
707
708         /**
709          * Setter for land-line number
710          * <p>
711          * @param landLineNumber Land-line number
712          */
713         public void setLandLineNumber (final Long landLineNumber) {
714                 this.landLineNumber = landLineNumber;
715         }
716
717         /**
718          * Getter for mobile number
719          * <p>
720          * @return Mobile number
721          */
722         public Long getMobileNumber () {
723                 return this.mobileNumber;
724         }
725
726         /**
727          * Setter for mobile number
728          * <p>
729          * @param mobileNumber Mobile number
730          */
731         public void setMobileNumber (final Long mobileNumber) {
732                 this.mobileNumber = mobileNumber;
733         }
734
735         /**
736          * Getter for mobile number's carrier
737          * <p>
738          * @return Mobile number's carrier
739          */
740         public MobileProvider getMobileProvider () {
741                 return this.mobileProvider;
742         }
743
744         /**
745          * Setter for mobile number's provider
746          * <p>
747          * @param mobileProvider Mobile number's provider
748          */
749         public void setMobileProvider (final MobileProvider mobileProvider) {
750                 this.mobileProvider = mobileProvider;
751         }
752
753         /**
754          * Getter for personal title
755          * <p>
756          * @return Personal title
757          */
758         public PersonalTitle getPersonalTitle () {
759                 return this.personalTitle;
760         }
761
762         /**
763          * Setter for personal title
764          * <p>
765          * @param personalTitle Personal title
766          */
767         public void setPersonalTitle (final PersonalTitle personalTitle) {
768                 this.personalTitle = personalTitle;
769         }
770
771         /**
772          * Getter for street
773          * <p>
774          * @return Street
775          */
776         public String getStreet () {
777                 return this.street;
778         }
779
780         /**
781          * Setter for street
782          * <p>
783          * @param street Street
784          */
785         public void setStreet (final String street) {
786                 this.street = street;
787         }
788
789         /**
790          * Getter for ZIP code
791          * <p>
792          * @return ZIP code
793          */
794         public Integer getZipCode () {
795                 return this.zipCode;
796         }
797
798         /**
799          * Setter for ZIP code
800          * <p>
801          * @param zipCode ZIP code
802          */
803         public void setZipCode (final Integer zipCode) {
804                 this.zipCode = zipCode;
805         }
806
807         @Override
808         public boolean isEmailAddressRegistered (final Contact contact) {
809                 // Cherck parameter
810                 if (null == contact) {
811                         // Throw NPE
812                         throw new NullPointerException("contact is null"); //NOI18N
813                 } else if (contact.getContactEmailAddress() == null) {
814                         // Throw again
815                         throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
816                 } else if (contact.getContactEmailAddress().isEmpty()) {
817                         // Is empty
818                         throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
819                 }
820
821                 // Default is not registered
822                 boolean isRegistered = false;
823
824                 // Determine it
825                 for (final Contact currentContact : this.contactListController.getAllContacts()) {
826                         // Is same contact found?
827                         if (currentContact.getContactEmailAddress().equals(contact.getContactEmailAddress())) {
828                                 // Found same email address
829                                 isRegistered = true;
830
831                                 // Skipp further iterations
832                                 break;
833                         }
834                 }
835
836                 // Return status
837                 return isRegistered;
838         }
839
840         @Override
841         public boolean isEmailAddressRegistered (final String emailAddress) {
842                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
843         }
844
845         @Override
846         public boolean isRequiredChangePersonalDataSet () {
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         }
855
856         @Override
857         public boolean isRequiredPersonalDataSet () {
858                 return ((this.getPersonalTitle() != null) &&
859                                 (this.getFirstName() != null) &&
860                                 (this.getFamilyName() != null) &&
861                                 (this.getStreet() != null) &&
862                                 (this.getHouseNumber() != null) &&
863                                 (this.getZipCode() != null) &&
864                                 (this.getCity() != null) &&
865                                 (this.getEmailAddress() != null) &&
866                                 (this.getEmailAddressRepeat() != null));
867         }
868
869         @Override
870         public boolean isSameEmailAddressEntered () {
871                 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
872         }
873
874         /**
875          * Clears this bean
876          */
877         private void clear () {
878                 // Clear all data
879                 // - personal data
880                 this.setPersonalTitle(null);
881                 this.setAcademicTitle(null);
882                 this.setFirstName(null);
883                 this.setFamilyName(null);
884                 this.setStreet(null);
885                 this.setHouseNumber(null);
886                 this.setHouseNumberExtension(null);
887                 this.setZipCode(null);
888                 this.setCity(null);
889                 this.setCountry(null);
890
891                 // - contact data
892                 this.clearEmailAddresses();
893                 this.setLandLineAreaCode(null);
894                 this.setLandLineCountry(null);
895                 this.setLandLineNumber(null);
896                 this.setMobileProvider(null);
897                 this.setMobileNumber(null);
898                 this.setFaxAreaCode(null);
899                 this.setFaxCountry(null);
900                 this.setFaxNumber(null);
901
902                 // - other data
903                 this.setBirthday(null);
904                 this.setComment(null);
905         }
906
907         /**
908          * Copies given contact data into the controller
909          * <p>
910          * @param contact Contact instance
911          */
912         private void copyFromContact (final Contact contact) {
913                 // Copy all fields:
914                 // - base data
915                 this.setPersonalTitle(contact.getContactPersonalTitle());
916                 this.setAcademicTitle(contact.getContactTitle());
917                 this.setFirstName(contact.getContactFirstName());
918                 this.setFamilyName(contact.getContactFamilyName());
919                 this.setStreet(contact.getContactStreet());
920                 this.setHouseNumber(contact.getContactHouseNumber());
921                 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
922                 this.setZipCode(contact.getContactZipCode());
923                 this.setCity(contact.getContactCity());
924                 this.setCountry(contact.getContactCountry());
925                 this.setEmailAddress(contact.getContactEmailAddress());
926                 this.setBirthday(contact.getContactBirthday());
927                 this.setComment(contact.getContactComment());
928
929                 // Get mobile, phone and fax instance
930                 final DialableFaxNumber fax = contact.getContactFaxNumber();
931                 final DialableLandLineNumber landLine = contact.getContactLandLineNumber();
932                 final DialableMobileNumber mobile = contact.getContactMobileNumber();
933
934                 // Is a fax number set?
935                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
936                         // Copy elements
937                         this.setFaxCountry(fax.getPhoneCountry());
938                         this.setFaxAreaCode(fax.getPhoneAreaCode());
939                         this.setFaxNumber(fax.getPhoneNumber());
940                 }
941
942                 // Is a land-line number set?
943                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneAreaCode() > 0)) {
944                         // Copy elements
945                         this.setLandLineCountry(landLine.getPhoneCountry());
946                         this.setLandLineAreaCode(landLine.getPhoneAreaCode());
947                         this.setLandLineNumber(landLine.getPhoneNumber());
948                 }
949
950                 // Is a mobile number set?
951                 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
952                         // Copy elements
953                         this.setMobileProvider(mobile.getMobileProvider());
954                         this.setMobileNumber(mobile.getMobileNumber());
955                 }
956         }
957
958         /**
959          * Copies all fields from this backing bean into given instance.
960          * <p>
961          * @param contact An instance of a Contact class
962          */
963         private void copyToContact (final Contact contact) {
964                 // Set other elements
965                 contact.setContactStreet(this.getStreet());
966                 contact.setContactHouseNumber(this.getHouseNumber());
967                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
968                 contact.setContactZipCode(this.getZipCode());
969                 contact.setContactCity(this.getCity());
970                 contact.setContactCountry(this.getCountry());
971                 contact.setContactEmailAddress(this.getEmailAddress());
972                 contact.setContactBirthday(this.getBirthday());
973                 contact.setContactComment(this.getComment());
974
975                 // Generate phone number
976                 final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
977                 final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
978                 final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
979
980                 // Don't set null or wrong references
981                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
982                         // Now the number must be given
983                         if (landLine.getPhoneAreaCode() == null) {
984                                 // Is null
985                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
986                         } else if (landLine.getPhoneAreaCode() < 1) {
987                                 // Abort here
988                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
989                         } else if (landLine.getPhoneNumber() == null) {
990                                 // Is null
991                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
992                         } else if (landLine.getPhoneNumber() < 1) {
993                                 // Abort here
994                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
995                         }
996
997                         // Set phone number
998                         contact.setContactLandLineNumber(landLine);
999                 }
1000
1001                 // Don't set null or wrong references
1002                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
1003                         // Now the number must be given
1004                         if (fax.getPhoneAreaCode() == null) {
1005                                 // Is null
1006                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
1007                         } else if (fax.getPhoneAreaCode() < 1) {
1008                                 // Abort here
1009                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
1010                         } else if (fax.getPhoneNumber() == null) {
1011                                 // Is null
1012                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
1013                         } else if (fax.getPhoneNumber() < 1) {
1014                                 // Abort here
1015                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
1016                         }
1017
1018                         // Set fax number
1019                         contact.setContactFaxNumber(fax);
1020                 }
1021
1022                 // Is the provider set?
1023                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
1024                         // Is the number set?
1025                         if (mobile.getMobileNumber() == null) {
1026                                 // Is null
1027                                 throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
1028                         } else if (mobile.getMobileNumber() < 1) {
1029                                 // Abort here
1030                                 throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
1031                         }
1032
1033                         // Set mobile number
1034                         contact.setContactMobileNumber(mobile);
1035                 }
1036         }
1037
1038 }