]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
Please cherry-pick:
[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.ObservableAdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
42 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
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.PizzaWebRequestHelperController;
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<ObservableAdminAddedContactEvent> addedContactEvent;
76
77         /**
78          * Administrative contact EJB
79          */
80         private AdminContactSessionBeanRemote adminContactBean;
81
82         /**
83          * Bean helper instance
84          */
85         @Inject
86         private PizzaWebRequestHelperController beanHelper;
87
88         /**
89          * Birth day
90          */
91         private Date birthday;
92
93         /**
94          * Cellphone number's carrier
95          */
96         private MobileProvider mobileCarrier;
97
98         /**
99          * Cellphone id number
100          */
101         private Long mobileId;
102
103         /**
104          * Cellphone number
105          */
106         private Long mobileNumber;
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 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<ObservableAdminUpdatedContactEvent> updatedContactEvent;
240
241         /**
242          * ZIP code
243          */
244         private Integer zipCode;
245
246         /**
247          * Default constructor
248          */
249         public PizzaAdminContactWebRequestBean () {
250         }
251
252         @Override
253         public String addContact () {
254                 // Are all minimum fields set?
255                 if (this.getGender() == null) {
256                         // Throw NPE
257                         throw new NullPointerException("gender 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                 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                 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         @Override
304         public void copyContactToController (final Contact contact) {
305                 // Log message
306                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N
307
308                 // The contact instance must be valid
309                 if (null == contact) {
310                         // Throw NPE again
311                         throw new NullPointerException("contact is null"); //NOI18N
312                 } else if (contact.getContactId() == null) {
313                         // Throw NPE again
314                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
315                 } else if (contact.getContactId() < 1) {
316                         // Not valid
317                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
318                 }
319
320                 // Set all fields: contact
321                 this.setContactId(contact.getContactId());
322                 this.setTitle(contact.getContactTitle());
323                 this.setBirthday(contact.getContactBirthday());
324                 this.setCity(contact.getContactCity());
325                 this.setComment(contact.getContactComment());
326                 this.setCountry(contact.getContactCountry());
327                 this.setEmailAddress(contact.getContactEmailAddress());
328                 this.setFamilyName(contact.getContactFamilyName());
329                 this.setFirstName(contact.getContactFirstName());
330                 this.setGender(contact.getContactGender());
331                 this.setHouseNumber(contact.getContactHouseNumber());
332                 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
333                 this.setStreet(contact.getContactStreet());
334                 this.setZipCode(contact.getContactZipCode());
335
336                 // Is the cell phone set?
337                 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
338                         // ... cellphone data
339                         this.setMobileId(contact.getContactMobileNumber().getPhoneId());
340                         this.setMobileCarrier(contact.getContactMobileNumber().getMobileProvider());
341                         this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
342                 }
343
344                 // Is the fax set?
345                 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
346                         // ... fax data
347                         this.setFaxId(contact.getContactFaxNumber().getPhoneId());
348                         this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
349                         this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
350                         this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
351                 }
352
353                 // Is the land-line number set?
354                 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
355                         // .. land-line data
356                         this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
357                         this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
358                         this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
359                         this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
360                 }
361
362                 // Log message
363                 //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
364         }
365
366         @Override
367         public Contact createContactInstance () {
368                 // Are all minimum fields set?
369                 if (this.getGender() == null) {
370                         // Throw NPE
371                         throw new NullPointerException("gender is null"); //NOI18N
372                 } else if (this.getFirstName() == null) {
373                         // Throw NPE
374                         throw new NullPointerException("firstName is null"); //NOI18N
375                 } else if (this.getFirstName().isEmpty()) {
376                         // Empty string
377                         throw new IllegalStateException("firstName is empty"); //NOI18N
378                 } else if (this.getFamilyName() == null) {
379                         // Throw NPE
380                         throw new NullPointerException("familyName is null"); //NOI18N
381                 } else if (this.getFamilyName().isEmpty()) {
382                         // Empty string
383                         throw new IllegalStateException("familyName is empty"); //NOI18N
384                 }
385
386                 // Generate phone number
387                 DialableLandLineNumber landLine = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
388                 DialableMobileNumber mobile = new MobileNumber(this.getMobileCarrier(), this.getMobileNumber());
389                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
390
391                 // Create new instance
392                 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
393
394                 // Add all others
395                 contact.setContactBirthday(this.getBirthday());
396                 contact.setContactStreet(this.getStreet());
397                 contact.setContactHouseNumber(this.getHouseNumber());
398                 contact.setContactZipCode(this.getZipCode());
399                 contact.setContactCity(this.getCity());
400                 contact.setContactCountry(this.getCountry());
401                 contact.setContactEmailAddress(this.getEmailAddress());
402                 contact.setContactBirthday(this.getBirthday());
403                 contact.setContactComment(this.getComment());
404
405                 // Set ownContact
406                 contact.setContactOwnContact(Boolean.TRUE);
407
408                 // Don't set null or wrong references
409                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
410                         // Now the number must be given
411                         if (landLine.getPhoneAreaCode() == null) {
412                                 // Is null
413                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
414                         } else if (landLine.getPhoneAreaCode() < 1) {
415                                 // Abort here
416                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
417                         } else if (landLine.getPhoneNumber() == null) {
418                                 // Is null
419                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
420                         } else if (landLine.getPhoneNumber() < 1) {
421                                 // Abort here
422                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
423                         }
424
425                         // Set phone number
426                         contact.setContactLandLineNumber(landLine);
427                 }
428
429                 // Don't set null or wrong references
430                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
431                         // Now the number must be given
432                         if (fax.getPhoneAreaCode() == null) {
433                                 // Is null
434                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
435                         } else if (fax.getPhoneAreaCode() < 1) {
436                                 // Abort here
437                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
438                         } else if (fax.getPhoneNumber() == null) {
439                                 // Is null
440                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
441                         } else if (fax.getPhoneNumber() < 1) {
442                                 // Abort here
443                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
444                         }
445
446                         // Set fax number
447                         contact.setContactFaxNumber(fax);
448                 }
449
450                 // Is the provider set?
451                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileCarrier() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
452                         // Is the number set?
453                         if (mobile.getPhoneNumber() == null) {
454                                 // Is null
455                                 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
456                         } else if (mobile.getPhoneNumber() < 1) {
457                                 // Abort here
458                                 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
459                         }
460
461                         // Set cellphone number
462                         contact.setContactMobileNumber(mobile);
463                 }
464
465                 // Return it
466                 return contact;
467         }
468
469         @Override
470         public String editContactData () {
471                 // Get contact instance
472                 Contact contact = this.beanHelper.getContact();
473
474                 // Check if contact instance is in helper and valid
475                 if (null == contact) {
476                         // Throw NPE
477                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
478                 } else if (contact.getContactId() == null) {
479                         // Throw NPE again
480                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
481                 } else if (contact.getContactId() < 1) {
482                         // Invalid id
483                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
484                 }
485
486                 // Update all data in contact
487                 this.updateContactData(contact);
488
489                 // Call EJB for updating contact data
490                 Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
491
492                 // Fire event
493                 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
494
495                 // Clear bean
496                 this.clear();
497
498                 // Return to contact list (for now)
499                 return "admin_list_contact"; //NOI18N
500         }
501
502         @Override
503         public String generateCellphoneNumber (final DialableMobileNumber cellphoneNumber) {
504                 // Is it null?
505                 if (null == cellphoneNumber) {
506                         // Return null
507                         return null;
508                 }
509
510                 // Get all data
511                 String number = String.format(
512                            "%s%d%d", //NOI18N
513                            cellphoneNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
514                            cellphoneNumber.getMobileProvider().getProviderDialPrefix(),
515                            cellphoneNumber.getPhoneNumber()
516            );
517
518                 // Return it
519                 return number;
520         }
521
522         @Override
523         public String generatePhoneNumber (final DialableNumber phoneNumber) {
524                 // Is it null?
525                 if (null == phoneNumber) {
526                         // Return null
527                         return null;
528                 }
529
530                 // Generate it
531                 String number = String.format(
532                            "%s%d%d", //NOI18N
533                            phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
534                            phoneNumber.getPhoneAreaCode(),
535                            phoneNumber.getPhoneNumber()
536            );
537
538                 // Return it
539                 return number;
540         }
541
542         @Override
543         @SuppressWarnings ("ReturnOfDateField")
544         public Date getBirthday () {
545                 return this.birthday;
546         }
547
548         @Override
549         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
550         public void setBirthday (final Date birthday) {
551                 this.birthday = birthday;
552         }
553
554         @Override
555         public MobileProvider getMobileCarrier () {
556                 return this.mobileCarrier;
557         }
558
559         @Override
560         public void setMobileCarrier (final MobileProvider mobileCarrier) {
561                 this.mobileCarrier = mobileCarrier;
562         }
563
564         @Override
565         public Long getMobileId () {
566                 return this.mobileId;
567         }
568
569         @Override
570         public void setMobileId (final Long mobileId) {
571                 this.mobileId = mobileId;
572         }
573
574         @Override
575         public Long getMobileNumber () {
576                 return this.mobileNumber;
577         }
578
579         @Override
580         public void setMobileNumber (Long mobileNumber) {
581                 this.mobileNumber = mobileNumber;
582         }
583
584         @Override
585         public String getCity () {
586                 return this.city;
587         }
588
589         @Override
590         public void setCity (final String city) {
591                 this.city = city;
592         }
593
594         @Override
595         public String getComment () {
596                 return this.comment;
597         }
598
599         @Override
600         public void setComment (final String comment) {
601                 this.comment = comment;
602         }
603
604         @Override
605         public Long getContactId () {
606                 return this.contactId;
607         }
608
609         @Override
610         public void setContactId (final Long contactId) {
611                 this.contactId = contactId;
612         }
613
614         @Override
615         public String getControllerType () {
616                 return "admin"; //NOI18N
617         }
618
619         @Override
620         @Deprecated
621         public void setControllerType (final String controllerType) {
622                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
623         }
624
625         @Override
626         public Country getCountry () {
627                 return this.country;
628         }
629
630         @Override
631         public void setCountry (final Country country) {
632                 this.country = country;
633         }
634
635         @Override
636         public String getEmailAddress () {
637                 return this.emailAddress;
638         }
639
640         @Override
641         public void setEmailAddress (final String emailAddress) {
642                 this.emailAddress = emailAddress;
643         }
644
645         @Override
646         public String getFamilyName () {
647                 return this.familyName;
648         }
649
650         @Override
651         public void setFamilyName (final String familyName) {
652                 this.familyName = familyName;
653         }
654
655         @Override
656         public Integer getFaxAreaCode () {
657                 return this.faxAreaCode;
658         }
659
660         @Override
661         public void setFaxAreaCode (final Integer faxAreaCode) {
662                 this.faxAreaCode = faxAreaCode;
663         }
664
665         @Override
666         public Country getFaxCountry () {
667                 return this.faxCountry;
668         }
669
670         @Override
671         public void setFaxCountry (final Country faxCountry) {
672                 this.faxCountry = faxCountry;
673         }
674
675         @Override
676         public Long getFaxId () {
677                 return this.faxId;
678         }
679
680         @Override
681         public void setFaxId (final Long faxId) {
682                 this.faxId = faxId;
683         }
684
685         @Override
686         public Long getFaxNumber () {
687                 return this.faxNumber;
688         }
689
690         @Override
691         public void setFaxNumber (final Long faxNumber) {
692                 this.faxNumber = faxNumber;
693         }
694
695         @Override
696         public String getFirstName () {
697                 return this.firstName;
698         }
699
700         @Override
701         public void setFirstName (final String firstName) {
702                 this.firstName = firstName;
703         }
704
705         @Override
706         public Gender getGender () {
707                 return this.gender;
708         }
709
710         @Override
711         public void setGender (final Gender gender) {
712                 this.gender = gender;
713         }
714
715         @Override
716         public Short getHouseNumber () {
717                 return this.houseNumber;
718         }
719
720         @Override
721         public void setHouseNumber (final Short houseNumber) {
722                 this.houseNumber = houseNumber;
723         }
724
725         @Override
726         public String getHouseNumberExtension () {
727                 return this.houseNumberExtension;
728         }
729
730         @Override
731         public void setHouseNumberExtension (final String houseNumberExtension) {
732                 this.houseNumberExtension = houseNumberExtension;
733         }
734
735         @Override
736         public Long getLandLineId () {
737                 return this.landLineId;
738         }
739
740         @Override
741         public void setLandLineId (final Long landLineId) {
742                 this.landLineId = landLineId;
743         }
744
745         @Override
746         public Integer getPhoneAreaCode () {
747                 return this.phoneAreaCode;
748         }
749
750         @Override
751         public void setPhoneAreaCode (final Integer phoneAreaCode) {
752                 this.phoneAreaCode = phoneAreaCode;
753         }
754
755         @Override
756         public Country getPhoneCountry () {
757                 return this.phoneCountry;
758         }
759
760         @Override
761         public void setPhoneCountry (final Country phoneCountry) {
762                 this.phoneCountry = phoneCountry;
763         }
764
765         @Override
766         public Long getPhoneNumber () {
767                 return this.phoneNumber;
768         }
769
770         @Override
771         public void setPhoneNumber (final Long phoneNumber) {
772                 this.phoneNumber = phoneNumber;
773         }
774
775         @Override
776         public String getStreet () {
777                 return this.street;
778         }
779
780         @Override
781         public void setStreet (final String street) {
782                 this.street = street;
783         }
784
785         @Override
786         public String getTitle () {
787                 return this.title;
788         }
789
790         @Override
791         public void setTitle (final String title) {
792                 this.title = title;
793         }
794
795         @Override
796         public Integer getZipCode () {
797                 return this.zipCode;
798         }
799
800         @Override
801         public void setZipCode (final Integer zipCode) {
802                 this.zipCode = zipCode;
803         }
804
805         /**
806          * Post-initialization of this class
807          */
808         @PostConstruct
809         public void init () {
810                 // Try it
811                 try {
812                         // Get initial context
813                         Context context = new InitialContext();
814
815                         // Try to lookup
816                         this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
817
818                         // Try to lookup (administative)
819                         this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
820                 } catch (final NamingException e) {
821                         // Throw again
822                         throw new FaceletException(e);
823                 }
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.setMobileCarrier(null);
860                 this.setMobileNumber(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.updateMobileNumber(contact, this.getMobileCarrier(), this.getMobileNumber());
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 }