]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
Continued with rewrites:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / contact / PizzaAdminContactWebRequestBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
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.cellphone.DialableCellphoneNumber;
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 Haeder<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.setStreet(contact.getContactStreet());
320                 this.setZipCode(contact.getContactZipCode());
321
322                 // Is the cell phone set?
323                 if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
324                         // ... cellphone data
325                         this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId());
326                         this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider());
327                         this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber());
328                 }
329
330                 // Is the fax set?
331                 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
332                         // ... fax data
333                         this.setFaxId(contact.getContactFaxNumber().getPhoneId());
334                         this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
335                         this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
336                         this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
337                 }
338
339                 // Is the land-line number set?
340                 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
341                         // .. land-line data
342                         this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
343                         this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
344                         this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
345                         this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
346                 }
347
348                 // Log message
349                 //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
350         }
351
352         @Override
353         public Contact createContactInstance () {
354                 // Are all minimum fields set?
355                 if (this.getGender() == null) {
356                         // Throw NPE
357                         throw new NullPointerException("gender is null"); //NOI18N
358                 } else if (this.getFirstName() == null) {
359                         // Throw NPE
360                         throw new NullPointerException("firstName is null"); //NOI18N
361                 } else if (this.getFirstName().isEmpty()) {
362                         // Empty string
363                         throw new IllegalStateException("firstName is empty"); //NOI18N
364                 } else if (this.getFamilyName() == null) {
365                         // Throw NPE
366                         throw new NullPointerException("familyName is null"); //NOI18N
367                 } else if (this.getFamilyName().isEmpty()) {
368                         // Empty string
369                         throw new IllegalStateException("familyName is empty"); //NOI18N
370                 }
371
372                 // Generate phone number
373                 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
374                 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
375                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
376
377                 // Create new instance
378                 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
379
380                 // Add all others
381                 contact.setContactBirthday(this.getBirthday());
382                 contact.setContactStreet(this.getStreet());
383                 contact.setContactHouseNumber(this.getHouseNumber());
384                 contact.setContactZipCode(this.getZipCode());
385                 contact.setContactCity(this.getCity());
386                 contact.setContactCountry(this.getCountry());
387                 contact.setContactEmailAddress(this.getEmailAddress());
388                 contact.setContactBirthday(this.getBirthday());
389                 contact.setContactComment(this.getComment());
390
391                 // Set ownContact
392                 contact.setContactOwnContact(Boolean.TRUE);
393
394                 // Don't set null or wrong references
395                 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
396                         // Now the number must be given
397                         if (phone.getPhoneAreaCode() == null) {
398                                 // Is null
399                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
400                         } else if (phone.getPhoneAreaCode() < 1) {
401                                 // Abort here
402                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
403                         } else if (phone.getPhoneNumber() == null) {
404                                 // Is null
405                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
406                         } else if (phone.getPhoneNumber() < 1) {
407                                 // Abort here
408                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
409                         }
410
411                         // Set phone number
412                         contact.setContactLandLineNumber(phone);
413                 }
414
415                 // Don't set null or wrong references
416                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
417                         // Now the number must be given
418                         if (fax.getPhoneAreaCode() == null) {
419                                 // Is null
420                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
421                         } else if (fax.getPhoneAreaCode() < 1) {
422                                 // Abort here
423                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
424                         } else if (fax.getPhoneNumber() == null) {
425                                 // Is null
426                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
427                         } else if (fax.getPhoneNumber() < 1) {
428                                 // Abort here
429                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
430                         }
431
432                         // Set fax number
433                         contact.setContactFaxNumber(fax);
434                 }
435
436                 // Is the provider set?
437                 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
438                         // Is the number set?
439                         if (cellphone.getPhoneNumber() == null) {
440                                 // Is null
441                                 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
442                         } else if (cellphone.getPhoneNumber() < 1) {
443                                 // Abort here
444                                 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
445                         }
446
447                         // Set cellphone number
448                         contact.setContactCellphoneNumber(cellphone);
449                 }
450
451                 // Return it
452                 return contact;
453         }
454
455         @Override
456         public String editContactData () {
457                 // Get contact instance
458                 Contact contact = this.beanHelper.getContact();
459
460                 // Check if contact instance is in helper and valid
461                 if (null == contact) {
462                         // Throw NPE
463                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
464                 } else if (contact.getContactId() == null) {
465                         // Throw NPE again
466                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
467                 } else if (contact.getContactId() < 1) {
468                         // Invalid id
469                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
470                 }
471
472                 // Update all data in contact
473                 this.updateContactData(contact);
474
475                 // Call EJB for updating contact data
476                 Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
477
478                 // Fire event
479                 this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact));
480
481                 // Clear bean
482                 this.clear();
483
484                 // Return to contact list (for now)
485                 return "admin_list_contact"; //NOI18N
486         }
487
488         @Override
489         public String generateCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) {
490                 // Is it null?
491                 if (null == cellphoneNumber) {
492                         // Return null
493                         return null;
494                 }
495
496                 // Get all data
497                 String number = String.format(
498                            "%s%d%d", //NOI18N
499                            cellphoneNumber.getCellphoneProvider().getProviderCountry().getCountryExternalDialPrefix(),
500                            cellphoneNumber.getCellphoneProvider().getProviderDialPrefix(),
501                            cellphoneNumber.getPhoneNumber()
502            );
503
504                 // Return it
505                 return number;
506         }
507
508         @Override
509         public String generatePhoneNumber (final DialableNumber phoneNumber) {
510                 // Is it null?
511                 if (null == phoneNumber) {
512                         // Return null
513                         return null;
514                 }
515
516                 // Generate it
517                 String number = String.format(
518                            "%s%d%d", //NOI18N
519                            phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
520                            phoneNumber.getPhoneAreaCode(),
521                            phoneNumber.getPhoneNumber()
522            );
523
524                 // Return it
525                 return number;
526         }
527
528         @Override
529         @SuppressWarnings ("ReturnOfDateField")
530         public Date getBirthday () {
531                 return this.birthday;
532         }
533
534         @Override
535         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
536         public void setBirthday (final Date birthday) {
537                 this.birthday = birthday;
538         }
539
540         @Override
541         public MobileProvider getCellphoneCarrier () {
542                 return this.cellphoneCarrier;
543         }
544
545         @Override
546         public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
547                 this.cellphoneCarrier = cellphoneCarrier;
548         }
549
550         @Override
551         public Long getCellphoneId () {
552                 return this.cellphoneId;
553         }
554
555         @Override
556         public void setCellphoneId (final Long cellphoneId) {
557                 this.cellphoneId = cellphoneId;
558         }
559
560         @Override
561         public Long getCellphoneNumber () {
562                 return this.cellphoneNumber;
563         }
564
565         @Override
566         public void setCellphoneNumber (Long cellphoneNumber) {
567                 this.cellphoneNumber = cellphoneNumber;
568         }
569
570         @Override
571         public String getCity () {
572                 return this.city;
573         }
574
575         @Override
576         public void setCity (final String city) {
577                 this.city = city;
578         }
579
580         @Override
581         public String getComment () {
582                 return this.comment;
583         }
584
585         @Override
586         public void setComment (final String comment) {
587                 this.comment = comment;
588         }
589
590         @Override
591         public Long getContactId () {
592                 return this.contactId;
593         }
594
595         @Override
596         public void setContactId (final Long contactId) {
597                 this.contactId = contactId;
598         }
599
600         @Override
601         public String getControllerType () {
602                 return "admin"; //NOI18N
603         }
604
605         @Override
606         @Deprecated
607         public void setControllerType (final String controllerType) {
608                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
609         }
610
611         @Override
612         public Country getCountry () {
613                 return this.country;
614         }
615
616         @Override
617         public void setCountry (final Country country) {
618                 this.country = country;
619         }
620
621         @Override
622         public String getEmailAddress () {
623                 return this.emailAddress;
624         }
625
626         @Override
627         public void setEmailAddress (final String emailAddress) {
628                 this.emailAddress = emailAddress;
629         }
630
631         @Override
632         public String getFamilyName () {
633                 return this.familyName;
634         }
635
636         @Override
637         public void setFamilyName (final String familyName) {
638                 this.familyName = familyName;
639         }
640
641         @Override
642         public Integer getFaxAreaCode () {
643                 return this.faxAreaCode;
644         }
645
646         @Override
647         public void setFaxAreaCode (final Integer faxAreaCode) {
648                 this.faxAreaCode = faxAreaCode;
649         }
650
651         @Override
652         public Country getFaxCountry () {
653                 return this.faxCountry;
654         }
655
656         @Override
657         public void setFaxCountry (final Country faxCountry) {
658                 this.faxCountry = faxCountry;
659         }
660
661         @Override
662         public Long getFaxId () {
663                 return this.faxId;
664         }
665
666         @Override
667         public void setFaxId (final Long faxId) {
668                 this.faxId = faxId;
669         }
670
671         @Override
672         public Long getFaxNumber () {
673                 return this.faxNumber;
674         }
675
676         @Override
677         public void setFaxNumber (final Long faxNumber) {
678                 this.faxNumber = faxNumber;
679         }
680
681         @Override
682         public String getFirstName () {
683                 return this.firstName;
684         }
685
686         @Override
687         public void setFirstName (final String firstName) {
688                 this.firstName = firstName;
689         }
690
691         @Override
692         public Gender getGender () {
693                 return this.gender;
694         }
695
696         @Override
697         public void setGender (final Gender gender) {
698                 this.gender = gender;
699         }
700
701         @Override
702         public Short getHouseNumber () {
703                 return this.houseNumber;
704         }
705
706         @Override
707         public void setHouseNumber (final Short houseNumber) {
708                 this.houseNumber = houseNumber;
709         }
710
711         @Override
712         public String getHouseNumberExtension () {
713                 return this.houseNumberExtension;
714         }
715
716         @Override
717         public void setHouseNumberExtension (final String houseNumberExtension) {
718                 this.houseNumberExtension = houseNumberExtension;
719         }
720
721         @Override
722         public Long getLandLineId () {
723                 return this.landLineId;
724         }
725
726         @Override
727         public void setLandLineId (final Long landLineId) {
728                 this.landLineId = landLineId;
729         }
730
731         @Override
732         public Integer getPhoneAreaCode () {
733                 return this.phoneAreaCode;
734         }
735
736         @Override
737         public void setPhoneAreaCode (final Integer phoneAreaCode) {
738                 this.phoneAreaCode = phoneAreaCode;
739         }
740
741         @Override
742         public Country getPhoneCountry () {
743                 return this.phoneCountry;
744         }
745
746         @Override
747         public void setPhoneCountry (final Country phoneCountry) {
748                 this.phoneCountry = phoneCountry;
749         }
750
751         @Override
752         public Long getPhoneNumber () {
753                 return this.phoneNumber;
754         }
755
756         @Override
757         public void setPhoneNumber (final Long phoneNumber) {
758                 this.phoneNumber = phoneNumber;
759         }
760
761         @Override
762         public String getStreet () {
763                 return this.street;
764         }
765
766         @Override
767         public void setStreet (final String street) {
768                 this.street = street;
769         }
770
771         @Override
772         public String getTitle () {
773                 return this.title;
774         }
775
776         @Override
777         public void setTitle (final String title) {
778                 this.title = title;
779         }
780
781         @Override
782         public Integer getZipCode () {
783                 return this.zipCode;
784         }
785
786         @Override
787         public void setZipCode (final Integer zipCode) {
788                 this.zipCode = zipCode;
789         }
790
791         /**
792          * Post-initialization of this class
793          */
794         @PostConstruct
795         public void init () {
796         }
797
798         @Override
799         public boolean isGenderRequired () {
800                 // Get context parameter
801                 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_gender_enabled"); //NOI18N
802
803                 // Is it set?
804                 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
805
806                 // Return value
807                 return isRequired;
808         }
809
810         /**
811          * Clears this bean
812          */
813         private void clear () {
814                 // Clear all data
815                 // - personal data
816                 this.setTitle(null);
817                 this.setFirstName(null);
818                 this.setFamilyName(null);
819                 this.setStreet(null);
820                 this.setHouseNumber(null);
821                 this.setZipCode(null);
822                 this.setCity(null);
823                 this.setCountry(null);
824
825                 // - contact data
826                 this.setEmailAddress(null);
827                 this.setPhoneCountry(null);
828                 this.setPhoneAreaCode(null);
829                 this.setPhoneNumber(null);
830                 this.setCellphoneCarrier(null);
831                 this.setCellphoneNumber(null);
832                 this.setFaxCountry(null);
833                 this.setFaxAreaCode(null);
834                 this.setFaxNumber(null);
835
836                 // - other data
837                 this.setBirthday(null);
838                 this.setComment(null);
839         }
840
841         /**
842          * Checks whether the given contact is found
843          * <p>
844          * @param contact Contact inastance
845          *
846          * @return Wether contact has been found
847          */
848         private boolean isSameContactFound (final Contact contact) {
849                 // Default is not found
850                 boolean IsFound = false;
851
852                 // Get iterator
853                 Iterator<Contact> iterator = this.contactController.allContacts().iterator();
854
855                 // Loop through all
856                 while (iterator.hasNext()) {
857                         // Get next contact
858                         Contact next = iterator.next();
859
860                         // Is the same?
861                         if (ContactUtils.isSameContact(contact, next)) {
862                                 // Yes, then abort loop
863                                 IsFound = false;
864                                 break;
865                         }
866                 }
867
868                 // Return status
869                 return IsFound;
870         }
871
872         /**
873          * Updates all data in contact instance.
874          * <p>
875          * @param contact Contact instance
876          */
877         private void updateContactData (final Contact contact) {
878                 // Contact instance should be valid
879                 if (null == contact) {
880                         // Throw NPE
881                         throw new NullPointerException("contact is null"); //NOI18N
882                 } else if (contact.getContactId() == null) {
883                         // Throw NPE again
884                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
885                 } else if (contact.getContactId() < 1) {
886                         // Invalid id
887                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
888                 }
889
890                 // Update all fields
891                 contact.setContactGender(this.getGender());
892                 contact.setContactTitle(this.getTitle());
893                 contact.setContactFirstName(this.getFirstName());
894                 contact.setContactFamilyName(this.getFamilyName());
895                 contact.setContactStreet(this.getStreet());
896                 contact.setContactHouseNumber(this.getHouseNumber());
897                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
898                 contact.setContactZipCode(this.getZipCode());
899                 contact.setContactCity(this.getCity());
900                 contact.setContactCountry(this.getCountry());
901
902                 // Update contact's cellphone number
903                 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
904
905                 // Update contact's land-line number
906                 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
907
908                 // Update contact's fax number
909                 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
910         }
911
912 }