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