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