]> git.mxchange.org Git - pizzaservice-war.git/blob
0cf671da912c10de06be85a06ff9f06d376ea548
[pizzaservice-war.git] /
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.phone;
18
19 import java.text.MessageFormat;
20 import javax.annotation.PostConstruct;
21 import javax.enterprise.context.RequestScoped;
22 import javax.enterprise.event.Event;
23 import javax.enterprise.event.Observes;
24 import javax.enterprise.inject.Any;
25 import javax.faces.view.facelets.FaceletException;
26 import javax.inject.Inject;
27 import javax.inject.Named;
28 import javax.naming.Context;
29 import javax.naming.InitialContext;
30 import javax.naming.NamingException;
31 import org.mxchange.jcontacts.contact.Contact;
32 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
33 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
34 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
35 import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
36 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
37 import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
38 import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
39 import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
40 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
41 import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
42 import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
43 import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
44 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
45 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
46 import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
47 import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
48 import org.mxchange.jcountry.data.Country;
49 import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
50 import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
51 import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
52 import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
53 import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
54 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
55 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
56 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
57 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
58 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
59 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
60 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
61 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
62 import org.mxchange.pizzaapplication.beans.BasePizzaController;
63 import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
64 import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
65
66 /**
67  * An administrative contact phone controller (bean)
68  * <p>
69  * @author Roland Häder<roland@mxchange.org>
70  */
71 @Named ("adminContactPhoneController")
72 @RequestScoped
73 public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController implements PizzaAdminContactPhoneWebRequestController {
74
75         /**
76          * Call-stack instance (5 may show BeanELResolver.getValue as caller)
77          */
78         private static final short THREAD_STACK = 5;
79
80         /**
81          * Serial number
82          */
83         private static final long serialVersionUID = 542_145_347_916L;
84
85         /**
86          * Event being fired when a fax number has been linked
87          */
88         @Inject
89         @Any
90         private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
91
92         /**
93          * Event being fired when a land-line number has been linked
94          */
95         @Inject
96         @Any
97         private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
98
99         /**
100          * Event being fired when a mobile number has been linked
101          */
102         @Inject
103         @Any
104         private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
105
106         /**
107          * Administrative EJB for phone number
108          */
109         private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
110
111         /**
112          * Administrative phone controller
113          */
114         @Inject
115         private PizzaAdminPhoneWebRequestController adminPhoneController;
116
117         /**
118          * Bean helper
119          */
120         @Inject
121         private PizzaWebRequestHelperController beanHelper;
122
123         /**
124          * Event being fired when a fax number has been unlinked
125          */
126         @Inject
127         @Any
128         private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
129
130         /**
131          * Event being fired when a land-line number has been unlinked
132          */
133         @Inject
134         @Any
135         private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
136
137         /**
138          * Event being fired when admin unlinks mobile from contact
139          */
140         @Inject
141         @Any
142         private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
143
144         /**
145          * Area code (city dial prefix) for fax number
146          */
147         private Integer faxAreaCode;
148
149         /**
150          * Country (for dial prefix) for fax number
151          */
152         private Country faxCountry;
153
154         /**
155          * Fax number
156          */
157         private Long faxNumber;
158
159         /**
160          * Area code (city dial prefix) for land-line number
161          */
162         private Integer landLineAreaCode;
163
164         /**
165          * Country (for dial prefix) for land-line number
166          */
167         private Country landLineCountry;
168
169         /**
170          * Land-line number
171          */
172         private Long landLineNumber;
173
174         /**
175          * Mobile provider
176          */
177         private MobileProvider mobileProvider;
178
179         /**
180          * Mobile number
181          */
182         private Long mobileNumber;
183
184         /**
185          * Default constructor
186          */
187         public PizzaAdminContactPhoneWebRequestBean () {
188                 // Call super constructor
189                 super();
190
191                 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
192                 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
193         }
194
195         /**
196          * Observes events being fired when an administrator has added a new
197          * contact.
198          * <p>
199          * @param event Event being fired
200          */
201         public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
202                 // The event must be valid
203                 if (null == event) {
204                         // Throw NPE
205                         throw new NullPointerException("event is null"); //NOI18N
206                 } else if (event.getAddedContact() == null) {
207                         // Throw again ...
208                         throw new NullPointerException("event.addedContact is null"); //NOI18N
209                 } else if (event.getAddedContact().getContactId() == null) {
210                         // ... and again
211                         throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
212                 } else if (event.getAddedContact().getContactId() < 1) {
213                         // Not valid
214                         throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
215                 }
216
217                 // Clear this bean
218                 this.clear();
219         }
220
221         /**
222          * Event observer for newly added users by administrator
223          * <p>
224          * @param event Event being fired
225          */
226         public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
227                 // event should not be null
228                 if (null == event) {
229                         // Throw NPE
230                         throw new NullPointerException("event is null"); //NOI18N
231                 } else if (event.getAddedUser() == null) {
232                         // Throw NPE again
233                         throw new NullPointerException("event.addedUser is null"); //NOI18N
234                 } else if (event.getAddedUser().getUserId() == null) {
235                         // userId is null
236                         throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
237                 } else if (event.getAddedUser().getUserId() < 1) {
238                         // Not avalid id
239                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
240                 }
241
242                 // Clear all data
243                 this.clear();
244         }
245
246         /**
247          * Event observer for updated contact data by administrators
248          * <p>
249          * @param event Updated contact data event
250          */
251         public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
252                 // event should not be null
253                 if (null == event) {
254                         // Throw NPE
255                         throw new NullPointerException("event is null"); //NOI18N
256                 } else if (event.getUpdatedContact() == null) {
257                         // Throw NPE again
258                         throw new NullPointerException("event.updatedContact is null"); //NOI18N
259                 } else if (event.getUpdatedContact().getContactId() == null) {
260                         // userId is null
261                         throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
262                 } else if (event.getUpdatedContact().getContactId() < 1) {
263                         // Not avalid id
264                         throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
265                 }
266
267                 // Clear all data
268                 this.clear();
269         }
270
271         /**
272          * Observer for events being fired when a bean helper has successfully
273          * created a contact instance.
274          * <p>
275          * @param event Event being fired
276          */
277         public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
278                 // Log message
279                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
280
281                 // The event instance must be valid
282                 if (null == event) {
283                         // Throw NPE again
284                         throw new NullPointerException("event is null"); //NOI18N
285                 } else if (event.getCreatedContact() == null) {
286                         // Throw NPE again
287                         throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
288                 } else if (event.getCreatedContact().getContactId() == null) {
289                         // Throw NPE again
290                         throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
291                 } else if (event.getCreatedContact().getContactId() < 1) {
292                         // Not valid
293                         throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
294                 }
295
296                 // Set it here
297                 this.setContact(event.getCreatedContact());
298         }
299
300         /**
301          * Observes events being fired when a bean helper has successfully created a
302          * fax number instance.
303          * <p>
304          * @param event Event being fired
305          */
306         public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
307                 // The event instance must be valid
308                 if (null == event) {
309                         // Throw NPE
310                         throw new NullPointerException("event is null"); //NOI18N
311                 } else if (event.getFaxNumber() == null) {
312                         // Throw NPE again
313                         throw new NullPointerException("event.faxNumber is null"); //NOI18N
314                 } else if (event.getFaxNumber().getPhoneId() == null) {
315                         // Throw NPE yet again
316                         throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
317                 } else if (event.getFaxNumber().getPhoneId() < 1) {
318                         // Throw NPE yet again
319                         throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
320                 }
321
322                 // Get fax number from event
323                 DialableFaxNumber number = event.getFaxNumber();
324
325                 // Copy all data to this bean
326                 this.setPhoneId(number.getPhoneId());
327                 this.setFaxCountry(number.getPhoneCountry());
328                 this.setFaxAreaCode(number.getPhoneAreaCode());
329                 this.setFaxNumber(number.getPhoneNumber());
330                 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
331                 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
332         }
333
334         /**
335          * Observes events being fired when a bean helper has successfully created a
336          * land-line number instance.
337          * <p>
338          * @param event Event being fired
339          */
340         public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
341                 // The event instance must be valid
342                 if (null == event) {
343                         // Throw NPE
344                         throw new NullPointerException("event is null"); //NOI18N
345                 } else if (event.getLandLineNumber() == null) {
346                         // Throw NPE again
347                         throw new NullPointerException("event.landLineNumber is null"); //NOI18N
348                 } else if (event.getLandLineNumber().getPhoneId() == null) {
349                         // Throw NPE yet again
350                         throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
351                 } else if (event.getLandLineNumber().getPhoneId() < 1) {
352                         // Throw NPE yet again
353                         throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
354                 }
355
356                 // Get fax number from event
357                 DialableLandLineNumber number = event.getLandLineNumber();
358
359                 // Copy all data to this bean
360                 this.setPhoneId(number.getPhoneId());
361                 this.setLandLineCountry(number.getPhoneCountry());
362                 this.setLandLineAreaCode(number.getPhoneAreaCode());
363                 this.setLandLineNumber(number.getPhoneNumber());
364                 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
365                 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
366         }
367
368         /**
369          * Observes events being fired when a bean helper has successfully created a
370          * mobile number instance.
371          * <p>
372          * @param event Event being fired
373          */
374         public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
375                 // The event instance must be valid
376                 if (null == event) {
377                         // Throw NPE
378                         throw new NullPointerException("event is null"); //NOI18N
379                 } else if (event.getMobileNumber() == null) {
380                         // Throw NPE again
381                         throw new NullPointerException("event.mobileNumber is null"); //NOI18N
382                 } else if (event.getMobileNumber().getPhoneId() == null) {
383                         // Throw NPE yet again
384                         throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
385                 } else if (event.getMobileNumber().getPhoneId() < 1) {
386                         // Throw NPE yet again
387                         throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
388                 }
389
390                 // Get fax number from event
391                 DialableMobileNumber number = event.getMobileNumber();
392
393                 // Copy all data to this bean
394                 this.setPhoneId(number.getPhoneId());
395                 this.setMobileProvider(number.getMobileProvider());
396                 this.setMobileNumber(number.getPhoneNumber());
397                 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
398                 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
399         }
400
401         /**
402          * Links fax number to contact from bean helper as "main fax number".
403          * <p>
404          * @return Redirect outcome
405          */
406         public String doLinkMainFaxNumber () {
407                 // Get contact from helper
408                 Contact contact = this.beanHelper.getContact();
409
410                 // Is all data properly set?
411                 if (null == contact) {
412                         // Throw NPE
413                         throw new NullPointerException("contact is null"); //NOI18N
414                 } else if (contact.getContactId() == null) {
415                         // Throw it again
416                         throw new NullPointerException("contact.contactId is null"); //NOI18N
417                 } else if (contact.getContactId() < 1) {
418                         // Is not valid
419                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
420                 } else if (this.getFaxCountry() == null) {
421                         // Throw NPE again
422                         throw new NullPointerException("this.faxCountry is null"); //NOI18N
423                 } else if (this.getFaxCountry().getCountryId() == null) {
424                         // Throw NPE again
425                         throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
426                 } else if (this.getFaxCountry().getCountryId() < 1) {
427                         // Invalid id number
428                         throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
429                 } else if (this.getFaxAreaCode() == null) {
430                         // Throw NPE again
431                         throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
432                 } else if (this.getFaxAreaCode() < 1) {
433                         // Invalid id number
434                         throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
435                 } else if (this.getFaxNumber() == null) {
436                         // Throw NPE again
437                         throw new NullPointerException("this.faxNumber is null"); //NOI18N
438                 } else if (this.getFaxNumber() < 1) {
439                         // Invalid id number
440                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
441                 }
442
443                 // Init instances
444                 Contact updatedContact;
445                 DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
446
447                 // Try it again
448                 try {
449                         // Link it, too
450                         updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, number);
451                 } catch (final PhoneNumberAlreadyLinkedException ex) {
452                         // Throw again as cause
453                         this.showFacesMessage("form_add_contact_fax:faxNumber", ex); //NOI18N
454                         return ""; //NOI18N
455                 }
456
457                 // Fire event
458                 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
459
460                 // Return to contact profile
461                 return "admin_show_contact"; //NOI18N
462         }
463
464         /**
465          * Links land-line number to contact from bean helper as "main land-line
466          * number".
467          * <p>
468          * @return Redirect outcome
469          */
470         public String doLinkMainLandLineNumber () {
471                 // Get contact from helper
472                 Contact contact = this.beanHelper.getContact();
473
474                 // Is all data properly set?
475                 if (null == contact) {
476                         // Throw NPE
477                         throw new NullPointerException("contact is null"); //NOI18N
478                 } else if (contact.getContactId() == null) {
479                         // Throw it again
480                         throw new NullPointerException("contact.contactId is null"); //NOI18N
481                 } else if (contact.getContactId() < 1) {
482                         // Is not valid
483                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
484                 } else if (this.getLandLineCountry() == null) {
485                         // Throw NPE again
486                         throw new NullPointerException("this.landLineCountry is null"); //NOI18N
487                 } else if (this.getLandLineCountry().getCountryId() == null) {
488                         // Throw NPE again
489                         throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
490                 } else if (this.getLandLineCountry().getCountryId() < 1) {
491                         // Invalid id number
492                         throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
493                 } else if (this.getLandLineAreaCode() == null) {
494                         // Throw NPE again
495                         throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
496                 } else if (this.getLandLineAreaCode() < 1) {
497                         // Invalid id number
498                         throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
499                 } else if (this.getLandLineNumber() == null) {
500                         // Throw NPE again
501                         throw new NullPointerException("this.landLineNumber is null"); //NOI18N
502                 } else if (this.getLandLineNumber() < 1) {
503                         // Invalid id number
504                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
505                 }
506
507                 // Init instance
508                 Contact updatedContact;
509                 DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
510
511                 // Try it again
512                 try {
513                         // Link it, too
514                         updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, number);
515                 } catch (final PhoneNumberAlreadyLinkedException ex) {
516                         // Throw again as cause
517                         this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex); //NOI18N
518                         return ""; //NOI18N
519                 }
520
521                 // Fire event
522                 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
523
524                 // Return to contact profile
525                 return "admin_show_contact"; //NOI18N
526         }
527
528         /**
529          * Links mobile number to contact from bean helper as "main mobile number".
530          * <p>
531          * @return Redirect outcome
532          */
533         public String doLinkMainMobileNumber () {
534                 // Get contact from helper
535                 Contact contact = this.beanHelper.getContact();
536
537                 // Is all data properly set?
538                 if (null == contact) {
539                         // Throw NPE
540                         throw new NullPointerException("contact is null"); //NOI18N
541                 } else if (contact.getContactId() == null) {
542                         // Throw it again
543                         throw new NullPointerException("contact.contactId is null"); //NOI18N
544                 } else if (contact.getContactId() < 1) {
545                         // Is not valid
546                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
547                 } else if (this.getMobileProvider() == null) {
548                         // Throw NPE
549                         throw new NullPointerException("this.mobileProvider is null"); //NOI18N
550                 } else if (this.getMobileProvider().getProviderId() == null) {
551                         // Throw NPE
552                         throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
553                 } else if (this.getMobileProvider().getProviderId() < 1) {
554                         // Throw NPE
555                         throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N
556                 } else if (this.getMobileNumber() == null) {
557                         // Throw NPE again
558                         throw new NullPointerException("this.mobileNumber is null"); //NOI18N
559                 } else if (this.getMobileNumber() < 1) {
560                         // Invalid id number
561                         throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N
562                 }
563
564                 // Init instance
565                 Contact updatedContact;
566                 DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
567
568                 // Try it again
569                 try {
570                         // Link it, too
571                         updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, number);
572                 } catch (final PhoneNumberAlreadyLinkedException ex) {
573                         // Throw again as cause
574                         this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex); //NOI18N
575                         return ""; //NOI18N
576                 }
577
578                 // Fire event
579                 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number));
580
581                 // Return to contact profile
582                 return "admin_show_contact"; //NOI18N
583         }
584
585         /**
586          * Getter for fax area code
587          * <p>
588          * @return Fax area code
589          */
590         public Integer getFaxAreaCode () {
591                 return this.faxAreaCode;
592         }
593
594         /**
595          * Setter for fax area code
596          * <p>
597          * @param faxAreaCode Fax area code
598          */
599         public void setFaxAreaCode (final Integer faxAreaCode) {
600                 this.faxAreaCode = faxAreaCode;
601         }
602
603         /**
604          * Getter for fax numbers country
605          * <p>
606          * @return Fax numbers country
607          */
608         public Country getFaxCountry () {
609                 return this.faxCountry;
610         }
611
612         /**
613          * Setter for fax numbers country
614          * <p>
615          * @param faxCountry Fax numbers country
616          */
617         public void setFaxCountry (final Country faxCountry) {
618                 this.faxCountry = faxCountry;
619         }
620
621         /**
622          * Getter for fax number
623          * <p>
624          * @return Fax number
625          */
626         public Long getFaxNumber () {
627                 return this.faxNumber;
628         }
629
630         /**
631          * Setter for fax number
632          * <p>
633          * @param faxNumber Fax number
634          */
635         public void setFaxNumber (final Long faxNumber) {
636                 this.faxNumber = faxNumber;
637         }
638
639         /**
640          * Getter for land-line area code
641          * <p>
642          * @return Land-line area code
643          */
644         public Integer getLandLineAreaCode () {
645                 return this.landLineAreaCode;
646         }
647
648         /**
649          * Setter for land-line area code
650          * <p>
651          * @param landLineAreaCode Land-line area code
652          */
653         public void setLandLineAreaCode (final Integer landLineAreaCode) {
654                 this.landLineAreaCode = landLineAreaCode;
655         }
656
657         /**
658          * Getter for land-line country
659          * <p>
660          * @return Land-line country
661          */
662         public Country getLandLineCountry () {
663                 return this.landLineCountry;
664         }
665
666         /**
667          * Setter for land-line country
668          * <p>
669          * @param landLineCountry Land-line country
670          */
671         public void setLandLineCountry (final Country landLineCountry) {
672                 this.landLineCountry = landLineCountry;
673         }
674
675         /**
676          * Getter for land-line number
677          * <p>
678          * @return Land-line number
679          */
680         public Long getLandLineNumber () {
681                 return this.landLineNumber;
682         }
683
684         /**
685          * Setter for land-line number
686          * <p>
687          * @param landLineNumber Land-line number
688          */
689         public void setLandLineNumber (final Long landLineNumber) {
690                 this.landLineNumber = landLineNumber;
691         }
692
693         /**
694          * Getter for mobile provider
695          * <p>
696          * @return Mobile provider
697          */
698         public MobileProvider getMobileProvider () {
699                 return this.mobileProvider;
700         }
701
702         /**
703          * Setter for mobile provider
704          * <p>
705          * @param mobileProvider Mobile provider
706          */
707         public void setMobileProvider (final MobileProvider mobileProvider) {
708                 this.mobileProvider = mobileProvider;
709         }
710
711         /**
712          * Getter for mobile number
713          * <p>
714          * @return Mobile number
715          */
716         public Long getMobileNumber () {
717                 return this.mobileNumber;
718         }
719
720         /**
721          * Setter for mobile number
722          * <p>
723          * @param mobileNumber Mobile number
724          */
725         public void setMobileNumber (final Long mobileNumber) {
726                 this.mobileNumber = mobileNumber;
727         }
728
729         /**
730          * Post-construction method
731          */
732         @PostConstruct
733         public void init () {
734                 // Try it
735                 try {
736                         // Get initial context
737                         Context context = new InitialContext();
738
739                         // Try to lookup the beans
740                         this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
741                 } catch (final NamingException e) {
742                         // Throw again
743                         throw new FaceletException(e);
744                 }
745         }
746
747         /**
748          * Unlinks fax data with current contact
749          * <p>
750          * @return Redirect outcome
751          */
752         public String unlinkFaxContactData () {
753                 // Is all data set
754                 if (this.beanHelper.getFaxNumber() == null) {
755                         // Not set, throw NPE
756                         throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
757                 } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
758                         // Throw NPE again
759                         throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
760                 } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
761                         // Invalid number
762                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
763                 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
764                         // Throw NPE again
765                         throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
766                 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
767                         // Throw it again ...
768                         throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
769                 } else if (this.beanHelper.getContact() == null) {
770                         // ... and throw again
771                         throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
772                 } else if (this.beanHelper.getContact().getContactId() == null) {
773                         // ... and again ...
774                         throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
775                 } else if (this.beanHelper.getContact().getContactId() < 1) {
776                         // Invalid id number
777                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
778                 }
779
780                 // Init contact instance
781                 Contact updatedContact;
782
783                 try {
784                         // Unlink it and return contact without fax instance
785                         updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
786                 } catch (final PhoneNumberNotLinkedException ex) {
787                         // Did not work
788                         this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
789                         return ""; //NOI18N
790                 }
791
792                 // Fire event
793                 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber()));
794
795                 // All fine here
796                 return "admin_show_contact"; //NOI18N
797         }
798
799         /**
800          * Unlinks land-line data with current contact
801          * <p>
802          * @return Redirect outcome
803          */
804         public String unlinkLandLineContactData () {
805                 // Is all data set
806                 if (this.beanHelper.getLandLineNumber() == null) {
807                         // Not set, throw NPE
808                         throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
809                 } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
810                         // Throw NPE again
811                         throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
812                 } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
813                         // Invalid number
814                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
815                 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
816                         // Throw NPE again
817                         throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
818                 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
819                         // Throw it again ...
820                         throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
821                 } else if (this.beanHelper.getContact() == null) {
822                         // ... and throw again
823                         throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
824                 } else if (this.beanHelper.getContact().getContactId() == null) {
825                         // ... and again ...
826                         throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
827                 } else if (this.beanHelper.getContact().getContactId() < 1) {
828                         // Invalid id number
829                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
830                 }
831
832                 // Init contact instance
833                 Contact updatedContact;
834
835                 try {
836                         // Unlink it and return contact without landLine instance
837                         updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
838                 } catch (final PhoneNumberNotLinkedException ex) {
839                         // Did not work
840                         this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
841                         return ""; //NOI18N
842                 }
843
844                 // Fire event
845                 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber()));
846
847                 // All fine here
848                 return "admin_show_contact"; //NOI18N
849         }
850
851         /**
852          * Unlinks mobile data with current contact
853          * <p>
854          * @return Redirect outcome
855          */
856         public String unlinkMobileContactData () {
857                 // Is all data set
858                 if (this.beanHelper.getMobileNumber() == null) {
859                         // Not set, throw NPE
860                         throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N
861                 } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) {
862                         // Throw NPE again
863                         throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N
864                 } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) {
865                         // Invalid number
866                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N
867                 } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) {
868                         // Throw NPE
869                         throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N
870                 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) {
871                         // ... throw again
872                         throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N
873                 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) {
874                         // Id not valid
875                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
876                 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) {
877                         // Throw NPE again
878                         throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N
879                 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) {
880                         // Throw it again ...
881                         throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N
882                 } else if (this.beanHelper.getContact() == null) {
883                         // ... and throw again
884                         throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
885                 } else if (this.beanHelper.getContact().getContactId() == null) {
886                         // ... and again ...
887                         throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
888                 } else if (this.beanHelper.getContact().getContactId() < 1) {
889                         // Invalid id number
890                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
891                 }
892
893                 // Init contact instance
894                 Contact updatedContact;
895
896                 try {
897                         // Unlink it and return contact without mobile instance
898                         updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber());
899                 } catch (final PhoneNumberNotLinkedException ex) {
900                         // Did not work
901                         this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
902                         return ""; //NOI18N
903                 }
904
905                 // Fire event
906                 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber()));
907
908                 // All fine here
909                 return "admin_show_contact"; //NOI18N
910         }
911
912         /**
913          * Clears this bean
914          */
915         private void clear () {
916                 // Clear all data
917         }
918
919 }