]> git.mxchange.org Git - jjobs-war.git/blob - src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java
Don't cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / contact / JobsAdminContactWebRequestBean.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jjobs.beans.contact;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.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.model.contact.AdminContactSessionBeanRemote;
31 import org.mxchange.jcontacts.model.contact.Contact;
32 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
33 import org.mxchange.jcontacts.model.contact.ContactUtils;
34 import org.mxchange.jcontacts.model.contact.UserContact;
35 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
36 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
37 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
38 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
39 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
40 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
41 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
42 import org.mxchange.jcountry.model.data.Country;
43 import org.mxchange.jjobs.beans.BaseJobsController;
44 import org.mxchange.jphone.model.phonenumbers.DialableNumber;
45 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
46 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
47 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
48 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
49 import org.mxchange.jphone.phonenumbers.model.mobile.DialableMobileNumber;
50 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
51 import org.mxchange.jphone.phonenumbers.model.mobileprovider.MobileProvider;
52
53 /**
54  * An administrative user controller (bean)
55  * <p>
56  * @author Roland Häder<roland@mxchange.org>
57  */
58 @Named ("adminContactController")
59 @RequestScoped
60 public class JobsAdminContactWebRequestBean extends BaseJobsController implements JobsAdminContactWebRequestController {
61
62         /**
63          * Serial number
64          */
65         private static final long serialVersionUID = 542_145_347_916L;
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/jjobs-ejb/adminContact!org.mxchange.jcontacts.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/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote")
104         private ContactSessionBeanRemote contactBean;
105
106         /**
107          * General contact controller
108          */
109         @Inject
110         private JobsContactWebRequestController 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 cmobile 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 JobsAdminContactWebRequestBean () {
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                 }
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          * <p>
490          * @return Redirect outcome
491          */
492         public String editContactData () {
493                 // Get contact instance
494                 final Contact contact = this.createContactInstance();
495
496                 // Check if contact instance is in helper and valid
497                 if (null == contact) {
498                         // Throw NPE
499                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
500                 } else if (contact.getContactId() == null) {
501                         // Throw NPE again
502                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
503                 } else if (contact.getContactId() < 1) {
504                         // Invalid id
505                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
506                 }
507
508                 // Update all data in contact
509                 this.updateContactData(contact);
510
511                 // Call EJB for updating contact data
512                 final Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
513
514                 // Fire event
515                 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
516
517                 // Clear bean
518                 this.clear();
519
520                 // Return to contact list (for now)
521                 return "admin_list_contact"; //NOI18N
522         }
523
524         /**
525          * Returns a text representation of given mobile number or null if not set.
526          * <p>
527          * @param mobileNumber Mobile number
528          * <p>
529          * @return Text representation or null
530          */
531         public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
532                 // Is it null?
533                 if (null == mobileNumber) {
534                         // Return null
535                         return null;
536                 }
537
538                 // Get all data
539                 final String number = String.format(
540                                          "%s%d%d", //NOI18N
541                                          mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
542                                          mobileNumber.getMobileProvider().getProviderDialPrefix(),
543                                          mobileNumber.getPhoneNumber()
544                          );
545
546                 // Return it
547                 return number;
548         }
549
550         /**
551          * Returns a text representation of given land-line or fax number or null if
552          * not set.
553          * <p>
554          * @param phoneNumber Land-line or fax number
555          * <p>
556          * @return Text representation or null
557          */
558         public String generatePhoneNumber (final DialableNumber phoneNumber) {
559                 // Is it null?
560                 if (null == phoneNumber) {
561                         // Return null
562                         return null;
563                 }
564
565                 // Generate it
566                 final String number = String.format(
567                                          "%s%d%d", //NOI18N
568                                          phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
569                                          phoneNumber.getPhoneAreaCode(),
570                                          phoneNumber.getPhoneNumber()
571                          );
572
573                 // Return it
574                 return number;
575         }
576
577         /**
578          * Getter for academic title
579          * <p>
580          * @return Academic title
581          */
582         public String getAcademicTitle () {
583                 return this.academicTitle;
584         }
585
586         /**
587          * Setter for academic title
588          * <p>
589          * @param academicTitle Academic title
590          */
591         public void setAcademicTitle (final String academicTitle) {
592                 this.academicTitle = academicTitle;
593         }
594
595         /**
596          * Getter for birth day
597          * <p>
598          * @return Birth day
599          */
600         @SuppressWarnings ("ReturnOfDateField")
601         public Date getBirthday () {
602                 return this.birthday;
603         }
604
605         /**
606          * Setter for birth day
607          * <p>
608          * @param birthday Birth day
609          */
610         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
611         public void setBirthday (final Date birthday) {
612                 this.birthday = birthday;
613         }
614
615         /**
616          * Getter for city name
617          * <p>
618          * @return City name
619          */
620         public String getCity () {
621                 return this.city;
622         }
623
624         /**
625          * Setter for city name
626          * <p>
627          * @param city City name
628          */
629         public void setCity (final String city) {
630                 this.city = city;
631         }
632
633         /**
634          * Getter for comments
635          * <p>
636          * @return Comments
637          */
638         public String getComment () {
639                 return this.comment;
640         }
641
642         /**
643          * Setter for comment
644          * <p>
645          * @param comment Comments
646          */
647         public void setComment (final String comment) {
648                 this.comment = comment;
649         }
650
651         /**
652          * Getter for contactCountry instance
653          * <p>
654          * @return Country instance
655          */
656         public Country getContactCountry () {
657                 return this.contactCountry;
658         }
659
660         /**
661          * Setter for contactCountry instance
662          * <p>
663          * @param contactCountry Country instance
664          */
665         public void setContactCountry (final Country contactCountry) {
666                 this.contactCountry = contactCountry;
667         }
668
669         /**
670          * Getter for contact id
671          * <p>
672          * @return Contact id
673          */
674         public Long getContactId () {
675                 return this.contactId;
676         }
677
678         /**
679          * Setter for contact id
680          * <p>
681          * @param contactId Contact id
682          */
683         public void setContactId (final Long contactId) {
684                 this.contactId = contactId;
685         }
686
687         @Override
688         public String getControllerType () {
689                 return "admin"; //NOI18N
690         }
691
692         @Override
693         @Deprecated
694         public void setControllerType (final String controllerType) {
695                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
696         }
697
698         /**
699          * Getter for email address
700          * <p>
701          * @return Email address
702          */
703         public String getEmailAddress () {
704                 return this.emailAddress;
705         }
706
707         /**
708          * Setter for email address
709          * <p>
710          * @param emailAddress Email address
711          */
712         public void setEmailAddress (final String emailAddress) {
713                 this.emailAddress = emailAddress;
714         }
715
716         /**
717          * Family name
718          * <p>
719          * @return the familyName
720          */
721         public String getFamilyName () {
722                 return this.familyName;
723         }
724
725         /**
726          * Family name
727          * <p>
728          * @param familyName the familyName to set
729          */
730         public void setFamilyName (final String familyName) {
731                 this.familyName = familyName;
732         }
733
734         /**
735          * Getter for fax number's area code
736          * <p>
737          * @return Fax number's area code
738          */
739         public Integer getFaxAreaCode () {
740                 return this.faxAreaCode;
741         }
742
743         /**
744          * Setter for fax number's area code
745          * <p>
746          * @param faxAreaCode Fax number's area code
747          */
748         public void setFaxAreaCode (final Integer faxAreaCode) {
749                 this.faxAreaCode = faxAreaCode;
750         }
751
752         /**
753          * Getter for fax's country instance
754          * <p>
755          * @return Fax' country instance
756          */
757         public Country getFaxCountry () {
758                 return this.faxCountry;
759         }
760
761         /**
762          * Setter for fax's country instance
763          * <p>
764          * @param faxCountry Fax' country instance
765          */
766         public void setFaxCountry (final Country faxCountry) {
767                 this.faxCountry = faxCountry;
768         }
769
770         /**
771          * Getter for fax id
772          * <p>
773          * @return Fax id
774          */
775         public Long getFaxId () {
776                 return this.faxId;
777         }
778
779         /**
780          * Setter for fax id
781          * <p>
782          * @param faxId Fax id
783          */
784         public void setFaxId (final Long faxId) {
785                 this.faxId = faxId;
786         }
787
788         /**
789          * Getter for fax number
790          * <p>
791          * @return Fax number
792          */
793         public Long getFaxNumber () {
794                 return this.faxNumber;
795         }
796
797         /**
798          * Setter for fax number
799          * <p>
800          * @param faxNumber Fax number
801          */
802         public void setFaxNumber (final Long faxNumber) {
803                 this.faxNumber = faxNumber;
804         }
805
806         /**
807          * Getter for first name
808          * <p>
809          * @return First name
810          */
811         public String getFirstName () {
812                 return this.firstName;
813         }
814
815         /**
816          * Setter for first name
817          * <p>
818          * @param firstName First name
819          */
820         public void setFirstName (final String firstName) {
821                 this.firstName = firstName;
822         }
823
824         /**
825          * Getter for house number
826          * <p>
827          * @return House number
828          */
829         public Short getHouseNumber () {
830                 return this.houseNumber;
831         }
832
833         /**
834          * Setter for house number
835          * <p>
836          * @param houseNumber House number
837          */
838         public void setHouseNumber (final Short houseNumber) {
839                 this.houseNumber = houseNumber;
840         }
841
842         /**
843          * Getter for house number extension. Example: 123a, 'a' is the extension
844          * and 123 is the house number.
845          * <p>
846          * @return House number extension
847          */
848         public String getHouseNumberExtension () {
849                 return this.houseNumberExtension;
850         }
851
852         /**
853          * Setter for house number extension
854          * <p>
855          * @param houseNumberExtension House number extension
856          */
857         public void setHouseNumberExtension (final String houseNumberExtension) {
858                 this.houseNumberExtension = houseNumberExtension;
859         }
860
861         /**
862          * Getter for land-line number's area code
863          * <p>
864          * @return Land-line number's area code
865          */
866         public Integer getLandLineAreaCode () {
867                 return this.landLineAreaCode;
868         }
869
870         /**
871          * Setter for land-line number's area code
872          * <p>
873          * @param landLineAreaCode Land-line number's area code
874          */
875         public void setLandLineAreaCode (final Integer landLineAreaCode) {
876                 this.landLineAreaCode = landLineAreaCode;
877         }
878
879         /**
880          * Getter for land-line number's country instance
881          * <p>
882          * @return Land-line number's country instance
883          */
884         public Country getLandLineCountry () {
885                 return this.landLineCountry;
886         }
887
888         /**
889          * Setter for land-line number's country instance
890          * <p>
891          * @param landLineCountry Land-line number's country instance
892          */
893         public void setLandLineCountry (final Country landLineCountry) {
894                 this.landLineCountry = landLineCountry;
895         }
896
897         /**
898          * Getter for land-line id
899          * <p>
900          * @return Land-line id
901          */
902         public Long getLandLineId () {
903                 return this.landLineId;
904         }
905
906         /**
907          * Setter for land-line id
908          * <p>
909          * @param landLineId Land-line id
910          */
911         public void setLandLineId (final Long landLineId) {
912                 this.landLineId = landLineId;
913         }
914
915         /**
916          * Getter for land-line number
917          * <p>
918          * @return Land-line number
919          */
920         public Long getLandLineNumber () {
921                 return this.landLineNumber;
922         }
923
924         /**
925          * Setter for land-line number
926          * <p>
927          * @param landLineNumber Land-line number
928          */
929         public void setLandLineNumber (final Long landLineNumber) {
930                 this.landLineNumber = landLineNumber;
931         }
932
933         /**
934          * Getter for mobile id
935          * <p>
936          * @return Mobile id
937          */
938         public Long getMobileId () {
939                 return this.mobileId;
940         }
941
942         /**
943          * Setter for mobile id
944          * <p>
945          * @param mobileId Mobile id
946          */
947         public void setMobileId (final Long mobileId) {
948                 this.mobileId = mobileId;
949         }
950
951         /**
952          * Getter for mobile number
953          * <p>
954          * @return Mobile number
955          */
956         public Long getMobileNumber () {
957                 return this.mobileNumber;
958         }
959
960         /**
961          * Setter for mobile number
962          * <p>
963          * @param mobileNumber Mobile number
964          */
965         public void setMobileNumber (final Long mobileNumber) {
966                 this.mobileNumber = mobileNumber;
967         }
968
969         /**
970          * Getter for mobile number's carrier
971          * <p>
972          * @return Mobile number's carrier
973          */
974         public MobileProvider getMobileProvider () {
975                 return this.mobileProvider;
976         }
977
978         /**
979          * Setter for mobile number's carrier prefix
980          * <p>
981          * @param mobileProvider Mobile number's carrier prefix
982          */
983         public void setMobileProvider (final MobileProvider mobileProvider) {
984                 this.mobileProvider = mobileProvider;
985         }
986
987         /**
988          * Getter for personal title
989          * <p>
990          * @return Personal title
991          */
992         public PersonalTitle getPersonalTitle () {
993                 return this.personalTitle;
994         }
995
996         /**
997          * Setter for personal title
998          * <p>
999          * @param personalTitle Personal title
1000          */
1001         public void setPersonalTitle (final PersonalTitle personalTitle) {
1002                 this.personalTitle = personalTitle;
1003         }
1004
1005         /**
1006          * Getter for street name
1007          * <p>
1008          * @return Street name
1009          */
1010         public String getStreet () {
1011                 return this.street;
1012         }
1013
1014         /**
1015          * Setter for street name
1016          * <p>
1017          * @param street Street name
1018          */
1019         public void setStreet (final String street) {
1020                 this.street = street;
1021         }
1022
1023         /**
1024          * Getter for ZIP code
1025          * <p>
1026          * @return ZIP code
1027          */
1028         public Integer getZipCode () {
1029                 return this.zipCode;
1030         }
1031
1032         /**
1033          * Setter for ZIP code
1034          * <p>
1035          * @param zipCode ZIP code
1036          */
1037         public void setZipCode (final Integer zipCode) {
1038                 this.zipCode = zipCode;
1039         }
1040
1041         @Override
1042         public void validateContactData () {
1043                 if (this.getPersonalTitle() == null) {
1044                         // Throw NPE again
1045                         throw new NullPointerException("contactController.gender is null"); //NOI18N
1046                 } else if (this.getFirstName() == null) {
1047                         // ... and again
1048                         throw new NullPointerException("contactController.firstName is null"); //NOI18N
1049                 } else if (this.getFirstName().isEmpty()) {
1050                         // ... and again
1051                         throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1052                 } else if (this.getFamilyName() == null) {
1053                         // ... and again
1054                         throw new NullPointerException("contactController.familyName is null"); //NOI18N
1055                 } else if (this.getFamilyName().isEmpty()) {
1056                         // ... and again
1057                         throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1058                 } else if (this.getEmailAddress() == null) {
1059                         // ... and again
1060                         throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1061                 } else if (this.getEmailAddress().isEmpty()) {
1062                         // ... and again
1063                         throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1064                 }
1065         }
1066
1067         /**
1068          * Clears this bean
1069          */
1070         private void clear () {
1071                 // Clear all data
1072                 // - personal data
1073                 this.setAcademicTitle(null);
1074                 this.setFirstName(null);
1075                 this.setFamilyName(null);
1076                 this.setStreet(null);
1077                 this.setHouseNumber(null);
1078                 this.setHouseNumberExtension(null);
1079                 this.setZipCode(null);
1080                 this.setCity(null);
1081                 this.setContactCountry(null);
1082
1083                 // - contact data
1084                 this.setEmailAddress(null);
1085                 this.setLandLineCountry(null);
1086                 this.setLandLineAreaCode(null);
1087                 this.setLandLineNumber(null);
1088                 this.setMobileProvider(null);
1089                 this.setMobileNumber(null);
1090                 this.setFaxCountry(null);
1091                 this.setFaxAreaCode(null);
1092                 this.setFaxNumber(null);
1093
1094                 // - other data
1095                 this.setBirthday(null);
1096                 this.setComment(null);
1097         }
1098
1099         /**
1100          * Checks whether the given contact is found
1101          * <p>
1102          * @param contact Contact instance
1103          *
1104          * @return Whether contact has been found
1105          */
1106         private boolean isSameContactFound (final Contact contact) {
1107                 // Default is not found
1108                 boolean IsFound = false;
1109
1110                 // Get iterator
1111                 final Iterator<Contact> iterator = this.contactController.allContacts().iterator();
1112
1113                 // Loop through all
1114                 while (iterator.hasNext()) {
1115                         // Get next contact
1116                         final Contact next = iterator.next();
1117
1118                         // Is the same?
1119                         if (ContactUtils.isSameContact(contact, next)) {
1120                                 // Yes, then abort loop
1121                                 IsFound = false;
1122                                 break;
1123                         }
1124                 }
1125
1126                 // Return status
1127                 return IsFound;
1128         }
1129
1130         /**
1131          * Updates all data in contact instance.
1132          * <p>
1133          * @param contact Contact instance
1134          */
1135         private void updateContactData (final Contact contact) {
1136                 // Contact instance should be valid
1137                 if (null == contact) {
1138                         // Throw NPE
1139                         throw new NullPointerException("contact is null"); //NOI18N
1140                 } else if (contact.getContactId() == null) {
1141                         // Throw NPE again
1142                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1143                 } else if (contact.getContactId() < 1) {
1144                         // Invalid id
1145                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1146                 }
1147
1148                 // Update all fields
1149                 contact.setContactPersonalTitle(this.getPersonalTitle());
1150                 contact.setContactTitle(this.getAcademicTitle());
1151                 contact.setContactFirstName(this.getFirstName());
1152                 contact.setContactFamilyName(this.getFamilyName());
1153                 contact.setContactStreet(this.getStreet());
1154                 contact.setContactHouseNumber(this.getHouseNumber());
1155                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1156                 contact.setContactZipCode(this.getZipCode());
1157                 contact.setContactCity(this.getCity());
1158                 contact.setContactCountry(this.getContactCountry());
1159
1160                 // Update contact's cmobile number
1161                 this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1162
1163                 // Update contact's land-line number
1164                 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1165
1166                 // Update contact's fax number
1167                 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
1168         }
1169
1170 }