]> 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.UserContact;
39 import org.mxchange.jcontacts.contact.title.PersonalTitle;
40 import org.mxchange.jcontacts.contact.utils.ContactUtils;
41 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
42 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
43 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
44 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
45 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
46 import org.mxchange.jcountry.data.Country;
47 import org.mxchange.jphone.phonenumbers.DialableNumber;
48 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
49 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
50 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
51 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
52 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
53 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
54 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
55
56 /**
57  * An administrative user bean (controller)
58  * <p>
59  * @author Roland Häder<roland@mxchange.org>
60  */
61 @Named ("adminContactController")
62 @RequestScoped
63 public class AddressbookAdminContactWebRequestBean extends BaseAddressbookController implements AddressbookAdminContactWebRequestController {
64
65         /**
66          * Serial number
67          */
68         private static final long serialVersionUID = 542_145_347_916L;
69
70         /**
71          * An event fired when the administrator has added a new contact
72          */
73         @Inject
74         @Any
75         private Event<ObservableAdminAddedContactEvent> addedContactEvent;
76
77         /**
78          * Administrative contact EJB
79          */
80         private AdminContactSessionBeanRemote adminContactBean;
81
82         /**
83          * Bean helper instance
84          */
85         @Inject
86         private AddressbookWebRequestHelperController beanHelper;
87
88         /**
89          * Birth day
90          */
91         private Date birthday;
92
93         /**
94          * City
95          */
96         private String city;
97
98         /**
99          * Optional comments
100          */
101         private String comment;
102
103         /**
104          * Remote contact bean
105          */
106         private ContactSessionBeanRemote contactBean;
107
108         /**
109          * General contact controller
110          */
111         @Inject
112         private AddressbookContactWebSessionController contactController;
113
114         /**
115          * Contact id
116          */
117         private Long contactId;
118
119         /**
120          * Country instance
121          */
122         private Country country;
123
124         /**
125          * Email address
126          */
127         private String emailAddress;
128
129         /**
130          * Family name
131          */
132         private String familyName;
133
134         /**
135          * Fax number's area code
136          */
137         private Integer faxAreaCode;
138
139         /**
140          * Country instance for fax number
141          */
142         private Country faxCountry;
143
144         /**
145          * Fax id number
146          */
147         private Long faxId;
148
149         /**
150          * Fax number
151          */
152         private Long faxNumber;
153
154         /**
155          * First name
156          */
157         private String firstName;
158
159         /**
160          * House number
161          */
162         private Short houseNumber;
163
164         /**
165          * House number extension
166          */
167         private String houseNumberExtension;
168
169         /**
170          * Whether a fax entry has been unlinked
171          */
172         private boolean isFaxUnlinked;
173
174         /**
175          * Whether a land-line number has been unlinked
176          */
177         private boolean isLandLineUnlinked;
178
179         /**
180          * Whether a cellphone entry has been unlinked
181          */
182         private boolean isMobileNumberUnlinked;
183
184         /**
185          * Phone number area code
186          */
187         private Integer landLineAreaCode;
188
189         /**
190          * Country instance for phone number
191          */
192         private Country landLineCountry;
193
194         /**
195          * Land-line id number
196          */
197         private Long landLineId;
198
199         /**
200          * Phone number
201          */
202         private Long landLineNumber;
203
204         /**
205          * Mobile id number
206          */
207         private Long mobileId;
208
209         /**
210          * Mobile number
211          */
212         private Long mobileNumber;
213
214         /**
215          * Mobile number's provider
216          */
217         private MobileProvider mobileProvider;
218
219         /**
220          * PersonalTitle instance
221          */
222         private PersonalTitle personalTitle;
223
224         /**
225          * Street
226          */
227         private String street;
228
229         /**
230          * Academic academicTitle
231          */
232         private String academicTitle;
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
545         @Override
546         @SuppressWarnings ("ReturnOfDateField")
547         public Date getBirthday () {
548                 return this.birthday;
549         }
550
551         @Override
552         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
553         public void setBirthday (final Date birthday) {
554                 this.birthday = birthday;
555         }
556
557         @Override
558         public String getCity () {
559                 return this.city;
560         }
561
562         @Override
563         public void setCity (final String city) {
564                 this.city = city;
565         }
566
567         @Override
568         public String getComment () {
569                 return this.comment;
570         }
571
572         @Override
573         public void setComment (final String comment) {
574                 this.comment = comment;
575         }
576
577         @Override
578         public Long getContactId () {
579                 return this.contactId;
580         }
581
582         @Override
583         public void setContactId (final Long contactId) {
584                 this.contactId = contactId;
585         }
586
587         @Override
588         public String getControllerType () {
589                 return "admin"; //NOI18N
590         }
591
592         @Override
593         @Deprecated
594         public void setControllerType (final String controllerType) {
595                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
596         }
597
598         @Override
599         public Country getCountry () {
600                 return this.country;
601         }
602
603         @Override
604         public void setCountry (final Country country) {
605                 this.country = country;
606         }
607
608         @Override
609         public String getEmailAddress () {
610                 return this.emailAddress;
611         }
612
613         @Override
614         public void setEmailAddress (final String emailAddress) {
615                 this.emailAddress = emailAddress;
616         }
617
618         @Override
619         public String getFamilyName () {
620                 return this.familyName;
621         }
622
623         @Override
624         public void setFamilyName (final String familyName) {
625                 this.familyName = familyName;
626         }
627
628         @Override
629         public Integer getFaxAreaCode () {
630                 return this.faxAreaCode;
631         }
632
633         @Override
634         public void setFaxAreaCode (final Integer faxAreaCode) {
635                 this.faxAreaCode = faxAreaCode;
636         }
637
638         @Override
639         public Country getFaxCountry () {
640                 return this.faxCountry;
641         }
642
643         @Override
644         public void setFaxCountry (final Country faxCountry) {
645                 this.faxCountry = faxCountry;
646         }
647
648         @Override
649         public Long getFaxId () {
650                 return this.faxId;
651         }
652
653         @Override
654         public void setFaxId (final Long faxId) {
655                 this.faxId = faxId;
656         }
657
658         @Override
659         public Long getFaxNumber () {
660                 return this.faxNumber;
661         }
662
663         @Override
664         public void setFaxNumber (final Long faxNumber) {
665                 this.faxNumber = faxNumber;
666         }
667
668         @Override
669         public String getFirstName () {
670                 return this.firstName;
671         }
672
673         @Override
674         public void setFirstName (final String firstName) {
675                 this.firstName = firstName;
676         }
677
678         @Override
679         public Short getHouseNumber () {
680                 return this.houseNumber;
681         }
682
683         @Override
684         public void setHouseNumber (final Short houseNumber) {
685                 this.houseNumber = houseNumber;
686         }
687
688         @Override
689         public String getHouseNumberExtension () {
690                 return this.houseNumberExtension;
691         }
692
693         @Override
694         public void setHouseNumberExtension (final String houseNumberExtension) {
695                 this.houseNumberExtension = houseNumberExtension;
696         }
697
698         @Override
699         public Integer getLandLineAreaCode () {
700                 return this.landLineAreaCode;
701         }
702
703         @Override
704         public void setLandLineAreaCode (final Integer landLineAreaCode) {
705                 this.landLineAreaCode = landLineAreaCode;
706         }
707
708         @Override
709         public Country getLandLineCountry () {
710                 return this.landLineCountry;
711         }
712
713         @Override
714         public void setLandLineCountry (final Country landLineCountry) {
715                 this.landLineCountry = landLineCountry;
716         }
717
718         @Override
719         public Long getLandLineId () {
720                 return this.landLineId;
721         }
722
723         @Override
724         public void setLandLineId (final Long landLineId) {
725                 this.landLineId = landLineId;
726         }
727
728         @Override
729         public Long getLandLineNumber () {
730                 return this.landLineNumber;
731         }
732
733         @Override
734         public void setLandLineNumber (final Long landLineNumber) {
735                 this.landLineNumber = landLineNumber;
736         }
737
738         @Override
739         public Long getMobileId () {
740                 return this.mobileId;
741         }
742
743         @Override
744         public void setMobileId (final Long mobileId) {
745                 this.mobileId = mobileId;
746         }
747
748         @Override
749         public Long getMobileNumber () {
750                 return this.mobileNumber;
751         }
752
753         @Override
754         public void setMobileNumber (Long mobileNumber) {
755                 this.mobileNumber = mobileNumber;
756         }
757
758         @Override
759         public MobileProvider getMobileProvider () {
760                 return this.mobileProvider;
761         }
762
763         @Override
764         public void setMobileProvider (final MobileProvider mobileProvider) {
765                 this.mobileProvider = mobileProvider;
766         }
767
768         @Override
769         public PersonalTitle getPersonalTitle () {
770                 return this.personalTitle;
771         }
772
773         @Override
774         public void setPersonalTitle (final PersonalTitle personalTitle) {
775                 this.personalTitle = personalTitle;
776         }
777
778         @Override
779         public String getStreet () {
780                 return this.street;
781         }
782
783         @Override
784         public void setStreet (final String street) {
785                 this.street = street;
786         }
787
788         @Override
789         public String getAcademicTitle () {
790                 return this.academicTitle;
791         }
792
793         @Override
794         public void setAcademicTitle (final String academicTitle) {
795                 this.academicTitle = academicTitle;
796         }
797
798         @Override
799         public Integer getZipCode () {
800                 return this.zipCode;
801         }
802
803         @Override
804         public void setZipCode (final Integer zipCode) {
805                 this.zipCode = zipCode;
806         }
807
808         /**
809          * Post-initialization of this class
810          */
811         @PostConstruct
812         public void init () {
813                 // Try it
814                 try {
815                         // Get initial context
816                         Context context = new InitialContext();
817
818                         // Try to lookup
819                         this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
820
821                         // Try to lookup (administative)
822                         this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
823                 } catch (final NamingException e) {
824                         // Throw again
825                         throw new FaceletException(e);
826                 }
827         }
828
829         @Override
830         public boolean isPersonalTitleRequired () {
831                 // Get context parameter
832                 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_personal_title_enabled"); //NOI18N
833
834                 // Is it set?
835                 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
836
837                 // Return value
838                 return isRequired;
839         }
840
841         /**
842          * Clears this bean
843          */
844         private void clear () {
845                 // Clear all data
846                 // - personal data
847                 this.setAcademicTitle(null);
848                 this.setFirstName(null);
849                 this.setFamilyName(null);
850                 this.setStreet(null);
851                 this.setHouseNumber(null);
852                 this.setHouseNumberExtension(null);
853                 this.setZipCode(null);
854                 this.setCity(null);
855                 this.setCountry(null);
856
857                 // - contact data
858                 this.setEmailAddress(null);
859                 this.setLandLineCountry(null);
860                 this.setLandLineAreaCode(null);
861                 this.setLandLineNumber(null);
862                 this.setMobileProvider(null);
863                 this.setMobileNumber(null);
864                 this.setFaxCountry(null);
865                 this.setFaxAreaCode(null);
866                 this.setFaxNumber(null);
867
868                 // - other data
869                 this.setBirthday(null);
870                 this.setComment(null);
871         }
872
873         /**
874          * Checks whether the given contact is found
875          * <p>
876          * @param contact Contact inastance
877          *
878          * @return Wether contact has been found
879          */
880         private boolean isSameContactFound (final Contact contact) {
881                 // Default is not found
882                 boolean IsFound = false;
883
884                 // Get iterator
885                 Iterator<Contact> iterator = this.contactController.allContacts().iterator();
886
887                 // Loop through all
888                 while (iterator.hasNext()) {
889                         // Get next contact
890                         Contact next = iterator.next();
891
892                         // Is the same?
893                         if (ContactUtils.isSameContact(contact, next)) {
894                                 // Yes, then abort loop
895                                 IsFound = false;
896                                 break;
897                         }
898                 }
899
900                 // Return status
901                 return IsFound;
902         }
903
904         /**
905          * Updates all data in contact instance.
906          * <p>
907          * @param contact Contact instance
908          */
909         private void updateContactData (final Contact contact) {
910                 // Contact instance should be valid
911                 if (null == contact) {
912                         // Throw NPE
913                         throw new NullPointerException("contact is null"); //NOI18N
914                 } else if (contact.getContactId() == null) {
915                         // Throw NPE again
916                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
917                 } else if (contact.getContactId() < 1) {
918                         // Invalid id
919                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
920                 }
921
922                 // Update all fields
923                 contact.setContactPersonalTitle(this.getPersonalTitle());
924                 contact.setContactTitle(this.getAcademicTitle());
925                 contact.setContactFirstName(this.getFirstName());
926                 contact.setContactFamilyName(this.getFamilyName());
927                 contact.setContactStreet(this.getStreet());
928                 contact.setContactHouseNumber(this.getHouseNumber());
929                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
930                 contact.setContactZipCode(this.getZipCode());
931                 contact.setContactCity(this.getCity());
932                 contact.setContactCountry(this.getCountry());
933
934                 // Update contact's cellphone number
935                 this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
936
937                 // Update contact's land-line number
938                 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
939
940                 // Update contact's fax number
941                 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
942         }
943
944 }