2 * Copyright (C) 2016 - 2022 Free Software Foundation
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;
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.inject.Inject;
27 import javax.inject.Named;
28 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
29 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
30 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
31 import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
32 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
33 import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
34 import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
35 import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
36 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
37 import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
38 import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
39 import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
40 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
41 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
42 import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
43 import org.mxchange.jcontacts.model.contact.Contact;
44 import org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote;
45 import org.mxchange.jcountry.model.data.Country;
46 import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
47 import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
48 import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
49 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
50 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
51 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
52 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
53 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
54 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
55 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
56 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
57 import org.mxchange.pizzaapplication.beans.BasePizzaBean;
58 import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
61 * An administrative contact phone controller (bean)
63 * @author Roland Häder<roland@mxchange.org>
65 @Named ("adminContactPhoneController")
67 public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaBean implements PizzaAdminContactPhoneWebRequestController {
70 * Call-stack instance (5 may show BeanELResolver.getValue as caller)
72 private static final short THREAD_STACK = 5;
77 private static final long serialVersionUID = 542_145_354_001L;
80 * Administrative EJB for phone number
82 @EJB (lookup = "java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote")
83 private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean;
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;
109 private Contact contact;
112 * Area code (city dial prefix) for fax number
114 private Integer faxAreaCode;
117 * Country (for dial prefix) for fax number
119 private Country faxCountry;
124 private Long faxNumber;
127 * Event being fired when a fax number has been unlinked
131 private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
134 * Area code (city dial prefix) for land-line number
136 private Integer landLineAreaCode;
139 * Country (for dial prefix) for land-line number
141 private Country landLineCountry;
146 private Long landLineNumber;
149 * Event being fired when a land-line number has been unlinked
153 private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
158 private Long mobileNumber;
161 * Event being fired when admin unlinks mobile from contact
165 private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
170 private MobileProvider mobileProvider;
173 * When fax number has been created
175 private Calendar phoneEntryCreated;
178 * When fax number has been updated
180 private Calendar phoneEntryUpdated;
183 * Phone id (primary key)
185 private Long phoneId;
188 * Default constructor
190 public PizzaAdminContactPhoneWebRequestBean () {
191 // Call super constructor
194 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
195 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
199 * Observes events being fired when an administrator has added a new
202 * @param event Event being fired
204 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
205 // The event must be valid
208 throw new NullPointerException("event is null"); //NOI18N
209 } else if (event.getAddedContact() == null) {
211 throw new NullPointerException("event.addedContact is null"); //NOI18N
212 } else if (event.getAddedContact().getContactId() == null) {
214 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
215 } else if (event.getAddedContact().getContactId() < 1) {
217 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
225 * Event observer for newly added users by administrator
227 * @param event Event being fired
229 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
230 // event should not be null
233 throw new NullPointerException("event is null"); //NOI18N
234 } else if (event.getAddedUser() == null) {
236 throw new NullPointerException("event.addedUser is null"); //NOI18N
237 } else if (event.getAddedUser().getUserId() == null) {
239 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
240 } else if (event.getAddedUser().getUserId() < 1) {
242 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
250 * Event observer for updated contact data by administrators
252 * @param event Updated contact data event
254 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
255 // event should not be null
258 throw new NullPointerException("event is null"); //NOI18N
259 } else if (event.getUpdatedContact() == null) {
261 throw new NullPointerException("event.updatedContact is null"); //NOI18N
262 } else if (event.getUpdatedContact().getContactId() == null) {
264 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
265 } else if (event.getUpdatedContact().getContactId() < 1) {
267 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
275 * Observer for events being fired when a bean helper has successfully
276 * created a contact instance.
278 * @param event Event being fired
280 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
282 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
284 // The event instance must be valid
287 throw new NullPointerException("event is null"); //NOI18N
288 } else if (event.getCreatedContact() == null) {
290 throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
291 } else if (event.getCreatedContact().getContactId() == null) {
293 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
294 } else if (event.getCreatedContact().getContactId() < 1) {
296 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
300 this.setContact(event.getCreatedContact());
304 * Observes events being fired when a bean helper has successfully created a
305 * fax number instance.
307 * @param event Event being fired
309 public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
310 // The event instance must be valid
313 throw new NullPointerException("event is null"); //NOI18N
314 } else if (event.getFaxNumber() == null) {
316 throw new NullPointerException("event.faxNumber is null"); //NOI18N
317 } else if (event.getFaxNumber().getPhoneId() == null) {
318 // Throw NPE yet again
319 throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
320 } else if (event.getFaxNumber().getPhoneId() < 1) {
321 // Throw NPE yet again
322 throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
325 // Get fax number from event
326 final DialableFaxNumber number = event.getFaxNumber();
328 // Copy all data to this bean
329 this.setPhoneId(number.getPhoneId());
330 this.setFaxCountry(number.getPhoneCountry());
331 this.setFaxAreaCode(number.getPhoneAreaCode());
332 this.setFaxNumber(number.getPhoneNumber());
333 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
334 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
338 * Observes events being fired when a bean helper has successfully created a
339 * land-line number instance.
341 * @param event Event being fired
343 public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
344 // The event instance must be valid
347 throw new NullPointerException("event is null"); //NOI18N
348 } else if (event.getLandLineNumber() == null) {
350 throw new NullPointerException("event.landLineNumber is null"); //NOI18N
351 } else if (event.getLandLineNumber().getPhoneId() == null) {
352 // Throw NPE yet again
353 throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
354 } else if (event.getLandLineNumber().getPhoneId() < 1) {
355 // Throw NPE yet again
356 throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
359 // Get fax number from event
360 final DialableLandLineNumber number = event.getLandLineNumber();
362 // Copy all data to this bean
363 this.setPhoneId(number.getPhoneId());
364 this.setLandLineCountry(number.getPhoneCountry());
365 this.setLandLineAreaCode(number.getPhoneAreaCode());
366 this.setLandLineNumber(number.getPhoneNumber());
367 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
368 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
372 * Observes events being fired when a bean helper has successfully created a
373 * mobile number instance.
375 * @param event Event being fired
377 public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
378 // The event instance must be valid
381 throw new NullPointerException("event is null"); //NOI18N
382 } else if (event.getMobileNumber() == null) {
384 throw new NullPointerException("event.mobileNumber is null"); //NOI18N
385 } else if (event.getMobileNumber().getPhoneId() == null) {
386 // Throw NPE yet again
387 throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
388 } else if (event.getMobileNumber().getPhoneId() < 1) {
389 // Throw NPE yet again
390 throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
393 // Get fax number from event
394 final DialableMobileNumber number = event.getMobileNumber();
396 // Copy all data to this bean
397 this.setPhoneId(number.getPhoneId());
398 this.setMobileProvider(number.getMobileProvider());
399 this.setMobileNumber(number.getPhoneNumber());
400 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
401 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
405 * Links fax number to contact from bean helper as "main fax number".
407 * @return Redirect outcome
409 public String doLinkMainFaxNumber () {
410 // Get contact from helper
411 final Contact targetContact = this.getContact();
413 // Is all data properly set?
414 if (null == targetContact) {
416 throw new NullPointerException("targetContact is null"); //NOI18N
417 } else if (targetContact.getContactId() == null) {
419 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
420 } else if (targetContact.getContactId() < 1) {
422 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
423 } else if (this.getFaxCountry() == null) {
425 throw new NullPointerException("this.faxCountry is null"); //NOI18N
426 } else if (this.getFaxCountry().getCountryId() == null) {
428 throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
429 } else if (this.getFaxCountry().getCountryId() < 1) {
431 throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
432 } else if (this.getFaxAreaCode() == null) {
434 throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
435 } else if (this.getFaxAreaCode() < 1) {
437 throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
438 } else if (this.getFaxNumber() == null) {
440 throw new NullPointerException("this.faxNumber is null"); //NOI18N
441 } else if (this.getFaxNumber() < 1) {
443 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
447 final Contact updatedContact;
448 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
453 updatedContact = this.adminContactPhoneBean.linkNewFaxNumberWithContact(targetContact, number);
454 } catch (final PhoneNumberAlreadyLinkedException ex) {
455 // Throw again as cause
456 this.showFacesException("form_add_contact_fax:faxNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
461 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
463 // Return to contact profile
464 return "admin_show_contact"; //NOI18N
468 * Links land-line number to contact from bean helper as "main land-line
471 * @return Redirect outcome
473 public String doLinkMainLandLineNumber () {
474 // Get contact from helper
475 final Contact targetContact = this.getContact();
477 // Is all data properly set?
478 if (null == targetContact) {
480 throw new NullPointerException("targetContact is null"); //NOI18N
481 } else if (targetContact.getContactId() == null) {
483 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
484 } else if (targetContact.getContactId() < 1) {
486 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
487 } else if (this.getLandLineCountry() == null) {
489 throw new NullPointerException("this.landLineCountry is null"); //NOI18N
490 } else if (this.getLandLineCountry().getCountryId() == null) {
492 throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
493 } else if (this.getLandLineCountry().getCountryId() < 1) {
495 throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
496 } else if (this.getLandLineAreaCode() == null) {
498 throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
499 } else if (this.getLandLineAreaCode() < 1) {
501 throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
502 } else if (this.getLandLineNumber() == null) {
504 throw new NullPointerException("this.landLineNumber is null"); //NOI18N
505 } else if (this.getLandLineNumber() < 1) {
507 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
511 final Contact updatedContact;
512 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
517 updatedContact = this.adminContactPhoneBean.linkNewLandLineNumberWithContact(targetContact, number);
518 } catch (final PhoneNumberAlreadyLinkedException ex) {
519 // Throw again as cause
520 this.showFacesException("form_add_contact_landLine:landLineNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
525 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
527 // Return to contact profile
528 return "admin_show_contact"; //NOI18N
532 * Links mobile number to contact from bean helper as "main mobile number".
534 * @return Redirect outcome
536 public String doLinkMainMobileNumber () {
537 // Get contact from helper
538 final Contact targetContact = this.getContact();
540 // Is all data properly set?
541 if (null == targetContact) {
543 throw new NullPointerException("targetContact is null"); //NOI18N
544 } else if (targetContact.getContactId() == null) {
546 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
547 } else if (targetContact.getContactId() < 1) {
549 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
550 } else if (this.getMobileProvider() == null) {
552 throw new NullPointerException("this.mobileProvider is null"); //NOI18N
553 } else if (this.getMobileProvider().getProviderId() == null) {
555 throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
556 } else if (this.getMobileProvider().getProviderId() < 1) {
558 throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N
559 } else if (this.getMobileNumber() == null) {
561 throw new NullPointerException("this.mobileNumber is null"); //NOI18N
562 } else if (this.getMobileNumber() < 1) {
564 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N
568 final Contact updatedContact;
569 final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
574 updatedContact = this.adminContactPhoneBean.linkNewMobileNumberWithContact(targetContact, number);
575 } catch (final PhoneNumberAlreadyLinkedException ex) {
576 // Throw again as cause
577 this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex); //NOI18N
582 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number));
584 // Return to contact profile
585 return "admin_show_contact"; //NOI18N
589 * Getter for contact instance
591 * @return Contact instance
593 public Contact getContact () {
598 * Setter for contact instance
600 * @param contact Contact instance
602 public void setContact (final Contact contact) {
603 this.contact = contact;
607 * Getter for fax area code
609 * @return Fax area code
611 public Integer getFaxAreaCode () {
612 return this.faxAreaCode;
616 * Setter for fax area code
618 * @param faxAreaCode Fax area code
620 public void setFaxAreaCode (final Integer faxAreaCode) {
621 this.faxAreaCode = faxAreaCode;
625 * Getter for fax numbers country
627 * @return Fax numbers country
629 public Country getFaxCountry () {
630 return this.faxCountry;
634 * Setter for fax numbers country
636 * @param faxCountry Fax numbers country
638 public void setFaxCountry (final Country faxCountry) {
639 this.faxCountry = faxCountry;
643 * Getter for fax number
647 public Long getFaxNumber () {
648 return this.faxNumber;
652 * Setter for fax number
654 * @param faxNumber Fax number
656 public void setFaxNumber (final Long faxNumber) {
657 this.faxNumber = faxNumber;
661 * Getter for land-line area code
663 * @return Land-line area code
665 public Integer getLandLineAreaCode () {
666 return this.landLineAreaCode;
670 * Setter for land-line area code
672 * @param landLineAreaCode Land-line area code
674 public void setLandLineAreaCode (final Integer landLineAreaCode) {
675 this.landLineAreaCode = landLineAreaCode;
679 * Getter for land-line country
681 * @return Land-line country
683 public Country getLandLineCountry () {
684 return this.landLineCountry;
688 * Setter for land-line country
690 * @param landLineCountry Land-line country
692 public void setLandLineCountry (final Country landLineCountry) {
693 this.landLineCountry = landLineCountry;
697 * Getter for land-line number
699 * @return Land-line number
701 public Long getLandLineNumber () {
702 return this.landLineNumber;
706 * Setter for land-line number
708 * @param landLineNumber Land-line number
710 public void setLandLineNumber (final Long landLineNumber) {
711 this.landLineNumber = landLineNumber;
715 * Getter for mobile number
717 * @return Mobile number
719 public Long getMobileNumber () {
720 return this.mobileNumber;
724 * Setter for mobile number
726 * @param mobileNumber Mobile number
728 public void setMobileNumber (final Long mobileNumber) {
729 this.mobileNumber = mobileNumber;
733 * Getter for mobile provider
735 * @return Mobile provider
737 public MobileProvider getMobileProvider () {
738 return this.mobileProvider;
742 * Setter for mobile provider
744 * @param mobileProvider Mobile provider
746 public void setMobileProvider (final MobileProvider mobileProvider) {
747 this.mobileProvider = mobileProvider;
751 * Setter for phone id
755 public Long getPhoneId () {
760 * Getter for phone id
762 * @param phoneId Phone id
764 public void setPhoneId (final Long phoneId) {
765 this.phoneId = phoneId;
769 * Unlinks fax data with current contact
771 * @return Redirect outcome
773 public String unlinkFaxContactData () {
774 // Create fax number instance
775 final DialableFaxNumber number = this.createFaxNumber();
778 if (number == null) {
779 // Not set, throw NPE
780 throw new NullPointerException("number is null"); //NOI18N
781 } else if (number.getPhoneId() == null) {
783 throw new NullPointerException("number.phoneId is null"); //NOI18N
784 } else if (number.getPhoneId() < 1) {
786 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
787 } else if (number.getPhoneNumber() == null) {
789 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
790 } else if (number.getPhoneNumber() < 1) {
791 // Throw it again ...
792 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
793 } else if (this.getContact() == null) {
794 // ... and throw again
795 throw new NullPointerException("this.contact is null"); //NOI18N
796 } else if (this.getContact().getContactId() == null) {
798 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
799 } else if (this.getContact().getContactId() < 1) {
801 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
804 // Init contact instance
805 final Contact updatedContact;
808 // Unlink it and return contact without fax instance
809 updatedContact = this.adminContactPhoneBean.unlinkFaxDataFromContact(this.getContact(), number);
810 } catch (final PhoneNumberNotLinkedException ex) {
812 this.showFacesException("form_unlink_contact_fax:faxNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
817 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, number));
820 return "admin_show_contact"; //NOI18N
824 * Unlinks land-line data with current contact
826 * @return Redirect outcome
828 public String unlinkLandLineContactData () {
829 // Create fax number instance
830 final DialableLandLineNumber number = this.createLandLineNumber();
833 if (number == null) {
834 // Not set, throw NPE
835 throw new NullPointerException("number is null"); //NOI18N
836 } else if (number.getPhoneId() == null) {
838 throw new NullPointerException("number.phoneId is null"); //NOI18N
839 } else if (number.getPhoneId() < 1) {
841 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
842 } else if (number.getPhoneNumber() == null) {
844 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
845 } else if (number.getPhoneNumber() < 1) {
846 // Throw it again ...
847 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
848 } else if (this.getContact() == null) {
849 // ... and throw again
850 throw new NullPointerException("this.contact is null"); //NOI18N
851 } else if (this.getContact().getContactId() == null) {
853 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
854 } else if (this.getContact().getContactId() < 1) {
856 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
859 // Init contact instance
860 final Contact updatedContact;
863 // Unlink it and return contact without landLine instance
864 updatedContact = this.adminContactPhoneBean.unlinkLandLineDataFromContact(this.getContact(), number);
865 } catch (final PhoneNumberNotLinkedException ex) {
867 this.showFacesException("form_unlink_contact_landLine:landLineNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
872 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, number));
875 return "admin_show_contact"; //NOI18N
879 * Unlinks mobile data with current contact
881 * @return Redirect outcome
883 public String unlinkMobileContactData () {
884 // Create fax number instance
885 final DialableMobileNumber number = this.createMobileNumber();
888 if (number == null) {
889 // Not set, throw NPE
890 throw new NullPointerException("number is null"); //NOI18N
891 } else if (number.getPhoneId() == null) {
893 throw new NullPointerException("number.phoneId is null"); //NOI18N
894 } else if (number.getPhoneId() < 1) {
896 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
897 } else if (number.getMobileProvider() == null) {
899 throw new NullPointerException("number.mobileProvider is null"); //NOI18N
900 } else if (number.getMobileProvider().getProviderId() == null) {
902 throw new NullPointerException("number.mobileProvider.providerId is null"); //NOI18N
903 } else if (number.getMobileProvider().getProviderId() < 1) {
905 throw new IllegalArgumentException(MessageFormat.format("number.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
906 } else if (number.getPhoneNumber() == null) {
908 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
909 } else if (number.getPhoneNumber() < 1) {
910 // Throw it again ...
911 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
912 } else if (this.getContact() == null) {
913 // ... and throw again
914 throw new NullPointerException("this.contact is null"); //NOI18N
915 } else if (this.getContact().getContactId() == null) {
917 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
918 } else if (this.getContact().getContactId() < 1) {
920 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
923 // Init contact instance
924 final Contact updatedContact;
927 // Unlink it and return contact without mobile instance
928 updatedContact = this.adminContactPhoneBean.unlinkMobileDataFromContact(this.getContact(), number);
929 } catch (final PhoneNumberNotLinkedException ex) {
931 this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
936 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, number));
939 return "admin_show_contact"; //NOI18N
945 private void clear () {
950 * Creates an instance of a DialableFaxNumber class
952 * @return DialableFaxNumber class
954 private DialableFaxNumber createFaxNumber () {
956 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
958 // Set all other fields
959 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
960 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
962 // Is id number there?
963 if (this.getPhoneId() instanceof Long) {
965 number.setPhoneId(this.getPhoneId());
973 * Returns an instance of a DialableLandLineNumber from all fields stored in
976 * @return An instance of a DialableLandLineNumber class
978 private DialableLandLineNumber createLandLineNumber () {
980 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
982 // Add all other data
983 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
984 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
987 if (this.getPhoneId() instanceof Long) {
989 number.setPhoneId(this.getPhoneId());
997 * Returns an instance of a DialableMobileNumber from all fields stored in
1000 * @return An instance of a DialableMobileNumber class
1002 private DialableMobileNumber createMobileNumber () {
1004 final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
1006 // Add all other data
1007 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
1008 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
1010 // Is id number set?
1011 if (this.getPhoneId() instanceof Long) {
1013 number.setPhoneId(this.getPhoneId());
1021 * Getter for phone entry created
1023 * @param faxNumberEntryCreated Phone entry created
1025 @SuppressWarnings ("ReturnOfDateField")
1026 private Calendar getPhoneEntryCreated () {
1027 return this.phoneEntryCreated;
1031 * Setter for phone entry created
1033 * @param phoneEntryCreated Phone entry created
1035 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1036 private void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
1037 this.phoneEntryCreated = phoneEntryCreated;
1041 * Getter for phone entry updated
1043 * @return Phone entry updated
1045 @SuppressWarnings ("ReturnOfDateField")
1046 private Calendar getPhoneEntryUpdated () {
1047 return this.phoneEntryUpdated;
1051 * Setter for phone entry updated
1053 * @param phoneEntryUpdated Phone entry updated
1055 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1056 private void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
1057 this.phoneEntryUpdated = phoneEntryUpdated;