]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
Please cherry-pick:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / contact / PizzaAdminContactWebRequestBean.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.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.AdminContactSessionBeanRemote;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
36 import org.mxchange.jcontacts.contact.ContactUtils;
37 import org.mxchange.jcontacts.contact.UserContact;
38 import org.mxchange.jcontacts.contact.title.PersonalTitle;
39 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
40 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
42 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
43 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
44 import org.mxchange.jcountry.data.Country;
45 import org.mxchange.jphone.phonenumbers.DialableNumber;
46 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
47 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
48 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
49 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
50 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
51 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
52 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
53 import org.mxchange.pizzaapplication.beans.BasePizzaController;
54 import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
55
56 /**
57  * Administrative user bean (controller)
58  * <p>
59  * @author Roland Häder<roland@mxchange.org>
60  */
61 @Named ("adminContactController")
62 @RequestScoped
63 public class PizzaAdminContactWebRequestBean extends BasePizzaController implements PizzaAdminContactWebRequestController {
64
65         /**
66          * Serial number
67          */
68         private static final long serialVersionUID = 542_145_347_916L;
69
70         /**
71          * Academic academicTitle
72          */
73         private String academicTitle;
74
75         /**
76          * An event fired when the administrator has added a new contact
77          */
78         @Inject
79         @Any
80         private Event<ObservableAdminAddedContactEvent> addedContactEvent;
81
82         /**
83          * Administrative contact EJB
84          */
85         private AdminContactSessionBeanRemote adminContactBean;
86
87         /**
88          * Bean helper instance
89          */
90         @Inject
91         private PizzaWebRequestHelperController beanHelper;
92
93         /**
94          * Birth day
95          */
96         private Date birthday;
97
98         /**
99          * City
100          */
101         private String city;
102
103         /**
104          * Optional comments
105          */
106         private String comment;
107
108         /**
109          * Remote contact bean
110          */
111         private ContactSessionBeanRemote contactBean;
112
113         /**
114          * General contact controller
115          */
116         @Inject
117         private PizzaContactWebSessionController contactController;
118
119         /**
120          * Contact id
121          */
122         private Long contactId;
123
124         /**
125          * Country instance
126          */
127         private Country contactCountry;
128
129         /**
130          * Email address
131          */
132         private String emailAddress;
133
134         /**
135          * Family name
136          */
137         private String familyName;
138
139         /**
140          * Fax number's area code
141          */
142         private Integer faxAreaCode;
143
144         /**
145          * Country instance for fax number
146          */
147         private Country faxCountry;
148
149         /**
150          * Fax id number
151          */
152         private Long faxId;
153
154         /**
155          * Fax number
156          */
157         private Long faxNumber;
158
159         /**
160          * First name
161          */
162         private String firstName;
163
164         /**
165          * House number
166          */
167         private Short houseNumber;
168
169         /**
170          * House number extension
171          */
172         private String houseNumberExtension;
173
174         /**
175          * Whether a fax entry has been unlinked
176          */
177         private boolean isFaxUnlinked;
178
179         /**
180          * Whether a land-line number has been unlinked
181          */
182         private boolean isLandLineUnlinked;
183
184         /**
185          * Whether a cmobile entry has been unlinked
186          */
187         private boolean isMobileNumberUnlinked;
188
189         /**
190          * Phone number area code
191          */
192         private Integer landLineAreaCode;
193
194         /**
195          * Country instance for phone number
196          */
197         private Country landLineCountry;
198
199         /**
200          * Land-line id number
201          */
202         private Long landLineId;
203
204         /**
205          * Phone number
206          */
207         private Long landLineNumber;
208
209         /**
210          * Mobile id number
211          */
212         private Long mobileId;
213
214         /**
215          * Mobile number
216          */
217         private Long mobileNumber;
218
219         /**
220          * Mobile number's provider
221          */
222         private MobileProvider mobileProvider;
223
224         /**
225          * PersonalTitle instance
226          */
227         private PersonalTitle personalTitle;
228
229         /**
230          * Street
231          */
232         private String street;
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 PizzaAdminContactWebRequestBean () {
250                 // Call super constructor
251                 super();
252         }
253
254         /**
255          * Adds contact data to database and redirects on success. If the contact is
256          * already found, a proper exception is thrown.
257          * <p>
258          * @return Redirect outcome
259          */
260         public String addContact () {
261                 // Are all minimum fields set?
262                 if (this.getPersonalTitle() == null) {
263                         // Throw NPE
264                         throw new NullPointerException("personalTitle is null"); //NOI18N
265                 } else if (this.getFirstName() == null) {
266                         // Throw NPE
267                         throw new NullPointerException("firstName is null"); //NOI18N
268                 } else if (this.getFirstName().isEmpty()) {
269                         // Empty string
270                         throw new IllegalStateException("firstName is empty"); //NOI18N
271                 } else if (this.getFamilyName() == null) {
272                         // Throw NPE
273                         throw new NullPointerException("familyName is null"); //NOI18N
274                 } else if (this.getFamilyName().isEmpty()) {
275                         // Empty string
276                         throw new IllegalStateException("familyName is empty"); //NOI18N
277                 }
278
279                 // Create new contact instance
280                 Contact contact = this.createContactInstance();
281
282                 // Default is not same contact
283                 if (this.isSameContactFound(contact)) {
284                         // Already registered
285                         throw new FaceletException(new ContactAlreadyAddedException(contact));
286                 }
287
288                 // Init contact
289                 Contact updatedContact;
290
291                 // Try to call EJB
292                 try {
293                         // Call EJB
294                         updatedContact = this.adminContactBean.addContact(contact);
295                 } catch (final ContactAlreadyAddedException ex) {
296                         // Throw again
297                         throw new FaceletException(ex);
298                 }
299
300                 // Fire event
301                 this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
302
303                 // Clear this bean
304                 this.clear();
305
306                 // Return outcome
307                 return "admin_list_contact"; //NOI18N
308         }
309
310         @Override
311         public void copyContactToController (final Contact contact) {
312                 // Log message
313                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N
314
315                 // The contact instance must be valid
316                 if (null == contact) {
317                         // Throw NPE again
318                         throw new NullPointerException("contact is null"); //NOI18N
319                 } else if (contact.getContactId() == null) {
320                         // Throw NPE again
321                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
322                 } else if (contact.getContactId() < 1) {
323                         // Not valid
324                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
325                 }
326
327                 // Set all fields: contact
328                 this.setContactId(contact.getContactId());
329                 this.setAcademicTitle(contact.getContactTitle());
330                 this.setBirthday(contact.getContactBirthday());
331                 this.setCity(contact.getContactCity());
332                 this.setComment(contact.getContactComment());
333                 this.setContactCountry(contact.getContactCountry());
334                 this.setEmailAddress(contact.getContactEmailAddress());
335                 this.setFamilyName(contact.getContactFamilyName());
336                 this.setFirstName(contact.getContactFirstName());
337                 this.setPersonalTitle(contact.getContactPersonalTitle());
338                 this.setHouseNumber(contact.getContactHouseNumber());
339                 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
340                 this.setStreet(contact.getContactStreet());
341                 this.setZipCode(contact.getContactZipCode());
342
343                 // Is the cell phone set?
344                 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
345                         // ... cmobile data
346                         this.setMobileId(contact.getContactMobileNumber().getPhoneId());
347                         this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
348                         this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
349                 }
350
351                 // Is the fax set?
352                 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
353                         // ... fax data
354                         this.setFaxId(contact.getContactFaxNumber().getPhoneId());
355                         this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
356                         this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
357                         this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
358                 }
359
360                 // Is the land-line number set?
361                 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
362                         // .. land-line data
363                         this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
364                         this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
365                         this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
366                         this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
367                 }
368
369                 // Log message
370                 //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
371         }
372
373         @Override
374         public Contact createContactInstance () {
375                 // Are all minimum fields set?
376                 if (this.getPersonalTitle() == null) {
377                         // Throw NPE
378                         throw new NullPointerException("personalTitle is null"); //NOI18N
379                 } else if (this.getFirstName() == null) {
380                         // Throw NPE
381                         throw new NullPointerException("firstName is null"); //NOI18N
382                 } else if (this.getFirstName().isEmpty()) {
383                         // Empty string
384                         throw new IllegalStateException("firstName is empty"); //NOI18N
385                 } else if (this.getFamilyName() == null) {
386                         // Throw NPE
387                         throw new NullPointerException("familyName is null"); //NOI18N
388                 } else if (this.getFamilyName().isEmpty()) {
389                         // Empty string
390                         throw new IllegalStateException("familyName is empty"); //NOI18N
391                 }
392
393                 // Generate phone number
394                 DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
395                 DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
396                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
397
398                 // Create new instance
399                 Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
400
401                 // Add all others
402                 contact.setContactTitle(this.getAcademicTitle());
403                 contact.setContactBirthday(this.getBirthday());
404                 contact.setContactStreet(this.getStreet());
405                 contact.setContactHouseNumber(this.getHouseNumber());
406                 contact.setContactZipCode(this.getZipCode());
407                 contact.setContactCity(this.getCity());
408                 contact.setContactCountry(this.getContactCountry());
409                 contact.setContactEmailAddress(this.getEmailAddress());
410                 contact.setContactBirthday(this.getBirthday());
411                 contact.setContactComment(this.getComment());
412
413                 // Set ownContact
414                 contact.setContactOwnContact(Boolean.TRUE);
415
416                 // Don't set null or wrong references
417                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
418                         // Now the number must be given
419                         if (landLine.getPhoneAreaCode() == null) {
420                                 // Is null
421                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
422                         } else if (landLine.getPhoneAreaCode() < 1) {
423                                 // Abort here
424                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
425                         } else if (landLine.getPhoneNumber() == null) {
426                                 // Is null
427                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
428                         } else if (landLine.getPhoneNumber() < 1) {
429                                 // Abort here
430                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
431                         }
432
433                         // Set phone number
434                         contact.setContactLandLineNumber(landLine);
435                 }
436
437                 // Don't set null or wrong references
438                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
439                         // Now the number must be given
440                         if (fax.getPhoneAreaCode() == null) {
441                                 // Is null
442                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
443                         } else if (fax.getPhoneAreaCode() < 1) {
444                                 // Abort here
445                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
446                         } else if (fax.getPhoneNumber() == null) {
447                                 // Is null
448                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
449                         } else if (fax.getPhoneNumber() < 1) {
450                                 // Abort here
451                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
452                         }
453
454                         // Set fax number
455                         contact.setContactFaxNumber(fax);
456                 }
457
458                 // Is the provider set?
459                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
460                         // Is the number set?
461                         if (mobile.getPhoneNumber() == null) {
462                                 // Is null
463                                 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
464                         } else if (mobile.getPhoneNumber() < 1) {
465                                 // Abort here
466                                 throw new IllegalArgumentException("cmobile.phoneNumber is zero or below."); //NOI18N
467                         }
468
469                         // Set cmobile number
470                         contact.setContactMobileNumber(mobile);
471                 }
472
473                 // Return it
474                 return contact;
475         }
476
477         /**
478          * Edits currently loaded contact's data in database.
479          * <p>
480          * @return Redirect outcome
481          */
482         public String editContactData () {
483                 // Get contact instance
484                 Contact contact = this.beanHelper.getContact();
485
486                 // Check if contact instance is in helper and valid
487                 if (null == contact) {
488                         // Throw NPE
489                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
490                 } else if (contact.getContactId() == null) {
491                         // Throw NPE again
492                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
493                 } else if (contact.getContactId() < 1) {
494                         // Invalid id
495                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
496                 }
497
498                 // Update all data in contact
499                 this.updateContactData(contact);
500
501                 // Call EJB for updating contact data
502                 Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
503
504                 // Fire event
505                 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
506
507                 // Clear bean
508                 this.clear();
509
510                 // Return to contact list (for now)
511                 return "admin_list_contact"; //NOI18N
512         }
513
514         /**
515          * Returns a text representation of given mobile number or null if not set.
516          * <p>
517          * @param mobileNumber Mobile number
518          * <p>
519          * @return Text representation or null
520          */
521         public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
522                 // Is it null?
523                 if (null == mobileNumber) {
524                         // Return null
525                         return null;
526                 }
527
528                 // Get all data
529                 String number = String.format(
530                            "%s%d%d", //NOI18N
531                            mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
532                            mobileNumber.getMobileProvider().getProviderDialPrefix(),
533                            mobileNumber.getPhoneNumber()
534            );
535
536                 // Return it
537                 return number;
538         }
539
540         /**
541          * Returns a text representation of given land-line or fax number or null if
542          * not set.
543          * <p>
544          * @param phoneNumber Land-line or fax number
545          * <p>
546          * @return Text representation or null
547          */
548         public String generatePhoneNumber (final DialableNumber phoneNumber) {
549                 // Is it null?
550                 if (null == phoneNumber) {
551                         // Return null
552                         return null;
553                 }
554
555                 // Generate it
556                 String number = String.format(
557                            "%s%d%d", //NOI18N
558                            phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
559                            phoneNumber.getPhoneAreaCode(),
560                            phoneNumber.getPhoneNumber()
561            );
562
563                 // Return it
564                 return number;
565         }
566
567         /**
568          * Getter for academic title
569          * <p>
570          * @return Academic title
571          */
572         public String getAcademicTitle () {
573                 return this.academicTitle;
574         }
575
576         /**
577          * Setter for academic title
578          * <p>
579          * @param academicTitle Academic title
580          */
581         public void setAcademicTitle (final String academicTitle) {
582                 this.academicTitle = academicTitle;
583         }
584
585         /**
586          * Getter for birth day
587          * <p>
588          * @return Birth day
589          */
590         @SuppressWarnings ("ReturnOfDateField")
591         public Date getBirthday () {
592                 return this.birthday;
593         }
594
595         /**
596          * Setter for birth day
597          * <p>
598          * @param birthday Birth day
599          */
600         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
601         public void setBirthday (final Date birthday) {
602                 this.birthday = birthday;
603         }
604
605         /**
606          * Getter for city name
607          * <p>
608          * @return City name
609          */
610         public String getCity () {
611                 return this.city;
612         }
613
614         /**
615          * Setter for city name
616          * <p>
617          * @param city City name
618          */
619         public void setCity (final String city) {
620                 this.city = city;
621         }
622
623         /**
624          * Getter for comments
625          * <p>
626          * @return Comments
627          */
628         public String getComment () {
629                 return this.comment;
630         }
631
632         /**
633          * Setter for comment
634          * <p>
635          * @param comment Comments
636          */
637         public void setComment (final String comment) {
638                 this.comment = comment;
639         }
640
641         /**
642          * Getter for contact id
643          * <p>
644          * @return Contact id
645          */
646         public Long getContactId () {
647                 return this.contactId;
648         }
649
650         /**
651          * Setter for contact id
652          * <p>
653          * @param contactId Contact id
654          */
655         public void setContactId (final Long contactId) {
656                 this.contactId = contactId;
657         }
658
659         @Override
660         public String getControllerType () {
661                 return "admin"; //NOI18N
662         }
663
664         @Override
665         @Deprecated
666         public void setControllerType (final String controllerType) {
667                 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
668         }
669
670         /**
671          * Getter for contactCountry instance
672          * <p>
673          * @return Country instance
674          */
675         public Country getContactCountry () {
676                 return this.contactCountry;
677         }
678
679         /**
680          * Setter for contactCountry instance
681          * <p>
682          * @param contactCountry Country instance
683          */
684         public void setContactCountry (final Country contactCountry) {
685                 this.contactCountry = contactCountry;
686         }
687
688         /**
689          * Getter for email address
690          * <p>
691          * @return Email address
692          */
693         public String getEmailAddress () {
694                 return this.emailAddress;
695         }
696
697         /**
698          * Setter for email address
699          * <p>
700          * @param emailAddress Email address
701          */
702         public void setEmailAddress (final String emailAddress) {
703                 this.emailAddress = emailAddress;
704         }
705
706         /**
707          * Family name
708          * <p>
709          * @return the familyName
710          */
711         public String getFamilyName () {
712                 return this.familyName;
713         }
714
715         /**
716          * Family name
717          * <p>
718          * @param familyName the familyName to set
719          */
720         public void setFamilyName (final String familyName) {
721                 this.familyName = familyName;
722         }
723
724         /**
725          * Getter for fax number's area code
726          * <p>
727          * @return Fax number's area code
728          */
729         public Integer getFaxAreaCode () {
730                 return this.faxAreaCode;
731         }
732
733         /**
734          * Setter for fax number's area code
735          * <p>
736          * @param faxAreaCode Fax number's area code
737          */
738         public void setFaxAreaCode (final Integer faxAreaCode) {
739                 this.faxAreaCode = faxAreaCode;
740         }
741
742         /**
743          * Getter for fax's country instance
744          * <p>
745          * @return Fax' country instance
746          */
747         public Country getFaxCountry () {
748                 return this.faxCountry;
749         }
750
751         /**
752          * Setter for fax's country instance
753          * <p>
754          * @param faxCountry Fax' country instance
755          */
756         public void setFaxCountry (final Country faxCountry) {
757                 this.faxCountry = faxCountry;
758         }
759
760         /**
761          * Getter for fax id
762          * <p>
763          * @return Fax id
764          */
765         public Long getFaxId () {
766                 return this.faxId;
767         }
768
769         /**
770          * Setter for fax id
771          * <p>
772          * @param faxId Fax id
773          */
774         public void setFaxId (final Long faxId) {
775                 this.faxId = faxId;
776         }
777
778         /**
779          * Getter for fax number
780          * <p>
781          * @return Fax number
782          */
783         public Long getFaxNumber () {
784                 return this.faxNumber;
785         }
786
787         /**
788          * Setter for fax number
789          * <p>
790          * @param faxNumber Fax number
791          */
792         public void setFaxNumber (final Long faxNumber) {
793                 this.faxNumber = faxNumber;
794         }
795
796         /**
797          * Getter for first name
798          * <p>
799          * @return First name
800          */
801         public String getFirstName () {
802                 return this.firstName;
803         }
804
805         /**
806          * Setter for first name
807          * <p>
808          * @param firstName First name
809          */
810         public void setFirstName (final String firstName) {
811                 this.firstName = firstName;
812         }
813
814         /**
815          * Getter for house number
816          * <p>
817          * @return House number
818          */
819         public Short getHouseNumber () {
820                 return this.houseNumber;
821         }
822
823         /**
824          * Setter for house number
825          * <p>
826          * @param houseNumber House number
827          */
828         public void setHouseNumber (final Short houseNumber) {
829                 this.houseNumber = houseNumber;
830         }
831
832         /**
833          * Getter for house number extension. Example: 123a, 'a' is the extension
834          * and 123 is the house number.
835          * <p>
836          * @return House number extension
837          */
838         public String getHouseNumberExtension () {
839                 return this.houseNumberExtension;
840         }
841
842         /**
843          * Setter for house number extension
844          * <p>
845          * @param houseNumberExtension House number extension
846          */
847         public void setHouseNumberExtension (final String houseNumberExtension) {
848                 this.houseNumberExtension = houseNumberExtension;
849         }
850
851         /**
852          * Getter for land-line number's area code
853          * <p>
854          * @return Land-line number's area code
855          */
856         public Integer getLandLineAreaCode () {
857                 return this.landLineAreaCode;
858         }
859
860         /**
861          * Setter for land-line number's area code
862          * <p>
863          * @param landLineAreaCode Land-line number's area code
864          */
865         public void setLandLineAreaCode (final Integer landLineAreaCode) {
866                 this.landLineAreaCode = landLineAreaCode;
867         }
868
869         /**
870          * Getter for land-line number's country instance
871          * <p>
872          * @return Land-line number's country instance
873          */
874         public Country getLandLineCountry () {
875                 return this.landLineCountry;
876         }
877
878         /**
879          * Setter for land-line number's country instance
880          * <p>
881          * @param landLineCountry Land-line number's country instance
882          */
883         public void setLandLineCountry (final Country landLineCountry) {
884                 this.landLineCountry = landLineCountry;
885         }
886
887         /**
888          * Getter for land-line id
889          * <p>
890          * @return Land-line id
891          */
892         public Long getLandLineId () {
893                 return this.landLineId;
894         }
895
896         /**
897          * Setter for land-line id
898          * <p>
899          * @param landLineId Land-line id
900          */
901         public void setLandLineId (final Long landLineId) {
902                 this.landLineId = landLineId;
903         }
904
905         /**
906          * Getter for land-line number
907          * <p>
908          * @return Land-line number
909          */
910         public Long getLandLineNumber () {
911                 return this.landLineNumber;
912         }
913
914         /**
915          * Setter for land-line number
916          * <p>
917          * @param landLineNumber Land-line number
918          */
919         public void setLandLineNumber (final Long landLineNumber) {
920                 this.landLineNumber = landLineNumber;
921         }
922
923         /**
924          * Getter for mobile id
925          * <p>
926          * @return Mobile id
927          */
928         public Long getMobileId () {
929                 return this.mobileId;
930         }
931
932         /**
933          * Setter for mobile id
934          * <p>
935          * @param mobileId Mobile id
936          */
937         public void setMobileId (final Long mobileId) {
938                 this.mobileId = mobileId;
939         }
940
941         /**
942          * Getter for mobile number
943          * <p>
944          * @return Mobile number
945          */
946         public Long getMobileNumber () {
947                 return this.mobileNumber;
948         }
949
950         /**
951          * Setter for mobile number
952          * <p>
953          * @param mobileNumber Mobile number
954          */
955         public void setMobileNumber (final Long mobileNumber) {
956                 this.mobileNumber = mobileNumber;
957         }
958
959         /**
960          * Getter for mobile number's carrier
961          * <p>
962          * @return Mobile number's carrier
963          */
964         public MobileProvider getMobileProvider () {
965                 return this.mobileProvider;
966         }
967
968         /**
969          * Setter for mobile number's carrier prefix
970          * <p>
971          * @param mobileProvider Mobile number's carrier prefix
972          */
973         public void setMobileProvider (final MobileProvider mobileProvider) {
974                 this.mobileProvider = mobileProvider;
975         }
976
977         /**
978          * Getter for personal title
979          * <p>
980          * @return Personal title
981          */
982         public PersonalTitle getPersonalTitle () {
983                 return this.personalTitle;
984         }
985
986         /**
987          * Setter for personal title
988          * <p>
989          * @param personalTitle Personal title
990          */
991         public void setPersonalTitle (final PersonalTitle personalTitle) {
992                 this.personalTitle = personalTitle;
993         }
994
995         /**
996          * Getter for street name
997          * <p>
998          * @return Street name
999          */
1000         public String getStreet () {
1001                 return this.street;
1002         }
1003
1004         /**
1005          * Setter for street name
1006          * <p>
1007          * @param street Street name
1008          */
1009         public void setStreet (final String street) {
1010                 this.street = street;
1011         }
1012
1013         /**
1014          * Getter for ZIP code
1015          * <p>
1016          * @return ZIP code
1017          */
1018         public Integer getZipCode () {
1019                 return this.zipCode;
1020         }
1021
1022         /**
1023          * Setter for ZIP code
1024          * <p>
1025          * @param zipCode ZIP code
1026          */
1027         public void setZipCode (final Integer zipCode) {
1028                 this.zipCode = zipCode;
1029         }
1030
1031         /**
1032          * Post-initialization of this class
1033          */
1034         @PostConstruct
1035         public void init () {
1036                 // Try it
1037                 try {
1038                         // Get initial context
1039                         Context context = new InitialContext();
1040
1041                         // Try to lookup
1042                         this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
1043
1044                         // Try to lookup (administative)
1045                         this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
1046                 } catch (final NamingException e) {
1047                         // Throw again
1048                         throw new FaceletException(e);
1049                 }
1050         }
1051
1052         @Override
1053         @Deprecated
1054         public boolean isPersonalTitleRequired () {
1055                 // Get context parameter
1056                 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_personal_title_enabled"); //NOI18N
1057
1058                 // Is it set?
1059                 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
1060
1061                 // Return value
1062                 return isRequired;
1063         }
1064
1065         @Override
1066         public void validateContactData () {
1067                 if (this.getPersonalTitle() == null) {
1068                         // Throw NPE again
1069                         throw new NullPointerException("contactController.gender is null"); //NOI18N
1070                 } else if (this.getFirstName() == null) {
1071                         // ... and again
1072                         throw new NullPointerException("contactController.firstName is null"); //NOI18N
1073                 } else if (this.getFirstName().isEmpty()) {
1074                         // ... and again
1075                         throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1076                 } else if (this.getFamilyName() == null) {
1077                         // ... and again
1078                         throw new NullPointerException("contactController.familyName is null"); //NOI18N
1079                 } else if (this.getFamilyName().isEmpty()) {
1080                         // ... and again
1081                         throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1082                 } else if (this.getEmailAddress() == null) {
1083                         // ... and again
1084                         throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1085                 } else if (this.getEmailAddress().isEmpty()) {
1086                         // ... and again
1087                         throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1088                 }
1089         }
1090
1091         /**
1092          * Clears this bean
1093          */
1094         private void clear () {
1095                 // Clear all data
1096                 // - personal data
1097                 this.setAcademicTitle(null);
1098                 this.setFirstName(null);
1099                 this.setFamilyName(null);
1100                 this.setStreet(null);
1101                 this.setHouseNumber(null);
1102                 this.setHouseNumberExtension(null);
1103                 this.setZipCode(null);
1104                 this.setCity(null);
1105                 this.setContactCountry(null);
1106
1107                 // - contact data
1108                 this.setEmailAddress(null);
1109                 this.setLandLineCountry(null);
1110                 this.setLandLineAreaCode(null);
1111                 this.setLandLineNumber(null);
1112                 this.setMobileProvider(null);
1113                 this.setMobileNumber(null);
1114                 this.setFaxCountry(null);
1115                 this.setFaxAreaCode(null);
1116                 this.setFaxNumber(null);
1117
1118                 // - other data
1119                 this.setBirthday(null);
1120                 this.setComment(null);
1121         }
1122
1123         /**
1124          * Checks whether the given contact is found
1125          * <p>
1126          * @param contact Contact inastance
1127          *
1128          * @return Wether contact has been found
1129          */
1130         private boolean isSameContactFound (final Contact contact) {
1131                 // Default is not found
1132                 boolean IsFound = false;
1133
1134                 // Get iterator
1135                 Iterator<Contact> iterator = this.contactController.allContacts().iterator();
1136
1137                 // Loop through all
1138                 while (iterator.hasNext()) {
1139                         // Get next contact
1140                         Contact next = iterator.next();
1141
1142                         // Is the same?
1143                         if (ContactUtils.isSameContact(contact, next)) {
1144                                 // Yes, then abort loop
1145                                 IsFound = false;
1146                                 break;
1147                         }
1148                 }
1149
1150                 // Return status
1151                 return IsFound;
1152         }
1153
1154         /**
1155          * Updates all data in contact instance.
1156          * <p>
1157          * @param contact Contact instance
1158          */
1159         private void updateContactData (final Contact contact) {
1160                 // Contact instance should be valid
1161                 if (null == contact) {
1162                         // Throw NPE
1163                         throw new NullPointerException("contact is null"); //NOI18N
1164                 } else if (contact.getContactId() == null) {
1165                         // Throw NPE again
1166                         throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1167                 } else if (contact.getContactId() < 1) {
1168                         // Invalid id
1169                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1170                 }
1171
1172                 // Update all fields
1173                 contact.setContactPersonalTitle(this.getPersonalTitle());
1174                 contact.setContactTitle(this.getAcademicTitle());
1175                 contact.setContactFirstName(this.getFirstName());
1176                 contact.setContactFamilyName(this.getFamilyName());
1177                 contact.setContactStreet(this.getStreet());
1178                 contact.setContactHouseNumber(this.getHouseNumber());
1179                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1180                 contact.setContactZipCode(this.getZipCode());
1181                 contact.setContactCity(this.getCity());
1182                 contact.setContactCountry(this.getContactCountry());
1183
1184                 // Update contact's cmobile number
1185                 this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1186
1187                 // Update contact's land-line number
1188                 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1189
1190                 // Update contact's fax number
1191                 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
1192         }
1193
1194 }