package org.mxchange.jjobs.beans.phone;
import java.text.MessageFormat;
+import java.util.Calendar;
import java.util.List;
-import java.util.Locale;
-import java.util.MissingResourceException;
import java.util.Objects;
-import java.util.ResourceBundle;
-import javax.annotation.PostConstruct;
+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.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
import org.mxchange.jcountry.data.Country;
import org.mxchange.jjobs.beans.BaseJobsController;
-import org.mxchange.jjobs.beans.helper.JobsWebRequestHelperController;
+import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
import org.mxchange.jphone.events.fax.deleted.AdminFaxNumberDeletedEvent;
import org.mxchange.jphone.events.fax.removed.AdminFaxNumberRemovedFromListEvent;
import org.mxchange.jphone.events.fax.removed.AdminRemoveFaxNumberFromListEvent;
import org.mxchange.jphone.events.fax.updated.AdminFaxNumberUpdatedEvent;
import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
import org.mxchange.jphone.events.landline.deleted.AdminLandLineNumberDeletedEvent;
import org.mxchange.jphone.events.landline.removed.AdminLandLineNumberRemovedFromListEvent;
import org.mxchange.jphone.events.landline.removed.AdminRemoveLandLineNumberFromListEvent;
import org.mxchange.jphone.events.landline.updated.AdminLandLineNumberUpdatedEvent;
import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
+import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
import org.mxchange.jphone.events.mobile.deleted.AdminMobileNumberDeletedEvent;
import org.mxchange.jphone.events.mobile.remove.AdminMobileNumberRemovedFromListEvent;
import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent;
import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
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.phonenumbers.phone.AdminPhoneSessionBeanRemote;
*/
@Named ("adminPhoneController")
@RequestScoped
-public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController implements JobsAdminPhoneWebRequestController {
+public class JobsAdminPhoneWebRequestBean extends BaseJobsController implements JobsAdminPhoneWebRequestController {
/**
* Call-stack position
/**
* Remote EJB for phone number (administrative)
*/
+ @EJB (lookup = "java:global/jjobs-ejb/adminPhone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote")
private AdminPhoneSessionBeanRemote adminPhoneBean;
- /**
- * Bean helper
- */
- @Inject
- private JobsWebRequestHelperController beanHelper;
-
/**
* fax number
*/
*/
private Country phoneCountry;
+ /**
+ * When the phone entry has been created (persisted)
+ */
+ private Calendar phoneEntryCreated;
+
+ /**
+ * When the phone entry has been updated
+ */
+ private Calendar phoneEntryUpdated;
+
+ /**
+ * Phone id (aka primary key)
+ */
+ private Long phoneId;
+
/**
* Phone number
*/
// System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
}
+ /**
+ * 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("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
+ }
+
+ // Get fax number from event
+ DialableFaxNumber number = event.getFaxNumber();
+
+ // Copy all data to this bean
+ this.setPhoneId(number.getPhoneId());
+ this.setPhoneCountry(number.getPhoneCountry());
+ this.setPhoneAreaCode(number.getPhoneAreaCode());
+ this.setPhoneNumber(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
+ }
+
+ // Get fax number from event
+ DialableLandLineNumber number = event.getLandLineNumber();
+
+ // Copy all data to this bean
+ this.setPhoneId(number.getPhoneId());
+ this.setPhoneCountry(number.getPhoneCountry());
+ this.setPhoneAreaCode(number.getPhoneAreaCode());
+ this.setPhoneNumber(number.getPhoneNumber());
+ this.setPhoneEntryCreated(number.getPhoneEntryCreated());
+ this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
+ }
+
+ /**
+ * Observes events being fired when a bean helper has successfully created a
+ * mobile number instance.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
+ // The event instance must be valid
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getMobileNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.mobileNumber is null"); //NOI18N
+ } else if (event.getMobileNumber().getPhoneId() == null) {
+ // Throw NPE yet again
+ throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
+ } else if (event.getMobileNumber().getPhoneId() < 1) {
+ // Throw NPE yet again
+ throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
+ }
+
+ // Get fax number from event
+ DialableMobileNumber number = event.getMobileNumber();
+
+ // Copy all data to this bean
+ this.setPhoneId(number.getPhoneId());
+ this.setMobileProvider(number.getMobileProvider());
+ this.setPhoneNumber(number.getPhoneNumber());
+ this.setPhoneEntryCreated(number.getPhoneEntryCreated());
+ this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
+ }
+
/**
* Returns a list of all unused ("non-linked") land-line numbers
* <p>
*/
public String deleteFaxData () {
// Get fax number from bean helper
- DialableFaxNumber number = this.beanHelper.getFaxNumber();
+ DialableFaxNumber number = this.createFaxNumber();
// Is all data set
if (number == null) {
*/
public String deleteLandLineData () {
// Get land-line number from helper
- DialableLandLineNumber number = this.beanHelper.getLandLineNumber();
+ DialableLandLineNumber number = this.createLandLineNumber();
// Is all data set
if (number == null) {
*/
public String deleteMobileData () {
// Get mobile number from helper
- DialableMobileNumber number = this.beanHelper.getMobileNumber();
+ DialableMobileNumber number = this.createMobileNumber();
// Is all data set
if (number == null) {
*/
public String doChangeFaxNumber () {
// Get fax number from bean helper
- DialableFaxNumber number = this.beanHelper.getFaxNumber();
+ DialableFaxNumber number = this.createFaxNumber();
// Is all data set
if (number == null) {
*/
public String doChangeLandLineNumber () {
// Get land-line number from helper
- DialableLandLineNumber number = this.beanHelper.getLandLineNumber();
+ DialableLandLineNumber number = this.createLandLineNumber();
// Is all data set
if (number == null) {
*/
public String doUpdateMobileNumber () {
// Get mobile number from helper
- DialableMobileNumber number = this.beanHelper.getMobileNumber();
+ DialableMobileNumber number = this.createMobileNumber();
// Is all data set
if (number == null) {
}
/**
- * Getter for dial number without prefix
+ * Getter for phone entry created timestamp
* <p>
- * @return Dial number without prefix
+ * @return Phone entry created timestamp
*/
- public Long getPhoneNumber () {
- return this.phoneNumber;
+ @SuppressWarnings ("ReturnOfDateField")
+ public Calendar getPhoneEntryCreated () {
+ return this.phoneEntryCreated;
}
/**
- * Setter for dial number without prefix
+ * Setter for phone entry created timestamp
* <p>
- * @param phoneNumber Dial number without prefix
+ * @param phoneEntryCreated Phone entry created timestamp
*/
- public void setPhoneNumber (final Long phoneNumber) {
- this.phoneNumber = phoneNumber;
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
+ this.phoneEntryCreated = phoneEntryCreated;
}
/**
- * Post-construction method
+ * Getter for phone entry updated timestamp
+ * <p>
+ * @return Phone entry updated timestamp
*/
- @PostConstruct
- public void init () {
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Try to lookup the beans
- this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminPhone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N
- } catch (final NamingException e) {
- // Throw it again
- throw new FaceletException(e);
- }
+ @SuppressWarnings ("ReturnOfDateField")
+ public Calendar getPhoneEntryUpdated () {
+ return this.phoneEntryUpdated;
}
/**
- * Returns given property key or throws an exception if not found.
+ * Setter for phone entry updated timestamp
* <p>
- * @param parameterKey Property key
- * <p>
- * @return Property value
- * <p>
- * @throws NullPointerException If given key is not found
- * @throws NumberFormatException If no number is given in context parameter
+ * @param phoneEntryUpdated Phone entry updated timestamp
*/
- protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException {
- // Get context parameter
- Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey));
- // Return it
- return contextValue;
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
+ this.phoneEntryUpdated = phoneEntryUpdated;
}
/**
- * Returns given property key or throws an exception if not found.
+ * Getter for phone id
* <p>
- * @param parameterKey Property key
- * <p>
- * @return Property value
- * <p>
- * @throws NullPointerException If given key is not found
+ * @return Phone id
*/
- protected String getStringContextParameter (final String parameterKey) throws NullPointerException {
- // Get context parameter
- String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey);
- // Is it null?
- if (null == contextValue) {
- // Throw NPE
- throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N
- }
- // Return it
- return contextValue;
+ public Long getPhoneId () {
+ return this.phoneId;
}
/**
- * Checks whether debug mode is enabled for given controller
- * <p>
- * @param controllerName Name of controller
+ * Setter for phone id
* <p>
- * @return Whether debug mode is enabled
+ * @param phoneId Phone id
*/
- protected boolean isDebugModeEnabled (final String controllerName) {
- // Parameters should be valid
- if (null == controllerName) {
- // Throw NPE
- throw new NullPointerException("controllerName is null"); //NOI18N
- } else if (controllerName.isEmpty()) {
- // Is empty
- throw new IllegalArgumentException("controllerName is empty"); //NOI18N
- }
- // Try to get context parameter
- String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N
- // Is it set and true?
- boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE;
- // Return it
- return isEnabled;
+ public void setPhoneId (final Long phoneId) {
+ this.phoneId = phoneId;
}
/**
- * Loads resource bundle for given locale. This must be implemented per
- * project so all projects can still customize their methods. Calling
- * ResourceBundleloadBundle() in this class means that also the bundle files
- * must be present here.
- * <p>
- * @param locale Locale from e.g. FacesContext
+ * Getter for dial number without prefix
* <p>
- * @return Initialized and loaded resource bundle
+ * @return Dial number without prefix
*/
- protected abstract ResourceBundle loadResourceBundle (final Locale locale);
+ public Long getPhoneNumber () {
+ return this.phoneNumber;
+ }
/**
- * Shows a faces message for given causing exception. The message from the
- * exception is being inserted into the message.
+ * Setter for dial number without prefix
* <p>
- * @param clientId Client id to send message to
- * @param cause Causing exception
+ * @param phoneNumber Dial number without prefix
*/
- protected void showFacesMessage (final String clientId, final Throwable cause) {
- // Get context and add message
- this.showFacesMessage(clientId, cause.getMessage());
+ public void setPhoneNumber (final Long phoneNumber) {
+ this.phoneNumber = phoneNumber;
}
/**
- * Shows a faces message with given message (i18n) key.
+ * Returns an instance of a DialableFaxNumber from all fields stored in this
+ * bean.
* <p>
- * @param clientId Client id to send message to
- * @param i18nKey Message key
+ * @return An instance of a DialableFaxNumber class
+ */
+ private DialableFaxNumber createFaxNumber () {
+ // Initialize it
+ DialableFaxNumber number = new FaxNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
+
+ // Add all other data
+ number.setPhoneEntryCreated(this.getPhoneEntryCreated());
+ number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
+
+ // Is id number set?
+ if (this.getPhoneId() instanceof Long) {
+ // Set it
+ number.setPhoneId(this.getPhoneId());
+ }
+
+ // Return it
+ return number;
+ }
+
+ /**
+ * Returns an instance of a DialableLandLineNumber from all fields stored in
+ * this bean.
* <p>
- * @throws NullPointerException If clientId or i18nKey is null
- * @throws IllegalArgumentException If clientId or i18nKey is empty
+ * @return An instance of a DialableLandLineNumber class
*/
- protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException {
- // Both parameter must be valid
- if (null == clientId) {
- // Throw NPE
- throw new NullPointerException("clientId is null"); //NOI18N
- } else if (clientId.isEmpty()) {
- // Is empty
- throw new IllegalArgumentException("clientId is null"); //NOI18N
- } else if (null == i18nKey) {
- // Throw NPE
- throw new NullPointerException("i18nKey is null"); //NOI18N
- } else if (i18nKey.isEmpty()) {
- // Is empty
- throw new IllegalArgumentException("i18nKey is null"); //NOI18N
+ private DialableLandLineNumber createLandLineNumber () {
+ // Initialize it
+ DialableLandLineNumber number = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
+
+ // Add all other data
+ number.setPhoneEntryCreated(this.getPhoneEntryCreated());
+ number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
+
+ // Is id number set?
+ if (this.getPhoneId() instanceof Long) {
+ // Set it
+ number.setPhoneId(this.getPhoneId());
}
- // Get current locale
- Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
- // Get bundle bundle
- ResourceBundle bundle = this.loadResourceBundle(locale);
- // Default is i18nKey
- String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N
- // Try it
- try {
- // Get message
- message = bundle.getString(i18nKey);
- } catch (final MissingResourceException ex) {
- // Did not find it, ignored
+
+ // Return it
+ return number;
+ }
+
+ /**
+ * Returns an instance of a DialableMobileNumber from all fields stored in
+ * this bean.
+ * <p>
+ * @return An instance of a DialableMobileNumber class
+ */
+ private DialableMobileNumber createMobileNumber () {
+ // Initialize it
+ DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getPhoneNumber());
+
+ // Add all other data
+ number.setPhoneEntryCreated(this.getPhoneEntryCreated());
+ number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
+
+ // Is id number set?
+ if (this.getPhoneId() instanceof Long) {
+ // Set it
+ number.setPhoneId(this.getPhoneId());
}
- // Get context and add message
- FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message));
+
+ // Return it
+ return number;
}
}