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