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