]> git.mxchange.org Git - jjobs-war.git/blob - src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java
Please cherry-pick/repeat:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / contact / JobsAdminContactWebRequestBean.java
1 /*
2  * Copyright (C) 2016 - 2020 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jjobs.beans.contact;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import javax.ejb.EJB;
22 import javax.enterprise.context.RequestScoped;
23 import javax.enterprise.event.Event;
24 import javax.enterprise.event.Observes;
25 import javax.enterprise.inject.Any;
26 import javax.faces.view.facelets.FaceletException;
27 import javax.inject.Inject;
28 import javax.inject.Named;
29 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
30 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
31 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
32 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
33 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
34 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
35 import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
36 import org.mxchange.jcontacts.model.contact.Contact;
37 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
38 import org.mxchange.jcontacts.model.contact.Contacts;
39 import org.mxchange.jcontacts.model.contact.UserContact;
40 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
41 import org.mxchange.jcountry.model.data.Country;
42 import org.mxchange.jjobs.beans.BaseJobsBean;
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
52 /**
53  * An administrative user controller (bean)
54  * <p>
55  * @author Roland Häder<roland@mxchange.org>
56  */
57 @Named ("adminContactController")
58 @RequestScoped
59 public class JobsAdminContactWebRequestBean extends BaseJobsBean implements JobsAdminContactWebRequestController {
60
61         /**
62          * Serial number
63          */
64         private static final long serialVersionUID = 542_145_347_916L;
65
66         /**
67          * Academic academicTitle
68          */
69         private String academicTitle;
70
71         /**
72          * An event fired when the administrator has added a new contact
73          */
74         @Inject
75         @Any
76         private Event<ObservableAdminAddedContactEvent> addedContactEvent;
77
78         /**
79          * Administrative contact EJB
80          */
81         @EJB (lookup = "java:global/jjobs-ejb/adminContact!org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote")
82         private AdminContactSessionBeanRemote adminContactBean;
83
84         /**
85          * Birth day
86          */
87         private Date birthday;
88
89         /**
90          * City
91          */
92         private String city;
93
94         /**
95          * Optional comments
96          */
97         private String comment;
98
99         /**
100          * EJB for general contact purposes
101          */
102         @EJB (lookup = "java:global/jjobs-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
103         private ContactSessionBeanRemote contactBean;
104
105         /**
106          * General contact controller
107          */
108         @Inject
109         private JobsContactWebRequestController contactController;
110
111         /**
112          * Country instance
113          */
114         private Country contactCountry;
115
116         /**
117          * Contact id
118          */
119         private Long contactId;
120
121         /**
122          * An instance of a contact list controller
123          */
124         @Inject
125         private JobsContactListWebViewController contactListController;
126
127         /**
128          * Email address
129          */
130         private String emailAddress;
131
132         /**
133          * Family name
134          */
135         private String familyName;
136
137         /**
138          * Fax number's area code
139          */
140         private Integer faxAreaCode;
141
142         /**
143          * Country instance for fax number
144          */
145         private Country faxCountry;
146
147         /**
148          * Fax id number
149          */
150         private Long faxId;
151
152         /**
153          * Fax number
154          */
155         private Long faxNumber;
156
157         /**
158          * First name
159          */
160         private String firstName;
161
162         /**
163          * House number
164          */
165         private Short houseNumber;
166
167         /**
168          * House number extension
169          */
170         private String houseNumberExtension;
171
172         /**
173          * Whether a fax entry has been unlinked
174          */
175         private boolean isFaxUnlinked;
176
177         /**
178          * Whether a land-line number has been unlinked
179          */
180         private boolean isLandLineUnlinked;
181
182         /**
183          * Whether a cmobile entry has been unlinked
184          */
185         private boolean isMobileNumberUnlinked;
186
187         /**
188          * Phone number area code
189          */
190         private Integer landLineAreaCode;
191
192         /**
193          * Country instance for phone number
194          */
195         private Country landLineCountry;
196
197         /**
198          * Land-line id number
199          */
200         private Long landLineId;
201
202         /**
203          * Phone number
204          */
205         private Long landLineNumber;
206
207         /**
208          * Mobile id number
209          */
210         private Long mobileId;
211
212         /**
213          * Mobile number
214          */
215         private Long mobileNumber;
216
217         /**
218          * Mobile number's provider
219          */
220         private MobileProvider mobileProvider;
221
222         /**
223          * PersonalTitle instance
224          */
225         private PersonalTitle personalTitle;
226
227         /**
228          * Street
229          */
230         private String street;
231
232         /**
233          * An event fired when the administrator has updated contact data
234          */
235         @Inject
236         @Any
237         private Event<ObservableAdminUpdatedContactEvent> updatedContactEvent;
238
239         /**
240          * ZIP code
241          */
242         private Integer zipCode;
243
244         /**
245          * Default constructor
246          */
247         public JobsAdminContactWebRequestBean () {
248                 // Call super constructor
249                 super();
250         }
251
252         /**
253          * Adds contact data to database and redirects on success. If the contact is
254          * already found, a proper exception is thrown.
255          */
256         public void addContact () {
257                 // Are all minimum fields set?
258                 if (this.getPersonalTitle() == null) {
259                         // Throw NPE
260                         throw new NullPointerException("personalTitle is null"); //NOI18N
261                 } else if (this.getFirstName() == null) {
262                         // Throw NPE
263                         throw new NullPointerException("firstName is null"); //NOI18N
264                 } else if (this.getFirstName().isEmpty()) {
265                         // Empty string
266                         throw new IllegalStateException("firstName is empty"); //NOI18N
267                 } else if (this.getFamilyName() == null) {
268                         // Throw NPE
269                         throw new NullPointerException("familyName is null"); //NOI18N
270                 } else if (this.getFamilyName().isEmpty()) {
271                         // Empty string
272                         throw new IllegalStateException("familyName is empty"); //NOI18N
273                 }
274
275                 // Create new contact instance
276                 final Contact contact = this.createContactInstance();
277
278                 // Default is not same contact
279                 if (this.contactListController.isSameContactFound(contact)) {
280                         // Already registered
281                         throw new FaceletException(new ContactAlreadyAddedException(contact));
282                 }
283
284                 // Init contact
285                 final Contact updatedContact;
286
287                 // Try to call EJB
288                 try {
289                         // Call EJB
290                         updatedContact = this.adminContactBean.addContact(contact);
291                 } catch (final ContactAlreadyAddedException ex) {
292                         // Throw again
293                         throw new FaceletException(ex);
294                 }
295
296                 // Fire event
297                 this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
298
299                 // Clear this bean
300                 this.clear();
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                 }
396
397                 // Generate phone number
398                 final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
399                 final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
400                 final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
401
402                 // Create new instance
403                 final Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
404
405                 // Is contact id set?
406                 if (this.getContactId() instanceof Long) {
407                         // Set it, too
408                         contact.setContactId(this.getContactId());
409                 }
410
411                 // Add all others
412                 contact.setContactTitle(this.getAcademicTitle());
413                 contact.setContactBirthday(this.getBirthday());
414                 contact.setContactStreet(this.getStreet());
415                 contact.setContactHouseNumber(this.getHouseNumber());
416                 contact.setContactZipCode(this.getZipCode());
417                 contact.setContactCity(this.getCity());
418                 contact.setContactCountry(this.getContactCountry());
419                 contact.setContactEmailAddress(this.getEmailAddress());
420                 contact.setContactBirthday(this.getBirthday());
421                 contact.setContactComment(this.getComment());
422
423                 // Set ownContact
424                 contact.setContactOwnContact(Boolean.TRUE);
425
426                 // Don't set null or wrong references
427                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
428                         // Now the number must be given
429                         if (landLine.getPhoneAreaCode() == null) {
430                                 // Is null
431                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
432                         } else if (landLine.getPhoneAreaCode() < 1) {
433                                 // Abort here
434                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
435                         } else if (landLine.getPhoneNumber() == null) {
436                                 // Is null
437                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
438                         } else if (landLine.getPhoneNumber() < 1) {
439                                 // Abort here
440                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
441                         }
442
443                         // Set phone number
444                         contact.setContactLandLineNumber(landLine);
445                 }
446
447                 // Don't set null or wrong references
448                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
449                         // Now the number must be given
450                         if (fax.getPhoneAreaCode() == null) {
451                                 // Is null
452                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
453                         } else if (fax.getPhoneAreaCode() < 1) {
454                                 // Abort here
455                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
456                         } else if (fax.getPhoneNumber() == null) {
457                                 // Is null
458                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
459                         } else if (fax.getPhoneNumber() < 1) {
460                                 // Abort here
461                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
462                         }
463
464                         // Set fax number
465                         contact.setContactFaxNumber(fax);
466                 }
467
468                 // Is the provider set?
469                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
470                         // Is the number set?
471                         if (mobile.getPhoneNumber() == null) {
472                                 // Is null
473                                 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
474                         } else if (mobile.getPhoneNumber() < 1) {
475                                 // Abort here
476                                 throw new IllegalArgumentException("cmobile.phoneNumber is zero or below."); //NOI18N
477                         }
478
479                         // Set cmobile number
480                         contact.setContactMobileNumber(mobile);
481                 }
482
483                 // Return it
484                 return contact;
485         }
486
487         /**
488          * Edits currently loaded contact's data in database.
489          */
490         public void editContactData () {
491                 // Get contact instance
492                 final Contact contact = this.createContactInstance();
493
494                 // Check if contact instance is in helper and valid
495                 if (null == contact) {
496                         // Throw NPE
497                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
498                 } else if (contact.getContactId() == null) {
499                         // Throw NPE again
500                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
501                 } else if (contact.getContactId() < 1) {
502                         // Invalid id
503                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
504                 }
505
506                 // Update all data in contact
507                 this.updateContactData(contact);
508
509                 // Call EJB for updating contact data
510                 final Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
511
512                 // Fire event
513                 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
514
515                 // Clear bean
516                 this.clear();
517         }
518
519         /**
520          * Returns a text representation of given mobile number or null if not set.
521          * <p>
522          * @param mobileNumber Mobile number
523          * <p>
524          * @return Text representation or null
525          */
526         public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
527                 // Is it null?
528                 if (null == mobileNumber) {
529                         // Return null
530                         return null;
531                 }
532
533                 // Get all data
534                 final String number = String.format(
535                                          "%s%d%d", //NOI18N
536                                          mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
537                                          mobileNumber.getMobileProvider().getProviderDialPrefix(),
538                                          mobileNumber.getPhoneNumber()
539                          );
540
541                 // Return it
542                 return number;
543         }
544
545         /**
546          * Returns a text representation of given land-line or fax number or null if
547          * not set.
548          * <p>
549          * @param phoneNumber Land-line or fax number
550          * <p>
551          * @return Text representation or null
552          */
553         public String generatePhoneNumber (final DialableNumber phoneNumber) {
554                 // Is it null?
555                 if (null == phoneNumber) {
556                         // Return null
557                         return null;
558                 }
559
560                 // Generate it
561                 final String number = String.format(
562                                          "%s%d%d", //NOI18N
563                                          phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
564                                          phoneNumber.getPhoneAreaCode(),
565                                          phoneNumber.getPhoneNumber()
566                          );
567
568                 // Return it
569                 return number;
570         }
571
572         /**
573          * Getter for academic title
574          * <p>
575          * @return Academic title
576          */
577         public String getAcademicTitle () {
578                 return this.academicTitle;
579         }
580
581         /**
582          * Setter for academic title
583          * <p>
584          * @param academicTitle Academic title
585          */
586         public void setAcademicTitle (final String academicTitle) {
587                 this.academicTitle = academicTitle;
588         }
589
590         /**
591          * Getter for birth day
592          * <p>
593          * @return Birth day
594          */
595         @SuppressWarnings ("ReturnOfDateField")
596         public Date getBirthday () {
597                 return this.birthday;
598         }
599
600         /**
601          * Setter for birth day
602          * <p>
603          * @param birthday Birth day
604          */
605         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
606         public void setBirthday (final Date birthday) {
607                 this.birthday = birthday;
608         }
609
610         /**
611          * Getter for city name
612          * <p>
613          * @return City name
614          */
615         public String getCity () {
616                 return this.city;
617         }
618
619         /**
620          * Setter for city name
621          * <p>
622          * @param city City name
623          */
624         public void setCity (final String city) {
625                 this.city = city;
626         }
627
628         /**
629          * Getter for comments
630          * <p>
631          * @return Comments
632          */
633         public String getComment () {
634                 return this.comment;
635         }
636
637         /**
638          * Setter for comment
639          * <p>
640          * @param comment Comments
641          */
642         public void setComment (final String comment) {
643                 this.comment = comment;
644         }
645
646         /**
647          * Getter for contactCountry instance
648          * <p>
649          * @return Country instance
650          */
651         public Country getContactCountry () {
652                 return this.contactCountry;
653         }
654
655         /**
656          * Setter for contactCountry instance
657          * <p>
658          * @param contactCountry Country instance
659          */
660         public void setContactCountry (final Country contactCountry) {
661                 this.contactCountry = contactCountry;
662         }
663
664         /**
665          * Getter for contact id
666          * <p>
667          * @return Contact id
668          */
669         public Long getContactId () {
670                 return this.contactId;
671         }
672
673         /**
674          * Setter for contact id
675          * <p>
676          * @param contactId Contact id
677          */
678         public void setContactId (final Long contactId) {
679                 this.contactId = contactId;
680         }
681
682         @Override
683         public String getControllerType () {
684                 return "admin"; //NOI18N
685         }
686
687         @Override
688         @Deprecated
689         public void setControllerType (final String controllerType) {
690                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
691         }
692
693         /**
694          * Getter for email address
695          * <p>
696          * @return Email address
697          */
698         public String getEmailAddress () {
699                 return this.emailAddress;
700         }
701
702         /**
703          * Setter for email address
704          * <p>
705          * @param emailAddress Email address
706          */
707         public void setEmailAddress (final String emailAddress) {
708                 this.emailAddress = emailAddress;
709         }
710
711         /**
712          * Family name
713          * <p>
714          * @return the familyName
715          */
716         public String getFamilyName () {
717                 return this.familyName;
718         }
719
720         /**
721          * Family name
722          * <p>
723          * @param familyName the familyName to set
724          */
725         public void setFamilyName (final String familyName) {
726                 this.familyName = familyName;
727         }
728
729         /**
730          * Getter for fax number's area code
731          * <p>
732          * @return Fax number's area code
733          */
734         public Integer getFaxAreaCode () {
735                 return this.faxAreaCode;
736         }
737
738         /**
739          * Setter for fax number's area code
740          * <p>
741          * @param faxAreaCode Fax number's area code
742          */
743         public void setFaxAreaCode (final Integer faxAreaCode) {
744                 this.faxAreaCode = faxAreaCode;
745         }
746
747         /**
748          * Getter for fax's country instance
749          * <p>
750          * @return Fax' country instance
751          */
752         public Country getFaxCountry () {
753                 return this.faxCountry;
754         }
755
756         /**
757          * Setter for fax's country instance
758          * <p>
759          * @param faxCountry Fax' country instance
760          */
761         public void setFaxCountry (final Country faxCountry) {
762                 this.faxCountry = faxCountry;
763         }
764
765         /**
766          * Getter for fax id
767          * <p>
768          * @return Fax id
769          */
770         public Long getFaxId () {
771                 return this.faxId;
772         }
773
774         /**
775          * Setter for fax id
776          * <p>
777          * @param faxId Fax id
778          */
779         public void setFaxId (final Long faxId) {
780                 this.faxId = faxId;
781         }
782
783         /**
784          * Getter for fax number
785          * <p>
786          * @return Fax number
787          */
788         public Long getFaxNumber () {
789                 return this.faxNumber;
790         }
791
792         /**
793          * Setter for fax number
794          * <p>
795          * @param faxNumber Fax number
796          */
797         public void setFaxNumber (final Long faxNumber) {
798                 this.faxNumber = faxNumber;
799         }
800
801         /**
802          * Getter for first name
803          * <p>
804          * @return First name
805          */
806         public String getFirstName () {
807                 return this.firstName;
808         }
809
810         /**
811          * Setter for first name
812          * <p>
813          * @param firstName First name
814          */
815         public void setFirstName (final String firstName) {
816                 this.firstName = firstName;
817         }
818
819         /**
820          * Getter for house number
821          * <p>
822          * @return House number
823          */
824         public Short getHouseNumber () {
825                 return this.houseNumber;
826         }
827
828         /**
829          * Setter for house number
830          * <p>
831          * @param houseNumber House number
832          */
833         public void setHouseNumber (final Short houseNumber) {
834                 this.houseNumber = houseNumber;
835         }
836
837         /**
838          * Getter for house number extension. Example: 123a, 'a' is the extension
839          * and 123 is the house number.
840          * <p>
841          * @return House number extension
842          */
843         public String getHouseNumberExtension () {
844                 return this.houseNumberExtension;
845         }
846
847         /**
848          * Setter for house number extension
849          * <p>
850          * @param houseNumberExtension House number extension
851          */
852         public void setHouseNumberExtension (final String houseNumberExtension) {
853                 this.houseNumberExtension = houseNumberExtension;
854         }
855
856         /**
857          * Getter for land-line number's area code
858          * <p>
859          * @return Land-line number's area code
860          */
861         public Integer getLandLineAreaCode () {
862                 return this.landLineAreaCode;
863         }
864
865         /**
866          * Setter for land-line number's area code
867          * <p>
868          * @param landLineAreaCode Land-line number's area code
869          */
870         public void setLandLineAreaCode (final Integer landLineAreaCode) {
871                 this.landLineAreaCode = landLineAreaCode;
872         }
873
874         /**
875          * Getter for land-line number's country instance
876          * <p>
877          * @return Land-line number's country instance
878          */
879         public Country getLandLineCountry () {
880                 return this.landLineCountry;
881         }
882
883         /**
884          * Setter for land-line number's country instance
885          * <p>
886          * @param landLineCountry Land-line number's country instance
887          */
888         public void setLandLineCountry (final Country landLineCountry) {
889                 this.landLineCountry = landLineCountry;
890         }
891
892         /**
893          * Getter for land-line id
894          * <p>
895          * @return Land-line id
896          */
897         public Long getLandLineId () {
898                 return this.landLineId;
899         }
900
901         /**
902          * Setter for land-line id
903          * <p>
904          * @param landLineId Land-line id
905          */
906         public void setLandLineId (final Long landLineId) {
907                 this.landLineId = landLineId;
908         }
909
910         /**
911          * Getter for land-line number
912          * <p>
913          * @return Land-line number
914          */
915         public Long getLandLineNumber () {
916                 return this.landLineNumber;
917         }
918
919         /**
920          * Setter for land-line number
921          * <p>
922          * @param landLineNumber Land-line number
923          */
924         public void setLandLineNumber (final Long landLineNumber) {
925                 this.landLineNumber = landLineNumber;
926         }
927
928         /**
929          * Getter for mobile id
930          * <p>
931          * @return Mobile id
932          */
933         public Long getMobileId () {
934                 return this.mobileId;
935         }
936
937         /**
938          * Setter for mobile id
939          * <p>
940          * @param mobileId Mobile id
941          */
942         public void setMobileId (final Long mobileId) {
943                 this.mobileId = mobileId;
944         }
945
946         /**
947          * Getter for mobile number
948          * <p>
949          * @return Mobile number
950          */
951         public Long getMobileNumber () {
952                 return this.mobileNumber;
953         }
954
955         /**
956          * Setter for mobile number
957          * <p>
958          * @param mobileNumber Mobile number
959          */
960         public void setMobileNumber (final Long mobileNumber) {
961                 this.mobileNumber = mobileNumber;
962         }
963
964         /**
965          * Getter for mobile number's carrier
966          * <p>
967          * @return Mobile number's carrier
968          */
969         public MobileProvider getMobileProvider () {
970                 return this.mobileProvider;
971         }
972
973         /**
974          * Setter for mobile number's carrier prefix
975          * <p>
976          * @param mobileProvider Mobile number's carrier prefix
977          */
978         public void setMobileProvider (final MobileProvider mobileProvider) {
979                 this.mobileProvider = mobileProvider;
980         }
981
982         /**
983          * Getter for personal title
984          * <p>
985          * @return Personal title
986          */
987         public PersonalTitle getPersonalTitle () {
988                 return this.personalTitle;
989         }
990
991         /**
992          * Setter for personal title
993          * <p>
994          * @param personalTitle Personal title
995          */
996         public void setPersonalTitle (final PersonalTitle personalTitle) {
997                 this.personalTitle = personalTitle;
998         }
999
1000         /**
1001          * Getter for street name
1002          * <p>
1003          * @return Street name
1004          */
1005         public String getStreet () {
1006                 return this.street;
1007         }
1008
1009         /**
1010          * Setter for street name
1011          * <p>
1012          * @param street Street name
1013          */
1014         public void setStreet (final String street) {
1015                 this.street = street;
1016         }
1017
1018         /**
1019          * Getter for ZIP code
1020          * <p>
1021          * @return ZIP code
1022          */
1023         public Integer getZipCode () {
1024                 return this.zipCode;
1025         }
1026
1027         /**
1028          * Setter for ZIP code
1029          * <p>
1030          * @param zipCode ZIP code
1031          */
1032         public void setZipCode (final Integer zipCode) {
1033                 this.zipCode = zipCode;
1034         }
1035
1036         @Override
1037         public void validateContactData () {
1038                 if (this.getPersonalTitle() == null) {
1039                         // Throw NPE again
1040                         throw new NullPointerException("contactController.gender is null"); //NOI18N
1041                 } else if (this.getFirstName() == null) {
1042                         // ... and again
1043                         throw new NullPointerException("contactController.firstName is null"); //NOI18N
1044                 } else if (this.getFirstName().isEmpty()) {
1045                         // ... and again
1046                         throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1047                 } else if (this.getFamilyName() == null) {
1048                         // ... and again
1049                         throw new NullPointerException("contactController.familyName is null"); //NOI18N
1050                 } else if (this.getFamilyName().isEmpty()) {
1051                         // ... and again
1052                         throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1053                 } else if (this.getEmailAddress() == null) {
1054                         // ... and again
1055                         throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1056                 } else if (this.getEmailAddress().isEmpty()) {
1057                         // ... and again
1058                         throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1059                 }
1060         }
1061
1062         /**
1063          * Clears this bean
1064          */
1065         private void clear () {
1066                 // Clear all data
1067                 // - personal data
1068                 this.setAcademicTitle(null);
1069                 this.setFirstName(null);
1070                 this.setFamilyName(null);
1071                 this.setStreet(null);
1072                 this.setHouseNumber(null);
1073                 this.setHouseNumberExtension(null);
1074                 this.setZipCode(null);
1075                 this.setCity(null);
1076                 this.setContactCountry(null);
1077
1078                 // - contact data
1079                 this.setEmailAddress(null);
1080                 this.setLandLineCountry(null);
1081                 this.setLandLineAreaCode(null);
1082                 this.setLandLineNumber(null);
1083                 this.setMobileProvider(null);
1084                 this.setMobileNumber(null);
1085                 this.setFaxCountry(null);
1086                 this.setFaxAreaCode(null);
1087                 this.setFaxNumber(null);
1088
1089                 // - other data
1090                 this.setBirthday(null);
1091                 this.setComment(null);
1092         }
1093
1094         /**
1095          * Updates all data in contact instance.
1096          * <p>
1097          * @param contact Contact instance
1098          */
1099         private void updateContactData (final Contact contact) {
1100                 // Contact instance should be valid
1101                 if (null == contact) {
1102                         // Throw NPE
1103                         throw new NullPointerException("contact is null"); //NOI18N
1104                 } else if (contact.getContactId() == null) {
1105                         // Throw NPE again
1106                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1107                 } else if (contact.getContactId() < 1) {
1108                         // Invalid id
1109                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1110                 }
1111
1112                 // Update all fields
1113                 contact.setContactPersonalTitle(this.getPersonalTitle());
1114                 contact.setContactTitle(this.getAcademicTitle());
1115                 contact.setContactFirstName(this.getFirstName());
1116                 contact.setContactFamilyName(this.getFamilyName());
1117                 contact.setContactStreet(this.getStreet());
1118                 contact.setContactHouseNumber(this.getHouseNumber());
1119                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1120                 contact.setContactZipCode(this.getZipCode());
1121                 contact.setContactCity(this.getCity());
1122                 contact.setContactCountry(this.getContactCountry());
1123
1124                 // Update contact's cmobile number
1125                 this.isMobileNumberUnlinked = Contacts.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1126
1127                 // Update contact's land-line number
1128                 this.isLandLineUnlinked = Contacts.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1129
1130                 // Update contact's fax number
1131                 this.isFaxUnlinked = Contacts.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
1132         }
1133
1134 }