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