]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java
Please cherry-pick:
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / contact / AddressbookAdminContactWebRequestBean.java
1 /*
2  * Copyright (C) 2016, 2017 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.ContactUtils;
39 import org.mxchange.jcontacts.contact.UserContact;
40 import org.mxchange.jcontacts.contact.title.PersonalTitle;
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          * Academic academicTitle
71          */
72         private String academicTitle;
73
74         /**
75          * An event fired when the administrator has added a new contact
76          */
77         @Inject
78         @Any
79         private Event<ObservableAdminAddedContactEvent> addedContactEvent;
80
81         /**
82          * Administrative contact EJB
83          */
84         private AdminContactSessionBeanRemote adminContactBean;
85
86         /**
87          * Bean helper instance
88          */
89         @Inject
90         private AddressbookWebRequestHelperController beanHelper;
91
92         /**
93          * Birth day
94          */
95         private Date birthday;
96
97         /**
98          * City
99          */
100         private String city;
101
102         /**
103          * Optional comments
104          */
105         private String comment;
106
107         /**
108          * Remote contact bean
109          */
110         private ContactSessionBeanRemote contactBean;
111
112         /**
113          * General contact controller
114          */
115         @Inject
116         private AddressbookContactWebSessionController contactController;
117
118         /**
119          * Contact id
120          */
121         private Long contactId;
122
123         /**
124          * Country instance
125          */
126         private Country country;
127
128         /**
129          * Email address
130          */
131         private String emailAddress;
132
133         /**
134          * Family name
135          */
136         private String familyName;
137
138         /**
139          * Fax number's area code
140          */
141         private Integer faxAreaCode;
142
143         /**
144          * Country instance for fax number
145          */
146         private Country faxCountry;
147
148         /**
149          * Fax id number
150          */
151         private Long faxId;
152
153         /**
154          * Fax number
155          */
156         private Long faxNumber;
157
158         /**
159          * First name
160          */
161         private String firstName;
162
163         /**
164          * House number
165          */
166         private Short houseNumber;
167
168         /**
169          * House number extension
170          */
171         private String houseNumberExtension;
172
173         /**
174          * Whether a fax entry has been unlinked
175          */
176         private boolean isFaxUnlinked;
177
178         /**
179          * Whether a land-line number has been unlinked
180          */
181         private boolean isLandLineUnlinked;
182
183         /**
184          * Whether a cellphone entry has been unlinked
185          */
186         private boolean isMobileNumberUnlinked;
187
188         /**
189          * Phone number area code
190          */
191         private Integer landLineAreaCode;
192
193         /**
194          * Country instance for phone number
195          */
196         private Country landLineCountry;
197
198         /**
199          * Land-line id number
200          */
201         private Long landLineId;
202
203         /**
204          * Phone number
205          */
206         private Long landLineNumber;
207
208         /**
209          * Mobile id number
210          */
211         private Long mobileId;
212
213         /**
214          * Mobile number
215          */
216         private Long mobileNumber;
217
218         /**
219          * Mobile number's provider
220          */
221         private MobileProvider mobileProvider;
222
223         /**
224          * PersonalTitle instance
225          */
226         private PersonalTitle personalTitle;
227
228         /**
229          * Street
230          */
231         private String street;
232
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.getPersonalTitle() == null) {
258                         // Throw NPE
259                         throw new NullPointerException("personalTitle 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.setAcademicTitle(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.setPersonalTitle(contact.getContactPersonalTitle());
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.getPersonalTitle() == null) {
372                         // Throw NPE
373                         throw new NullPointerException("personalTitle 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.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
395
396                 // Add all others
397                 contact.setContactTitle(this.getAcademicTitle());
398                 contact.setContactBirthday(this.getBirthday());
399                 contact.setContactStreet(this.getStreet());
400                 contact.setContactHouseNumber(this.getHouseNumber());
401                 contact.setContactZipCode(this.getZipCode());
402                 contact.setContactCity(this.getCity());
403                 contact.setContactCountry(this.getCountry());
404                 contact.setContactEmailAddress(this.getEmailAddress());
405                 contact.setContactBirthday(this.getBirthday());
406                 contact.setContactComment(this.getComment());
407
408                 // Set ownContact
409                 contact.setContactOwnContact(Boolean.TRUE);
410
411                 // Don't set null or wrong references
412                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
413                         // Now the number must be given
414                         if (landLine.getPhoneAreaCode() == null) {
415                                 // Is null
416                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
417                         } else if (landLine.getPhoneAreaCode() < 1) {
418                                 // Abort here
419                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
420                         } else if (landLine.getPhoneNumber() == null) {
421                                 // Is null
422                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
423                         } else if (landLine.getPhoneNumber() < 1) {
424                                 // Abort here
425                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
426                         }
427
428                         // Set phone number
429                         contact.setContactLandLineNumber(landLine);
430                 }
431
432                 // Don't set null or wrong references
433                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
434                         // Now the number must be given
435                         if (fax.getPhoneAreaCode() == null) {
436                                 // Is null
437                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
438                         } else if (fax.getPhoneAreaCode() < 1) {
439                                 // Abort here
440                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
441                         } else if (fax.getPhoneNumber() == null) {
442                                 // Is null
443                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
444                         } else if (fax.getPhoneNumber() < 1) {
445                                 // Abort here
446                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
447                         }
448
449                         // Set fax number
450                         contact.setContactFaxNumber(fax);
451                 }
452
453                 // Is the provider set?
454                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
455                         // Is the number set?
456                         if (mobile.getPhoneNumber() == null) {
457                                 // Is null
458                                 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
459                         } else if (mobile.getPhoneNumber() < 1) {
460                                 // Abort here
461                                 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
462                         }
463
464                         // Set cellphone number
465                         contact.setContactMobileNumber(mobile);
466                 }
467
468                 // Return it
469                 return contact;
470         }
471
472         @Override
473         public String editContactData () {
474                 // Get contact instance
475                 Contact contact = this.beanHelper.getContact();
476
477                 // Check if contact instance is in helper and valid
478                 if (null == contact) {
479                         // Throw NPE
480                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
481                 } else if (contact.getContactId() == null) {
482                         // Throw NPE again
483                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
484                 } else if (contact.getContactId() < 1) {
485                         // Invalid id
486                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
487                 }
488
489                 // Update all data in contact
490                 this.updateContactData(contact);
491
492                 // Call EJB for updating contact data
493                 Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
494
495                 // Fire event
496                 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
497
498                 // Clear bean
499                 this.clear();
500
501                 // Return to contact list (for now)
502                 return "admin_list_contact"; //NOI18N
503         }
504
505         @Override
506         public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
507                 // Is it null?
508                 if (null == mobileNumber) {
509                         // Return null
510                         return null;
511                 }
512
513                 // Get all data
514                 String number = String.format(
515                            "%s%d%d", //NOI18N
516                            mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
517                            mobileNumber.getMobileProvider().getProviderDialPrefix(),
518                            mobileNumber.getPhoneNumber()
519            );
520
521                 // Return it
522                 return number;
523         }
524
525         @Override
526         public String generatePhoneNumber (final DialableNumber phoneNumber) {
527                 // Is it null?
528                 if (null == phoneNumber) {
529                         // Return null
530                         return null;
531                 }
532
533                 // Generate it
534                 String number = String.format(
535                            "%s%d%d", //NOI18N
536                            phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
537                            phoneNumber.getPhoneAreaCode(),
538                            phoneNumber.getPhoneNumber()
539            );
540
541                 // Return it
542                 return number;
543         }
544         @Override
545         public String getAcademicTitle () {
546                 return this.academicTitle;
547         }
548         @Override
549         public void setAcademicTitle (final String academicTitle) {
550                 this.academicTitle = academicTitle;
551         }
552
553         @Override
554         @SuppressWarnings ("ReturnOfDateField")
555         public Date getBirthday () {
556                 return this.birthday;
557         }
558
559         @Override
560         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
561         public void setBirthday (final Date birthday) {
562                 this.birthday = birthday;
563         }
564
565         @Override
566         public String getCity () {
567                 return this.city;
568         }
569
570         @Override
571         public void setCity (final String city) {
572                 this.city = city;
573         }
574
575         @Override
576         public String getComment () {
577                 return this.comment;
578         }
579
580         @Override
581         public void setComment (final String comment) {
582                 this.comment = comment;
583         }
584
585         @Override
586         public Long getContactId () {
587                 return this.contactId;
588         }
589
590         @Override
591         public void setContactId (final Long contactId) {
592                 this.contactId = contactId;
593         }
594
595         @Override
596         public String getControllerType () {
597                 return "admin"; //NOI18N
598         }
599
600         @Override
601         @Deprecated
602         public void setControllerType (final String controllerType) {
603                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
604         }
605
606         @Override
607         public Country getCountry () {
608                 return this.country;
609         }
610
611         @Override
612         public void setCountry (final Country country) {
613                 this.country = country;
614         }
615
616         @Override
617         public String getEmailAddress () {
618                 return this.emailAddress;
619         }
620
621         @Override
622         public void setEmailAddress (final String emailAddress) {
623                 this.emailAddress = emailAddress;
624         }
625
626         @Override
627         public String getFamilyName () {
628                 return this.familyName;
629         }
630
631         @Override
632         public void setFamilyName (final String familyName) {
633                 this.familyName = familyName;
634         }
635
636         @Override
637         public Integer getFaxAreaCode () {
638                 return this.faxAreaCode;
639         }
640
641         @Override
642         public void setFaxAreaCode (final Integer faxAreaCode) {
643                 this.faxAreaCode = faxAreaCode;
644         }
645
646         @Override
647         public Country getFaxCountry () {
648                 return this.faxCountry;
649         }
650
651         @Override
652         public void setFaxCountry (final Country faxCountry) {
653                 this.faxCountry = faxCountry;
654         }
655
656         @Override
657         public Long getFaxId () {
658                 return this.faxId;
659         }
660
661         @Override
662         public void setFaxId (final Long faxId) {
663                 this.faxId = faxId;
664         }
665
666         @Override
667         public Long getFaxNumber () {
668                 return this.faxNumber;
669         }
670
671         @Override
672         public void setFaxNumber (final Long faxNumber) {
673                 this.faxNumber = faxNumber;
674         }
675
676         @Override
677         public String getFirstName () {
678                 return this.firstName;
679         }
680
681         @Override
682         public void setFirstName (final String firstName) {
683                 this.firstName = firstName;
684         }
685
686         @Override
687         public Short getHouseNumber () {
688                 return this.houseNumber;
689         }
690
691         @Override
692         public void setHouseNumber (final Short houseNumber) {
693                 this.houseNumber = houseNumber;
694         }
695
696         @Override
697         public String getHouseNumberExtension () {
698                 return this.houseNumberExtension;
699         }
700
701         @Override
702         public void setHouseNumberExtension (final String houseNumberExtension) {
703                 this.houseNumberExtension = houseNumberExtension;
704         }
705
706         @Override
707         public Integer getLandLineAreaCode () {
708                 return this.landLineAreaCode;
709         }
710
711         @Override
712         public void setLandLineAreaCode (final Integer landLineAreaCode) {
713                 this.landLineAreaCode = landLineAreaCode;
714         }
715
716         @Override
717         public Country getLandLineCountry () {
718                 return this.landLineCountry;
719         }
720
721         @Override
722         public void setLandLineCountry (final Country landLineCountry) {
723                 this.landLineCountry = landLineCountry;
724         }
725
726         @Override
727         public Long getLandLineId () {
728                 return this.landLineId;
729         }
730
731         @Override
732         public void setLandLineId (final Long landLineId) {
733                 this.landLineId = landLineId;
734         }
735
736         @Override
737         public Long getLandLineNumber () {
738                 return this.landLineNumber;
739         }
740
741         @Override
742         public void setLandLineNumber (final Long landLineNumber) {
743                 this.landLineNumber = landLineNumber;
744         }
745
746         @Override
747         public Long getMobileId () {
748                 return this.mobileId;
749         }
750
751         @Override
752         public void setMobileId (final Long mobileId) {
753                 this.mobileId = mobileId;
754         }
755
756         @Override
757         public Long getMobileNumber () {
758                 return this.mobileNumber;
759         }
760
761         @Override
762         public void setMobileNumber (Long mobileNumber) {
763                 this.mobileNumber = mobileNumber;
764         }
765
766         @Override
767         public MobileProvider getMobileProvider () {
768                 return this.mobileProvider;
769         }
770
771         @Override
772         public void setMobileProvider (final MobileProvider mobileProvider) {
773                 this.mobileProvider = mobileProvider;
774         }
775
776         @Override
777         public PersonalTitle getPersonalTitle () {
778                 return this.personalTitle;
779         }
780
781         @Override
782         public void setPersonalTitle (final PersonalTitle personalTitle) {
783                 this.personalTitle = personalTitle;
784         }
785
786         @Override
787         public String getStreet () {
788                 return this.street;
789         }
790
791         @Override
792         public void setStreet (final String street) {
793                 this.street = street;
794         }
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/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
819
820                         // Try to lookup (administative)
821                         this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/addressbook-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 isPersonalTitleRequired () {
830                 // Get context parameter
831                 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_personal_title_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.setAcademicTitle(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.setContactPersonalTitle(this.getPersonalTitle());
923                 contact.setContactTitle(this.getAcademicTitle());
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 }