2 * Copyright (C) 2016, 2017 Roland Häder
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.
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.
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/>.
17 package org.mxchange.jjobs.beans.contact.phone;
19 import java.text.MessageFormat;
20 import java.util.Locale;
21 import java.util.MissingResourceException;
22 import java.util.ResourceBundle;
23 import javax.annotation.PostConstruct;
24 import javax.enterprise.context.RequestScoped;
25 import javax.enterprise.event.Event;
26 import javax.enterprise.event.Observes;
27 import javax.enterprise.inject.Any;
28 import javax.faces.application.FacesMessage;
29 import javax.faces.context.FacesContext;
30 import javax.faces.view.facelets.FaceletException;
31 import javax.inject.Inject;
32 import javax.inject.Named;
33 import javax.naming.Context;
34 import javax.naming.InitialContext;
35 import javax.naming.NamingException;
36 import org.mxchange.jcontacts.contact.Contact;
37 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
38 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
39 import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
40 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
41 import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
42 import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
43 import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
44 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
45 import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
46 import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
47 import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
48 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
49 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
50 import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
51 import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
52 import org.mxchange.jcountry.data.Country;
53 import org.mxchange.jjobs.beans.BaseJobsController;
54 import org.mxchange.jjobs.beans.helper.JobsWebRequestHelperController;
55 import org.mxchange.jjobs.beans.phone.JobsAdminPhoneWebRequestController;
56 import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
57 import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
58 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
59 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
60 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
61 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
62 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
63 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
64 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
65 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
68 * An administrative contact phone controller (bean)
70 * @author Roland Häder<roland@mxchange.org>
72 @Named ("adminContactPhoneController")
74 public abstract class JobsAdminContactPhoneWebRequestBean extends BaseJobsController implements JobsAdminContactPhoneWebRequestController {
77 * Call-stack instance (5 may show BeanELResolver.getValue as caller)
79 private static final short THREAD_STACK = 5;
84 private static final long serialVersionUID = 542_145_347_916L;
87 * Event being fired when a fax number has been linked
91 private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
94 * Event being fired when a land-line number has been linked
98 private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
101 * Event being fired when a mobile number has been linked
105 private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
108 * Administrative EJB for phone number
110 private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
113 * Administrative phone controller
116 private JobsAdminPhoneWebRequestController adminPhoneController;
122 private JobsWebRequestHelperController beanHelper;
125 * Event being fired when a fax number has been unlinked
129 private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
132 * Event being fired when a land-line number has been unlinked
136 private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
139 * Event being fired when admin unlinks mobile from contact
143 private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
146 * Default constructor
148 public JobsAdminContactPhoneWebRequestBean () {
149 // Call super constructor
152 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
153 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
157 * Observes events being fired when an administrator has added a new
160 * @param event Event being fired
162 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
163 // The event must be valid
166 throw new NullPointerException("event is null"); //NOI18N
167 } else if (event.getAddedContact() == null) {
169 throw new NullPointerException("event.addedContact is null"); //NOI18N
170 } else if (event.getAddedContact().getContactId() == null) {
172 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
173 } else if (event.getAddedContact().getContactId() < 1) {
175 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
183 * Event observer for newly added users by administrator
185 * @param event Event being fired
187 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
188 // event should not be null
191 throw new NullPointerException("event is null"); //NOI18N
192 } else if (event.getAddedUser() == null) {
194 throw new NullPointerException("event.addedUser is null"); //NOI18N
195 } else if (event.getAddedUser().getUserId() == null) {
197 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
198 } else if (event.getAddedUser().getUserId() < 1) {
200 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
208 * Event observer for updated contact data by administrators
210 * @param event Updated contact data event
212 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
213 // event should not be null
216 throw new NullPointerException("event is null"); //NOI18N
217 } else if (event.getUpdatedContact() == null) {
219 throw new NullPointerException("event.updatedContact is null"); //NOI18N
220 } else if (event.getUpdatedContact().getContactId() == null) {
222 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
223 } else if (event.getUpdatedContact().getContactId() < 1) {
225 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
233 public String doLinkAddFaxNumber (final Contact contact) {
234 // Is all data properly set?
235 if (null == contact) {
237 throw new NullPointerException("contact is null"); //NOI18N
238 } else if (contact.getContactId() == null) {
240 throw new NullPointerException("contact.contactId is null"); //NOI18N
241 } else if (contact.getContactId() < 1) {
243 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
244 } 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))) {
245 // All fields are empty
246 throw new NullPointerException("faxNumber, mobileProvider and phoneNumer are null"); //NOI18N
247 } else if ((this.adminPhoneController.getFaxNumber() instanceof DialableFaxNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
248 // All fields are set
249 throw new IllegalStateException("faxNumber, mobileProvider and phoneNumer are all set"); //NOI18N
250 } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
251 // No country selected
252 this.showFacesMessage("form_add_contact_fax:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
254 } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
255 // No area code entered
256 this.showFacesMessage("form_add_contact_fax:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
258 } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
259 // No phone number entered
260 this.showFacesMessage("form_add_contact_fax:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
265 Contact updatedContact;
266 DialableFaxNumber faxNumber = this.adminPhoneController.getFaxNumber();
270 // All fine so far, then which was choosen?
271 if (faxNumber instanceof DialableFaxNumber) {
272 // User has choosen number
273 updatedContact = this.adminPhoneBean.linkExistingFaxNumberWithContact(contact, faxNumber);
275 // Create new instance
276 faxNumber = new FaxNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
279 updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, faxNumber);
281 } catch (final PhoneNumberAlreadyLinkedException ex) {
282 // Throw again as cause
283 this.showFacesMessage("form_add_contact_fax:phoneNumber", ex); //NOI18N
288 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, faxNumber));
290 // Return to contact profile
291 return "admin_show_contact"; //NOI18N
295 public String doLinkAddLandLineNumber (final Contact contact) {
296 // Is all data properly set?
297 if (null == contact) {
299 throw new NullPointerException("contact is null"); //NOI18N
300 } else if (contact.getContactId() == null) {
302 throw new NullPointerException("contact.contactId is null"); //NOI18N
303 } else if (contact.getContactId() < 1) {
305 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
306 } 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))) {
307 // All fields are empty
308 throw new NullPointerException("landLineNumber, mobileProvider and phoneNumer are null"); //NOI18N
309 } else if ((this.adminPhoneController.getLandLineNumber() instanceof DialableLandLineNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
310 // All fields are set
311 throw new IllegalStateException("landLineNumber, mobileProvider and phoneNumer are all set"); //NOI18N
312 } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
313 // No country selected
314 this.showFacesMessage("form_add_contact_landLine:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
316 } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
317 // No area code entered
318 this.showFacesMessage("form_add_contact_landLine:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
320 } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
321 // No phone number entered
322 this.showFacesMessage("form_add_contact_landLine:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
327 Contact updatedContact;
328 DialableLandLineNumber landLineNumber = this.adminPhoneController.getLandLineNumber();
332 // All fine so far, then which was choosen?
333 if (landLineNumber instanceof DialableLandLineNumber) {
334 // User has choosen number
335 updatedContact = this.adminPhoneBean.linkExistingLandLineNumberWithContact(contact, landLineNumber);
337 // Create new instance
338 landLineNumber = new LandLineNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
341 updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, landLineNumber);
343 } catch (final PhoneNumberAlreadyLinkedException ex) {
344 // Throw again as cause
345 this.showFacesMessage("form_add_contact_landLine:phoneNumber", ex); //NOI18N
350 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, landLineNumber));
352 // Return to contact profile
353 return "admin_show_contact"; //NOI18N
357 public String doLinkAddMobileNumber (final Contact contact) {
358 // Is all data properly set?
359 if (null == contact) {
361 throw new NullPointerException("contact is null"); //NOI18N
362 } else if (contact.getContactId() == null) {
364 throw new NullPointerException("contact.contactId is null"); //NOI18N
365 } else if (contact.getContactId() < 1) {
367 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
368 } else if ((this.adminPhoneController.getMobileNumber() == null) && (this.adminPhoneController.getMobileProvider() == null) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
369 // All fields are empty
370 throw new NullPointerException("mobileNumber, mobileProvider and phoneNumer are null"); //NOI18N
371 } else if ((this.adminPhoneController.getMobileNumber() instanceof DialableMobileNumber) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
372 // All fields are set
373 throw new IllegalStateException("mobileNumber, mobileProvider and phoneNumer are all set"); //NOI18N
374 } else if ((this.adminPhoneController.getMobileProvider() == null) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
375 // No mobile provider selected
376 this.showFacesMessage("form_add_contact_mobile:phoneCountry", "ERROR_ADMIN_NO_PHONE_MOBILE_PROVIDER_SELECTED"); //NOI18N
378 } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider)) {
379 // No phone number entered
380 this.showFacesMessage("form_add_contact_mobile:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
385 Contact updatedContact;
386 DialableMobileNumber mobileNumber = this.adminPhoneController.getMobileNumber();
390 // All fine so far, then which was choosen?
391 if (mobileNumber instanceof DialableMobileNumber) {
392 // User has choosen number
393 updatedContact = this.adminPhoneBean.linkExistingMobileNumberWithContact(contact, mobileNumber);
395 // Create new instance
396 mobileNumber = new MobileNumber(this.adminPhoneController.getMobileProvider(), this.adminPhoneController.getPhoneNumber());
399 updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, mobileNumber);
401 } catch (final PhoneNumberAlreadyLinkedException ex) {
402 // Throw again as cause
403 this.showFacesMessage("form_add_contact_mobile:phoneNumber", ex); //NOI18N
408 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, mobileNumber));
410 // Return to contact profile
411 return "admin_show_contact"; //NOI18N
415 * Post-construction method
418 public void init () {
421 // Get initial context
422 Context context = new InitialContext();
424 // Try to lookup the beans
425 this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
426 } catch (final NamingException e) {
428 throw new FaceletException(e);
433 public String unlinkFaxContactData () {
435 if (this.beanHelper.getFaxNumber() == null) {
436 // Not set, throw NPE
437 throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
438 } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
440 throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
441 } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
443 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
444 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
446 throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
447 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
448 // Throw it again ...
449 throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
450 } else if (this.beanHelper.getContact() == null) {
451 // ... and throw again
452 throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
453 } else if (this.beanHelper.getContact().getContactId() == null) {
455 throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
456 } else if (this.beanHelper.getContact().getContactId() < 1) {
458 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
461 // Init contact instance
462 Contact updatedContact;
465 // Unlink it and return contact without fax instance
466 updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
467 } catch (final PhoneNumberNotLinkedException ex) {
469 this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
474 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber()));
477 return "admin_show_contact"; //NOI18N
481 public String unlinkLandLineContactData () {
483 if (this.beanHelper.getLandLineNumber() == null) {
484 // Not set, throw NPE
485 throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
486 } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
488 throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
489 } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
491 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
492 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
494 throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
495 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
496 // Throw it again ...
497 throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
498 } else if (this.beanHelper.getContact() == null) {
499 // ... and throw again
500 throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
501 } else if (this.beanHelper.getContact().getContactId() == null) {
503 throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
504 } else if (this.beanHelper.getContact().getContactId() < 1) {
506 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
509 // Init contact instance
510 Contact updatedContact;
513 // Unlink it and return contact without landLine instance
514 updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
515 } catch (final PhoneNumberNotLinkedException ex) {
517 this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
522 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber()));
525 return "admin_show_contact"; //NOI18N
529 public String unlinkMobileContactData () {
531 if (this.beanHelper.getMobileNumber() == null) {
532 // Not set, throw NPE
533 throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N
534 } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) {
536 throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N
537 } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) {
539 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N
540 } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) {
542 throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N
543 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) {
545 throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N
546 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) {
548 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
549 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) {
551 throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N
552 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) {
553 // Throw it again ...
554 throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N
555 } else if (this.beanHelper.getContact() == null) {
556 // ... and throw again
557 throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
558 } else if (this.beanHelper.getContact().getContactId() == null) {
560 throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
561 } else if (this.beanHelper.getContact().getContactId() < 1) {
563 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
566 // Init contact instance
567 Contact updatedContact;
570 // Unlink it and return contact without mobile instance
571 updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber());
572 } catch (final PhoneNumberNotLinkedException ex) {
574 this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
579 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber()));
582 return "admin_show_contact"; //NOI18N
588 private void clear () {
593 * Returns given property key or throws an exception if not found.
595 * @param parameterKey Property key
597 * @return Property value
599 * @throws NullPointerException If given key is not found
600 * @throws NumberFormatException If no number is given in context parameter
602 protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException {
603 // Get context parameter
604 Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey));
610 * Returns given property key or throws an exception if not found.
612 * @param parameterKey Property key
614 * @return Property value
616 * @throws NullPointerException If given key is not found
618 protected String getStringContextParameter (final String parameterKey) throws NullPointerException {
619 // Get context parameter
620 String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey);
622 if (null == contextValue) {
624 throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N
631 * Checks whether debug mode is enabled for given controller
633 * @param controllerName Name of controller
635 * @return Whether debug mode is enabled
637 protected boolean isDebugModeEnabled (final String controllerName) {
638 // Parameters should be valid
639 if (null == controllerName) {
641 throw new NullPointerException("controllerName is null"); //NOI18N
642 } else if (controllerName.isEmpty()) {
644 throw new IllegalArgumentException("controllerName is empty"); //NOI18N
646 // Try to get context parameter
647 String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N
648 // Is it set and true?
649 boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE;
655 * Loads resource bundle for given locale. This must be implemented per
656 * project so all projects can still customize their methods. Calling
657 * ResourceBundleloadBundle() in this class means that also the bundle files
658 * must be present here.
660 * @param locale Locale from e.g. FacesContext
662 * @return Initialized and loaded resource bundle
664 protected abstract ResourceBundle loadResourceBundle (final Locale locale);
667 * Shows a faces message for given causing exception. The message from the
668 * exception is being inserted into the message.
670 * @param clientId Client id to send message to
671 * @param cause Causing exception
673 protected void showFacesMessage (final String clientId, final Throwable cause) {
674 // Get context and add message
675 this.showFacesMessage(clientId, cause.getMessage());
679 * Shows a faces message with given message (i18n) key.
681 * @param clientId Client id to send message to
682 * @param i18nKey Message key
684 * @throws NullPointerException If clientId or i18nKey is null
685 * @throws IllegalArgumentException If clientId or i18nKey is empty
687 protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException {
688 // Both parameter must be valid
689 if (null == clientId) {
691 throw new NullPointerException("clientId is null"); //NOI18N
692 } else if (clientId.isEmpty()) {
694 throw new IllegalArgumentException("clientId is null"); //NOI18N
695 } else if (null == i18nKey) {
697 throw new NullPointerException("i18nKey is null"); //NOI18N
698 } else if (i18nKey.isEmpty()) {
700 throw new IllegalArgumentException("i18nKey is null"); //NOI18N
702 // Get current locale
703 Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
705 ResourceBundle bundle = this.loadResourceBundle(locale);
706 // Default is i18nKey
707 String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N
711 message = bundle.getString(i18nKey);
712 } catch (final MissingResourceException ex) {
713 // Did not find it, ignored
715 // Get context and add message
716 FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message));