/*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2022 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
package org.mxchange.jfinancials.beans.contact.phone;
import java.text.MessageFormat;
-import javax.annotation.PostConstruct;
+import java.util.Date;
+import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Any;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
-import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
-import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
-import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
-import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
-import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
-import org.mxchange.jcountry.data.Country;
-import org.mxchange.jfinancials.beans.BaseFinancialsController;
-import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestHelperController;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jfinancials.beans.BaseFinancialsBean;
import org.mxchange.jfinancials.beans.phone.FinancialsAdminPhoneWebRequestController;
-import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
-import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
-import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
-import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
+import org.mxchange.jphone.exceptions.phone.PhoneNumberAlreadyLinkedException;
+import org.mxchange.jphone.exceptions.phone.PhoneNumberNotLinkedException;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
/**
*/
@Named ("adminContactPhoneController")
@RequestScoped
-public class FinancialsAdminContactPhoneWebRequestBean extends BaseFinancialsController implements FinancialsAdminContactPhoneWebRequestController {
+public class FinancialsAdminContactPhoneWebRequestBean extends BaseFinancialsBean implements FinancialsAdminContactPhoneWebRequestController {
/**
* Call-stack instance (5 may show BeanELResolver.getValue as caller)
*/
private static final long serialVersionUID = 542_145_347_916L;
+ /**
+ * Administrative EJB for phone number
+ */
+ @EJB (lookup = "java:global/jfinancials-ejb/adminContactPhone!org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote")
+ private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean;
+
/**
* Event being fired when a fax number has been linked
*/
private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
/**
- * Event being fired when a mobile number has been linked
+ * Administrative phone controller
*/
@Inject
- @Any
- private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
+ private FinancialsAdminPhoneWebRequestController adminPhoneController;
/**
- * Administrative EJB for phone number
+ * Contact instance
*/
- private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
+ private Contact contact;
/**
- * Administrative phone controller
+ * Area code (city dial prefix) for fax number
*/
- @Inject
- private FinancialsAdminPhoneWebRequestController adminPhoneController;
+ private Integer faxAreaCode;
/**
- * Bean helper
+ * Country (for dial prefix) for fax number
*/
- @Inject
- private FinancialsWebRequestHelperController beanHelper;
+ private Country faxCountry;
+
+ /**
+ * Fax number
+ */
+ private Long faxNumber;
/**
* Event being fired when a fax number has been unlinked
@Any
private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
+ /**
+ * Area code (city dial prefix) for land-line number
+ */
+ private Integer landLineAreaCode;
+
+ /**
+ * Country (for dial prefix) for land-line number
+ */
+ private Country landLineCountry;
+
+ /**
+ * Land-line number
+ */
+ private Long landLineNumber;
+
/**
* Event being fired when a land-line number has been unlinked
*/
private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
/**
- * Event being fired when admin unlinks mobile from contact
+ * When phone number has been created
*/
- @Inject
- @Any
- private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
+ private Date phoneEntryCreated;
+
+ /**
+ * When phone number has been updated
+ */
+ private Date phoneEntryUpdated;
+
+ /**
+ * Phone id (primary key)
+ */
+ private Long phoneId;
/**
* Default constructor
* @param event Event being fired
*/
public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Updated contact data event
*/
public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
this.clear();
}
- @Override
- public String doLinkAddFaxNumber (final Contact contact) {
- // Is all data properly set?
- if (null == contact) {
+ /**
+ * Observer for events being fired when a bean helper has successfully
+ * created a contact instance.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
+ // Log message
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
+
+ // The event instance must be valid
+ if (null == event) {
+ // Throw NPE again
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getCreatedContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.createdContact is null"); //NOI18N
+ } else if (event.getCreatedContact().getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N
+ } else if (event.getCreatedContact().getContactId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
+ }
+
+ // Set it here
+ this.setContact(event.getCreatedContact());
+ }
+
+ /**
+ * Observes events being fired when a bean helper has successfully created a
+ * fax number instance.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
+ // The event instance must be valid
+ if (null == event) {
// Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw it again
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Is not valid
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
- } else if ((this.adminPhoneController.getFaxNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
- // All fields are empty
- throw new NullPointerException("faxNumber, mobileProvider and phoneNumer are null"); //NOI18N
- } else if ((this.adminPhoneController.getFaxNumber() instanceof DialableFaxNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
- // All fields are set
- throw new IllegalStateException("faxNumber, mobileProvider and phoneNumer are all set"); //NOI18N
- } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
- // No country selected
- this.showFacesMessage("form_add_contact_fax:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
- return ""; //NOI18N
- } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
- // No area code entered
- this.showFacesMessage("form_add_contact_fax:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
- return ""; //NOI18N
- } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
- // No phone number entered
- this.showFacesMessage("form_add_contact_fax:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
- return ""; //NOI18N
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getFaxNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.faxNumber is null"); //NOI18N
+ } else if (event.getFaxNumber().getPhoneId() == null) {
+ // Throw NPE yet again
+ throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
+ } else if (event.getFaxNumber().getPhoneId() < 1) {
+ // Throw NPE yet again
+ throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
}
- // Init instances
- Contact updatedContact;
- DialableFaxNumber faxNumber = this.adminPhoneController.getFaxNumber();
+ // Get fax number from event
+ final DialableFaxNumber number = event.getFaxNumber();
- // Try it again
- try {
- // All fine so far, then which was choosen?
- if (faxNumber instanceof DialableFaxNumber) {
- // User has choosen number
- updatedContact = this.adminPhoneBean.linkExistingFaxNumberWithContact(contact, faxNumber);
- } else {
- // Create new instance
- faxNumber = new FaxNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
-
- // Link it, too
- updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, faxNumber);
- }
- } catch (final PhoneNumberAlreadyLinkedException ex) {
- // Throw again as cause
- this.showFacesMessage("form_add_contact_fax:phoneNumber", ex); //NOI18N
- return ""; //NOI18N
+ // Copy all data to this bean
+ this.setPhoneId(number.getPhoneId());
+ this.setFaxCountry(number.getPhoneCountry());
+ this.setFaxAreaCode(number.getPhoneAreaCode());
+ this.setFaxNumber(number.getPhoneNumber());
+ this.setPhoneEntryCreated(number.getPhoneEntryCreated());
+ this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
+ }
+
+ /**
+ * Observes events being fired when a bean helper has successfully created a
+ * land-line number instance.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
+ // The event instance must be valid
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getLandLineNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.landLineNumber is null"); //NOI18N
+ } else if (event.getLandLineNumber().getPhoneId() == null) {
+ // Throw NPE yet again
+ throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
+ } else if (event.getLandLineNumber().getPhoneId() < 1) {
+ // Throw NPE yet again
+ throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
}
- // Fire event
- this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, faxNumber));
+ // Get fax number from event
+ final DialableLandLineNumber number = event.getLandLineNumber();
- // Return to contact profile
- return "admin_show_contact"; //NOI18N
+ // Copy all data to this bean
+ this.setPhoneId(number.getPhoneId());
+ this.setLandLineCountry(number.getPhoneCountry());
+ this.setLandLineAreaCode(number.getPhoneAreaCode());
+ this.setLandLineNumber(number.getPhoneNumber());
+ this.setPhoneEntryCreated(number.getPhoneEntryCreated());
+ this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
+ }
+
+ /**
+ * Event observer for updated contact data by the user
+ * <p>
+ * @param event Updated contact data event
+ */
+ public void afterUpdatedContactDataEvent (@Observes final ObservableUpdatedContactEvent event) {
+ // Event and contained entity instance should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedContact is null"); //NOI18N
+ } else if (event.getUpdatedContact().getContactId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
+ } else if (event.getUpdatedContact().getContactId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+ }
+
+ // Clear all data
+ this.clear();
}
- @Override
- public String doLinkAddLandLineNumber (final Contact contact) {
+ /**
+ * Links fax number to contact from bean helper as "main fax number".
+ * <p>
+ * @return Redirect outcome
+ */
+ public String doLinkMainFaxNumber () {
+ // Get contact from helper
+ final Contact targetContact = this.getContact();
+
// Is all data properly set?
- if (null == contact) {
+ if (null == targetContact) {
// Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
+ throw new NullPointerException("targetContact is null"); //NOI18N
+ } else if (targetContact.getContactId() == null) {
// Throw it again
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
+ throw new NullPointerException("targetContact.contactId is null"); //NOI18N
+ } else if (targetContact.getContactId() < 1) {
// Is not valid
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
- } else if ((this.adminPhoneController.getLandLineNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
- // All fields are empty
- throw new NullPointerException("landLineNumber, mobileProvider and phoneNumer are null"); //NOI18N
- } else if ((this.adminPhoneController.getLandLineNumber() instanceof DialableLandLineNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
- // All fields are set
- throw new IllegalStateException("landLineNumber, mobileProvider and phoneNumer are all set"); //NOI18N
- } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
- // No country selected
- this.showFacesMessage("form_add_contact_landLine:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
- return ""; //NOI18N
- } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
- // No area code entered
- this.showFacesMessage("form_add_contact_landLine:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
- return ""; //NOI18N
- } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
- // No phone number entered
- this.showFacesMessage("form_add_contact_landLine:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
- return ""; //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
+ } else if (this.getFaxCountry() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.faxCountry is null"); //NOI18N
+ } else if (this.getFaxCountry().getCountryId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
+ } else if (this.getFaxCountry().getCountryId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
+ } else if (this.getFaxAreaCode() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
+ } else if (this.getFaxAreaCode() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
+ } else if (this.getFaxNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.faxNumber is null"); //NOI18N
+ } else if (this.getFaxNumber() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
}
- // Init instance
- Contact updatedContact;
- DialableLandLineNumber landLineNumber = this.adminPhoneController.getLandLineNumber();
+ // Init instances
+ final Contact updatedContact;
+ final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
// Try it again
try {
- // All fine so far, then which was choosen?
- if (landLineNumber instanceof DialableLandLineNumber) {
- // User has choosen number
- updatedContact = this.adminPhoneBean.linkExistingLandLineNumberWithContact(contact, landLineNumber);
- } else {
- // Create new instance
- landLineNumber = new LandLineNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
-
- // Link it, too
- updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, landLineNumber);
- }
- } catch (final PhoneNumberAlreadyLinkedException ex) {
+ // Link it, too
+ updatedContact = this.adminContactPhoneBean.linkNewFaxNumberWithContact(targetContact, number);
+ } catch (final PhoneNumberAlreadyLinkedException | ContactNotFoundException ex) {
// Throw again as cause
- this.showFacesMessage("form_add_contact_landLine:phoneNumber", ex); //NOI18N
+ this.showFacesMessage("form_add_contact_fax:faxNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
// Fire event
- this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, landLineNumber));
+ this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
// Return to contact profile
return "admin_show_contact"; //NOI18N
}
- @Override
- public String doLinkAddMobileNumber (final Contact contact) {
+ /**
+ * Links land-line number to contact from bean helper as "main land-line
+ * number".
+ * <p>
+ * @return Redirect outcome
+ */
+ public String doLinkMainLandLineNumber () {
+ // Get contact from helper
+ final Contact targetContact = this.getContact();
+
// Is all data properly set?
- if (null == contact) {
+ if (null == targetContact) {
// Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
+ throw new NullPointerException("targetContact is null"); //NOI18N
+ } else if (targetContact.getContactId() == null) {
// Throw it again
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
+ throw new NullPointerException("targetContact.contactId is null"); //NOI18N
+ } else if (targetContact.getContactId() < 1) {
// Is not valid
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
- } else if ((this.adminPhoneController.getMobileNumber() == null) && (this.adminPhoneController.getMobileProvider() == null) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
- // All fields are empty
- throw new NullPointerException("mobileNumber, mobileProvider and phoneNumer are null"); //NOI18N
- } else if ((this.adminPhoneController.getMobileNumber() instanceof DialableMobileNumber) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
- // All fields are set
- throw new IllegalStateException("mobileNumber, mobileProvider and phoneNumer are all set"); //NOI18N
- } else if ((this.adminPhoneController.getMobileProvider() == null) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
- // No mobile provider selected
- this.showFacesMessage("form_add_contact_mobile:phoneCountry", "ERROR_ADMIN_NO_PHONE_MOBILE_PROVIDER_SELECTED"); //NOI18N
- return ""; //NOI18N
- } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider)) {
- // No phone number entered
- this.showFacesMessage("form_add_contact_mobile:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
- return ""; //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
+ } else if (this.getLandLineCountry() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.landLineCountry is null"); //NOI18N
+ } else if (this.getLandLineCountry().getCountryId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
+ } else if (this.getLandLineCountry().getCountryId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
+ } else if (this.getLandLineAreaCode() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
+ } else if (this.getLandLineAreaCode() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
+ } else if (this.getLandLineNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.landLineNumber is null"); //NOI18N
+ } else if (this.getLandLineNumber() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
}
// Init instance
- Contact updatedContact;
- DialableMobileNumber mobileNumber = this.adminPhoneController.getMobileNumber();
+ final Contact updatedContact;
+ final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
// Try it again
try {
- // All fine so far, then which was choosen?
- if (mobileNumber instanceof DialableMobileNumber) {
- // User has choosen number
- updatedContact = this.adminPhoneBean.linkExistingMobileNumberWithContact(contact, mobileNumber);
- } else {
- // Create new instance
- mobileNumber = new MobileNumber(this.adminPhoneController.getMobileProvider(), this.adminPhoneController.getPhoneNumber());
-
- // Link it, too
- updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, mobileNumber);
- }
- } catch (final PhoneNumberAlreadyLinkedException ex) {
+ // Link it, too
+ updatedContact = this.adminContactPhoneBean.linkNewLandLineNumberWithContact(targetContact, number);
+ } catch (final PhoneNumberAlreadyLinkedException | ContactNotFoundException ex) {
// Throw again as cause
- this.showFacesMessage("form_add_contact_mobile:phoneNumber", ex); //NOI18N
+ this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
// Fire event
- this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, mobileNumber));
+ this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
// Return to contact profile
return "admin_show_contact"; //NOI18N
}
/**
- * Post-construction method
+ * Getter for contact instance
+ * <p>
+ * @return Contact instance
*/
- @PostConstruct
- public void init () {
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Try to lookup the beans
- this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
- } catch (final NamingException e) {
- // Throw again
- throw new FaceletException(e);
- }
+ public Contact getContact () {
+ return this.contact;
+ }
+
+ /**
+ * Setter for contact instance
+ * <p>
+ * @param contact Contact instance
+ */
+ public void setContact (final Contact contact) {
+ this.contact = contact;
+ }
+
+ /**
+ * Getter for fax area code
+ * <p>
+ * @return Fax area code
+ */
+ public Integer getFaxAreaCode () {
+ return this.faxAreaCode;
+ }
+
+ /**
+ * Setter for fax area code
+ * <p>
+ * @param faxAreaCode Fax area code
+ */
+ public void setFaxAreaCode (final Integer faxAreaCode) {
+ this.faxAreaCode = faxAreaCode;
+ }
+
+ /**
+ * Getter for fax numbers country
+ * <p>
+ * @return Fax numbers country
+ */
+ public Country getFaxCountry () {
+ return this.faxCountry;
+ }
+
+ /**
+ * Setter for fax numbers country
+ * <p>
+ * @param faxCountry Fax numbers country
+ */
+ public void setFaxCountry (final Country faxCountry) {
+ this.faxCountry = faxCountry;
+ }
+
+ /**
+ * Getter for fax number
+ * <p>
+ * @return Fax number
+ */
+ public Long getFaxNumber () {
+ return this.faxNumber;
+ }
+
+ /**
+ * Setter for fax number
+ * <p>
+ * @param faxNumber Fax number
+ */
+ public void setFaxNumber (final Long faxNumber) {
+ this.faxNumber = faxNumber;
+ }
+
+ /**
+ * Getter for land-line area code
+ * <p>
+ * @return Land-line area code
+ */
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
+ }
+
+ /**
+ * Setter for land-line area code
+ * <p>
+ * @param landLineAreaCode Land-line area code
+ */
+ public void setLandLineAreaCode (final Integer landLineAreaCode) {
+ this.landLineAreaCode = landLineAreaCode;
+ }
+
+ /**
+ * Getter for land-line country
+ * <p>
+ * @return Land-line country
+ */
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
+ }
+
+ /**
+ * Setter for land-line country
+ * <p>
+ * @param landLineCountry Land-line country
+ */
+ public void setLandLineCountry (final Country landLineCountry) {
+ this.landLineCountry = landLineCountry;
+ }
+
+ /**
+ * Getter for land-line number
+ * <p>
+ * @return Land-line number
+ */
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
+ }
+
+ /**
+ * Setter for land-line number
+ * <p>
+ * @param landLineNumber Land-line number
+ */
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
+ }
+
+ /**
+ * Setter for phone id
+ * <p>
+ * @return Phone id
+ */
+ public Long getPhoneId () {
+ return this.phoneId;
}
- @Override
+ /**
+ * Getter for phone id
+ * <p>
+ * @param phoneId Phone id
+ */
+ public void setPhoneId (final Long phoneId) {
+ this.phoneId = phoneId;
+ }
+
+ /**
+ * Unlinks fax data with current contact
+ * <p>
+ * @return Redirect outcome
+ */
public String unlinkFaxContactData () {
+ // Create fax number instance
+ final DialableFaxNumber number = this.createFaxNumber();
+
// Is all data set
- if (this.beanHelper.getFaxNumber() == null) {
+ if (number == null) {
// Not set, throw NPE
- throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
- } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
+ throw new NullPointerException("number is null"); //NOI18N
+ } else if (number.getPhoneId() == null) {
// Throw NPE again
- throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
- } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
+ throw new NullPointerException("number.phoneId is null"); //NOI18N
+ } else if (number.getPhoneId() < 1) {
// Invalid number
- throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
- } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
+ throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
+ } else if (number.getPhoneNumber() == null) {
// Throw NPE again
- throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
- } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
+ throw new NullPointerException("number.phoneNumber is null"); //NOI18N
+ } else if (number.getPhoneNumber() < 1) {
// Throw it again ...
- throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
- } else if (this.beanHelper.getContact() == null) {
+ throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
+ } else if (this.getContact() == null) {
// ... and throw again
- throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
- } else if (this.beanHelper.getContact().getContactId() == null) {
+ throw new NullPointerException("this.contact is null"); //NOI18N
+ } else if (this.getContact().getContactId() == null) {
// ... and again ...
- throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
- } else if (this.beanHelper.getContact().getContactId() < 1) {
+ throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+ } else if (this.getContact().getContactId() < 1) {
// Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
}
// Init contact instance
- Contact updatedContact;
+ final Contact updatedContact;
try {
// Unlink it and return contact without fax instance
- updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
- } catch (final PhoneNumberNotLinkedException ex) {
+ updatedContact = this.adminContactPhoneBean.unlinkFaxDataFromContact(this.getContact(), number);
+ } catch (final PhoneNumberNotLinkedException | ContactNotFoundException ex) {
// Did not work
- this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
+ this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
// Fire event
- this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber()));
+ this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, number));
// All fine here
return "admin_show_contact"; //NOI18N
}
- @Override
+ /**
+ * Unlinks land-line data with current contact
+ * <p>
+ * @return Redirect outcome
+ */
public String unlinkLandLineContactData () {
+ // Create fax number instance
+ final DialableLandLineNumber number = this.createLandLineNumber();
+
// Is all data set
- if (this.beanHelper.getLandLineNumber() == null) {
+ if (number == null) {
// Not set, throw NPE
- throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
- } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
+ throw new NullPointerException("number is null"); //NOI18N
+ } else if (number.getPhoneId() == null) {
// Throw NPE again
- throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
- } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
+ throw new NullPointerException("number.phoneId is null"); //NOI18N
+ } else if (number.getPhoneId() < 1) {
// Invalid number
- throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
- } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
+ throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
+ } else if (number.getPhoneNumber() == null) {
// Throw NPE again
- throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
- } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
+ throw new NullPointerException("number.phoneNumber is null"); //NOI18N
+ } else if (number.getPhoneNumber() < 1) {
// Throw it again ...
- throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
- } else if (this.beanHelper.getContact() == null) {
+ throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
+ } else if (this.getContact() == null) {
// ... and throw again
- throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
- } else if (this.beanHelper.getContact().getContactId() == null) {
+ throw new NullPointerException("this.contact is null"); //NOI18N
+ } else if (this.getContact().getContactId() == null) {
// ... and again ...
- throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
- } else if (this.beanHelper.getContact().getContactId() < 1) {
+ throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+ } else if (this.getContact().getContactId() < 1) {
// Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
}
// Init contact instance
- Contact updatedContact;
+ final Contact updatedContact;
try {
// Unlink it and return contact without landLine instance
- updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
- } catch (final PhoneNumberNotLinkedException ex) {
+ updatedContact = this.adminContactPhoneBean.unlinkLandLineDataFromContact(this.getContact(), number);
+ } catch (final PhoneNumberNotLinkedException | ContactNotFoundException ex) {
// Did not work
- this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
+ this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
// Fire event
- this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber()));
+ this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, number));
// All fine here
return "admin_show_contact"; //NOI18N
}
- @Override
- public String unlinkMobileContactData () {
- // Is all data set
- if (this.beanHelper.getMobileNumber() == null) {
- // Not set, throw NPE
- throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N
- } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) {
- // Throw NPE again
- throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N
- } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N
- } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) {
- // Throw NPE
- throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N
- } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) {
- // ... throw again
- throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N
- } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) {
- // Id not valid
- throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
- } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N
- } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) {
- // Throw it again ...
- throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N
- } else if (this.beanHelper.getContact() == null) {
- // ... and throw again
- throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
- } else if (this.beanHelper.getContact().getContactId() == null) {
- // ... and again ...
- throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
- } else if (this.beanHelper.getContact().getContactId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
- }
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data
+ }
- // Init contact instance
- Contact updatedContact;
+ /**
+ * Creates an instance of a DialableFaxNumber class
+ * <p>
+ * @return DialableFaxNumber class
+ */
+ private DialableFaxNumber createFaxNumber () {
+ // Instanciate it
+ final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
- try {
- // Unlink it and return contact without mobile instance
- updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber());
- } catch (final PhoneNumberNotLinkedException ex) {
- // Did not work
- this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
- return ""; //NOI18N
- }
+ // Set all other fields
+ number.setPhoneEntryCreated(this.getPhoneEntryCreated());
+ number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
+ number.setPhoneId(this.getPhoneId());
- // Fire event
- this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber()));
+ // Return it
+ return number;
+ }
- // All fine here
- return "admin_show_contact"; //NOI18N
+ /**
+ * Returns an instance of a DialableLandLineNumber from all fields stored in
+ * this bean.
+ * <p>
+ * @return An instance of a DialableLandLineNumber class
+ */
+ private DialableLandLineNumber createLandLineNumber () {
+ // Initialize it
+ final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+
+ // Add all other data
+ number.setPhoneEntryCreated(this.getPhoneEntryCreated());
+ number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
+ number.setPhoneId(this.getPhoneId());
+
+ // Return it
+ return number;
}
/**
- * Clears this bean
+ * Getter for phone entry created
+ * <p>
+ * @return Phone entry created
*/
- private void clear () {
- // Clear all data
+ @SuppressWarnings ("ReturnOfDateField")
+ private Date getPhoneEntryCreated () {
+ return this.phoneEntryCreated;
+ }
+
+ /**
+ * Setter for phone entry created
+ * <p>
+ * @param phoneEntryCreated Phone entry created
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ private void setPhoneEntryCreated (final Date phoneEntryCreated) {
+ this.phoneEntryCreated = phoneEntryCreated;
+ }
+
+ /**
+ * Getter for phone entry updated
+ * <p>
+ * @return Phone entry updated
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ private Date getPhoneEntryUpdated () {
+ return this.phoneEntryUpdated;
+ }
+
+ /**
+ * Setter for phone entry updated
+ * <p>
+ * @param phoneEntryUpdated Phone entry updated
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ private void setPhoneEntryUpdated (final Date phoneEntryUpdated) {
+ this.phoneEntryUpdated = phoneEntryUpdated;
}
}