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.pizzaapplication.beans.contact.phone;
19 import java.text.MessageFormat;
20 import javax.annotation.PostConstruct;
21 import javax.enterprise.context.RequestScoped;
22 import javax.enterprise.event.Event;
23 import javax.enterprise.event.Observes;
24 import javax.enterprise.inject.Any;
25 import javax.faces.view.facelets.FaceletException;
26 import javax.inject.Inject;
27 import javax.inject.Named;
28 import javax.naming.Context;
29 import javax.naming.InitialContext;
30 import javax.naming.NamingException;
31 import org.mxchange.jcontacts.contact.Contact;
32 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
33 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
34 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
35 import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
36 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
37 import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
38 import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
39 import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
40 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
41 import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
42 import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
43 import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
44 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
45 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
46 import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
47 import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
48 import org.mxchange.jcountry.data.Country;
49 import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
50 import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
51 import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
52 import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
53 import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
54 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
55 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
56 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
57 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
58 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
59 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
60 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
61 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
62 import org.mxchange.pizzaapplication.beans.BasePizzaController;
63 import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
64 import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
67 * An administrative contact phone controller (bean)
69 * @author Roland Häder<roland@mxchange.org>
71 @Named ("adminContactPhoneController")
73 public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController implements PizzaAdminContactPhoneWebRequestController {
76 * Call-stack instance (5 may show BeanELResolver.getValue as caller)
78 private static final short THREAD_STACK = 5;
83 private static final long serialVersionUID = 542_145_347_916L;
86 * Event being fired when a fax number has been linked
90 private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
93 * Event being fired when a land-line number has been linked
97 private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
100 * Event being fired when a mobile number has been linked
104 private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
107 * Administrative EJB for phone number
109 private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
112 * Administrative phone controller
115 private PizzaAdminPhoneWebRequestController adminPhoneController;
121 private PizzaWebRequestHelperController beanHelper;
124 * Event being fired when a fax number has been unlinked
128 private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
131 * Event being fired when a land-line number has been unlinked
135 private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
138 * Event being fired when admin unlinks mobile from contact
142 private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
145 * Area code (city dial prefix) for fax number
147 private Integer faxAreaCode;
150 * Country (for dial prefix) for fax number
152 private Country faxCountry;
157 private Long faxNumber;
160 * Area code (city dial prefix) for land-line number
162 private Integer landLineAreaCode;
165 * Country (for dial prefix) for land-line number
167 private Country landLineCountry;
172 private Long landLineNumber;
177 private MobileProvider mobileProvider;
182 private Long mobileNumber;
185 * Default constructor
187 public PizzaAdminContactPhoneWebRequestBean () {
188 // Call super constructor
191 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
192 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
196 * Observes events being fired when an administrator has added a new
199 * @param event Event being fired
201 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
202 // The event must be valid
205 throw new NullPointerException("event is null"); //NOI18N
206 } else if (event.getAddedContact() == null) {
208 throw new NullPointerException("event.addedContact is null"); //NOI18N
209 } else if (event.getAddedContact().getContactId() == null) {
211 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
212 } else if (event.getAddedContact().getContactId() < 1) {
214 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
222 * Event observer for newly added users by administrator
224 * @param event Event being fired
226 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
227 // event should not be null
230 throw new NullPointerException("event is null"); //NOI18N
231 } else if (event.getAddedUser() == null) {
233 throw new NullPointerException("event.addedUser is null"); //NOI18N
234 } else if (event.getAddedUser().getUserId() == null) {
236 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
237 } else if (event.getAddedUser().getUserId() < 1) {
239 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
247 * Event observer for updated contact data by administrators
249 * @param event Updated contact data event
251 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
252 // event should not be null
255 throw new NullPointerException("event is null"); //NOI18N
256 } else if (event.getUpdatedContact() == null) {
258 throw new NullPointerException("event.updatedContact is null"); //NOI18N
259 } else if (event.getUpdatedContact().getContactId() == null) {
261 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
262 } else if (event.getUpdatedContact().getContactId() < 1) {
264 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
272 * Observer for events being fired when a bean helper has successfully
273 * created a contact instance.
275 * @param event Event being fired
277 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
279 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
281 // The event instance must be valid
284 throw new NullPointerException("event is null"); //NOI18N
285 } else if (event.getCreatedContact() == null) {
287 throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
288 } else if (event.getCreatedContact().getContactId() == null) {
290 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
291 } else if (event.getCreatedContact().getContactId() < 1) {
293 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
297 this.setContact(event.getCreatedContact());
301 * Observes events being fired when a bean helper has successfully created a
302 * fax number instance.
304 * @param event Event being fired
306 public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
307 // The event instance must be valid
310 throw new NullPointerException("event is null"); //NOI18N
311 } else if (event.getFaxNumber() == null) {
313 throw new NullPointerException("event.faxNumber is null"); //NOI18N
314 } else if (event.getFaxNumber().getPhoneId() == null) {
315 // Throw NPE yet again
316 throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
317 } else if (event.getFaxNumber().getPhoneId() < 1) {
318 // Throw NPE yet again
319 throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
322 // Get fax number from event
323 DialableFaxNumber number = event.getFaxNumber();
325 // Copy all data to this bean
326 this.setPhoneId(number.getPhoneId());
327 this.setFaxCountry(number.getPhoneCountry());
328 this.setFaxAreaCode(number.getPhoneAreaCode());
329 this.setFaxNumber(number.getPhoneNumber());
330 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
331 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
335 * Observes events being fired when a bean helper has successfully created a
336 * land-line number instance.
338 * @param event Event being fired
340 public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
341 // The event instance must be valid
344 throw new NullPointerException("event is null"); //NOI18N
345 } else if (event.getLandLineNumber() == null) {
347 throw new NullPointerException("event.landLineNumber is null"); //NOI18N
348 } else if (event.getLandLineNumber().getPhoneId() == null) {
349 // Throw NPE yet again
350 throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
351 } else if (event.getLandLineNumber().getPhoneId() < 1) {
352 // Throw NPE yet again
353 throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
356 // Get fax number from event
357 DialableLandLineNumber number = event.getLandLineNumber();
359 // Copy all data to this bean
360 this.setPhoneId(number.getPhoneId());
361 this.setLandLineCountry(number.getPhoneCountry());
362 this.setLandLineAreaCode(number.getPhoneAreaCode());
363 this.setLandLineNumber(number.getPhoneNumber());
364 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
365 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
369 * Observes events being fired when a bean helper has successfully created a
370 * mobile number instance.
372 * @param event Event being fired
374 public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
375 // The event instance must be valid
378 throw new NullPointerException("event is null"); //NOI18N
379 } else if (event.getMobileNumber() == null) {
381 throw new NullPointerException("event.mobileNumber is null"); //NOI18N
382 } else if (event.getMobileNumber().getPhoneId() == null) {
383 // Throw NPE yet again
384 throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
385 } else if (event.getMobileNumber().getPhoneId() < 1) {
386 // Throw NPE yet again
387 throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
390 // Get fax number from event
391 DialableMobileNumber number = event.getMobileNumber();
393 // Copy all data to this bean
394 this.setPhoneId(number.getPhoneId());
395 this.setMobileProvider(number.getMobileProvider());
396 this.setMobileNumber(number.getPhoneNumber());
397 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
398 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
402 * Links fax number to contact from bean helper as "main fax number".
404 * @return Redirect outcome
406 public String doLinkMainFaxNumber () {
407 // Get contact from helper
408 Contact contact = this.beanHelper.getContact();
410 // Is all data properly set?
411 if (null == contact) {
413 throw new NullPointerException("contact is null"); //NOI18N
414 } else if (contact.getContactId() == null) {
416 throw new NullPointerException("contact.contactId is null"); //NOI18N
417 } else if (contact.getContactId() < 1) {
419 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
420 } else if (this.getFaxCountry() == null) {
422 throw new NullPointerException("this.faxCountry is null"); //NOI18N
423 } else if (this.getFaxCountry().getCountryId() == null) {
425 throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
426 } else if (this.getFaxCountry().getCountryId() < 1) {
428 throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
429 } else if (this.getFaxAreaCode() == null) {
431 throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
432 } else if (this.getFaxAreaCode() < 1) {
434 throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
435 } else if (this.getFaxNumber() == null) {
437 throw new NullPointerException("this.faxNumber is null"); //NOI18N
438 } else if (this.getFaxNumber() < 1) {
440 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
444 Contact updatedContact;
445 DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
450 updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, number);
451 } catch (final PhoneNumberAlreadyLinkedException ex) {
452 // Throw again as cause
453 this.showFacesMessage("form_add_contact_fax:faxNumber", ex); //NOI18N
458 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
460 // Return to contact profile
461 return "admin_show_contact"; //NOI18N
465 * Links land-line number to contact from bean helper as "main land-line
468 * @return Redirect outcome
470 public String doLinkMainLandLineNumber () {
471 // Get contact from helper
472 Contact contact = this.beanHelper.getContact();
474 // Is all data properly set?
475 if (null == contact) {
477 throw new NullPointerException("contact is null"); //NOI18N
478 } else if (contact.getContactId() == null) {
480 throw new NullPointerException("contact.contactId is null"); //NOI18N
481 } else if (contact.getContactId() < 1) {
483 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
484 } else if (this.getLandLineCountry() == null) {
486 throw new NullPointerException("this.landLineCountry is null"); //NOI18N
487 } else if (this.getLandLineCountry().getCountryId() == null) {
489 throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
490 } else if (this.getLandLineCountry().getCountryId() < 1) {
492 throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
493 } else if (this.getLandLineAreaCode() == null) {
495 throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
496 } else if (this.getLandLineAreaCode() < 1) {
498 throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
499 } else if (this.getLandLineNumber() == null) {
501 throw new NullPointerException("this.landLineNumber is null"); //NOI18N
502 } else if (this.getLandLineNumber() < 1) {
504 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
508 Contact updatedContact;
509 DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
514 updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, number);
515 } catch (final PhoneNumberAlreadyLinkedException ex) {
516 // Throw again as cause
517 this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex); //NOI18N
522 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
524 // Return to contact profile
525 return "admin_show_contact"; //NOI18N
529 * Links mobile number to contact from bean helper as "main mobile number".
531 * @return Redirect outcome
533 public String doLinkMainMobileNumber () {
534 // Get contact from helper
535 Contact contact = this.beanHelper.getContact();
537 // Is all data properly set?
538 if (null == contact) {
540 throw new NullPointerException("contact is null"); //NOI18N
541 } else if (contact.getContactId() == null) {
543 throw new NullPointerException("contact.contactId is null"); //NOI18N
544 } else if (contact.getContactId() < 1) {
546 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
547 } else if (this.getMobileProvider() == null) {
549 throw new NullPointerException("this.mobileProvider is null"); //NOI18N
550 } else if (this.getMobileProvider().getProviderId() == null) {
552 throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
553 } else if (this.getMobileProvider().getProviderId() < 1) {
555 throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N
556 } else if (this.getMobileNumber() == null) {
558 throw new NullPointerException("this.mobileNumber is null"); //NOI18N
559 } else if (this.getMobileNumber() < 1) {
561 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N
565 Contact updatedContact;
566 DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
571 updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, number);
572 } catch (final PhoneNumberAlreadyLinkedException ex) {
573 // Throw again as cause
574 this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex); //NOI18N
579 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number));
581 // Return to contact profile
582 return "admin_show_contact"; //NOI18N
586 * Getter for fax area code
588 * @return Fax area code
590 public Integer getFaxAreaCode () {
591 return this.faxAreaCode;
595 * Setter for fax area code
597 * @param faxAreaCode Fax area code
599 public void setFaxAreaCode (final Integer faxAreaCode) {
600 this.faxAreaCode = faxAreaCode;
604 * Getter for fax numbers country
606 * @return Fax numbers country
608 public Country getFaxCountry () {
609 return this.faxCountry;
613 * Setter for fax numbers country
615 * @param faxCountry Fax numbers country
617 public void setFaxCountry (final Country faxCountry) {
618 this.faxCountry = faxCountry;
622 * Getter for fax number
626 public Long getFaxNumber () {
627 return this.faxNumber;
631 * Setter for fax number
633 * @param faxNumber Fax number
635 public void setFaxNumber (final Long faxNumber) {
636 this.faxNumber = faxNumber;
640 * Getter for land-line area code
642 * @return Land-line area code
644 public Integer getLandLineAreaCode () {
645 return this.landLineAreaCode;
649 * Setter for land-line area code
651 * @param landLineAreaCode Land-line area code
653 public void setLandLineAreaCode (final Integer landLineAreaCode) {
654 this.landLineAreaCode = landLineAreaCode;
658 * Getter for land-line country
660 * @return Land-line country
662 public Country getLandLineCountry () {
663 return this.landLineCountry;
667 * Setter for land-line country
669 * @param landLineCountry Land-line country
671 public void setLandLineCountry (final Country landLineCountry) {
672 this.landLineCountry = landLineCountry;
676 * Getter for land-line number
678 * @return Land-line number
680 public Long getLandLineNumber () {
681 return this.landLineNumber;
685 * Setter for land-line number
687 * @param landLineNumber Land-line number
689 public void setLandLineNumber (final Long landLineNumber) {
690 this.landLineNumber = landLineNumber;
694 * Getter for mobile provider
696 * @return Mobile provider
698 public MobileProvider getMobileProvider () {
699 return this.mobileProvider;
703 * Setter for mobile provider
705 * @param mobileProvider Mobile provider
707 public void setMobileProvider (final MobileProvider mobileProvider) {
708 this.mobileProvider = mobileProvider;
712 * Getter for mobile number
714 * @return Mobile number
716 public Long getMobileNumber () {
717 return this.mobileNumber;
721 * Setter for mobile number
723 * @param mobileNumber Mobile number
725 public void setMobileNumber (final Long mobileNumber) {
726 this.mobileNumber = mobileNumber;
730 * Post-construction method
733 public void init () {
736 // Get initial context
737 Context context = new InitialContext();
739 // Try to lookup the beans
740 this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
741 } catch (final NamingException e) {
743 throw new FaceletException(e);
748 * Unlinks fax data with current contact
750 * @return Redirect outcome
752 public String unlinkFaxContactData () {
754 if (this.beanHelper.getFaxNumber() == null) {
755 // Not set, throw NPE
756 throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
757 } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
759 throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
760 } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
762 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
763 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
765 throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
766 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
767 // Throw it again ...
768 throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
769 } else if (this.beanHelper.getContact() == null) {
770 // ... and throw again
771 throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
772 } else if (this.beanHelper.getContact().getContactId() == null) {
774 throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
775 } else if (this.beanHelper.getContact().getContactId() < 1) {
777 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
780 // Init contact instance
781 Contact updatedContact;
784 // Unlink it and return contact without fax instance
785 updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
786 } catch (final PhoneNumberNotLinkedException ex) {
788 this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
793 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber()));
796 return "admin_show_contact"; //NOI18N
800 * Unlinks land-line data with current contact
802 * @return Redirect outcome
804 public String unlinkLandLineContactData () {
806 if (this.beanHelper.getLandLineNumber() == null) {
807 // Not set, throw NPE
808 throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
809 } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
811 throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
812 } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
814 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
815 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
817 throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
818 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
819 // Throw it again ...
820 throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
821 } else if (this.beanHelper.getContact() == null) {
822 // ... and throw again
823 throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
824 } else if (this.beanHelper.getContact().getContactId() == null) {
826 throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
827 } else if (this.beanHelper.getContact().getContactId() < 1) {
829 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
832 // Init contact instance
833 Contact updatedContact;
836 // Unlink it and return contact without landLine instance
837 updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
838 } catch (final PhoneNumberNotLinkedException ex) {
840 this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
845 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber()));
848 return "admin_show_contact"; //NOI18N
852 * Unlinks mobile data with current contact
854 * @return Redirect outcome
856 public String unlinkMobileContactData () {
858 if (this.beanHelper.getMobileNumber() == null) {
859 // Not set, throw NPE
860 throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N
861 } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) {
863 throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N
864 } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) {
866 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N
867 } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) {
869 throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N
870 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) {
872 throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N
873 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) {
875 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
876 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) {
878 throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N
879 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) {
880 // Throw it again ...
881 throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N
882 } else if (this.beanHelper.getContact() == null) {
883 // ... and throw again
884 throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
885 } else if (this.beanHelper.getContact().getContactId() == null) {
887 throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
888 } else if (this.beanHelper.getContact().getContactId() < 1) {
890 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
893 // Init contact instance
894 Contact updatedContact;
897 // Unlink it and return contact without mobile instance
898 updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber());
899 } catch (final PhoneNumberNotLinkedException ex) {
901 this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
906 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber()));
909 return "admin_show_contact"; //NOI18N
915 private void clear () {