]> git.mxchange.org Git - jfinancials-war.git/blob - src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsAdminContactPhoneWebRequestBean.java
Please cherry-pick:
[jfinancials-war.git] / src / java / org / mxchange / jfinancials / beans / contact / phone / FinancialsAdminContactPhoneWebRequestBean.java
1 /*
2  * Copyright (C) 2016 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.jfinancials.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.update.ObservableAdminUpdatedContactEvent;
34 import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
35 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
36 import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
37 import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
38 import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
39 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
40 import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
41 import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
42 import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
43 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
44 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
45 import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
46 import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
47 import org.mxchange.jcountry.data.Country;
48 import org.mxchange.jfinancials.beans.BaseFinancialsController;
49 import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestHelperController;
50 import org.mxchange.jfinancials.beans.phone.FinancialsAdminPhoneWebRequestController;
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 FinancialsAdminContactPhoneWebRequestBean extends BaseFinancialsController implements FinancialsAdminContactPhoneWebRequestController {
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 FinancialsAdminPhoneWebRequestController adminPhoneController;
112
113         /**
114          * Bean helper
115          */
116         @Inject
117         private FinancialsWebRequestHelperController 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          * Default constructor
142          */
143         public FinancialsAdminContactPhoneWebRequestBean () {
144                 // Call super constructor
145                 super();
146
147                 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
148                 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
149         }
150
151         /**
152          * Observes events being fired when an administrator has added a new
153          * contact.
154          * <p>
155          * @param event Event being fired
156          */
157         public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
158                 // The event must be valid
159                 if (null == event) {
160                         // Throw NPE
161                         throw new NullPointerException("event is null"); //NOI18N
162                 } else if (event.getAddedContact() == null) {
163                         // Throw again ...
164                         throw new NullPointerException("event.addedContact is null"); //NOI18N
165                 } else if (event.getAddedContact().getContactId() == null) {
166                         // ... and again
167                         throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
168                 } else if (event.getAddedContact().getContactId() < 1) {
169                         // Not valid
170                         throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
171                 }
172
173                 // Clear this bean
174                 this.clear();
175         }
176
177         /**
178          * Event observer for newly added users by administrator
179          * <p>
180          * @param event Event being fired
181          */
182         public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
183                 // event should not be null
184                 if (null == event) {
185                         // Throw NPE
186                         throw new NullPointerException("event is null"); //NOI18N
187                 } else if (event.getAddedUser() == null) {
188                         // Throw NPE again
189                         throw new NullPointerException("event.addedUser is null"); //NOI18N
190                 } else if (event.getAddedUser().getUserId() == null) {
191                         // userId is null
192                         throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
193                 } else if (event.getAddedUser().getUserId() < 1) {
194                         // Not avalid id
195                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
196                 }
197
198                 // Clear all data
199                 this.clear();
200         }
201
202         /**
203          * Event observer for updated contact data by administrators
204          * <p>
205          * @param event Updated contact data event
206          */
207         public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
208                 // event should not be null
209                 if (null == event) {
210                         // Throw NPE
211                         throw new NullPointerException("event is null"); //NOI18N
212                 } else if (event.getUpdatedContact() == null) {
213                         // Throw NPE again
214                         throw new NullPointerException("event.updatedContact is null"); //NOI18N
215                 } else if (event.getUpdatedContact().getContactId() == null) {
216                         // userId is null
217                         throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
218                 } else if (event.getUpdatedContact().getContactId() < 1) {
219                         // Not avalid id
220                         throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
221                 }
222
223                 // Clear all data
224                 this.clear();
225         }
226
227         @Override
228         public String doLinkAddFaxNumber (final Contact contact) {
229                 // Is all data properly set?
230                 if (null == contact) {
231                         // Throw NPE
232                         throw new NullPointerException("contact is null"); //NOI18N
233                 } else if (contact.getContactId() == null) {
234                         // Throw it again
235                         throw new NullPointerException("contact.contactId is null"); //NOI18N
236                 } else if (contact.getContactId() < 1) {
237                         // Is not valid
238                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
239                 } else if ((this.adminPhoneController.getFaxNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
240                         // All fields are empty
241                         throw new NullPointerException("choosenFaxNumber, mobileProvider and phoneNumer are null"); //NOI18N
242                 } else if ((this.adminPhoneController.getFaxNumber() instanceof DialableFaxNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
243                         // All fields are set
244                         throw new IllegalStateException("choosenFaxNumber, mobileProvider and phoneNumer are all set"); //NOI18N
245                 } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
246                         // No country selected
247                         this.showFacesMessage("form_add_contact_fax:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
248                         return ""; //NOI18N
249                 } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
250                         // No area code entered
251                         this.showFacesMessage("form_add_contact_fax:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
252                         return ""; //NOI18N
253                 } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
254                         // No phone number entered
255                         this.showFacesMessage("form_add_contact_fax:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
256                         return ""; //NOI18N
257                 }
258
259                 // Init instances
260                 Contact updatedContact;
261                 DialableFaxNumber faxNumber = this.adminPhoneController.getFaxNumber();
262
263                 // Try it again
264                 try {
265                         // All fine so far, then which was choosen?
266                         if (faxNumber instanceof DialableFaxNumber) {
267                                 // User has choosen number
268                                 updatedContact = this.adminPhoneBean.linkExistingFaxNumberWithContact(contact, faxNumber);
269                         } else {
270                                 // Create new instance
271                                 faxNumber = new FaxNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
272
273                                 // Link it, too
274                                 updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, faxNumber);
275                         }
276                 } catch (final PhoneNumberAlreadyLinkedException ex) {
277                         // Throw again as cause
278                         this.showFacesMessage("form_add_contact_fax:phoneNumber", ex); //NOI18N
279                         return ""; //NOI18N
280                 }
281
282                 // Fire event
283                 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, faxNumber));
284
285                 // Return to contact profile
286                 return "admin_show_contact"; //NOI18N
287         }
288
289         @Override
290         public String doLinkAddLandLineNumber (final Contact contact) {
291                 // Is all data properly set?
292                 if (null == contact) {
293                         // Throw NPE
294                         throw new NullPointerException("contact is null"); //NOI18N
295                 } else if (contact.getContactId() == null) {
296                         // Throw it again
297                         throw new NullPointerException("contact.contactId is null"); //NOI18N
298                 } else if (contact.getContactId() < 1) {
299                         // Is not valid
300                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
301                 } else if ((this.adminPhoneController.getLandLineNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
302                         // All fields are empty
303                         throw new NullPointerException("choosenLandLineNumber, mobileProvider and phoneNumer are null"); //NOI18N
304                 } else if ((this.adminPhoneController.getLandLineNumber() instanceof DialableLandLineNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
305                         // All fields are set
306                         throw new IllegalStateException("choosenLandLineNumber, mobileProvider and phoneNumer are all set"); //NOI18N
307                 } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
308                         // No country selected
309                         this.showFacesMessage("form_add_contact_landLine:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
310                         return ""; //NOI18N
311                 } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
312                         // No area code entered
313                         this.showFacesMessage("form_add_contact_landLine:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
314                         return ""; //NOI18N
315                 } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
316                         // No phone number entered
317                         this.showFacesMessage("form_add_contact_landLine:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
318                         return ""; //NOI18N
319                 }
320
321                 // Init instance
322                 Contact updatedContact;
323                 DialableLandLineNumber landLineNumber = this.adminPhoneController.getLandLineNumber();
324
325                 // Try it again
326                 try {
327                         // All fine so far, then which was choosen?
328                         if (landLineNumber instanceof DialableLandLineNumber) {
329                                 // User has choosen number
330                                 updatedContact = this.adminPhoneBean.linkExistingLandLineNumberWithContact(contact, landLineNumber);
331                         } else {
332                                 // Create new instance
333                                 landLineNumber = new LandLineNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
334
335                                 // Link it, too
336                                 updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, landLineNumber);
337                         }
338                 } catch (final PhoneNumberAlreadyLinkedException ex) {
339                         // Throw again as cause
340                         this.showFacesMessage("form_add_contact_landLine:phoneNumber", ex); //NOI18N
341                         return ""; //NOI18N
342                 }
343
344                 // Fire event
345                 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, landLineNumber));
346
347                 // Return to contact profile
348                 return "admin_show_contact"; //NOI18N
349         }
350
351         @Override
352         public String doLinkAddMobileNumber (final Contact contact) {
353                 // Is all data properly set?
354                 if (null == contact) {
355                         // Throw NPE
356                         throw new NullPointerException("contact is null"); //NOI18N
357                 } else if (contact.getContactId() == null) {
358                         // Throw it again
359                         throw new NullPointerException("contact.contactId is null"); //NOI18N
360                 } else if (contact.getContactId() < 1) {
361                         // Is not valid
362                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
363                 } else if ((this.adminPhoneController.getMobileNumber() == null) && (this.adminPhoneController.getMobileProvider() == null) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
364                         // All fields are empty
365                         throw new NullPointerException("choosenMobileNumber, mobileProvider and phoneNumer are null"); //NOI18N
366                 } else if ((this.adminPhoneController.getMobileNumber() instanceof DialableMobileNumber) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
367                         // All fields are set
368                         throw new IllegalStateException("choosenMobileNumber, mobileProvider and phoneNumer are all set"); //NOI18N
369                 } else if ((this.adminPhoneController.getMobileProvider() == null) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
370                         // No mobile provider selected
371                         this.showFacesMessage("form_add_contact_mobile:phoneCountry", "ERROR_ADMIN_NO_PHONE_MOBILE_PROVIDER_SELECTED"); //NOI18N
372                         return ""; //NOI18N
373                 } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider)) {
374                         // No phone number entered
375                         this.showFacesMessage("form_add_contact_mobile:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
376                         return ""; //NOI18N
377                 }
378
379                 // Init instance
380                 Contact updatedContact;
381                 DialableMobileNumber mobileNumber = this.adminPhoneController.getMobileNumber();
382
383                 // Try it again
384                 try {
385                         // All fine so far, then which was choosen?
386                         if (mobileNumber instanceof DialableMobileNumber) {
387                                 // User has choosen number
388                                 updatedContact = this.adminPhoneBean.linkExistingMobileNumberWithContact(contact, mobileNumber);
389                         } else {
390                                 // Create new instance
391                                 mobileNumber = new MobileNumber(this.adminPhoneController.getMobileProvider(), this.adminPhoneController.getPhoneNumber());
392
393                                 // Link it, too
394                                 updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, mobileNumber);
395                         }
396                 } catch (final PhoneNumberAlreadyLinkedException ex) {
397                         // Throw again as cause
398                         this.showFacesMessage("form_add_contact_mobile:phoneNumber", ex); //NOI18N
399                         return ""; //NOI18N
400                 }
401
402                 // Fire event
403                 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, mobileNumber));
404
405                 // Return to contact profile
406                 return "admin_show_contact"; //NOI18N
407         }
408
409         /**
410          * Post-construction method
411          */
412         @PostConstruct
413         public void init () {
414                 // Try it
415                 try {
416                         // Get initial context
417                         Context context = new InitialContext();
418
419                         // Try to lookup the beans
420                         this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
421                 } catch (final NamingException e) {
422                         // Throw again
423                         throw new FaceletException(e);
424                 }
425         }
426
427         @Override
428         public String unlinkFaxContactData () {
429                 // Is all data set
430                 if (this.beanHelper.getFaxNumber() == null) {
431                         // Not set, throw NPE
432                         throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
433                 } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
434                         // Throw NPE again
435                         throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
436                 } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
437                         // Invalid number
438                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
439                 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
440                         // Throw NPE again
441                         throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
442                 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
443                         // Throw it again ...
444                         throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
445                 } else if (this.beanHelper.getContact() == null) {
446                         // ... and throw again
447                         throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
448                 } else if (this.beanHelper.getContact().getContactId() == null) {
449                         // ... and again ...
450                         throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
451                 } else if (this.beanHelper.getContact().getContactId() < 1) {
452                         // Invalid id number
453                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
454                 }
455
456                 // Init contact instance
457                 Contact updatedContact;
458
459                 try {
460                         // Unlink it and return contact without fax instance
461                         updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
462                 } catch (final PhoneNumberNotLinkedException ex) {
463                         // Did not work
464                         this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
465                         return ""; //NOI18N
466                 }
467
468                 // Fire event
469                 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber()));
470
471                 // All fine here
472                 return "admin_show_contact"; //NOI18N
473         }
474
475         @Override
476         public String unlinkLandLineContactData () {
477                 // Is all data set
478                 if (this.beanHelper.getLandLineNumber() == null) {
479                         // Not set, throw NPE
480                         throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
481                 } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
482                         // Throw NPE again
483                         throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
484                 } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
485                         // Invalid number
486                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
487                 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
488                         // Throw NPE again
489                         throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
490                 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
491                         // Throw it again ...
492                         throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
493                 } else if (this.beanHelper.getContact() == null) {
494                         // ... and throw again
495                         throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
496                 } else if (this.beanHelper.getContact().getContactId() == null) {
497                         // ... and again ...
498                         throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
499                 } else if (this.beanHelper.getContact().getContactId() < 1) {
500                         // Invalid id number
501                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
502                 }
503
504                 // Init contact instance
505                 Contact updatedContact;
506
507                 try {
508                         // Unlink it and return contact without landLine instance
509                         updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
510                 } catch (final PhoneNumberNotLinkedException ex) {
511                         // Did not work
512                         this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
513                         return ""; //NOI18N
514                 }
515
516                 // Fire event
517                 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber()));
518
519                 // All fine here
520                 return "admin_show_contact"; //NOI18N
521         }
522
523         @Override
524         public String unlinkMobileContactData () {
525                 // Is all data set
526                 if (this.beanHelper.getMobileNumber() == null) {
527                         // Not set, throw NPE
528                         throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N
529                 } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) {
530                         // Throw NPE again
531                         throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N
532                 } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) {
533                         // Invalid number
534                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N
535                 } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) {
536                         // Throw NPE
537                         throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N
538                 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) {
539                         // ... throw again
540                         throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N
541                 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) {
542                         // Id not valid
543                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
544                 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) {
545                         // Throw NPE again
546                         throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N
547                 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) {
548                         // Throw it again ...
549                         throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N
550                 } else if (this.beanHelper.getContact() == null) {
551                         // ... and throw again
552                         throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
553                 } else if (this.beanHelper.getContact().getContactId() == null) {
554                         // ... and again ...
555                         throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
556                 } else if (this.beanHelper.getContact().getContactId() < 1) {
557                         // Invalid id number
558                         throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
559                 }
560
561                 // Init contact instance
562                 Contact updatedContact;
563
564                 try {
565                         // Unlink it and return contact without mobile instance
566                         updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber());
567                 } catch (final PhoneNumberNotLinkedException ex) {
568                         // Did not work
569                         this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
570                         return ""; //NOI18N
571                 }
572
573                 // Fire event
574                 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber()));
575
576                 // All fine here
577                 return "admin_show_contact"; //NOI18N
578         }
579
580         /**
581          * Clears this bean
582          */
583         private void clear () {
584                 // Clear all data
585         }
586
587 }