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