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