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