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.addressbook.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.addressbook.beans.BaseAddressbookController;
32 import org.mxchange.addressbook.beans.helper.AddressbookWebRequestHelperController;
33 import org.mxchange.addressbook.beans.phone.AddressbookAdminPhoneWebRequestController;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
36 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
37 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
38 import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
39 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
40 import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
41 import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
42 import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
43 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
44 import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
45 import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
46 import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
47 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
48 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
49 import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
50 import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
51 import org.mxchange.jcountry.data.Country;
52 import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
53 import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
54 import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
55 import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
56 import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
57 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
58 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
59 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
60 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
61 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
62 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
63 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
64 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
67 * An administrative contact phone controller (bean)
69 * @author Roland Häder<roland@mxchange.org>
71 @Named ("adminContactPhoneController")
73 public class AddressbookAdminContactPhoneWebRequestBean extends BaseAddressbookController implements AddressbookAdminContactPhoneWebRequestController {
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 AddressbookAdminPhoneWebRequestController adminPhoneController;
121 private AddressbookWebRequestHelperController beanHelper;
125 * Area code (city dial prefix) for fax number
127 private Integer faxAreaCode;
130 * Country (for dial prefix) for fax number
132 private Country faxCountry;
137 private Long faxNumber;
139 * Event being fired when a fax number has been unlinked
143 private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
146 * Area code (city dial prefix) for land-line number
148 private Integer landLineAreaCode;
151 * Country (for dial prefix) for land-line number
153 private Country landLineCountry;
158 private Long landLineNumber;
160 * Event being fired when a land-line number has been unlinked
164 private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
169 private Long mobileNumber;
171 * Event being fired when admin unlinks mobile from contact
175 private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
179 private MobileProvider mobileProvider;
182 * Default constructor
184 public AddressbookAdminContactPhoneWebRequestBean () {
185 // Call super constructor
188 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
189 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
193 * Observes events being fired when an administrator has added a new
196 * @param event Event being fired
198 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
199 // The event must be valid
202 throw new NullPointerException("event is null"); //NOI18N
203 } else if (event.getAddedContact() == null) {
205 throw new NullPointerException("event.addedContact is null"); //NOI18N
206 } else if (event.getAddedContact().getContactId() == null) {
208 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
209 } else if (event.getAddedContact().getContactId() < 1) {
211 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
219 * Event observer for newly added users by administrator
221 * @param event Event being fired
223 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
224 // event should not be null
227 throw new NullPointerException("event is null"); //NOI18N
228 } else if (event.getAddedUser() == null) {
230 throw new NullPointerException("event.addedUser is null"); //NOI18N
231 } else if (event.getAddedUser().getUserId() == null) {
233 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
234 } else if (event.getAddedUser().getUserId() < 1) {
236 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
244 * Event observer for updated contact data by administrators
246 * @param event Updated contact data event
248 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
249 // event should not be null
252 throw new NullPointerException("event is null"); //NOI18N
253 } else if (event.getUpdatedContact() == null) {
255 throw new NullPointerException("event.updatedContact is null"); //NOI18N
256 } else if (event.getUpdatedContact().getContactId() == null) {
258 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
259 } else if (event.getUpdatedContact().getContactId() < 1) {
261 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
269 * Observer for events being fired when a bean helper has successfully
270 * created a contact instance.
272 * @param event Event being fired
274 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
276 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
278 // The event instance must be valid
281 throw new NullPointerException("event is null"); //NOI18N
282 } else if (event.getCreatedContact() == null) {
284 throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
285 } else if (event.getCreatedContact().getContactId() == null) {
287 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
288 } else if (event.getCreatedContact().getContactId() < 1) {
290 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
294 this.setContact(event.getCreatedContact());
298 * Observes events being fired when a bean helper has successfully created a
299 * fax number instance.
301 * @param event Event being fired
303 public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
304 // The event instance must be valid
307 throw new NullPointerException("event is null"); //NOI18N
308 } else if (event.getFaxNumber() == null) {
310 throw new NullPointerException("event.faxNumber is null"); //NOI18N
311 } else if (event.getFaxNumber().getPhoneId() == null) {
312 // Throw NPE yet again
313 throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
314 } else if (event.getFaxNumber().getPhoneId() < 1) {
315 // Throw NPE yet again
316 throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
319 // Get fax number from event
320 DialableFaxNumber number = event.getFaxNumber();
322 // Copy all data to this bean
323 this.setPhoneId(number.getPhoneId());
324 this.setFaxCountry(number.getPhoneCountry());
325 this.setFaxAreaCode(number.getPhoneAreaCode());
326 this.setFaxNumber(number.getPhoneNumber());
327 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
328 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
332 * Observes events being fired when a bean helper has successfully created a
333 * land-line number instance.
335 * @param event Event being fired
337 public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
338 // The event instance must be valid
341 throw new NullPointerException("event is null"); //NOI18N
342 } else if (event.getLandLineNumber() == null) {
344 throw new NullPointerException("event.landLineNumber is null"); //NOI18N
345 } else if (event.getLandLineNumber().getPhoneId() == null) {
346 // Throw NPE yet again
347 throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
348 } else if (event.getLandLineNumber().getPhoneId() < 1) {
349 // Throw NPE yet again
350 throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
353 // Get fax number from event
354 DialableLandLineNumber number = event.getLandLineNumber();
356 // Copy all data to this bean
357 this.setPhoneId(number.getPhoneId());
358 this.setLandLineCountry(number.getPhoneCountry());
359 this.setLandLineAreaCode(number.getPhoneAreaCode());
360 this.setLandLineNumber(number.getPhoneNumber());
361 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
362 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
366 * Observes events being fired when a bean helper has successfully created a
367 * mobile number instance.
369 * @param event Event being fired
371 public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
372 // The event instance must be valid
375 throw new NullPointerException("event is null"); //NOI18N
376 } else if (event.getMobileNumber() == null) {
378 throw new NullPointerException("event.mobileNumber is null"); //NOI18N
379 } else if (event.getMobileNumber().getPhoneId() == null) {
380 // Throw NPE yet again
381 throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
382 } else if (event.getMobileNumber().getPhoneId() < 1) {
383 // Throw NPE yet again
384 throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
387 // Get fax number from event
388 DialableMobileNumber number = event.getMobileNumber();
390 // Copy all data to this bean
391 this.setPhoneId(number.getPhoneId());
392 this.setMobileProvider(number.getMobileProvider());
393 this.setMobileNumber(number.getPhoneNumber());
394 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
395 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
399 * Links fax number to contact from bean helper as "main fax number".
401 * @return Redirect outcome
403 public String doLinkMainFaxNumber () {
404 // Get contact from helper
405 Contact contact = this.beanHelper.getContact();
407 // Is all data properly set?
408 if (null == contact) {
410 throw new NullPointerException("contact is null"); //NOI18N
411 } else if (contact.getContactId() == null) {
413 throw new NullPointerException("contact.contactId is null"); //NOI18N
414 } else if (contact.getContactId() < 1) {
416 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
417 } else if (this.getFaxCountry() == null) {
419 throw new NullPointerException("this.faxCountry is null"); //NOI18N
420 } else if (this.getFaxCountry().getCountryId() == null) {
422 throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
423 } else if (this.getFaxCountry().getCountryId() < 1) {
425 throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
426 } else if (this.getFaxAreaCode() == null) {
428 throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
429 } else if (this.getFaxAreaCode() < 1) {
431 throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
432 } else if (this.getFaxNumber() == null) {
434 throw new NullPointerException("this.faxNumber is null"); //NOI18N
435 } else if (this.getFaxNumber() < 1) {
437 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
441 Contact updatedContact;
442 DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
447 updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, number);
448 } catch (final PhoneNumberAlreadyLinkedException ex) {
449 // Throw again as cause
450 this.showFacesMessage("form_add_contact_fax:faxNumber", ex); //NOI18N
455 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
457 // Return to contact profile
458 return "admin_show_contact"; //NOI18N
462 * Links land-line number to contact from bean helper as "main land-line
465 * @return Redirect outcome
467 public String doLinkMainLandLineNumber () {
468 // Get contact from helper
469 Contact contact = this.beanHelper.getContact();
471 // Is all data properly set?
472 if (null == contact) {
474 throw new NullPointerException("contact is null"); //NOI18N
475 } else if (contact.getContactId() == null) {
477 throw new NullPointerException("contact.contactId is null"); //NOI18N
478 } else if (contact.getContactId() < 1) {
480 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
481 } else if (this.getLandLineCountry() == null) {
483 throw new NullPointerException("this.landLineCountry is null"); //NOI18N
484 } else if (this.getLandLineCountry().getCountryId() == null) {
486 throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
487 } else if (this.getLandLineCountry().getCountryId() < 1) {
489 throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
490 } else if (this.getLandLineAreaCode() == null) {
492 throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
493 } else if (this.getLandLineAreaCode() < 1) {
495 throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
496 } else if (this.getLandLineNumber() == null) {
498 throw new NullPointerException("this.landLineNumber is null"); //NOI18N
499 } else if (this.getLandLineNumber() < 1) {
501 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
505 Contact updatedContact;
506 DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
511 updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, number);
512 } catch (final PhoneNumberAlreadyLinkedException ex) {
513 // Throw again as cause
514 this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex); //NOI18N
519 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
521 // Return to contact profile
522 return "admin_show_contact"; //NOI18N
526 * Links mobile number to contact from bean helper as "main mobile number".
528 * @return Redirect outcome
530 public String doLinkMainMobileNumber () {
531 // Get contact from helper
532 Contact contact = this.beanHelper.getContact();
534 // Is all data properly set?
535 if (null == contact) {
537 throw new NullPointerException("contact is null"); //NOI18N
538 } else if (contact.getContactId() == null) {
540 throw new NullPointerException("contact.contactId is null"); //NOI18N
541 } else if (contact.getContactId() < 1) {
543 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
544 } else if (this.getMobileProvider() == null) {
546 throw new NullPointerException("this.mobileProvider is null"); //NOI18N
547 } else if (this.getMobileProvider().getProviderId() == null) {
549 throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
550 } else if (this.getMobileProvider().getProviderId() < 1) {
552 throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N
553 } else if (this.getMobileNumber() == null) {
555 throw new NullPointerException("this.mobileNumber is null"); //NOI18N
556 } else if (this.getMobileNumber() < 1) {
558 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N
562 Contact updatedContact;
563 DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
568 updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, number);
569 } catch (final PhoneNumberAlreadyLinkedException ex) {
570 // Throw again as cause
571 this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex); //NOI18N
576 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number));
578 // Return to contact profile
579 return "admin_show_contact"; //NOI18N
583 * Getter for fax area code
585 * @return Fax area code
587 public Integer getFaxAreaCode () {
588 return this.faxAreaCode;
592 * Setter for fax area code
594 * @param faxAreaCode Fax area code
596 public void setFaxAreaCode (final Integer faxAreaCode) {
597 this.faxAreaCode = faxAreaCode;
601 * Getter for fax numbers country
603 * @return Fax numbers country
605 public Country getFaxCountry () {
606 return this.faxCountry;
610 * Setter for fax numbers country
612 * @param faxCountry Fax numbers country
614 public void setFaxCountry (final Country faxCountry) {
615 this.faxCountry = faxCountry;
619 * Getter for fax number
623 public Long getFaxNumber () {
624 return this.faxNumber;
628 * Setter for fax number
630 * @param faxNumber Fax number
632 public void setFaxNumber (final Long faxNumber) {
633 this.faxNumber = faxNumber;
637 * Getter for land-line area code
639 * @return Land-line area code
641 public Integer getLandLineAreaCode () {
642 return this.landLineAreaCode;
646 * Setter for land-line area code
648 * @param landLineAreaCode Land-line area code
650 public void setLandLineAreaCode (final Integer landLineAreaCode) {
651 this.landLineAreaCode = landLineAreaCode;
655 * Getter for land-line country
657 * @return Land-line country
659 public Country getLandLineCountry () {
660 return this.landLineCountry;
664 * Setter for land-line country
666 * @param landLineCountry Land-line country
668 public void setLandLineCountry (final Country landLineCountry) {
669 this.landLineCountry = landLineCountry;
673 * Getter for land-line number
675 * @return Land-line number
677 public Long getLandLineNumber () {
678 return this.landLineNumber;
682 * Setter for land-line number
684 * @param landLineNumber Land-line number
686 public void setLandLineNumber (final Long landLineNumber) {
687 this.landLineNumber = landLineNumber;
692 * Getter for mobile number
694 * @return Mobile number
696 public Long getMobileNumber () {
697 return this.mobileNumber;
701 * Setter for mobile number
703 * @param mobileNumber Mobile number
705 public void setMobileNumber (final Long mobileNumber) {
706 this.mobileNumber = mobileNumber;
709 * Getter for mobile provider
711 * @return Mobile provider
713 public MobileProvider getMobileProvider () {
714 return this.mobileProvider;
717 * Setter for mobile provider
719 * @param mobileProvider Mobile provider
721 public void setMobileProvider (final MobileProvider mobileProvider) {
722 this.mobileProvider = mobileProvider;
726 * Post-construction method
729 public void init () {
732 // Get initial context
733 Context context = new InitialContext();
735 // Try to lookup the beans
736 this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/addressbook-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
737 } catch (final NamingException e) {
739 throw new FaceletException(e);
744 * Unlinks fax data with current contact
746 * @return Redirect outcome
748 public String unlinkFaxContactData () {
750 if (this.beanHelper.getFaxNumber() == null) {
751 // Not set, throw NPE
752 throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
753 } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
755 throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
756 } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
758 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
759 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
761 throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
762 } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
763 // Throw it again ...
764 throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
765 } else if (this.beanHelper.getContact() == null) {
766 // ... and throw again
767 throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
768 } else if (this.beanHelper.getContact().getContactId() == null) {
770 throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
771 } else if (this.beanHelper.getContact().getContactId() < 1) {
773 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
776 // Init contact instance
777 Contact updatedContact;
780 // Unlink it and return contact without fax instance
781 updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
782 } catch (final PhoneNumberNotLinkedException ex) {
784 this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
789 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber()));
792 return "admin_show_contact"; //NOI18N
796 * Unlinks land-line data with current contact
798 * @return Redirect outcome
800 public String unlinkLandLineContactData () {
802 if (this.beanHelper.getLandLineNumber() == null) {
803 // Not set, throw NPE
804 throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
805 } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
807 throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
808 } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
810 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
811 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
813 throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
814 } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
815 // Throw it again ...
816 throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
817 } else if (this.beanHelper.getContact() == null) {
818 // ... and throw again
819 throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
820 } else if (this.beanHelper.getContact().getContactId() == null) {
822 throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
823 } else if (this.beanHelper.getContact().getContactId() < 1) {
825 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
828 // Init contact instance
829 Contact updatedContact;
832 // Unlink it and return contact without landLine instance
833 updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
834 } catch (final PhoneNumberNotLinkedException ex) {
836 this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
841 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber()));
844 return "admin_show_contact"; //NOI18N
848 * Unlinks mobile data with current contact
850 * @return Redirect outcome
852 public String unlinkMobileContactData () {
854 if (this.beanHelper.getMobileNumber() == null) {
855 // Not set, throw NPE
856 throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N
857 } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) {
859 throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N
860 } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) {
862 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N
863 } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) {
865 throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N
866 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) {
868 throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N
869 } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) {
871 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
872 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) {
874 throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N
875 } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) {
876 // Throw it again ...
877 throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N
878 } else if (this.beanHelper.getContact() == null) {
879 // ... and throw again
880 throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
881 } else if (this.beanHelper.getContact().getContactId() == null) {
883 throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
884 } else if (this.beanHelper.getContact().getContactId() < 1) {
886 throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
889 // Init contact instance
890 Contact updatedContact;
893 // Unlink it and return contact without mobile instance
894 updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber());
895 } catch (final PhoneNumberNotLinkedException ex) {
897 this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
902 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber()));
905 return "admin_show_contact"; //NOI18N
911 private void clear () {
912 // @TODO Clear all data