]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
API has changed: no more cellphone, now is mobile
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / contact / PizzaAdminContactWebRequestBean.java
1 /*
2  * Copyright (C) 2016 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.pizzaapplication.beans.contact;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.Iterator;
22 import javax.annotation.PostConstruct;
23 import javax.enterprise.context.RequestScoped;
24 import javax.enterprise.event.Event;
25 import javax.enterprise.inject.Any;
26 import javax.faces.context.FacesContext;
27 import javax.faces.view.facelets.FaceletException;
28 import javax.inject.Inject;
29 import javax.inject.Named;
30 import javax.naming.Context;
31 import javax.naming.InitialContext;
32 import javax.naming.NamingException;
33 import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
36 import org.mxchange.jcontacts.contact.UserContact;
37 import org.mxchange.jcontacts.contact.gender.Gender;
38 import org.mxchange.jcontacts.contact.utils.ContactUtils;
39 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
40 import org.mxchange.jcontacts.events.contact.add.AdminContactAddedEvent;
41 import org.mxchange.jcontacts.events.contact.update.AdminContactUpdatedEvent;
42 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
43 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
44 import org.mxchange.jcountry.data.Country;
45 import org.mxchange.jphone.phonenumbers.DialableNumber;
46 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
47 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
48 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
49 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
50 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
51 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
52 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
53 import org.mxchange.pizzaapplication.beans.BasePizzaController;
54 import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController;
55
56 /**
57  * Administrative user bean (controller)
58  * <p>
59  * @author Roland Häder<roland@mxchange.org>
60  */
61 @Named ("adminContactController")
62 @RequestScoped
63 public class PizzaAdminContactWebRequestBean extends BasePizzaController implements PizzaAdminContactWebRequestController {
64
65         /**
66          * Serial number
67          */
68         private static final long serialVersionUID = 542_145_347_916L;
69
70         /**
71          * An event fired when the administrator has added a new contact
72          */
73         @Inject
74         @Any
75         private Event<AdminAddedContactEvent> addedContactEvent;
76
77         /**
78          * Administrative contact EJB
79          */
80         private AdminContactSessionBeanRemote adminContactBean;
81
82         /**
83          * Admin helper instance
84          */
85         @Inject
86         private PizzaWebRequestController beanHelper;
87
88         /**
89          * Birth day
90          */
91         private Date birthday;
92
93         /**
94          * Cellphone number's carrier
95          */
96         private MobileProvider cellphoneCarrier;
97
98         /**
99          * Cellphone id number
100          */
101         private Long cellphoneId;
102
103         /**
104          * Cellphone number
105          */
106         private Long cellphoneNumber;
107
108         /**
109          * City
110          */
111         private String city;
112
113         /**
114          * Optional comments
115          */
116         private String comment;
117
118         /**
119          * Remote contact bean
120          */
121         private final ContactSessionBeanRemote contactBean;
122
123         /**
124          * General contact controller
125          */
126         @Inject
127         private PizzaContactWebSessionController contactController;
128
129         /**
130          * Contact id
131          */
132         private Long contactId;
133
134         /**
135          * Country instance
136          */
137         private Country country;
138
139         /**
140          * Email address
141          */
142         private String emailAddress;
143
144         /**
145          * Family name
146          */
147         private String familyName;
148
149         /**
150          * Fax number's area code
151          */
152         private Integer faxAreaCode;
153
154         /**
155          * Country instance for fax number
156          */
157         private Country faxCountry;
158
159         /**
160          * Fax id number
161          */
162         private Long faxId;
163
164         /**
165          * Fax number
166          */
167         private Long faxNumber;
168
169         /**
170          * First name
171          */
172         private String firstName;
173
174         /**
175          * Gender instance
176          */
177         private Gender gender;
178
179         /**
180          * House number
181          */
182         private Short houseNumber;
183
184         /**
185          * House number extension
186          */
187         private String houseNumberExtension;
188
189         /**
190          * Whether a cellphone entry has been unlinked
191          */
192         private boolean isCellphoneUnlinked;
193
194         /**
195          * Whether a fax entry has been unlinked
196          */
197         private boolean isFaxUnlinked;
198
199         /**
200          * Whether a land-line number has been unlinked
201          */
202         private boolean isLandLineUnlinked;
203
204         /**
205          * Land-line id number
206          */
207         private Long landLineId;
208
209         /**
210          * Phone number area code
211          */
212         private Integer phoneAreaCode;
213
214         /**
215          * Country instance for phone number
216          */
217         private Country phoneCountry;
218
219         /**
220          * Phone number
221          */
222         private Long phoneNumber;
223
224         /**
225          * Street
226          */
227         private String street;
228
229         /**
230          * Title
231          */
232         private String title;
233
234         /**
235          * An event fired when the administrator has updated contact data
236          */
237         @Inject
238         @Any
239         private Event<AdminUpdatedContactEvent> updatedContactEvent;
240
241         /**
242          * ZIP code
243          */
244         private Integer zipCode;
245
246         /**
247          * Default constructor
248          */
249         public PizzaAdminContactWebRequestBean () {
250                 // Try it
251                 try {
252                         // Get initial context
253                         Context context = new InitialContext();
254
255                         // Try to lookup
256                         this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
257
258                         // Try to lookup (administative)
259                         this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
260                 } catch (final NamingException e) {
261                         // Throw again
262                         throw new FaceletException(e);
263                 }
264         }
265
266         @Override
267         public String addContact () {
268                 // Are all minimum fields set?
269                 if (this.getGender() == null) {
270                         // Throw NPE
271                         throw new NullPointerException("gender is null"); //NOI18N
272                 } else if (this.getFirstName() == null) {
273                         // Throw NPE
274                         throw new NullPointerException("firstName is null"); //NOI18N
275                 } else if (this.getFirstName().isEmpty()) {
276                         // Empty string
277                         throw new IllegalStateException("firstName is empty"); //NOI18N
278                 } else if (this.getFamilyName() == null) {
279                         // Throw NPE
280                         throw new NullPointerException("familyName is null"); //NOI18N
281                 } else if (this.getFamilyName().isEmpty()) {
282                         // Empty string
283                         throw new IllegalStateException("familyName is empty"); //NOI18N
284                 }
285
286                 // Create new contact instance
287                 Contact contact = this.createContactInstance();
288
289                 // Default is not same contact
290                 if (this.isSameContactFound(contact)) {
291                         // Already registered
292                         throw new FaceletException(new ContactAlreadyAddedException(contact));
293                 }
294
295                 // Init contact
296                 Contact updatedContact;
297
298                 // Try to call EJB
299                 try {
300                         // Call EJB
301                         updatedContact = this.adminContactBean.addContact(contact);
302                 } catch (final ContactAlreadyAddedException ex) {
303                         // Throw again
304                         throw new FaceletException(ex);
305                 }
306
307                 // Fire event
308                 this.addedContactEvent.fire(new AdminContactAddedEvent(updatedContact));
309
310                 // Clear this bean
311                 this.clear();
312
313                 // Return outcome
314                 return "admin_list_contact"; //NOI18N
315         }
316
317         @Override
318         public void copyContactToController (final Contact contact) {
319                 // Log message
320                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N
321
322                 // The contact instance must be valid
323                 if (null == contact) {
324                         // Throw NPE again
325                         throw new NullPointerException("contact is null"); //NOI18N
326                 } else if (contact.getContactId() == null) {
327                         // Throw NPE again
328                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
329                 } else if (contact.getContactId() < 1) {
330                         // Not valid
331                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
332                 }
333
334                 // Set all fields: contact
335                 this.setContactId(contact.getContactId());
336                 this.setTitle(contact.getContactTitle());
337                 this.setBirthday(contact.getContactBirthday());
338                 this.setCity(contact.getContactCity());
339                 this.setComment(contact.getContactComment());
340                 this.setCountry(contact.getContactCountry());
341                 this.setEmailAddress(contact.getContactEmailAddress());
342                 this.setFamilyName(contact.getContactFamilyName());
343                 this.setFirstName(contact.getContactFirstName());
344                 this.setGender(contact.getContactGender());
345                 this.setHouseNumber(contact.getContactHouseNumber());
346                 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
347                 this.setStreet(contact.getContactStreet());
348                 this.setZipCode(contact.getContactZipCode());
349
350                 // Is the cell phone set?
351                 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
352                         // ... cellphone data
353                         this.setCellphoneId(contact.getContactMobileNumber().getPhoneId());
354                         this.setCellphoneCarrier(contact.getContactMobileNumber().getMobileProvider());
355                         this.setCellphoneNumber(contact.getContactMobileNumber().getPhoneNumber());
356                 }
357
358                 // Is the fax set?
359                 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
360                         // ... fax data
361                         this.setFaxId(contact.getContactFaxNumber().getPhoneId());
362                         this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
363                         this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
364                         this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
365                 }
366
367                 // Is the land-line number set?
368                 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
369                         // .. land-line data
370                         this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
371                         this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
372                         this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
373                         this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
374                 }
375
376                 // Log message
377                 //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
378         }
379
380         @Override
381         public Contact createContactInstance () {
382                 // Are all minimum fields set?
383                 if (this.getGender() == null) {
384                         // Throw NPE
385                         throw new NullPointerException("gender is null"); //NOI18N
386                 } else if (this.getFirstName() == null) {
387                         // Throw NPE
388                         throw new NullPointerException("firstName is null"); //NOI18N
389                 } else if (this.getFirstName().isEmpty()) {
390                         // Empty string
391                         throw new IllegalStateException("firstName is empty"); //NOI18N
392                 } else if (this.getFamilyName() == null) {
393                         // Throw NPE
394                         throw new NullPointerException("familyName is null"); //NOI18N
395                 } else if (this.getFamilyName().isEmpty()) {
396                         // Empty string
397                         throw new IllegalStateException("familyName is empty"); //NOI18N
398                 }
399
400                 // Generate phone number
401                 DialableLandLineNumber landLineNumber = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
402                 DialableMobileNumber mobileNumber = new MobileNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
403                 DialableFaxNumber faxNumber = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
404
405                 // Create new instance
406                 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
407
408                 // Add all others
409                 contact.setContactBirthday(this.getBirthday());
410                 contact.setContactStreet(this.getStreet());
411                 contact.setContactHouseNumber(this.getHouseNumber());
412                 contact.setContactZipCode(this.getZipCode());
413                 contact.setContactCity(this.getCity());
414                 contact.setContactCountry(this.getCountry());
415                 contact.setContactEmailAddress(this.getEmailAddress());
416                 contact.setContactBirthday(this.getBirthday());
417                 contact.setContactComment(this.getComment());
418
419                 // Set ownContact
420                 contact.setContactOwnContact(Boolean.TRUE);
421
422                 // Don't set null or wrong references
423                 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
424                         // Now the number must be given
425                         if (landLineNumber.getPhoneAreaCode() == null) {
426                                 // Is null
427                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
428                         } else if (landLineNumber.getPhoneAreaCode() < 1) {
429                                 // Abort here
430                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
431                         } else if (landLineNumber.getPhoneNumber() == null) {
432                                 // Is null
433                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
434                         } else if (landLineNumber.getPhoneNumber() < 1) {
435                                 // Abort here
436                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
437                         }
438
439                         // Set phone number
440                         contact.setContactLandLineNumber(landLineNumber);
441                 }
442
443                 // Don't set null or wrong references
444                 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
445                         // Now the number must be given
446                         if (faxNumber.getPhoneAreaCode() == null) {
447                                 // Is null
448                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
449                         } else if (faxNumber.getPhoneAreaCode() < 1) {
450                                 // Abort here
451                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
452                         } else if (faxNumber.getPhoneNumber() == null) {
453                                 // Is null
454                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
455                         } else if (faxNumber.getPhoneNumber() < 1) {
456                                 // Abort here
457                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
458                         }
459
460                         // Set fax number
461                         contact.setContactFaxNumber(faxNumber);
462                 }
463
464                 // Is the provider set?
465                 if ((mobileNumber instanceof DialableMobileNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
466                         // Is the number set?
467                         if (mobileNumber.getPhoneNumber() == null) {
468                                 // Is null
469                                 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
470                         } else if (mobileNumber.getPhoneNumber() < 1) {
471                                 // Abort here
472                                 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
473                         }
474
475                         // Set cellphone number
476                         contact.setContactMobileNumber(mobileNumber);
477                 }
478
479                 // Return it
480                 return contact;
481         }
482
483         @Override
484         public String editContactData () {
485                 // Get contact instance
486                 Contact contact = this.beanHelper.getContact();
487
488                 // Check if contact instance is in helper and valid
489                 if (null == contact) {
490                         // Throw NPE
491                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
492                 } else if (contact.getContactId() == null) {
493                         // Throw NPE again
494                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
495                 } else if (contact.getContactId() < 1) {
496                         // Invalid id
497                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
498                 }
499
500                 // Update all data in contact
501                 this.updateContactData(contact);
502
503                 // Call EJB for updating contact data
504                 Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
505
506                 // Fire event
507                 this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact));
508
509                 // Clear bean
510                 this.clear();
511
512                 // Return to contact list (for now)
513                 return "admin_list_contact"; //NOI18N
514         }
515
516         @Override
517         public String generateCellphoneNumber (final DialableMobileNumber cellphoneNumber) {
518                 // Is it null?
519                 if (null == cellphoneNumber) {
520                         // Return null
521                         return null;
522                 }
523
524                 // Get all data
525                 String number = String.format(
526                            "%s%d%d", //NOI18N
527                            cellphoneNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
528                            cellphoneNumber.getMobileProvider().getProviderDialPrefix(),
529                            cellphoneNumber.getPhoneNumber()
530            );
531
532                 // Return it
533                 return number;
534         }
535
536         @Override
537         public String generatePhoneNumber (final DialableNumber phoneNumber) {
538                 // Is it null?
539                 if (null == phoneNumber) {
540                         // Return null
541                         return null;
542                 }
543
544                 // Generate it
545                 String number = String.format(
546                            "%s%d%d", //NOI18N
547                            phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
548                            phoneNumber.getPhoneAreaCode(),
549                            phoneNumber.getPhoneNumber()
550            );
551
552                 // Return it
553                 return number;
554         }
555
556         @Override
557         @SuppressWarnings ("ReturnOfDateField")
558         public Date getBirthday () {
559                 return this.birthday;
560         }
561
562         @Override
563         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
564         public void setBirthday (final Date birthday) {
565                 this.birthday = birthday;
566         }
567
568         @Override
569         public MobileProvider getCellphoneCarrier () {
570                 return this.cellphoneCarrier;
571         }
572
573         @Override
574         public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
575                 this.cellphoneCarrier = cellphoneCarrier;
576         }
577
578         @Override
579         public Long getCellphoneId () {
580                 return this.cellphoneId;
581         }
582
583         @Override
584         public void setCellphoneId (final Long cellphoneId) {
585                 this.cellphoneId = cellphoneId;
586         }
587
588         @Override
589         public Long getCellphoneNumber () {
590                 return this.cellphoneNumber;
591         }
592
593         @Override
594         public void setCellphoneNumber (Long cellphoneNumber) {
595                 this.cellphoneNumber = cellphoneNumber;
596         }
597
598         @Override
599         public String getCity () {
600                 return this.city;
601         }
602
603         @Override
604         public void setCity (final String city) {
605                 this.city = city;
606         }
607
608         @Override
609         public String getComment () {
610                 return this.comment;
611         }
612
613         @Override
614         public void setComment (final String comment) {
615                 this.comment = comment;
616         }
617
618         @Override
619         public Long getContactId () {
620                 return this.contactId;
621         }
622
623         @Override
624         public void setContactId (final Long contactId) {
625                 this.contactId = contactId;
626         }
627
628         @Override
629         public String getControllerType () {
630                 return "admin"; //NOI18N
631         }
632
633         @Override
634         @Deprecated
635         public void setControllerType (final String controllerType) {
636                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
637         }
638
639         @Override
640         public Country getCountry () {
641                 return this.country;
642         }
643
644         @Override
645         public void setCountry (final Country country) {
646                 this.country = country;
647         }
648
649         @Override
650         public String getEmailAddress () {
651                 return this.emailAddress;
652         }
653
654         @Override
655         public void setEmailAddress (final String emailAddress) {
656                 this.emailAddress = emailAddress;
657         }
658
659         @Override
660         public String getFamilyName () {
661                 return this.familyName;
662         }
663
664         @Override
665         public void setFamilyName (final String familyName) {
666                 this.familyName = familyName;
667         }
668
669         @Override
670         public Integer getFaxAreaCode () {
671                 return this.faxAreaCode;
672         }
673
674         @Override
675         public void setFaxAreaCode (final Integer faxAreaCode) {
676                 this.faxAreaCode = faxAreaCode;
677         }
678
679         @Override
680         public Country getFaxCountry () {
681                 return this.faxCountry;
682         }
683
684         @Override
685         public void setFaxCountry (final Country faxCountry) {
686                 this.faxCountry = faxCountry;
687         }
688
689         @Override
690         public Long getFaxId () {
691                 return this.faxId;
692         }
693
694         @Override
695         public void setFaxId (final Long faxId) {
696                 this.faxId = faxId;
697         }
698
699         @Override
700         public Long getFaxNumber () {
701                 return this.faxNumber;
702         }
703
704         @Override
705         public void setFaxNumber (final Long faxNumber) {
706                 this.faxNumber = faxNumber;
707         }
708
709         @Override
710         public String getFirstName () {
711                 return this.firstName;
712         }
713
714         @Override
715         public void setFirstName (final String firstName) {
716                 this.firstName = firstName;
717         }
718
719         @Override
720         public Gender getGender () {
721                 return this.gender;
722         }
723
724         @Override
725         public void setGender (final Gender gender) {
726                 this.gender = gender;
727         }
728
729         @Override
730         public Short getHouseNumber () {
731                 return this.houseNumber;
732         }
733
734         @Override
735         public void setHouseNumber (final Short houseNumber) {
736                 this.houseNumber = houseNumber;
737         }
738
739         @Override
740         public String getHouseNumberExtension () {
741                 return this.houseNumberExtension;
742         }
743
744         @Override
745         public void setHouseNumberExtension (final String houseNumberExtension) {
746                 this.houseNumberExtension = houseNumberExtension;
747         }
748
749         @Override
750         public Long getLandLineId () {
751                 return this.landLineId;
752         }
753
754         @Override
755         public void setLandLineId (final Long landLineId) {
756                 this.landLineId = landLineId;
757         }
758
759         @Override
760         public Integer getPhoneAreaCode () {
761                 return this.phoneAreaCode;
762         }
763
764         @Override
765         public void setPhoneAreaCode (final Integer phoneAreaCode) {
766                 this.phoneAreaCode = phoneAreaCode;
767         }
768
769         @Override
770         public Country getPhoneCountry () {
771                 return this.phoneCountry;
772         }
773
774         @Override
775         public void setPhoneCountry (final Country phoneCountry) {
776                 this.phoneCountry = phoneCountry;
777         }
778
779         @Override
780         public Long getPhoneNumber () {
781                 return this.phoneNumber;
782         }
783
784         @Override
785         public void setPhoneNumber (final Long phoneNumber) {
786                 this.phoneNumber = phoneNumber;
787         }
788
789         @Override
790         public String getStreet () {
791                 return this.street;
792         }
793
794         @Override
795         public void setStreet (final String street) {
796                 this.street = street;
797         }
798
799         @Override
800         public String getTitle () {
801                 return this.title;
802         }
803
804         @Override
805         public void setTitle (final String title) {
806                 this.title = title;
807         }
808
809         @Override
810         public Integer getZipCode () {
811                 return this.zipCode;
812         }
813
814         @Override
815         public void setZipCode (final Integer zipCode) {
816                 this.zipCode = zipCode;
817         }
818
819         /**
820          * Post-initialization of this class
821          */
822         @PostConstruct
823         public void init () {
824         }
825
826         @Override
827         public boolean isGenderRequired () {
828                 // Get context parameter
829                 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_gender_enabled"); //NOI18N
830
831                 // Is it set?
832                 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
833
834                 // Return value
835                 return isRequired;
836         }
837
838         /**
839          * Clears this bean
840          */
841         private void clear () {
842                 // Clear all data
843                 // - personal data
844                 this.setTitle(null);
845                 this.setFirstName(null);
846                 this.setFamilyName(null);
847                 this.setStreet(null);
848                 this.setHouseNumber(null);
849                 this.setHouseNumberExtension(null);
850                 this.setZipCode(null);
851                 this.setCity(null);
852                 this.setCountry(null);
853
854                 // - contact data
855                 this.setEmailAddress(null);
856                 this.setPhoneCountry(null);
857                 this.setPhoneAreaCode(null);
858                 this.setPhoneNumber(null);
859                 this.setCellphoneCarrier(null);
860                 this.setCellphoneNumber(null);
861                 this.setFaxCountry(null);
862                 this.setFaxAreaCode(null);
863                 this.setFaxNumber(null);
864
865                 // - other data
866                 this.setBirthday(null);
867                 this.setComment(null);
868         }
869
870         /**
871          * Checks whether the given contact is found
872          * <p>
873          * @param contact Contact inastance
874          *
875          * @return Wether contact has been found
876          */
877         private boolean isSameContactFound (final Contact contact) {
878                 // Default is not found
879                 boolean IsFound = false;
880
881                 // Get iterator
882                 Iterator<Contact> iterator = this.contactController.allContacts().iterator();
883
884                 // Loop through all
885                 while (iterator.hasNext()) {
886                         // Get next contact
887                         Contact next = iterator.next();
888
889                         // Is the same?
890                         if (ContactUtils.isSameContact(contact, next)) {
891                                 // Yes, then abort loop
892                                 IsFound = false;
893                                 break;
894                         }
895                 }
896
897                 // Return status
898                 return IsFound;
899         }
900
901         /**
902          * Updates all data in contact instance.
903          * <p>
904          * @param contact Contact instance
905          */
906         private void updateContactData (final Contact contact) {
907                 // Contact instance should be valid
908                 if (null == contact) {
909                         // Throw NPE
910                         throw new NullPointerException("contact is null"); //NOI18N
911                 } else if (contact.getContactId() == null) {
912                         // Throw NPE again
913                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
914                 } else if (contact.getContactId() < 1) {
915                         // Invalid id
916                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
917                 }
918
919                 // Update all fields
920                 contact.setContactGender(this.getGender());
921                 contact.setContactTitle(this.getTitle());
922                 contact.setContactFirstName(this.getFirstName());
923                 contact.setContactFamilyName(this.getFamilyName());
924                 contact.setContactStreet(this.getStreet());
925                 contact.setContactHouseNumber(this.getHouseNumber());
926                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
927                 contact.setContactZipCode(this.getZipCode());
928                 contact.setContactCity(this.getCity());
929                 contact.setContactCountry(this.getCountry());
930
931                 // Update contact's cellphone number
932                 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
933
934                 // Update contact's land-line number
935                 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
936
937                 // Update contact's fax number
938                 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
939         }
940
941 }