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