2 * Copyright (C) 2016 - 2020 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.exceptions.PhoneNumberAlreadyLinkedException;
50 import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
51 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
52 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
53 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
54 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
55 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
56 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
57 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
58 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
59 import org.mxchange.pizzaapplication.beans.BasePizzaBean;
60 import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
63 * An administrative contact phone controller (bean)
65 * @author Roland Häder<roland@mxchange.org>
67 @Named ("adminContactPhoneController")
69 public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaBean implements PizzaAdminContactPhoneWebRequestController {
72 * Call-stack instance (5 may show BeanELResolver.getValue as caller)
74 private static final short THREAD_STACK = 5;
79 private static final long serialVersionUID = 542_145_347_916L;
82 * Administrative EJB for phone number
84 @EJB (lookup = "java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote")
85 private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean;
88 * Event being fired when a fax number has been linked
92 private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
95 * Event being fired when a land-line number has been linked
99 private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
102 * Event being fired when a mobile number has been linked
106 private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
109 * Administrative phone controller
112 private PizzaAdminPhoneWebRequestController adminPhoneController;
117 private Contact contact;
120 * Area code (city dial prefix) for fax number
122 private Integer faxAreaCode;
125 * Country (for dial prefix) for fax number
127 private Country faxCountry;
132 private Long faxNumber;
135 * Event being fired when a fax number has been unlinked
139 private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
142 * Area code (city dial prefix) for land-line number
144 private Integer landLineAreaCode;
147 * Country (for dial prefix) for land-line number
149 private Country landLineCountry;
154 private Long landLineNumber;
157 * Event being fired when a land-line number has been unlinked
161 private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
166 private Long mobileNumber;
169 * Event being fired when admin unlinks mobile from contact
173 private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
178 private MobileProvider mobileProvider;
181 * When fax number has been created
183 private Calendar phoneEntryCreated;
186 * When fax number has been updated
188 private Calendar phoneEntryUpdated;
191 * Phone id (primary key)
193 private Long phoneId;
196 * Default constructor
198 public PizzaAdminContactPhoneWebRequestBean () {
199 // Call super constructor
202 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
203 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
207 * Observes events being fired when an administrator has added a new
210 * @param event Event being fired
212 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
213 // The event must be valid
216 throw new NullPointerException("event is null"); //NOI18N
217 } else if (event.getAddedContact() == null) {
219 throw new NullPointerException("event.addedContact is null"); //NOI18N
220 } else if (event.getAddedContact().getContactId() == null) {
222 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
223 } else if (event.getAddedContact().getContactId() < 1) {
225 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
233 * Event observer for newly added users by administrator
235 * @param event Event being fired
237 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
238 // event should not be null
241 throw new NullPointerException("event is null"); //NOI18N
242 } else if (event.getAddedUser() == null) {
244 throw new NullPointerException("event.addedUser is null"); //NOI18N
245 } else if (event.getAddedUser().getUserId() == null) {
247 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
248 } else if (event.getAddedUser().getUserId() < 1) {
250 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
258 * Event observer for updated contact data by administrators
260 * @param event Updated contact data event
262 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
263 // event should not be null
266 throw new NullPointerException("event is null"); //NOI18N
267 } else if (event.getUpdatedContact() == null) {
269 throw new NullPointerException("event.updatedContact is null"); //NOI18N
270 } else if (event.getUpdatedContact().getContactId() == null) {
272 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
273 } else if (event.getUpdatedContact().getContactId() < 1) {
275 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
283 * Observer for events being fired when a bean helper has successfully
284 * created a contact instance.
286 * @param event Event being fired
288 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
290 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
292 // The event instance must be valid
295 throw new NullPointerException("event is null"); //NOI18N
296 } else if (event.getCreatedContact() == null) {
298 throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
299 } else if (event.getCreatedContact().getContactId() == null) {
301 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
302 } else if (event.getCreatedContact().getContactId() < 1) {
304 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
308 this.setContact(event.getCreatedContact());
312 * Observes events being fired when a bean helper has successfully created a
313 * fax number instance.
315 * @param event Event being fired
317 public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
318 // The event instance must be valid
321 throw new NullPointerException("event is null"); //NOI18N
322 } else if (event.getFaxNumber() == null) {
324 throw new NullPointerException("event.faxNumber is null"); //NOI18N
325 } else if (event.getFaxNumber().getPhoneId() == null) {
326 // Throw NPE yet again
327 throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
328 } else if (event.getFaxNumber().getPhoneId() < 1) {
329 // Throw NPE yet again
330 throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
333 // Get fax number from event
334 final DialableFaxNumber number = event.getFaxNumber();
336 // Copy all data to this bean
337 this.setPhoneId(number.getPhoneId());
338 this.setFaxCountry(number.getPhoneCountry());
339 this.setFaxAreaCode(number.getPhoneAreaCode());
340 this.setFaxNumber(number.getPhoneNumber());
341 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
342 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
346 * Observes events being fired when a bean helper has successfully created a
347 * land-line number instance.
349 * @param event Event being fired
351 public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
352 // The event instance must be valid
355 throw new NullPointerException("event is null"); //NOI18N
356 } else if (event.getLandLineNumber() == null) {
358 throw new NullPointerException("event.landLineNumber is null"); //NOI18N
359 } else if (event.getLandLineNumber().getPhoneId() == null) {
360 // Throw NPE yet again
361 throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
362 } else if (event.getLandLineNumber().getPhoneId() < 1) {
363 // Throw NPE yet again
364 throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
367 // Get fax number from event
368 final DialableLandLineNumber number = event.getLandLineNumber();
370 // Copy all data to this bean
371 this.setPhoneId(number.getPhoneId());
372 this.setLandLineCountry(number.getPhoneCountry());
373 this.setLandLineAreaCode(number.getPhoneAreaCode());
374 this.setLandLineNumber(number.getPhoneNumber());
375 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
376 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
380 * Observes events being fired when a bean helper has successfully created a
381 * mobile number instance.
383 * @param event Event being fired
385 public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
386 // The event instance must be valid
389 throw new NullPointerException("event is null"); //NOI18N
390 } else if (event.getMobileNumber() == null) {
392 throw new NullPointerException("event.mobileNumber is null"); //NOI18N
393 } else if (event.getMobileNumber().getPhoneId() == null) {
394 // Throw NPE yet again
395 throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
396 } else if (event.getMobileNumber().getPhoneId() < 1) {
397 // Throw NPE yet again
398 throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
401 // Get fax number from event
402 final DialableMobileNumber number = event.getMobileNumber();
404 // Copy all data to this bean
405 this.setPhoneId(number.getPhoneId());
406 this.setMobileProvider(number.getMobileProvider());
407 this.setMobileNumber(number.getPhoneNumber());
408 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
409 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
413 * Links fax number to contact from bean helper as "main fax number".
415 * @return Redirect outcome
417 public String doLinkMainFaxNumber () {
418 // Get contact from helper
419 final Contact targetContact = this.getContact();
421 // Is all data properly set?
422 if (null == targetContact) {
424 throw new NullPointerException("targetContact is null"); //NOI18N
425 } else if (targetContact.getContactId() == null) {
427 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
428 } else if (targetContact.getContactId() < 1) {
430 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
431 } else if (this.getFaxCountry() == null) {
433 throw new NullPointerException("this.faxCountry is null"); //NOI18N
434 } else if (this.getFaxCountry().getCountryId() == null) {
436 throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
437 } else if (this.getFaxCountry().getCountryId() < 1) {
439 throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
440 } else if (this.getFaxAreaCode() == null) {
442 throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
443 } else if (this.getFaxAreaCode() < 1) {
445 throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
446 } else if (this.getFaxNumber() == null) {
448 throw new NullPointerException("this.faxNumber is null"); //NOI18N
449 } else if (this.getFaxNumber() < 1) {
451 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
455 final Contact updatedContact;
456 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
461 updatedContact = this.adminContactPhoneBean.linkNewFaxNumberWithContact(targetContact, number);
462 } catch (final PhoneNumberAlreadyLinkedException ex) {
463 // Throw again as cause
464 this.showFacesMessage("form_add_contact_fax:faxNumber", ex); //NOI18N
469 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
471 // Return to contact profile
472 return "admin_show_contact"; //NOI18N
476 * Links land-line number to contact from bean helper as "main land-line
479 * @return Redirect outcome
481 public String doLinkMainLandLineNumber () {
482 // Get contact from helper
483 final Contact targetContact = this.getContact();
485 // Is all data properly set?
486 if (null == targetContact) {
488 throw new NullPointerException("targetContact is null"); //NOI18N
489 } else if (targetContact.getContactId() == null) {
491 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
492 } else if (targetContact.getContactId() < 1) {
494 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
495 } else if (this.getLandLineCountry() == null) {
497 throw new NullPointerException("this.landLineCountry is null"); //NOI18N
498 } else if (this.getLandLineCountry().getCountryId() == null) {
500 throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
501 } else if (this.getLandLineCountry().getCountryId() < 1) {
503 throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
504 } else if (this.getLandLineAreaCode() == null) {
506 throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
507 } else if (this.getLandLineAreaCode() < 1) {
509 throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
510 } else if (this.getLandLineNumber() == null) {
512 throw new NullPointerException("this.landLineNumber is null"); //NOI18N
513 } else if (this.getLandLineNumber() < 1) {
515 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
519 final Contact updatedContact;
520 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
525 updatedContact = this.adminContactPhoneBean.linkNewLandLineNumberWithContact(targetContact, number);
526 } catch (final PhoneNumberAlreadyLinkedException ex) {
527 // Throw again as cause
528 this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex); //NOI18N
533 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
535 // Return to contact profile
536 return "admin_show_contact"; //NOI18N
540 * Links mobile number to contact from bean helper as "main mobile number".
542 * @return Redirect outcome
544 public String doLinkMainMobileNumber () {
545 // Get contact from helper
546 final Contact targetContact = this.getContact();
548 // Is all data properly set?
549 if (null == targetContact) {
551 throw new NullPointerException("targetContact is null"); //NOI18N
552 } else if (targetContact.getContactId() == null) {
554 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
555 } else if (targetContact.getContactId() < 1) {
557 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
558 } else if (this.getMobileProvider() == null) {
560 throw new NullPointerException("this.mobileProvider is null"); //NOI18N
561 } else if (this.getMobileProvider().getProviderId() == null) {
563 throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
564 } else if (this.getMobileProvider().getProviderId() < 1) {
566 throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N
567 } else if (this.getMobileNumber() == null) {
569 throw new NullPointerException("this.mobileNumber is null"); //NOI18N
570 } else if (this.getMobileNumber() < 1) {
572 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N
576 final Contact updatedContact;
577 final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
582 updatedContact = this.adminContactPhoneBean.linkNewMobileNumberWithContact(targetContact, number);
583 } catch (final PhoneNumberAlreadyLinkedException ex) {
584 // Throw again as cause
585 this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex); //NOI18N
590 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number));
592 // Return to contact profile
593 return "admin_show_contact"; //NOI18N
597 * Getter for contact instance
599 * @return Contact instance
601 public Contact getContact () {
606 * Setter for contact instance
608 * @param contact Contact instance
610 public void setContact (final Contact contact) {
611 this.contact = contact;
615 * Getter for fax area code
617 * @return Fax area code
619 public Integer getFaxAreaCode () {
620 return this.faxAreaCode;
624 * Setter for fax area code
626 * @param faxAreaCode Fax area code
628 public void setFaxAreaCode (final Integer faxAreaCode) {
629 this.faxAreaCode = faxAreaCode;
633 * Getter for fax numbers country
635 * @return Fax numbers country
637 public Country getFaxCountry () {
638 return this.faxCountry;
642 * Setter for fax numbers country
644 * @param faxCountry Fax numbers country
646 public void setFaxCountry (final Country faxCountry) {
647 this.faxCountry = faxCountry;
651 * Getter for fax number
655 public Long getFaxNumber () {
656 return this.faxNumber;
660 * Setter for fax number
662 * @param faxNumber Fax number
664 public void setFaxNumber (final Long faxNumber) {
665 this.faxNumber = faxNumber;
669 * Getter for land-line area code
671 * @return Land-line area code
673 public Integer getLandLineAreaCode () {
674 return this.landLineAreaCode;
678 * Setter for land-line area code
680 * @param landLineAreaCode Land-line area code
682 public void setLandLineAreaCode (final Integer landLineAreaCode) {
683 this.landLineAreaCode = landLineAreaCode;
687 * Getter for land-line country
689 * @return Land-line country
691 public Country getLandLineCountry () {
692 return this.landLineCountry;
696 * Setter for land-line country
698 * @param landLineCountry Land-line country
700 public void setLandLineCountry (final Country landLineCountry) {
701 this.landLineCountry = landLineCountry;
705 * Getter for land-line number
707 * @return Land-line number
709 public Long getLandLineNumber () {
710 return this.landLineNumber;
714 * Setter for land-line number
716 * @param landLineNumber Land-line number
718 public void setLandLineNumber (final Long landLineNumber) {
719 this.landLineNumber = landLineNumber;
723 * Getter for mobile number
725 * @return Mobile number
727 public Long getMobileNumber () {
728 return this.mobileNumber;
732 * Setter for mobile number
734 * @param mobileNumber Mobile number
736 public void setMobileNumber (final Long mobileNumber) {
737 this.mobileNumber = mobileNumber;
741 * Getter for mobile provider
743 * @return Mobile provider
745 public MobileProvider getMobileProvider () {
746 return this.mobileProvider;
750 * Setter for mobile provider
752 * @param mobileProvider Mobile provider
754 public void setMobileProvider (final MobileProvider mobileProvider) {
755 this.mobileProvider = mobileProvider;
759 * Setter for phone id
763 public Long getPhoneId () {
768 * Getter for phone id
770 * @param phoneId Phone id
772 public void setPhoneId (final Long phoneId) {
773 this.phoneId = phoneId;
777 * Unlinks fax data with current contact
779 * @return Redirect outcome
781 public String unlinkFaxContactData () {
782 // Create fax number instance
783 final DialableFaxNumber number = this.createFaxNumber();
786 if (number == null) {
787 // Not set, throw NPE
788 throw new NullPointerException("number is null"); //NOI18N
789 } else if (number.getPhoneId() == null) {
791 throw new NullPointerException("number.phoneId is null"); //NOI18N
792 } else if (number.getPhoneId() < 1) {
794 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
795 } else if (number.getPhoneNumber() == null) {
797 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
798 } else if (number.getPhoneNumber() < 1) {
799 // Throw it again ...
800 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
801 } else if (this.getContact() == null) {
802 // ... and throw again
803 throw new NullPointerException("this.contact is null"); //NOI18N
804 } else if (this.getContact().getContactId() == null) {
806 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
807 } else if (this.getContact().getContactId() < 1) {
809 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
812 // Init contact instance
813 final Contact updatedContact;
816 // Unlink it and return contact without fax instance
817 updatedContact = this.adminContactPhoneBean.unlinkFaxDataFromContact(this.getContact(), number);
818 } catch (final PhoneNumberNotLinkedException ex) {
820 this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
825 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, number));
828 return "admin_show_contact"; //NOI18N
832 * Unlinks land-line data with current contact
834 * @return Redirect outcome
836 public String unlinkLandLineContactData () {
837 // Create fax number instance
838 final DialableLandLineNumber number = this.createLandLineNumber();
841 if (number == null) {
842 // Not set, throw NPE
843 throw new NullPointerException("number is null"); //NOI18N
844 } else if (number.getPhoneId() == null) {
846 throw new NullPointerException("number.phoneId is null"); //NOI18N
847 } else if (number.getPhoneId() < 1) {
849 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
850 } else if (number.getPhoneNumber() == null) {
852 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
853 } else if (number.getPhoneNumber() < 1) {
854 // Throw it again ...
855 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
856 } else if (this.getContact() == null) {
857 // ... and throw again
858 throw new NullPointerException("this.contact is null"); //NOI18N
859 } else if (this.getContact().getContactId() == null) {
861 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
862 } else if (this.getContact().getContactId() < 1) {
864 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
867 // Init contact instance
868 final Contact updatedContact;
871 // Unlink it and return contact without landLine instance
872 updatedContact = this.adminContactPhoneBean.unlinkLandLineDataFromContact(this.getContact(), number);
873 } catch (final PhoneNumberNotLinkedException ex) {
875 this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
880 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, number));
883 return "admin_show_contact"; //NOI18N
887 * Unlinks mobile data with current contact
889 * @return Redirect outcome
891 public String unlinkMobileContactData () {
892 // Create fax number instance
893 final DialableMobileNumber number = this.createMobileNumber();
896 if (number == null) {
897 // Not set, throw NPE
898 throw new NullPointerException("number is null"); //NOI18N
899 } else if (number.getPhoneId() == null) {
901 throw new NullPointerException("number.phoneId is null"); //NOI18N
902 } else if (number.getPhoneId() < 1) {
904 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
905 } else if (number.getMobileProvider() == null) {
907 throw new NullPointerException("number.mobileProvider is null"); //NOI18N
908 } else if (number.getMobileProvider().getProviderId() == null) {
910 throw new NullPointerException("number.mobileProvider.providerId is null"); //NOI18N
911 } else if (number.getMobileProvider().getProviderId() < 1) {
913 throw new IllegalArgumentException(MessageFormat.format("number.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
914 } else if (number.getPhoneNumber() == null) {
916 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
917 } else if (number.getPhoneNumber() < 1) {
918 // Throw it again ...
919 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
920 } else if (this.getContact() == null) {
921 // ... and throw again
922 throw new NullPointerException("this.contact is null"); //NOI18N
923 } else if (this.getContact().getContactId() == null) {
925 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
926 } else if (this.getContact().getContactId() < 1) {
928 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
931 // Init contact instance
932 final Contact updatedContact;
935 // Unlink it and return contact without mobile instance
936 updatedContact = this.adminContactPhoneBean.unlinkMobileDataFromContact(this.getContact(), number);
937 } catch (final PhoneNumberNotLinkedException ex) {
939 this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
944 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, number));
947 return "admin_show_contact"; //NOI18N
953 private void clear () {
958 * Creates an instance of a DialableFaxNumber class
960 * @return DialableFaxNumber class
962 private DialableFaxNumber createFaxNumber () {
964 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
966 // Set all other fields
967 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
968 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
970 // Is id number there?
971 if (this.getPhoneId() instanceof Long) {
973 number.setPhoneId(this.getPhoneId());
981 * Returns an instance of a DialableLandLineNumber from all fields stored in
984 * @return An instance of a DialableLandLineNumber class
986 private DialableLandLineNumber createLandLineNumber () {
988 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
990 // Add all other data
991 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
992 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
995 if (this.getPhoneId() instanceof Long) {
997 number.setPhoneId(this.getPhoneId());
1005 * Returns an instance of a DialableMobileNumber from all fields stored in
1008 * @return An instance of a DialableMobileNumber class
1010 private DialableMobileNumber createMobileNumber () {
1012 final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
1014 // Add all other data
1015 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
1016 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
1018 // Is id number set?
1019 if (this.getPhoneId() instanceof Long) {
1021 number.setPhoneId(this.getPhoneId());
1029 * Getter for phone entry created
1031 * @param faxNumberEntryCreated Phone entry created
1033 @SuppressWarnings ("ReturnOfDateField")
1034 private Calendar getPhoneEntryCreated () {
1035 return this.phoneEntryCreated;
1039 * Setter for phone entry created
1041 * @param phoneEntryCreated Phone entry created
1043 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1044 private void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
1045 this.phoneEntryCreated = phoneEntryCreated;
1049 * Getter for phone entry updated
1051 * @return Phone entry updated
1053 @SuppressWarnings ("ReturnOfDateField")
1054 private Calendar getPhoneEntryUpdated () {
1055 return this.phoneEntryUpdated;
1059 * Setter for phone entry updated
1061 * @param phoneEntryUpdated Phone entry updated
1063 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1064 private void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
1065 this.phoneEntryUpdated = phoneEntryUpdated;