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 java.util.Calendar;
21 import javax.annotation.PostConstruct;
22 import javax.enterprise.context.RequestScoped;
23 import javax.enterprise.event.Event;
24 import javax.enterprise.event.Observes;
25 import javax.enterprise.inject.Any;
26 import javax.faces.view.facelets.FaceletException;
27 import javax.inject.Inject;
28 import javax.inject.Named;
29 import javax.naming.Context;
30 import javax.naming.InitialContext;
31 import javax.naming.NamingException;
32 import org.mxchange.jcontacts.contact.Contact;
33 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
34 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
35 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
36 import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
37 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
38 import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
39 import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
40 import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
41 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
42 import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
43 import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
44 import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
45 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
46 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
47 import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
48 import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
49 import org.mxchange.jcountry.data.Country;
50 import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
51 import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
52 import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
53 import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
54 import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
55 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
56 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
57 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
58 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
59 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
60 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
61 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
62 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
63 import org.mxchange.pizzaapplication.beans.BasePizzaController;
64 import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
65 import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
68 * An administrative contact phone controller (bean)
70 * @author Roland Häder<roland@mxchange.org>
72 @Named ("adminContactPhoneController")
74 public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController implements PizzaAdminContactPhoneWebRequestController {
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 * Administrative EJB for phone number
89 private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean;
92 * Event being fired when a fax number has been linked
96 private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
99 * Event being fired when a land-line number has been linked
103 private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
106 * Event being fired when a mobile number has been linked
110 private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
113 * Administrative phone controller
116 private PizzaAdminPhoneWebRequestController adminPhoneController;
122 private PizzaWebRequestHelperController beanHelper;
127 private Contact contact;
130 * Area code (city dial prefix) for fax number
132 private Integer faxAreaCode;
135 * Country (for dial prefix) for fax number
137 private Country faxCountry;
142 private Long faxNumber;
145 * Event being fired when a fax number has been unlinked
149 private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
152 * Area code (city dial prefix) for land-line number
154 private Integer landLineAreaCode;
157 * Country (for dial prefix) for land-line number
159 private Country landLineCountry;
164 private Long landLineNumber;
167 * Event being fired when a land-line number has been unlinked
171 private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
176 private Long mobileNumber;
179 * Event being fired when admin unlinks mobile from contact
183 private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
188 private MobileProvider mobileProvider;
191 * When fax number has been created
193 private Calendar phoneEntryCreated;
196 * When fax number has been updated
198 private Calendar phoneEntryUpdated;
201 * Phone id (primary key)
203 private Long phoneId;
206 * Default constructor
208 public PizzaAdminContactPhoneWebRequestBean () {
209 // Call super constructor
212 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
213 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
217 * Observes events being fired when an administrator has added a new
220 * @param event Event being fired
222 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
223 // The event must be valid
226 throw new NullPointerException("event is null"); //NOI18N
227 } else if (event.getAddedContact() == null) {
229 throw new NullPointerException("event.addedContact is null"); //NOI18N
230 } else if (event.getAddedContact().getContactId() == null) {
232 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
233 } else if (event.getAddedContact().getContactId() < 1) {
235 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
243 * Event observer for newly added users by administrator
245 * @param event Event being fired
247 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
248 // event should not be null
251 throw new NullPointerException("event is null"); //NOI18N
252 } else if (event.getAddedUser() == null) {
254 throw new NullPointerException("event.addedUser is null"); //NOI18N
255 } else if (event.getAddedUser().getUserId() == null) {
257 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
258 } else if (event.getAddedUser().getUserId() < 1) {
260 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
268 * Event observer for updated contact data by administrators
270 * @param event Updated contact data event
272 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
273 // event should not be null
276 throw new NullPointerException("event is null"); //NOI18N
277 } else if (event.getUpdatedContact() == null) {
279 throw new NullPointerException("event.updatedContact is null"); //NOI18N
280 } else if (event.getUpdatedContact().getContactId() == null) {
282 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
283 } else if (event.getUpdatedContact().getContactId() < 1) {
285 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
293 * Observer for events being fired when a bean helper has successfully
294 * created a contact instance.
296 * @param event Event being fired
298 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
300 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
302 // The event instance must be valid
305 throw new NullPointerException("event is null"); //NOI18N
306 } else if (event.getCreatedContact() == null) {
308 throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
309 } else if (event.getCreatedContact().getContactId() == null) {
311 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
312 } else if (event.getCreatedContact().getContactId() < 1) {
314 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
318 this.setContact(event.getCreatedContact());
322 * Observes events being fired when a bean helper has successfully created a
323 * fax number instance.
325 * @param event Event being fired
327 public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
328 // The event instance must be valid
331 throw new NullPointerException("event is null"); //NOI18N
332 } else if (event.getFaxNumber() == null) {
334 throw new NullPointerException("event.faxNumber is null"); //NOI18N
335 } else if (event.getFaxNumber().getPhoneId() == null) {
336 // Throw NPE yet again
337 throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
338 } else if (event.getFaxNumber().getPhoneId() < 1) {
339 // Throw NPE yet again
340 throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
343 // Get fax number from event
344 DialableFaxNumber number = event.getFaxNumber();
346 // Copy all data to this bean
347 this.setPhoneId(number.getPhoneId());
348 this.setFaxCountry(number.getPhoneCountry());
349 this.setFaxAreaCode(number.getPhoneAreaCode());
350 this.setFaxNumber(number.getPhoneNumber());
351 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
352 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
356 * Observes events being fired when a bean helper has successfully created a
357 * land-line number instance.
359 * @param event Event being fired
361 public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
362 // The event instance must be valid
365 throw new NullPointerException("event is null"); //NOI18N
366 } else if (event.getLandLineNumber() == null) {
368 throw new NullPointerException("event.landLineNumber is null"); //NOI18N
369 } else if (event.getLandLineNumber().getPhoneId() == null) {
370 // Throw NPE yet again
371 throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
372 } else if (event.getLandLineNumber().getPhoneId() < 1) {
373 // Throw NPE yet again
374 throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
377 // Get fax number from event
378 DialableLandLineNumber number = event.getLandLineNumber();
380 // Copy all data to this bean
381 this.setPhoneId(number.getPhoneId());
382 this.setLandLineCountry(number.getPhoneCountry());
383 this.setLandLineAreaCode(number.getPhoneAreaCode());
384 this.setLandLineNumber(number.getPhoneNumber());
385 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
386 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
390 * Observes events being fired when a bean helper has successfully created a
391 * mobile number instance.
393 * @param event Event being fired
395 public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
396 // The event instance must be valid
399 throw new NullPointerException("event is null"); //NOI18N
400 } else if (event.getMobileNumber() == null) {
402 throw new NullPointerException("event.mobileNumber is null"); //NOI18N
403 } else if (event.getMobileNumber().getPhoneId() == null) {
404 // Throw NPE yet again
405 throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
406 } else if (event.getMobileNumber().getPhoneId() < 1) {
407 // Throw NPE yet again
408 throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
411 // Get fax number from event
412 DialableMobileNumber number = event.getMobileNumber();
414 // Copy all data to this bean
415 this.setPhoneId(number.getPhoneId());
416 this.setMobileProvider(number.getMobileProvider());
417 this.setMobileNumber(number.getPhoneNumber());
418 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
419 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
423 * Links fax number to contact from bean helper as "main fax number".
425 * @return Redirect outcome
427 public String doLinkMainFaxNumber () {
428 // Get contact from helper
429 Contact targetContact = this.getContact();
431 // Is all data properly set?
432 if (null == targetContact) {
434 throw new NullPointerException("targetContact is null"); //NOI18N
435 } else if (targetContact.getContactId() == null) {
437 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
438 } else if (targetContact.getContactId() < 1) {
440 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
441 } else if (this.getFaxCountry() == null) {
443 throw new NullPointerException("this.faxCountry is null"); //NOI18N
444 } else if (this.getFaxCountry().getCountryId() == null) {
446 throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
447 } else if (this.getFaxCountry().getCountryId() < 1) {
449 throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
450 } else if (this.getFaxAreaCode() == null) {
452 throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
453 } else if (this.getFaxAreaCode() < 1) {
455 throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
456 } else if (this.getFaxNumber() == null) {
458 throw new NullPointerException("this.faxNumber is null"); //NOI18N
459 } else if (this.getFaxNumber() < 1) {
461 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
465 Contact updatedContact;
466 DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
471 updatedContact = this.adminContactPhoneBean.linkNewFaxNumberWithContact(targetContact, number);
472 } catch (final PhoneNumberAlreadyLinkedException ex) {
473 // Throw again as cause
474 this.showFacesMessage("form_add_contact_fax:faxNumber", ex); //NOI18N
479 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
481 // Return to contact profile
482 return "admin_show_contact"; //NOI18N
486 * Links land-line number to contact from bean helper as "main land-line
489 * @return Redirect outcome
491 public String doLinkMainLandLineNumber () {
492 // Get contact from helper
493 Contact targetContact = this.getContact();
495 // Is all data properly set?
496 if (null == targetContact) {
498 throw new NullPointerException("targetContact is null"); //NOI18N
499 } else if (targetContact.getContactId() == null) {
501 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
502 } else if (targetContact.getContactId() < 1) {
504 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
505 } else if (this.getLandLineCountry() == null) {
507 throw new NullPointerException("this.landLineCountry is null"); //NOI18N
508 } else if (this.getLandLineCountry().getCountryId() == null) {
510 throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
511 } else if (this.getLandLineCountry().getCountryId() < 1) {
513 throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
514 } else if (this.getLandLineAreaCode() == null) {
516 throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
517 } else if (this.getLandLineAreaCode() < 1) {
519 throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
520 } else if (this.getLandLineNumber() == null) {
522 throw new NullPointerException("this.landLineNumber is null"); //NOI18N
523 } else if (this.getLandLineNumber() < 1) {
525 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
529 Contact updatedContact;
530 DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
535 updatedContact = this.adminContactPhoneBean.linkNewLandLineNumberWithContact(targetContact, number);
536 } catch (final PhoneNumberAlreadyLinkedException ex) {
537 // Throw again as cause
538 this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex); //NOI18N
543 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
545 // Return to contact profile
546 return "admin_show_contact"; //NOI18N
550 * Links mobile number to contact from bean helper as "main mobile number".
552 * @return Redirect outcome
554 public String doLinkMainMobileNumber () {
555 // Get contact from helper
556 Contact targetContact = this.getContact();
558 // Is all data properly set?
559 if (null == targetContact) {
561 throw new NullPointerException("targetContact is null"); //NOI18N
562 } else if (targetContact.getContactId() == null) {
564 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
565 } else if (targetContact.getContactId() < 1) {
567 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
568 } else if (this.getMobileProvider() == null) {
570 throw new NullPointerException("this.mobileProvider is null"); //NOI18N
571 } else if (this.getMobileProvider().getProviderId() == null) {
573 throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
574 } else if (this.getMobileProvider().getProviderId() < 1) {
576 throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N
577 } else if (this.getMobileNumber() == null) {
579 throw new NullPointerException("this.mobileNumber is null"); //NOI18N
580 } else if (this.getMobileNumber() < 1) {
582 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N
586 Contact updatedContact;
587 DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
592 updatedContact = this.adminContactPhoneBean.linkNewMobileNumberWithContact(targetContact, number);
593 } catch (final PhoneNumberAlreadyLinkedException ex) {
594 // Throw again as cause
595 this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex); //NOI18N
600 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number));
602 // Return to contact profile
603 return "admin_show_contact"; //NOI18N
607 * Getter for contact instance
609 * @return Contact instance
611 public Contact getContact () {
616 * Setter for contact instance
618 * @param contact Contact instance
620 public void setContact (final Contact contact) {
621 this.contact = contact;
625 * Getter for fax area code
627 * @return Fax area code
629 public Integer getFaxAreaCode () {
630 return this.faxAreaCode;
634 * Setter for fax area code
636 * @param faxAreaCode Fax area code
638 public void setFaxAreaCode (final Integer faxAreaCode) {
639 this.faxAreaCode = faxAreaCode;
643 * Getter for fax numbers country
645 * @return Fax numbers country
647 public Country getFaxCountry () {
648 return this.faxCountry;
652 * Setter for fax numbers country
654 * @param faxCountry Fax numbers country
656 public void setFaxCountry (final Country faxCountry) {
657 this.faxCountry = faxCountry;
661 * Getter for fax number
665 public Long getFaxNumber () {
666 return this.faxNumber;
670 * Setter for fax number
672 * @param faxNumber Fax number
674 public void setFaxNumber (final Long faxNumber) {
675 this.faxNumber = faxNumber;
679 * Getter for land-line area code
681 * @return Land-line area code
683 public Integer getLandLineAreaCode () {
684 return this.landLineAreaCode;
688 * Setter for land-line area code
690 * @param landLineAreaCode Land-line area code
692 public void setLandLineAreaCode (final Integer landLineAreaCode) {
693 this.landLineAreaCode = landLineAreaCode;
697 * Getter for land-line country
699 * @return Land-line country
701 public Country getLandLineCountry () {
702 return this.landLineCountry;
706 * Setter for land-line country
708 * @param landLineCountry Land-line country
710 public void setLandLineCountry (final Country landLineCountry) {
711 this.landLineCountry = landLineCountry;
715 * Getter for land-line number
717 * @return Land-line number
719 public Long getLandLineNumber () {
720 return this.landLineNumber;
724 * Setter for land-line number
726 * @param landLineNumber Land-line number
728 public void setLandLineNumber (final Long landLineNumber) {
729 this.landLineNumber = landLineNumber;
733 * Getter for mobile number
735 * @return Mobile number
737 public Long getMobileNumber () {
738 return this.mobileNumber;
742 * Setter for mobile number
744 * @param mobileNumber Mobile number
746 public void setMobileNumber (final Long mobileNumber) {
747 this.mobileNumber = mobileNumber;
751 * Getter for mobile provider
753 * @return Mobile provider
755 public MobileProvider getMobileProvider () {
756 return this.mobileProvider;
760 * Setter for mobile provider
762 * @param mobileProvider Mobile provider
764 public void setMobileProvider (final MobileProvider mobileProvider) {
765 this.mobileProvider = mobileProvider;
769 * Setter for phone id
773 public Long getPhoneId () {
778 * Getter for phone id
780 * @param phoneId Phone id
782 public void setPhoneId (final Long phoneId) {
783 this.phoneId = phoneId;
787 * Post-construction method
790 public void init () {
793 // Get initial context
794 Context context = new InitialContext();
796 // Try to lookup the beans
797 this.adminContactPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
798 } catch (final NamingException e) {
800 throw new FaceletException(e);
805 * Unlinks fax data with current contact
807 * @return Redirect outcome
809 public String unlinkFaxContactData () {
810 // Create fax number instance
811 DialableFaxNumber number = this.createFaxNumber();
814 if (number == null) {
815 // Not set, throw NPE
816 throw new NullPointerException("number is null"); //NOI18N
817 } else if (number.getPhoneId() == null) {
819 throw new NullPointerException("number.phoneId is null"); //NOI18N
820 } else if (number.getPhoneId() < 1) {
822 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
823 } else if (number.getPhoneNumber() == null) {
825 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
826 } else if (number.getPhoneNumber() < 1) {
827 // Throw it again ...
828 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
829 } else if (this.getContact() == null) {
830 // ... and throw again
831 throw new NullPointerException("this.contact is null"); //NOI18N
832 } else if (this.getContact().getContactId() == null) {
834 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
835 } else if (this.getContact().getContactId() < 1) {
837 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
840 // Init contact instance
841 Contact updatedContact;
844 // Unlink it and return contact without fax instance
845 updatedContact = this.adminContactPhoneBean.unlinkFaxDataFromContact(this.getContact(), number);
846 } catch (final PhoneNumberNotLinkedException ex) {
848 this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
853 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, number));
856 return "admin_show_contact"; //NOI18N
860 * Unlinks land-line data with current contact
862 * @return Redirect outcome
864 public String unlinkLandLineContactData () {
865 // Create fax number instance
866 DialableLandLineNumber number = this.createLandLineNumber();
869 if (number == null) {
870 // Not set, throw NPE
871 throw new NullPointerException("number is null"); //NOI18N
872 } else if (number.getPhoneId() == null) {
874 throw new NullPointerException("number.phoneId is null"); //NOI18N
875 } else if (number.getPhoneId() < 1) {
877 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
878 } else if (number.getPhoneNumber() == null) {
880 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
881 } else if (number.getPhoneNumber() < 1) {
882 // Throw it again ...
883 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
884 } else if (this.getContact() == null) {
885 // ... and throw again
886 throw new NullPointerException("this.contact is null"); //NOI18N
887 } else if (this.getContact().getContactId() == null) {
889 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
890 } else if (this.getContact().getContactId() < 1) {
892 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
895 // Init contact instance
896 Contact updatedContact;
899 // Unlink it and return contact without landLine instance
900 updatedContact = this.adminContactPhoneBean.unlinkLandLineDataFromContact(this.getContact(), number);
901 } catch (final PhoneNumberNotLinkedException ex) {
903 this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
908 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, number));
911 return "admin_show_contact"; //NOI18N
915 * Unlinks mobile data with current contact
917 * @return Redirect outcome
919 public String unlinkMobileContactData () {
920 // Create fax number instance
921 DialableMobileNumber number = this.createMobileNumber();
924 if (number == null) {
925 // Not set, throw NPE
926 throw new NullPointerException("number is null"); //NOI18N
927 } else if (number.getPhoneId() == null) {
929 throw new NullPointerException("number.phoneId is null"); //NOI18N
930 } else if (number.getPhoneId() < 1) {
932 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
933 } else if (number.getMobileProvider() == null) {
935 throw new NullPointerException("number.mobileProvider is null"); //NOI18N
936 } else if (number.getMobileProvider().getProviderId() == null) {
938 throw new NullPointerException("number.mobileProvider.providerId is null"); //NOI18N
939 } else if (number.getMobileProvider().getProviderId() < 1) {
941 throw new IllegalArgumentException(MessageFormat.format("number.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
942 } else if (number.getPhoneNumber() == null) {
944 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
945 } else if (number.getPhoneNumber() < 1) {
946 // Throw it again ...
947 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
948 } else if (this.getContact() == null) {
949 // ... and throw again
950 throw new NullPointerException("this.contact is null"); //NOI18N
951 } else if (this.getContact().getContactId() == null) {
953 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
954 } else if (this.getContact().getContactId() < 1) {
956 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
959 // Init contact instance
960 Contact updatedContact;
963 // Unlink it and return contact without mobile instance
964 updatedContact = this.adminContactPhoneBean.unlinkMobileDataFromContact(this.getContact(), number);
965 } catch (final PhoneNumberNotLinkedException ex) {
967 this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
972 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, number));
975 return "admin_show_contact"; //NOI18N
981 private void clear () {
986 * Creates an instance of a DialableFaxNumber class
988 * @return DialableFaxNumber class
990 private DialableFaxNumber createFaxNumber () {
992 DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
994 // Set all other fields
995 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
996 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
998 // Is id number there?
999 if (this.getPhoneId() instanceof Long) {
1001 number.setPhoneId(this.getPhoneId());
1009 * Returns an instance of a DialableLandLineNumber from all fields stored in
1012 * @return An instance of a DialableLandLineNumber class
1014 private DialableLandLineNumber createLandLineNumber () {
1016 DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1018 // Add all other data
1019 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
1020 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
1022 // Is id number set?
1023 if (this.getPhoneId() instanceof Long) {
1025 number.setPhoneId(this.getPhoneId());
1033 * Returns an instance of a DialableMobileNumber from all fields stored in
1036 * @return An instance of a DialableMobileNumber class
1038 private DialableMobileNumber createMobileNumber () {
1040 DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
1042 // Add all other data
1043 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
1044 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
1046 // Is id number set?
1047 if (this.getPhoneId() instanceof Long) {
1049 number.setPhoneId(this.getPhoneId());
1057 * Getter for phone entry created
1059 * @param faxNumberEntryCreated Phone entry created
1061 @SuppressWarnings ("ReturnOfDateField")
1062 private Calendar getPhoneEntryCreated () {
1063 return this.phoneEntryCreated;
1067 * Setter for phone entry created
1069 * @param phoneEntryCreated Phone entry created
1071 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1072 private void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
1073 this.phoneEntryCreated = phoneEntryCreated;
1077 * Getter for phone entry updated
1079 * @return Phone entry updated
1081 @SuppressWarnings ("ReturnOfDateField")
1082 private Calendar getPhoneEntryUpdated () {
1083 return this.phoneEntryUpdated;
1087 * Setter for phone entry updated
1089 * @param phoneEntryUpdated Phone entry updated
1091 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1092 private void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
1093 this.phoneEntryUpdated = phoneEntryUpdated;