]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
Updated copyright year
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / contact / PizzaAdminContactWebRequestBean.java
1 /*
2  * Copyright (C) 2016 - 2024 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.pizzaapplication.beans.contact;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.Iterator;
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.view.facelets.FaceletException;
28 import javax.inject.Inject;
29 import javax.inject.Named;
30 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
31 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
32 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
33 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
34 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
35 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
36 import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
37 import org.mxchange.jcontacts.model.contact.Contact;
38 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
39 import org.mxchange.jcontacts.model.contact.UserContact;
40 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
41 import org.mxchange.jcontacts.model.utils.ContactUtils;
42 import org.mxchange.jcountry.model.data.Country;
43 import org.mxchange.jphone.model.phonenumbers.DialableNumber;
44 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
45 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
46 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
47 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
48 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
49 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
50 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
51 import org.mxchange.pizzaapplication.beans.BasePizzaBean;
52
53 /**
54  * Administrative user bean (controller)
55  * <p>
56  * @author Roland Häder<roland@mxchange.org>
57  */
58 @Named ("adminContactController")
59 @RequestScoped
60 public class PizzaAdminContactWebRequestBean extends BasePizzaBean implements PizzaAdminContactWebRequestController {
61
62         /**
63          * Serial number
64          */
65         private static final long serialVersionUID = 542_145_351_001L;
66
67         /**
68          * Academic academicTitle
69          */
70         private String academicTitle;
71
72         /**
73          * An event fired when the administrator has added a new contact
74          */
75         @Inject
76         @Any
77         private Event<ObservableAdminAddedContactEvent> addedContactEvent;
78
79         /**
80          * Administrative contact EJB
81          */
82         @EJB (lookup = "java:global/pizzaservice-ejb/adminContact!org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote")
83         private AdminContactSessionBeanRemote adminContactBean;
84
85         /**
86          * Birth day
87          */
88         private Date birthday;
89
90         /**
91          * City
92          */
93         private String city;
94
95         /**
96          * Optional comments
97          */
98         private String comment;
99
100         /**
101          * EJB for general contact purposes
102          */
103         @EJB (lookup = "java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
104         private ContactSessionBeanRemote contactBean;
105
106         /**
107          * General contact controller
108          */
109         @Inject
110         private PizzaContactWebRequestController contactController;
111
112         /**
113          * Country instance
114          */
115         private Country contactCountry;
116
117         /**
118          * Contact id
119          */
120         private Long contactId;
121
122         /**
123          * Email address
124          */
125         private String emailAddress;
126
127         /**
128          * Family name
129          */
130         private String familyName;
131
132         /**
133          * Fax number's area code
134          */
135         private Integer faxAreaCode;
136
137         /**
138          * Country instance for fax number
139          */
140         private Country faxCountry;
141
142         /**
143          * Fax id number
144          */
145         private Long faxId;
146
147         /**
148          * Fax number
149          */
150         private Long faxNumber;
151
152         /**
153          * First name
154          */
155         private String firstName;
156
157         /**
158          * House number
159          */
160         private Short houseNumber;
161
162         /**
163          * House number extension
164          */
165         private String houseNumberExtension;
166
167         /**
168          * Whether a fax entry has been unlinked
169          */
170         private boolean isFaxUnlinked;
171
172         /**
173          * Whether a land-line number has been unlinked
174          */
175         private boolean isLandLineUnlinked;
176
177         /**
178          * Whether a mobile entry has been unlinked
179          */
180         private boolean isMobileNumberUnlinked;
181
182         /**
183          * Phone number area code
184          */
185         private Integer landLineAreaCode;
186
187         /**
188          * Country instance for phone number
189          */
190         private Country landLineCountry;
191
192         /**
193          * Land-line id number
194          */
195         private Long landLineId;
196
197         /**
198          * Phone number
199          */
200         private Long landLineNumber;
201
202         /**
203          * Mobile id number
204          */
205         private Long mobileId;
206
207         /**
208          * Mobile number
209          */
210         private Long mobileNumber;
211
212         /**
213          * Mobile number's provider
214          */
215         private MobileProvider mobileProvider;
216
217         /**
218          * PersonalTitle instance
219          */
220         private PersonalTitle personalTitle;
221
222         /**
223          * Street
224          */
225         private String street;
226
227         /**
228          * An event fired when the administrator has updated contact data
229          */
230         @Inject
231         @Any
232         private Event<ObservableAdminUpdatedContactEvent> updatedContactEvent;
233
234         /**
235          * ZIP code
236          */
237         private Integer zipCode;
238
239         /**
240          * Default constructor
241          */
242         public PizzaAdminContactWebRequestBean () {
243                 // Call super constructor
244                 super();
245         }
246
247         /**
248          * Adds contact data to database and redirects on success. If the contact is
249          * already found, a proper exception is thrown.
250          * <p>
251          * @return Redirect outcome
252          */
253         public String addContact () {
254                 // Are all minimum fields set?
255                 if (this.getPersonalTitle() == null) {
256                         // Throw NPE
257                         throw new NullPointerException("personalTitle is null"); //NOI18N
258                 } else if (this.getFirstName() == null) {
259                         // Throw NPE
260                         throw new NullPointerException("firstName is null"); //NOI18N
261                 } else if (this.getFirstName().isEmpty()) {
262                         // Empty string
263                         throw new IllegalStateException("firstName is empty"); //NOI18N
264                 } else if (this.getFamilyName() == null) {
265                         // Throw NPE
266                         throw new NullPointerException("familyName is null"); //NOI18N
267                 } else if (this.getFamilyName().isEmpty()) {
268                         // Empty string
269                         throw new IllegalStateException("familyName is empty"); //NOI18N
270                 }
271
272                 // Create new contact instance
273                 final Contact contact = this.createContactInstance();
274
275                 // Default is not same contact
276                 if (this.isSameContactFound(contact)) {
277                         // Already registered
278                         throw new FaceletException(new ContactAlreadyAddedException(contact));
279                 }
280
281                 // Init contact
282                 final Contact updatedContact;
283
284                 // Try to call EJB
285                 try {
286                         // Call EJB
287                         updatedContact = this.adminContactBean.addContact(contact);
288                 } catch (final ContactAlreadyAddedException ex) {
289                         // Throw again
290                         throw new FaceletException(ex);
291                 }
292
293                 // Fire event
294                 this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
295
296                 // Clear this bean
297                 this.clear();
298
299                 // Return outcome
300                 return "admin_list_contact"; //NOI18N
301         }
302
303         /**
304          * Observer for events being fired when a bean helper has successfully
305          * created a contact instance.
306          * <p>
307          * @param event Event being fired
308          */
309         public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
310                 // Log message
311                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
312
313                 // The event instance must be valid
314                 if (null == event) {
315                         // Throw NPE again
316                         throw new NullPointerException("event is null"); //NOI18N
317                 } else if (event.getCreatedContact() == null) {
318                         // Throw NPE again
319                         throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
320                 } else if (event.getCreatedContact().getContactId() == null) {
321                         // Throw NPE again
322                         throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
323                 } else if (event.getCreatedContact().getContactId() < 1) {
324                         // Not valid
325                         throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
326                 }
327
328                 // Get contact instance from event
329                 final Contact contact = event.getCreatedContact();
330
331                 // Set all fields: contact
332                 this.setContactId(contact.getContactId());
333                 this.setAcademicTitle(contact.getContactTitle());
334                 this.setBirthday(contact.getContactBirthday());
335                 this.setCity(contact.getContactCity());
336                 this.setComment(contact.getContactComment());
337                 this.setContactCountry(contact.getContactCountry());
338                 this.setEmailAddress(contact.getContactEmailAddress());
339                 this.setFamilyName(contact.getContactFamilyName());
340                 this.setFirstName(contact.getContactFirstName());
341                 this.setPersonalTitle(contact.getContactPersonalTitle());
342                 this.setHouseNumber(contact.getContactHouseNumber());
343                 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
344                 this.setStreet(contact.getContactStreet());
345                 this.setZipCode(contact.getContactZipCode());
346
347                 // Is the cell phone set?
348                 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
349                         // ... cmobile data
350                         this.setMobileId(contact.getContactMobileNumber().getPhoneId());
351                         this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
352                         this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
353                 }
354
355                 // Is the fax set?
356                 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
357                         // ... fax data
358                         this.setFaxId(contact.getContactFaxNumber().getPhoneId());
359                         this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
360                         this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
361                         this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
362                 }
363
364                 // Is the land-line number set?
365                 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
366                         // .. land-line data
367                         this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
368                         this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
369                         this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
370                         this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
371                 }
372
373                 // Log message
374                 //* NOISY-DEBUG: */ System.out.println("AdminContactController::afterCreatedContactEvent(): EXIT!"); //NOI18N
375         }
376
377         @Override
378         public Contact createContactInstance () {
379                 // Are all minimum fields set?
380                 if (this.getPersonalTitle() == null) {
381                         // Throw NPE
382                         throw new NullPointerException("personalTitle is null"); //NOI18N
383                 } else if (this.getFirstName() == null) {
384                         // Throw NPE
385                         throw new NullPointerException("firstName is null"); //NOI18N
386                 } else if (this.getFirstName().isEmpty()) {
387                         // Empty string
388                         throw new IllegalStateException("firstName is empty"); //NOI18N
389                 } else if (this.getFamilyName() == null) {
390                         // Throw NPE
391                         throw new NullPointerException("familyName is null"); //NOI18N
392                 } else if (this.getFamilyName().isEmpty()) {
393                         // Empty string
394                         throw new IllegalStateException("familyName is empty"); //NOI18N
395                 } else if (this.getContactCountry() == null) {
396                         // Throw NPE
397                         throw new NullPointerException("contactCountry is null"); //NOI18N
398                 } else if (this.getContactCountry().getCountryId() == null) {
399                         // Throw it again
400                         throw new NullPointerException("contactCountry.countryId is null"); //NOI18N
401                 } else if (this.getContactCountry().getCountryId() < 1) {
402                         // Throw IAE
403                         throw new IllegalArgumentException(MessageFormat.format("contactCountry.countryId={0} is invalid", this.getContactCountry().getCountryId())); //NOI18N
404                 }
405
406                 // Generate phone number
407                 final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
408                 final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
409                 final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
410
411                 // Create new instance
412                 final Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
413
414                 // Is contact id set?
415                 if (this.getContactId() instanceof Long) {
416                         // Set it, too
417                         contact.setContactId(this.getContactId());
418                 }
419
420                 // Create new instance
421                 final Contact localContact = new UserContact(
422                                           this.getPersonalTitle(),
423                                           this.getFirstName(),
424                                           this.getFamilyName(),
425                                           this.getContactCountry(),
426                                           Boolean.FALSE,
427                                           this.getStreet(),
428                                           this.getHouseNumber(),
429                                           this.getHouseNumberExtension(),
430                                           this.getZipCode(),
431                                           this.getCity(),
432                                           this.getEmailAddress(),
433                                           this.getAcademicTitle(),
434                                           this.getBirthday(),
435                                           this.getComment()
436                           );
437
438                 // Add missing fields
439                 localContact.setContactId(this.getContactId());
440
441                 // Don't set null or wrong references
442                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
443                         // Now the number must be given
444                         if (landLine.getPhoneAreaCode() == null) {
445                                 // Is null
446                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
447                         } else if (landLine.getPhoneAreaCode() < 1) {
448                                 // Abort here
449                                 throw new IllegalStateException("phone.phoneAreaCode is zero or below."); //NOI18N
450                         } else if (landLine.getPhoneNumber() == null) {
451                                 // Is null
452                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
453                         } else if (landLine.getPhoneNumber() < 1) {
454                                 // Abort here
455                                 throw new IllegalStateException("phone.phoneNumber is zero or below."); //NOI18N
456                         }
457
458                         // Set phone number
459                         contact.setContactLandLineNumber(landLine);
460                 }
461
462                 // Don't set null or wrong references
463                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
464                         // Now the number must be given
465                         if (fax.getPhoneAreaCode() == null) {
466                                 // Is null
467                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
468                         } else if (fax.getPhoneAreaCode() < 1) {
469                                 // Abort here
470                                 throw new IllegalStateException("fax.phoneAreaCode is zero or below."); //NOI18N
471                         } else if (fax.getPhoneNumber() == null) {
472                                 // Is null
473                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
474                         } else if (fax.getPhoneNumber() < 1) {
475                                 // Abort here
476                                 throw new IllegalStateException("fax.phoneNumber is zero or below."); //NOI18N
477                         }
478
479                         // Set fax number
480                         contact.setContactFaxNumber(fax);
481                 }
482
483                 // Is the provider set?
484                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
485                         // Is the number set?
486                         if (mobile.getPhoneNumber() == null) {
487                                 // Is null
488                                 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
489                         } else if (mobile.getPhoneNumber() < 1) {
490                                 // Abort here
491                                 throw new IllegalStateException("cmobile.phoneNumber is zero or below."); //NOI18N
492                         }
493
494                         // Set cmobile number
495                         contact.setContactMobileNumber(mobile);
496                 }
497
498                 // Return it
499                 return contact;
500         }
501
502         /**
503          * Edits currently loaded contact's data in database.
504          * <p>
505          * @return Redirect outcome
506          */
507         public String editContactData () {
508                 // Get contact instance
509                 final Contact contact = this.createContactInstance();
510
511                 // Check if contact instance is in helper and valid
512                 if (null == contact) {
513                         // Throw NPE
514                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
515                 } else if (contact.getContactId() == null) {
516                         // Throw NPE again
517                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
518                 } else if (contact.getContactId() < 1) {
519                         // Invalid id
520                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
521                 }
522
523                 // Update all data in contact
524                 this.updateContactData(contact);
525
526                 // Call EJB for updating contact data
527                 final Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
528
529                 // Fire event
530                 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
531
532                 // Clear bean
533                 this.clear();
534
535                 // Return to contact list (for now)
536                 return "admin_list_contact"; //NOI18N
537         }
538
539         /**
540          * Returns a text representation of given mobile number or null if not set.
541          * <p>
542          * @param mobileNumber Mobile number
543          * <p>
544          * @return Text representation or null
545          */
546         public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
547                 // Is it null?
548                 if (null == mobileNumber) {
549                         // Return null
550                         return null;
551                 }
552
553                 // Get all data
554                 final String number = String.format(
555                                          "%s%d%d", //NOI18N
556                                          mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
557                                          mobileNumber.getMobileProvider().getProviderDialPrefix(),
558                                          mobileNumber.getPhoneNumber()
559                          );
560
561                 // Return it
562                 return number;
563         }
564
565         /**
566          * Returns a text representation of given land-line or fax number or null if
567          * not set.
568          * <p>
569          * @param phoneNumber Land-line or fax number
570          * <p>
571          * @return Text representation or null
572          */
573         public String generatePhoneNumber (final DialableNumber phoneNumber) {
574                 // Is it null?
575                 if (null == phoneNumber) {
576                         // Return null
577                         return null;
578                 }
579
580                 // Generate it
581                 final String number = String.format(
582                                          "%s%d%d", //NOI18N
583                                          phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
584                                          phoneNumber.getPhoneAreaCode(),
585                                          phoneNumber.getPhoneNumber()
586                          );
587
588                 // Return it
589                 return number;
590         }
591
592         /**
593          * Getter for academic title
594          * <p>
595          * @return Academic title
596          */
597         public String getAcademicTitle () {
598                 return this.academicTitle;
599         }
600
601         /**
602          * Setter for academic title
603          * <p>
604          * @param academicTitle Academic title
605          */
606         public void setAcademicTitle (final String academicTitle) {
607                 this.academicTitle = academicTitle;
608         }
609
610         /**
611          * Getter for birth day
612          * <p>
613          * @return Birth day
614          */
615         @SuppressWarnings ("ReturnOfDateField")
616         public Date getBirthday () {
617                 return this.birthday;
618         }
619
620         /**
621          * Setter for birth day
622          * <p>
623          * @param birthday Birth day
624          */
625         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
626         public void setBirthday (final Date birthday) {
627                 this.birthday = birthday;
628         }
629
630         /**
631          * Getter for city name
632          * <p>
633          * @return City name
634          */
635         public String getCity () {
636                 return this.city;
637         }
638
639         /**
640          * Setter for city name
641          * <p>
642          * @param city City name
643          */
644         public void setCity (final String city) {
645                 this.city = city;
646         }
647
648         /**
649          * Getter for comments
650          * <p>
651          * @return Comments
652          */
653         public String getComment () {
654                 return this.comment;
655         }
656
657         /**
658          * Setter for comment
659          * <p>
660          * @param comment Comments
661          */
662         public void setComment (final String comment) {
663                 this.comment = comment;
664         }
665
666         /**
667          * Getter for contactCountry instance
668          * <p>
669          * @return Country instance
670          */
671         public Country getContactCountry () {
672                 return this.contactCountry;
673         }
674
675         /**
676          * Setter for contactCountry instance
677          * <p>
678          * @param contactCountry Country instance
679          */
680         public void setContactCountry (final Country contactCountry) {
681                 this.contactCountry = contactCountry;
682         }
683
684         /**
685          * Getter for contact id
686          * <p>
687          * @return Contact id
688          */
689         public Long getContactId () {
690                 return this.contactId;
691         }
692
693         /**
694          * Setter for contact id
695          * <p>
696          * @param contactId Contact id
697          */
698         public void setContactId (final Long contactId) {
699                 this.contactId = contactId;
700         }
701
702         @Override
703         public String getControllerType () {
704                 return "admin"; //NOI18N
705         }
706
707         @Override
708         @Deprecated
709         public void setControllerType (final String controllerType) {
710                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
711         }
712
713         /**
714          * Getter for email address
715          * <p>
716          * @return Email address
717          */
718         public String getEmailAddress () {
719                 return this.emailAddress;
720         }
721
722         /**
723          * Setter for email address
724          * <p>
725          * @param emailAddress Email address
726          */
727         public void setEmailAddress (final String emailAddress) {
728                 this.emailAddress = emailAddress;
729         }
730
731         /**
732          * Family name
733          * <p>
734          * @return the familyName
735          */
736         public String getFamilyName () {
737                 return this.familyName;
738         }
739
740         /**
741          * Family name
742          * <p>
743          * @param familyName the familyName to set
744          */
745         public void setFamilyName (final String familyName) {
746                 this.familyName = familyName;
747         }
748
749         /**
750          * Getter for fax number's area code
751          * <p>
752          * @return Fax number's area code
753          */
754         public Integer getFaxAreaCode () {
755                 return this.faxAreaCode;
756         }
757
758         /**
759          * Setter for fax number's area code
760          * <p>
761          * @param faxAreaCode Fax number's area code
762          */
763         public void setFaxAreaCode (final Integer faxAreaCode) {
764                 this.faxAreaCode = faxAreaCode;
765         }
766
767         /**
768          * Getter for fax's country instance
769          * <p>
770          * @return Fax' country instance
771          */
772         public Country getFaxCountry () {
773                 return this.faxCountry;
774         }
775
776         /**
777          * Setter for fax's country instance
778          * <p>
779          * @param faxCountry Fax' country instance
780          */
781         public void setFaxCountry (final Country faxCountry) {
782                 this.faxCountry = faxCountry;
783         }
784
785         /**
786          * Getter for fax id
787          * <p>
788          * @return Fax id
789          */
790         public Long getFaxId () {
791                 return this.faxId;
792         }
793
794         /**
795          * Setter for fax id
796          * <p>
797          * @param faxId Fax id
798          */
799         public void setFaxId (final Long faxId) {
800                 this.faxId = faxId;
801         }
802
803         /**
804          * Getter for fax number
805          * <p>
806          * @return Fax number
807          */
808         public Long getFaxNumber () {
809                 return this.faxNumber;
810         }
811
812         /**
813          * Setter for fax number
814          * <p>
815          * @param faxNumber Fax number
816          */
817         public void setFaxNumber (final Long faxNumber) {
818                 this.faxNumber = faxNumber;
819         }
820
821         /**
822          * Getter for first name
823          * <p>
824          * @return First name
825          */
826         public String getFirstName () {
827                 return this.firstName;
828         }
829
830         /**
831          * Setter for first name
832          * <p>
833          * @param firstName First name
834          */
835         public void setFirstName (final String firstName) {
836                 this.firstName = firstName;
837         }
838
839         /**
840          * Getter for house number
841          * <p>
842          * @return House number
843          */
844         public Short getHouseNumber () {
845                 return this.houseNumber;
846         }
847
848         /**
849          * Setter for house number
850          * <p>
851          * @param houseNumber House number
852          */
853         public void setHouseNumber (final Short houseNumber) {
854                 this.houseNumber = houseNumber;
855         }
856
857         /**
858          * Getter for house number extension. Example: 123a, 'a' is the extension
859          * and 123 is the house number.
860          * <p>
861          * @return House number extension
862          */
863         public String getHouseNumberExtension () {
864                 return this.houseNumberExtension;
865         }
866
867         /**
868          * Setter for house number extension
869          * <p>
870          * @param houseNumberExtension House number extension
871          */
872         public void setHouseNumberExtension (final String houseNumberExtension) {
873                 this.houseNumberExtension = houseNumberExtension;
874         }
875
876         /**
877          * Getter for land-line number's area code
878          * <p>
879          * @return Land-line number's area code
880          */
881         public Integer getLandLineAreaCode () {
882                 return this.landLineAreaCode;
883         }
884
885         /**
886          * Setter for land-line number's area code
887          * <p>
888          * @param landLineAreaCode Land-line number's area code
889          */
890         public void setLandLineAreaCode (final Integer landLineAreaCode) {
891                 this.landLineAreaCode = landLineAreaCode;
892         }
893
894         /**
895          * Getter for land-line number's country instance
896          * <p>
897          * @return Land-line number's country instance
898          */
899         public Country getLandLineCountry () {
900                 return this.landLineCountry;
901         }
902
903         /**
904          * Setter for land-line number's country instance
905          * <p>
906          * @param landLineCountry Land-line number's country instance
907          */
908         public void setLandLineCountry (final Country landLineCountry) {
909                 this.landLineCountry = landLineCountry;
910         }
911
912         /**
913          * Getter for land-line id
914          * <p>
915          * @return Land-line id
916          */
917         public Long getLandLineId () {
918                 return this.landLineId;
919         }
920
921         /**
922          * Setter for land-line id
923          * <p>
924          * @param landLineId Land-line id
925          */
926         public void setLandLineId (final Long landLineId) {
927                 this.landLineId = landLineId;
928         }
929
930         /**
931          * Getter for land-line number
932          * <p>
933          * @return Land-line number
934          */
935         public Long getLandLineNumber () {
936                 return this.landLineNumber;
937         }
938
939         /**
940          * Setter for land-line number
941          * <p>
942          * @param landLineNumber Land-line number
943          */
944         public void setLandLineNumber (final Long landLineNumber) {
945                 this.landLineNumber = landLineNumber;
946         }
947
948         /**
949          * Getter for mobile id
950          * <p>
951          * @return Mobile id
952          */
953         public Long getMobileId () {
954                 return this.mobileId;
955         }
956
957         /**
958          * Setter for mobile id
959          * <p>
960          * @param mobileId Mobile id
961          */
962         public void setMobileId (final Long mobileId) {
963                 this.mobileId = mobileId;
964         }
965
966         /**
967          * Getter for mobile number
968          * <p>
969          * @return Mobile number
970          */
971         public Long getMobileNumber () {
972                 return this.mobileNumber;
973         }
974
975         /**
976          * Setter for mobile number
977          * <p>
978          * @param mobileNumber Mobile number
979          */
980         public void setMobileNumber (final Long mobileNumber) {
981                 this.mobileNumber = mobileNumber;
982         }
983
984         /**
985          * Getter for mobile number's carrier
986          * <p>
987          * @return Mobile number's carrier
988          */
989         public MobileProvider getMobileProvider () {
990                 return this.mobileProvider;
991         }
992
993         /**
994          * Setter for mobile number's carrier prefix
995          * <p>
996          * @param mobileProvider Mobile number's carrier prefix
997          */
998         public void setMobileProvider (final MobileProvider mobileProvider) {
999                 this.mobileProvider = mobileProvider;
1000         }
1001
1002         /**
1003          * Getter for personal title
1004          * <p>
1005          * @return Personal title
1006          */
1007         public PersonalTitle getPersonalTitle () {
1008                 return this.personalTitle;
1009         }
1010
1011         /**
1012          * Setter for personal title
1013          * <p>
1014          * @param personalTitle Personal title
1015          */
1016         public void setPersonalTitle (final PersonalTitle personalTitle) {
1017                 this.personalTitle = personalTitle;
1018         }
1019
1020         /**
1021          * Getter for street name
1022          * <p>
1023          * @return Street name
1024          */
1025         public String getStreet () {
1026                 return this.street;
1027         }
1028
1029         /**
1030          * Setter for street name
1031          * <p>
1032          * @param street Street name
1033          */
1034         public void setStreet (final String street) {
1035                 this.street = street;
1036         }
1037
1038         /**
1039          * Getter for ZIP code
1040          * <p>
1041          * @return ZIP code
1042          */
1043         public Integer getZipCode () {
1044                 return this.zipCode;
1045         }
1046
1047         /**
1048          * Setter for ZIP code
1049          * <p>
1050          * @param zipCode ZIP code
1051          */
1052         public void setZipCode (final Integer zipCode) {
1053                 this.zipCode = zipCode;
1054         }
1055
1056         @Override
1057         public boolean isRequiredPersonalDataSet () {
1058                 return ((this.getPersonalTitle() != null) &&
1059                                 (this.getFirstName() != null) &&
1060                                 (this.getFamilyName() != null) &&
1061                                 (this.getStreet() != null) &&
1062                                 (this.getHouseNumber() != null) &&
1063                                 (this.getZipCode() != null) &&
1064                                 (this.getCity() != null) &&
1065                                 (this.getEmailAddress() != null));
1066         }
1067
1068         @Override
1069         public void validateContactData () {
1070                 if (this.getPersonalTitle() == null) {
1071                         // Throw NPE again
1072                         throw new NullPointerException("contactController.personalTitle is null"); //NOI18N
1073                 } else if (this.getFirstName() == null) {
1074                         // ... and again
1075                         throw new NullPointerException("contactController.firstName is null"); //NOI18N
1076                 } else if (this.getFirstName().isEmpty()) {
1077                         // ... and again
1078                         throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1079                 } else if (this.getFamilyName() == null) {
1080                         // ... and again
1081                         throw new NullPointerException("contactController.familyName is null"); //NOI18N
1082                 } else if (this.getFamilyName().isEmpty()) {
1083                         // ... and again
1084                         throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1085                 } else if (this.getEmailAddress() == null) {
1086                         // ... and again
1087                         throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1088                 } else if (this.getEmailAddress().isEmpty()) {
1089                         // ... and again
1090                         throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1091                 }
1092         }
1093
1094         /**
1095          * Clears this bean
1096          */
1097         private void clear () {
1098                 // Clear all data
1099                 // - personal data
1100                 this.setAcademicTitle(null);
1101                 this.setFirstName(null);
1102                 this.setFamilyName(null);
1103                 this.setStreet(null);
1104                 this.setHouseNumber(null);
1105                 this.setHouseNumberExtension(null);
1106                 this.setZipCode(null);
1107                 this.setCity(null);
1108                 this.setContactCountry(null);
1109
1110                 // - contact data
1111                 this.setEmailAddress(null);
1112                 this.setLandLineCountry(null);
1113                 this.setLandLineAreaCode(null);
1114                 this.setLandLineNumber(null);
1115                 this.setMobileProvider(null);
1116                 this.setMobileNumber(null);
1117                 this.setFaxCountry(null);
1118                 this.setFaxAreaCode(null);
1119                 this.setFaxNumber(null);
1120
1121                 // - other data
1122                 this.setBirthday(null);
1123                 this.setComment(null);
1124         }
1125
1126         /**
1127          * Checks whether the given contact is found
1128          * <p>
1129          * @param contact Contact instance
1130          * <p>
1131          * @return Whether contact has been found
1132          */
1133         private boolean isSameContactFound (final Contact contact) {
1134                 // Default is not found
1135                 boolean IsFound = false;
1136
1137                 // Get iterator
1138                 final Iterator<Contact> iterator = this.contactController.allContacts().iterator();
1139
1140                 // Loop through all
1141                 while (iterator.hasNext()) {
1142                         // Get next contact
1143                         final Contact next = iterator.next();
1144
1145                         // Is the same?
1146                         if (ContactUtils.isSameContact(contact, next)) {
1147                                 // Yes, then abort loop
1148                                 IsFound = false;
1149                                 break;
1150                         }
1151                 }
1152
1153                 // Return status
1154                 return IsFound;
1155         }
1156
1157         /**
1158          * Updates all data in contact instance.
1159          * <p>
1160          * @param contact Contact instance
1161          */
1162         private void updateContactData (final Contact contact) {
1163                 // Contact instance should be valid
1164                 if (null == contact) {
1165                         // Throw NPE
1166                         throw new NullPointerException("contact is null"); //NOI18N
1167                 } else if (contact.getContactId() == null) {
1168                         // Throw NPE again
1169                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1170                 } else if (contact.getContactId() < 1) {
1171                         // Invalid id
1172                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1173                 }
1174
1175                 // Update all fields
1176                 contact.setContactPersonalTitle(this.getPersonalTitle());
1177                 contact.setContactTitle(this.getAcademicTitle());
1178                 contact.setContactFirstName(this.getFirstName());
1179                 contact.setContactFamilyName(this.getFamilyName());
1180                 contact.setContactStreet(this.getStreet());
1181                 contact.setContactHouseNumber(this.getHouseNumber());
1182                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1183                 contact.setContactZipCode(this.getZipCode());
1184                 contact.setContactCity(this.getCity());
1185                 contact.setContactCountry(this.getContactCountry());
1186
1187                 // Update contact's cmobile number
1188                 this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1189
1190                 // Update contact's land-line number
1191                 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1192
1193                 // Update contact's fax number
1194                 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
1195         }
1196
1197 }