From: Roland Häder Date: Wed, 22 Apr 2020 14:49:38 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5e064cff676110a6bce3b63eed8356b0d105636f;p=jjobs-war.git Don't cherry-pick: - renamed backing beans and their interfaces to JJobs - fixed JNDI name - fixed converters/validators because of JFinancials -> JJobs cherry-picking, otherwise you have to write that all from scratch ... Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestBean.java deleted file mode 100644 index e6cbd863..00000000 --- a/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestBean.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.mobile; - -import java.text.MessageFormat; -import java.util.Date; -import java.util.List; -import java.util.Objects; -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.inject.Inject; -import javax.inject.Named; -import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jjobs.beans.mobile.list.FinancialsMobileListWebViewController; -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.remove.AdminRemoveMobileNumberFromListEvent; -import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent; -import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent; -import org.mxchange.jphone.model.phonenumbers.mobile.AdminMobileSessionBeanRemote; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; - -/** - * Administrative bean (controller) for mobile numbers - *

- * @author Roland Häder - */ -@Named ("adminMobileController") -@RequestScoped -public class FinancialsAdminMobileWebRequestBean extends BaseJobsBean implements FinancialsAdminMobileWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 184_598_175_371_269_017L; - - /** - * Remote EJB for phone number (administrative) - */ - @EJB (lookup = "java:global/jjobs-ejb/adminMobile!org.mxchange.jphone.model.phonenumbers.mobile.AdminMobileSessionBeanRemote") - private AdminMobileSessionBeanRemote adminMobileBean; - - /** - * When the phone entry has been created (persisted) - */ - private Date mobileEntryCreated; - - /** - * When the phone entry has been updated - */ - private Date mobileEntryUpdated; - - /** - * Mobile id (aka primary key) - */ - private Long mobileId; - - /** - * Generic hone controller - */ - @Inject - private FinancialsMobileListWebViewController mobileListController; - - /** - * Mobile number - */ - private Long mobileNumber; - - /** - * Event being fired when an administrator has deleted mobile number - */ - @Inject - @Any - private Event mobileNumberDeletedEvent; - - /** - * Event being fired when an administrator has updated land-line number - */ - @Inject - @Any - private Event mobileNumberUpdatedEvent; - - /** - * Mobile provider - */ - private MobileProvider mobileProvider; - - /** - * Event being fired when a list of all unused mobile numbers is being - * created. - */ - @Inject - @Any - private Event removeLinkedMobileNumbersEvent; - - /** - * Chosen mobile number - */ - private DialableMobileNumber selectedMobileNumber; - - /** - * Default constructor - */ - public FinancialsAdminMobileWebRequestBean () { - // Call super constructor - super(); - } - - /** - * Observes events being fired when a bean helper has successfully created a - * mobile number instance. - *

- * @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().getMobileId() == null) { - // Throw NPE yet again - throw new NullPointerException("event.mobileNumber.mobileId is null"); //NOI18N - } else if (event.getMobileNumber().getMobileId() < 1) { - // Throw NPE yet again - throw new NullPointerException(MessageFormat.format("event.mobileNumber.mobileId={0} is invalid", event.getMobileNumber().getMobileId())); //NOI18N - } - - // Get fax number from event - final DialableMobileNumber number = event.getMobileNumber(); - - // Copy all data to this bean - this.setMobileId(number.getMobileId()); - this.setMobileProvider(number.getMobileProvider()); - this.setMobileNumber(number.getMobileNumber()); - this.setMobileEntryCreated(number.getMobileEntryCreated()); - this.setMobileEntryUpdated(number.getMobileEntryUpdated()); - } - - /** - * Returns a list of all unused ("non-linked") mobile numbers - *

- * @return List with all unused mobile numbers - */ - public List allNonLinkedMobileNumbers () { - // Get list of all mobile numbers - final List numbers = this.mobileListController.getAllMobileNumbers(); - - // Visit all controllers to reduce the list - this.removeLinkedMobileNumbersEvent.fire(new AdminMobileNumberRemovedFromListEvent(numbers)); - - // Return it - return numbers; - } - - /** - * Deletes given mobile entry data - */ - public void deleteMobileData () { - // Get mobile number from helper - final DialableMobileNumber number = this.createMobileNumber(); - - // Is all data set - if (number == null) { - // Not set, throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (number.getMobileId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N - } else if (number.getMobileId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid", number.getMobileId())); //NOI18N - } else if (number.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N - } else if (number.getMobileProvider().getProviderId() == null) { - // ... throw again - throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N - } else if (number.getMobileProvider().getProviderId() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N - } else if (number.getMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N - } else if (number.getMobileNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", number.getMobileNumber())); //NOI18N - } - - // Call EJB - this.adminMobileBean.deleteMobileData(number); - - // Fire event - this.mobileNumberDeletedEvent.fire(new AdminMobileNumberDeletedEvent(number)); - } - - /** - * Changes mobile entry data - *

- * @return Redirect outcome - */ - public String doUpdateMobileNumber () { - // Get mobile number from helper - final DialableMobileNumber number = this.createMobileNumber(); - - // Is all data set - if (number == null) { - // Not set, throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (number.getMobileId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N - } else if (number.getMobileId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid", number.getMobileId())); //NOI18N - } else if (number.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N - } else if (number.getMobileProvider().getProviderId() == null) { - // ... throw again - throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N - } else if (number.getMobileProvider().getProviderId() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N - } else if (number.getMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N - } else if (number.getMobileNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", number.getMobileNumber())); //NOI18N - } else if (this.getMobileProvider() == null) { - // Throw NPE again - throw new NullPointerException("this.mobileProvider is null"); //NOI18N - } else if (this.getMobileProvider().getProviderId() == null) { - // Throw NPE again ... - throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N - } else if (this.getMobileProvider().getProviderId() < 0) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("this.mobileProvider.providerId={0} is not valid.", this.getMobileProvider().getProviderId())); //NOI18N - } else if (this.getMobileNumber() == null) { - // Throw NPE - throw new NullPointerException("this.phoneNumber is null"); //NOI18N - } - - // Is the mobile provider and number the same? - if ((Objects.equals(this.getMobileProvider(), number.getMobileProvider())) && (Objects.equals(this.getMobileNumber(), number.getMobileNumber()))) { - // Show message - this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED", FacesMessage.SEVERITY_WARN); //NOI18N - - // No difference in both together, no need to edit - return ""; //NOI18N - } - - // Set all data - number.setMobileProvider(this.getMobileProvider()); - number.setMobileNumber(this.getMobileNumber()); - - // Send to bean - final DialableMobileNumber updatedNumber = this.adminMobileBean.updateMobileData(number); - - // Fire event - this.mobileNumberUpdatedEvent.fire(new AdminMobileNumberUpdatedEvent(updatedNumber)); - - // All fine, redirect - return "admin_show_mobile"; //NOI18N - } - - /** - * Getter for phone entry created timestamp - *

- * @return Mobile entry created timestamp - */ - @SuppressWarnings ("ReturnOfDateField") - public Date getMobileEntryCreated () { - return this.mobileEntryCreated; - } - - /** - * Setter for phone entry created timestamp - *

- * @param mobileEntryCreated Mobile entry created timestamp - */ - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setMobileEntryCreated (final Date mobileEntryCreated) { - this.mobileEntryCreated = mobileEntryCreated; - } - - /** - * Getter for phone entry updated timestamp - *

- * @return Mobile entry updated timestamp - */ - @SuppressWarnings ("ReturnOfDateField") - public Date getMobileEntryUpdated () { - return this.mobileEntryUpdated; - } - - /** - * Setter for phone entry updated timestamp - *

- * @param mobileEntryUpdated Mobile entry updated timestamp - */ - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setMobileEntryUpdated (final Date mobileEntryUpdated) { - this.mobileEntryUpdated = mobileEntryUpdated; - } - - /** - * Getter for phone id - *

- * @return Mobile id - */ - public Long getMobileId () { - return this.mobileId; - } - - /** - * Setter for phone id - *

- * @param mobileId Mobile id - */ - public void setMobileId (final Long mobileId) { - this.mobileId = mobileId; - } - - /** - * Getter for dial number without prefix - *

- * @return Dial number without prefix - */ - public Long getMobileNumber () { - return this.mobileNumber; - } - - /** - * Setter for dial number without prefix - *

- * @param mobileNumber Dial number without prefix - */ - public void setMobileNumber (final Long mobileNumber) { - this.mobileNumber = mobileNumber; - } - - /** - * Getter for mobile provider - *

- * @return Mobile provider - */ - public MobileProvider getMobileProvider () { - return this.mobileProvider; - } - - /** - * Setter for mobile provider - *

- * @param mobileProvider Mobile provider - */ - public void setMobileProvider (final MobileProvider mobileProvider) { - this.mobileProvider = mobileProvider; - } - - /** - * Getter for chosen mobile number - *

- * @return mobile number - */ - public DialableMobileNumber getSelectedMobileNumber () { - return this.selectedMobileNumber; - } - - /** - * Setter for chosen mobile number - *

- * @param selectedMobileNumber mobile number - */ - public void setSelectedMobileNumber (final DialableMobileNumber selectedMobileNumber) { - this.selectedMobileNumber = selectedMobileNumber; - } - - /** - * Returns an instance of a DialableMobileNumber from all fields stored in - * this bean. - *

- * @return An instance of a DialableMobileNumber class - */ - private DialableMobileNumber createMobileNumber () { - // Initialize it - final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); - - // Add all other data - number.setMobileEntryCreated(this.getMobileEntryCreated()); - number.setMobileEntryUpdated(this.getMobileEntryUpdated()); - number.setMobileId(this.getMobileId()); - - // Return it - return number; - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestController.java b/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestController.java deleted file mode 100644 index 269629df..00000000 --- a/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestController.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.mobile; - -import java.io.Serializable; - -/** - * An interface for a request web controller (bean) for administrative phone - * number purposes. - *

- * @author Roland Häder - */ -public interface FinancialsAdminMobileWebRequestController extends Serializable { - -} diff --git a/src/java/org/mxchange/jjobs/beans/mobile/JobsAdminMobileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/mobile/JobsAdminMobileWebRequestBean.java new file mode 100644 index 00000000..bb15e54a --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/mobile/JobsAdminMobileWebRequestBean.java @@ -0,0 +1,423 @@ +/* + * Copyright (C) 2016 - 2020 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.mobile; + +import java.text.MessageFormat; +import java.util.Date; +import java.util.List; +import java.util.Objects; +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.inject.Inject; +import javax.inject.Named; +import org.mxchange.jjobs.beans.BaseJobsBean; +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.remove.AdminRemoveMobileNumberFromListEvent; +import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent; +import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent; +import org.mxchange.jphone.model.phonenumbers.mobile.AdminMobileSessionBeanRemote; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jjobs.beans.mobile.list.JobsMobileListWebViewController; + +/** + * Administrative bean (controller) for mobile numbers + *

+ * @author Roland Häder + */ +@Named ("adminMobileController") +@RequestScoped +public class JobsAdminMobileWebRequestBean extends BaseJobsBean implements JobsAdminMobileWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 184_598_175_371_269_017L; + + /** + * Remote EJB for phone number (administrative) + */ + @EJB (lookup = "java:global/jjobs-ejb/adminMobile!org.mxchange.jphone.model.phonenumbers.mobile.AdminMobileSessionBeanRemote") + private AdminMobileSessionBeanRemote adminMobileBean; + + /** + * When the phone entry has been created (persisted) + */ + private Date mobileEntryCreated; + + /** + * When the phone entry has been updated + */ + private Date mobileEntryUpdated; + + /** + * Mobile id (aka primary key) + */ + private Long mobileId; + + /** + * Generic hone controller + */ + @Inject + private JobsMobileListWebViewController mobileListController; + + /** + * Mobile number + */ + private Long mobileNumber; + + /** + * Event being fired when an administrator has deleted mobile number + */ + @Inject + @Any + private Event mobileNumberDeletedEvent; + + /** + * Event being fired when an administrator has updated land-line number + */ + @Inject + @Any + private Event mobileNumberUpdatedEvent; + + /** + * Mobile provider + */ + private MobileProvider mobileProvider; + + /** + * Event being fired when a list of all unused mobile numbers is being + * created. + */ + @Inject + @Any + private Event removeLinkedMobileNumbersEvent; + + /** + * Chosen mobile number + */ + private DialableMobileNumber selectedMobileNumber; + + /** + * Default constructor + */ + public JobsAdminMobileWebRequestBean () { + // Call super constructor + super(); + } + + /** + * Observes events being fired when a bean helper has successfully created a + * mobile number instance. + *

+ * @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().getMobileId() == null) { + // Throw NPE yet again + throw new NullPointerException("event.mobileNumber.mobileId is null"); //NOI18N + } else if (event.getMobileNumber().getMobileId() < 1) { + // Throw NPE yet again + throw new NullPointerException(MessageFormat.format("event.mobileNumber.mobileId={0} is invalid", event.getMobileNumber().getMobileId())); //NOI18N + } + + // Get fax number from event + final DialableMobileNumber number = event.getMobileNumber(); + + // Copy all data to this bean + this.setMobileId(number.getMobileId()); + this.setMobileProvider(number.getMobileProvider()); + this.setMobileNumber(number.getMobileNumber()); + this.setMobileEntryCreated(number.getMobileEntryCreated()); + this.setMobileEntryUpdated(number.getMobileEntryUpdated()); + } + + /** + * Returns a list of all unused ("non-linked") mobile numbers + *

+ * @return List with all unused mobile numbers + */ + public List allNonLinkedMobileNumbers () { + // Get list of all mobile numbers + final List numbers = this.mobileListController.getAllMobileNumbers(); + + // Visit all controllers to reduce the list + this.removeLinkedMobileNumbersEvent.fire(new AdminMobileNumberRemovedFromListEvent(numbers)); + + // Return it + return numbers; + } + + /** + * Deletes given mobile entry data + */ + public void deleteMobileData () { + // Get mobile number from helper + final DialableMobileNumber number = this.createMobileNumber(); + + // Is all data set + if (number == null) { + // Not set, throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (number.getMobileId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N + } else if (number.getMobileId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid", number.getMobileId())); //NOI18N + } else if (number.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N + } else if (number.getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N + } else if (number.getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N + } else if (number.getMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N + } else if (number.getMobileNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", number.getMobileNumber())); //NOI18N + } + + // Call EJB + this.adminMobileBean.deleteMobileData(number); + + // Fire event + this.mobileNumberDeletedEvent.fire(new AdminMobileNumberDeletedEvent(number)); + } + + /** + * Changes mobile entry data + *

+ * @return Redirect outcome + */ + public String doUpdateMobileNumber () { + // Get mobile number from helper + final DialableMobileNumber number = this.createMobileNumber(); + + // Is all data set + if (number == null) { + // Not set, throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (number.getMobileId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N + } else if (number.getMobileId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid", number.getMobileId())); //NOI18N + } else if (number.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N + } else if (number.getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N + } else if (number.getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N + } else if (number.getMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N + } else if (number.getMobileNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", number.getMobileNumber())); //NOI18N + } else if (this.getMobileProvider() == null) { + // Throw NPE again + throw new NullPointerException("this.mobileProvider is null"); //NOI18N + } else if (this.getMobileProvider().getProviderId() == null) { + // Throw NPE again ... + throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N + } else if (this.getMobileProvider().getProviderId() < 0) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.mobileProvider.providerId={0} is not valid.", this.getMobileProvider().getProviderId())); //NOI18N + } else if (this.getMobileNumber() == null) { + // Throw NPE + throw new NullPointerException("this.phoneNumber is null"); //NOI18N + } + + // Is the mobile provider and number the same? + if ((Objects.equals(this.getMobileProvider(), number.getMobileProvider())) && (Objects.equals(this.getMobileNumber(), number.getMobileNumber()))) { + // Show message + this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED", FacesMessage.SEVERITY_WARN); //NOI18N + + // No difference in both together, no need to edit + return ""; //NOI18N + } + + // Set all data + number.setMobileProvider(this.getMobileProvider()); + number.setMobileNumber(this.getMobileNumber()); + + // Send to bean + final DialableMobileNumber updatedNumber = this.adminMobileBean.updateMobileData(number); + + // Fire event + this.mobileNumberUpdatedEvent.fire(new AdminMobileNumberUpdatedEvent(updatedNumber)); + + // All fine, redirect + return "admin_show_mobile"; //NOI18N + } + + /** + * Getter for phone entry created timestamp + *

+ * @return Mobile entry created timestamp + */ + @SuppressWarnings ("ReturnOfDateField") + public Date getMobileEntryCreated () { + return this.mobileEntryCreated; + } + + /** + * Setter for phone entry created timestamp + *

+ * @param mobileEntryCreated Mobile entry created timestamp + */ + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setMobileEntryCreated (final Date mobileEntryCreated) { + this.mobileEntryCreated = mobileEntryCreated; + } + + /** + * Getter for phone entry updated timestamp + *

+ * @return Mobile entry updated timestamp + */ + @SuppressWarnings ("ReturnOfDateField") + public Date getMobileEntryUpdated () { + return this.mobileEntryUpdated; + } + + /** + * Setter for phone entry updated timestamp + *

+ * @param mobileEntryUpdated Mobile entry updated timestamp + */ + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setMobileEntryUpdated (final Date mobileEntryUpdated) { + this.mobileEntryUpdated = mobileEntryUpdated; + } + + /** + * Getter for phone id + *

+ * @return Mobile id + */ + public Long getMobileId () { + return this.mobileId; + } + + /** + * Setter for phone id + *

+ * @param mobileId Mobile id + */ + public void setMobileId (final Long mobileId) { + this.mobileId = mobileId; + } + + /** + * Getter for dial number without prefix + *

+ * @return Dial number without prefix + */ + public Long getMobileNumber () { + return this.mobileNumber; + } + + /** + * Setter for dial number without prefix + *

+ * @param mobileNumber Dial number without prefix + */ + public void setMobileNumber (final Long mobileNumber) { + this.mobileNumber = mobileNumber; + } + + /** + * Getter for mobile provider + *

+ * @return Mobile provider + */ + public MobileProvider getMobileProvider () { + return this.mobileProvider; + } + + /** + * Setter for mobile provider + *

+ * @param mobileProvider Mobile provider + */ + public void setMobileProvider (final MobileProvider mobileProvider) { + this.mobileProvider = mobileProvider; + } + + /** + * Getter for chosen mobile number + *

+ * @return mobile number + */ + public DialableMobileNumber getSelectedMobileNumber () { + return this.selectedMobileNumber; + } + + /** + * Setter for chosen mobile number + *

+ * @param selectedMobileNumber mobile number + */ + public void setSelectedMobileNumber (final DialableMobileNumber selectedMobileNumber) { + this.selectedMobileNumber = selectedMobileNumber; + } + + /** + * Returns an instance of a DialableMobileNumber from all fields stored in + * this bean. + *

+ * @return An instance of a DialableMobileNumber class + */ + private DialableMobileNumber createMobileNumber () { + // Initialize it + final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); + + // Add all other data + number.setMobileEntryCreated(this.getMobileEntryCreated()); + number.setMobileEntryUpdated(this.getMobileEntryUpdated()); + number.setMobileId(this.getMobileId()); + + // Return it + return number; + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/mobile/JobsAdminMobileWebRequestController.java b/src/java/org/mxchange/jjobs/beans/mobile/JobsAdminMobileWebRequestController.java new file mode 100644 index 00000000..db181a8e --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/mobile/JobsAdminMobileWebRequestController.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2016 - 2020 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.mobile; + +import java.io.Serializable; + +/** + * An interface for a request web controller (bean) for administrative phone + * number purposes. + *

+ * @author Roland Häder + */ +public interface JobsAdminMobileWebRequestController extends Serializable { + +} diff --git a/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewBean.java deleted file mode 100644 index fdc286b3..00000000 --- a/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewBean.java +++ /dev/null @@ -1,426 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.mobile.list; - -import fish.payara.cdi.jsr107.impl.NamedCache; -import java.text.MessageFormat; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import javax.annotation.PostConstruct; -import javax.cache.Cache; -import javax.ejb.EJB; -import javax.enterprise.event.Observes; -import javax.faces.view.ViewScoped; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; -import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; -import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent; -import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent; -import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent; -import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.MobileSessionBeanRemote; -import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; - -/** - * Administrative listing controller (bean) for mobile numbers - *

- * @author Roland Häder - */ -@Named ("mobileListController") -@ViewScoped -public class FinancialsMobileListWebViewBean extends BaseJobsBean implements FinancialsMobileListWebViewController { - - /** - * Serial number - */ - private static final long serialVersionUID = 491_058_674_675_690_106L; - - /** - * A list of all mobile numbers - */ - private final List allMobileNumbers; - - /** - * A list of filtered mobile numbers - */ - private List filteredMobileNumbers; - - /** - * General EJB for mobile numbers - */ - @EJB (lookup = "java:global/jjobs-ejb/mobile!org.mxchange.jphone.model.phonenumbers.mobile.MobileSessionBeanRemote") - private MobileSessionBeanRemote mobileBean; - - /** - * Cache for mobile numbers - */ - @Inject - @NamedCache (cacheName = "mobileNumberCache") - private transient Cache mobileNumberCache; - - /** - * Default constructor - */ - public FinancialsMobileListWebViewBean () { - // Call super constructor - super(); - - // Init list - this.allMobileNumbers = new LinkedList<>(); - } - - /** - * Observes events being fired when an administrator has added a new - * contact. - *

- * @param event Event being fired - */ - public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { - // The event must be valid - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedContact() == null) { - // Throw again ... - throw new NullPointerException("event.addedContact is null"); //NOI18N - } else if (event.getAddedContact().getContactId() == null) { - // ... and again - throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N - } else if (event.getAddedContact().getContactId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N - } - - // Update contact's mobile, land-line and mobile number - this.updateContactMobileNumbers(event.getAddedContact()); - - // Clear this bean - this.clear(); - } - - /** - * Event observer for newly added users by administrator - *

- * @param event Event being fired - */ - public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent 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.getAddedUser() == null) { - // Throw NPE again - throw new NullPointerException("event.addedUser is null"); //NOI18N - } else if (event.getAddedUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.addedUser.userId is null"); //NOI18N - } else if (event.getAddedUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N - } - - // Update contact's mobile, land-line and mobile number - this.updateContactMobileNumbers(event.getAddedUser().getUserContact()); - - // Clear all data - this.clear(); - } - - /** - * Observes events being fired when an administrator has deleted a land-line - * number - *

- * @param event Event being fired - */ - public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent 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.getDeletedMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N - } else if (event.getDeletedMobileNumber().getMobileId() == null) { - // userId is null - throw new NullPointerException("event.deletedMobileNumber.mobileId is null"); //NOI18N - } else if (event.getDeletedMobileNumber().getMobileId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("mobileId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getMobileId())); //NOI18N - } - - // Update contact's mobile, land-line and mobile number - this.getAllMobileNumbers().remove(event.getDeletedMobileNumber()); - - // Clear all data - this.clear(); - } - - /** - * Observes events being fired when an administrator has a linked a - * land-line number - *

- * @param event Event being fired - */ - public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) { - // Is the event fine? - if (event == null) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getContact() == null) { - // Throw again ... - throw new NullPointerException("event.contact is null"); //NOI18N - } else if (event.getContact().getContactId() == null) { - // Throw again ... - throw new NullPointerException("event.contact.contactId is null"); //NOI18N - } else if (event.getContact().getContactId() < 1) { - // Throw again ... - throw new NullPointerException(MessageFormat.format("event.contact.contactId={0} is invalid", event.getContact().getContactId())); //NOI18N - } else if (event.getContact().getContactMobileNumber() == null) { - // Throw again ... - throw new NullPointerException("event.contact.contactMobileNumber is null"); //NOI18N - } else if (event.getContact().getContactMobileNumber().getMobileId() == null) { - // Throw again ... - throw new NullPointerException("event.contact.contactMobileNumber.mobileId is null"); //NOI18N - } else if (event.getContact().getContactMobileNumber().getMobileId() < 1) { - // Throw again ... - throw new NullPointerException(MessageFormat.format("event.contact.contactMobileNumber.mobileId={0} is invalid", event.getContact().getContactMobileNumber().getMobileId())); //NOI18N - } else if (event.getLinkedMobileNumber() == null) { - // Throw again ... - throw new NullPointerException("event.linkedMobileNumer is null"); //NOI18N - } - - // Is the id number in linked number not set? - if (event.getLinkedMobileNumber().getMobileId() == null) { - // Then it is a new number, so add it from contact as there the id number has been set - this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber()); - } - } - - /** - * Observes events being fired when an administrator has updated contact - * data. - *

- * @param event Event being fired - */ - public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent 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 - } - - // Update contact's mobile, land-line and mobile number - this.updateContactMobileNumbers(event.getUpdatedContact()); - - // Clear all data - this.clear(); - } - - /** - * Observes events being fired when an administrator has updated a land-line - * number. - *

- * @param event Event being fired - */ - public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent 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.getUpdatedMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N - } else if (event.getUpdatedMobileNumber().getMobileId() == null) { - // userId is null - throw new NullPointerException("event.updatedMobileNumber.mobileId is null"); //NOI18N - } else if (event.getUpdatedMobileNumber().getMobileId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("mobileId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getMobileId())); //NOI18N - } - - // Uniquely add it - this.uniqueAddMobileNumber(event.getUpdatedMobileNumber()); - - // Clear it - this.clear(); - } - - @Override - public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws MobileEntityNotFoundException { - // Validate paramter - if (null == mobileNumberId) { - // Throw NPE - throw new NullPointerException("mobileNumberId is null"); //NOI18N - } else if (mobileNumberId < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("mobileNumberId={0} is invalid.", mobileNumberId)); //NOI18N - } else if (!this.mobileNumberCache.containsKey(mobileNumberId)) { - // Not found - throw new MobileEntityNotFoundException(mobileNumberId); - } - - // Get it from cache - final DialableMobileNumber mobileNumber = this.mobileNumberCache.get(mobileNumberId); - - // Return it - return mobileNumber; - } - - @Override - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getAllMobileNumbers () { - return this.allMobileNumbers; - } - - /** - * Getter for filtered mobile numbers - *

- * @return Filtered mobile numbers - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredMobileNumbers () { - return this.filteredMobileNumbers; - } - - /** - * Setter for filtered mobile numbers - *

- * @param filteredMobileNumbers Filtered mobile numbers - */ - @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredMobileNumbers (final List filteredMobileNumbers) { - this.filteredMobileNumbers = filteredMobileNumbers; - } - - /** - * Post-construction method - */ - @PostConstruct - public void initializeList () { - // Is cache there? - if (!this.mobileNumberCache.iterator().hasNext()) { - // Add all - for (final DialableMobileNumber currentNumber : this.mobileBean.fetchAllMobileNumbers()) { - // Add it to cache - this.mobileNumberCache.put(currentNumber.getMobileId(), currentNumber); - } - } - - // Is cache filled and list is empty - if ((this.mobileNumberCache.iterator().hasNext()) && (this.getAllMobileNumbers().isEmpty())) { - // Build up list - for (final Cache.Entry currentEntry : this.mobileNumberCache) { - // Add to list - this.getAllMobileNumbers().add(currentEntry.getValue()); - } - - // Sort list - this.getAllMobileNumbers().sort(new Comparator() { - @Override - public int compare (final DialableMobileNumber mobileNumber1, final DialableMobileNumber mobileNumber2) { - return mobileNumber1.getMobileId() > mobileNumber2.getMobileId() ? 1 : mobileNumber1.getMobileId() < mobileNumber2.getMobileId() ? -1 : 0; - } - }); - - // Set full list - this.setFilteredMobileNumbers(this.getAllMobileNumbers()); - } - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all data - } - - /** - * Uniquely add given land-line number to this bean's list. First remove the - * old instance (by id number), then re-add it again. - *

- * @param mobileNumber Land-line number to add - */ - private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) { - // Make sure the parameter is valid - if (null == mobileNumber) { - // Throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getMobileId() == null) { - // Throw again ... - throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N - } else if (mobileNumber.getMobileId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid.", mobileNumber.getMobileId())); //NOI18N - } - - // First remove it - if (!this.getAllMobileNumbers().remove(mobileNumber)) { - // Did not work, try by id number - for (final DialableMobileNumber currentNumber : this.getAllMobileNumbers()) { - // Is id number the same? - if (Objects.equals(currentNumber.getMobileId(), mobileNumber.getMobileId())) { - // Found it - this.getAllMobileNumbers().remove(currentNumber); - break; - } - } - } - - // ... then add it - this.getAllMobileNumbers().add(mobileNumber); - } - - /** - * Updates given contact's mobile number - *

- * @param contact Contact instance - */ - private void updateContactMobileNumbers (final Contact contact) { - // Parameter must be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Id number is not valid - } - - // Is land-line set? - if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Unique-add it - this.uniqueAddMobileNumber(contact.getContactMobileNumber()); - } - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewController.java b/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewController.java deleted file mode 100644 index 1b45c3ab..00000000 --- a/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewController.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.mobile.list; - -import java.io.Serializable; -import java.util.List; -import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; - -/** - * An interface for a request web controller (bean) for administrative phone - * number purposes. - *

- * @author Roland Häder - */ -public interface FinancialsMobileListWebViewController extends Serializable { - - /** - * Returns a list of all mobile numbers. For performance reasons, the - * controller (bean) should be view-scoped as from user to user nothing - * changes. And the controller's post-construct method should load all - * numbers and cache it in the controller. - *

- * @return List of all mobile numbers - */ - List getAllMobileNumbers (); - - /** - * Finds a mobile entry by given id number - *

- * @param mobileNumberId Mobile entry id number - *

- * @return A valid mobile instance - *

- * @throws MobileEntityNotFoundException If the entity was not found - */ - DialableMobileNumber findMobileNumberById (Long mobileNumberId) throws MobileEntityNotFoundException; - -} diff --git a/src/java/org/mxchange/jjobs/beans/mobile/list/JobsMobileListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/mobile/list/JobsMobileListWebViewBean.java new file mode 100644 index 00000000..3fe9c493 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/mobile/list/JobsMobileListWebViewBean.java @@ -0,0 +1,426 @@ +/* + * Copyright (C) 2016 - 2020 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.mobile.list; + +import fish.payara.cdi.jsr107.impl.NamedCache; +import java.text.MessageFormat; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import javax.annotation.PostConstruct; +import javax.cache.Cache; +import javax.ejb.EJB; +import javax.enterprise.event.Observes; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent; +import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent; +import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.MobileSessionBeanRemote; +import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; + +/** + * Administrative listing controller (bean) for mobile numbers + *

+ * @author Roland Häder + */ +@Named ("mobileListController") +@ViewScoped +public class JobsMobileListWebViewBean extends BaseJobsBean implements JobsMobileListWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 491_058_674_675_690_106L; + + /** + * A list of all mobile numbers + */ + private final List allMobileNumbers; + + /** + * A list of filtered mobile numbers + */ + private List filteredMobileNumbers; + + /** + * General EJB for mobile numbers + */ + @EJB (lookup = "java:global/jjobs-ejb/mobile!org.mxchange.jphone.model.phonenumbers.mobile.MobileSessionBeanRemote") + private MobileSessionBeanRemote mobileBean; + + /** + * Cache for mobile numbers + */ + @Inject + @NamedCache (cacheName = "mobileNumberCache") + private transient Cache mobileNumberCache; + + /** + * Default constructor + */ + public JobsMobileListWebViewBean () { + // Call super constructor + super(); + + // Init list + this.allMobileNumbers = new LinkedList<>(); + } + + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedContact() == null) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N + } + + // Update contact's mobile, land-line and mobile number + this.updateContactMobileNumbers(event.getAddedContact()); + + // Clear this bean + this.clear(); + } + + /** + * Event observer for newly added users by administrator + *

+ * @param event Event being fired + */ + public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent 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.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + } + + // Update contact's mobile, land-line and mobile number + this.updateContactMobileNumbers(event.getAddedUser().getUserContact()); + + // Clear all data + this.clear(); + } + + /** + * Observes events being fired when an administrator has deleted a land-line + * number + *

+ * @param event Event being fired + */ + public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent 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.getDeletedMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N + } else if (event.getDeletedMobileNumber().getMobileId() == null) { + // userId is null + throw new NullPointerException("event.deletedMobileNumber.mobileId is null"); //NOI18N + } else if (event.getDeletedMobileNumber().getMobileId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("mobileId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getMobileId())); //NOI18N + } + + // Update contact's mobile, land-line and mobile number + this.getAllMobileNumbers().remove(event.getDeletedMobileNumber()); + + // Clear all data + this.clear(); + } + + /** + * Observes events being fired when an administrator has a linked a + * land-line number + *

+ * @param event Event being fired + */ + public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) { + // Is the event fine? + if (event == null) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getContact() == null) { + // Throw again ... + throw new NullPointerException("event.contact is null"); //NOI18N + } else if (event.getContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactId is null"); //NOI18N + } else if (event.getContact().getContactId() < 1) { + // Throw again ... + throw new NullPointerException(MessageFormat.format("event.contact.contactId={0} is invalid", event.getContact().getContactId())); //NOI18N + } else if (event.getContact().getContactMobileNumber() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactMobileNumber is null"); //NOI18N + } else if (event.getContact().getContactMobileNumber().getMobileId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactMobileNumber.mobileId is null"); //NOI18N + } else if (event.getContact().getContactMobileNumber().getMobileId() < 1) { + // Throw again ... + throw new NullPointerException(MessageFormat.format("event.contact.contactMobileNumber.mobileId={0} is invalid", event.getContact().getContactMobileNumber().getMobileId())); //NOI18N + } else if (event.getLinkedMobileNumber() == null) { + // Throw again ... + throw new NullPointerException("event.linkedMobileNumer is null"); //NOI18N + } + + // Is the id number in linked number not set? + if (event.getLinkedMobileNumber().getMobileId() == null) { + // Then it is a new number, so add it from contact as there the id number has been set + this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber()); + } + } + + /** + * Observes events being fired when an administrator has updated contact + * data. + *

+ * @param event Event being fired + */ + public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent 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 + } + + // Update contact's mobile, land-line and mobile number + this.updateContactMobileNumbers(event.getUpdatedContact()); + + // Clear all data + this.clear(); + } + + /** + * Observes events being fired when an administrator has updated a land-line + * number. + *

+ * @param event Event being fired + */ + public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent 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.getUpdatedMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N + } else if (event.getUpdatedMobileNumber().getMobileId() == null) { + // userId is null + throw new NullPointerException("event.updatedMobileNumber.mobileId is null"); //NOI18N + } else if (event.getUpdatedMobileNumber().getMobileId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("mobileId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getMobileId())); //NOI18N + } + + // Uniquely add it + this.uniqueAddMobileNumber(event.getUpdatedMobileNumber()); + + // Clear it + this.clear(); + } + + @Override + public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws MobileEntityNotFoundException { + // Validate paramter + if (null == mobileNumberId) { + // Throw NPE + throw new NullPointerException("mobileNumberId is null"); //NOI18N + } else if (mobileNumberId < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("mobileNumberId={0} is invalid.", mobileNumberId)); //NOI18N + } else if (!this.mobileNumberCache.containsKey(mobileNumberId)) { + // Not found + throw new MobileEntityNotFoundException(mobileNumberId); + } + + // Get it from cache + final DialableMobileNumber mobileNumber = this.mobileNumberCache.get(mobileNumberId); + + // Return it + return mobileNumber; + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllMobileNumbers () { + return this.allMobileNumbers; + } + + /** + * Getter for filtered mobile numbers + *

+ * @return Filtered mobile numbers + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredMobileNumbers () { + return this.filteredMobileNumbers; + } + + /** + * Setter for filtered mobile numbers + *

+ * @param filteredMobileNumbers Filtered mobile numbers + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredMobileNumbers (final List filteredMobileNumbers) { + this.filteredMobileNumbers = filteredMobileNumbers; + } + + /** + * Post-construction method + */ + @PostConstruct + public void initializeList () { + // Is cache there? + if (!this.mobileNumberCache.iterator().hasNext()) { + // Add all + for (final DialableMobileNumber currentNumber : this.mobileBean.fetchAllMobileNumbers()) { + // Add it to cache + this.mobileNumberCache.put(currentNumber.getMobileId(), currentNumber); + } + } + + // Is cache filled and list is empty + if ((this.mobileNumberCache.iterator().hasNext()) && (this.getAllMobileNumbers().isEmpty())) { + // Build up list + for (final Cache.Entry currentEntry : this.mobileNumberCache) { + // Add to list + this.getAllMobileNumbers().add(currentEntry.getValue()); + } + + // Sort list + this.getAllMobileNumbers().sort(new Comparator() { + @Override + public int compare (final DialableMobileNumber mobileNumber1, final DialableMobileNumber mobileNumber2) { + return mobileNumber1.getMobileId() > mobileNumber2.getMobileId() ? 1 : mobileNumber1.getMobileId() < mobileNumber2.getMobileId() ? -1 : 0; + } + }); + + // Set full list + this.setFilteredMobileNumbers(this.getAllMobileNumbers()); + } + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all data + } + + /** + * Uniquely add given land-line number to this bean's list. First remove the + * old instance (by id number), then re-add it again. + *

+ * @param mobileNumber Land-line number to add + */ + private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) { + // Make sure the parameter is valid + if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getMobileId() == null) { + // Throw again ... + throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N + } else if (mobileNumber.getMobileId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid.", mobileNumber.getMobileId())); //NOI18N + } + + // First remove it + if (!this.getAllMobileNumbers().remove(mobileNumber)) { + // Did not work, try by id number + for (final DialableMobileNumber currentNumber : this.getAllMobileNumbers()) { + // Is id number the same? + if (Objects.equals(currentNumber.getMobileId(), mobileNumber.getMobileId())) { + // Found it + this.getAllMobileNumbers().remove(currentNumber); + break; + } + } + } + + // ... then add it + this.getAllMobileNumbers().add(mobileNumber); + } + + /** + * Updates given contact's mobile number + *

+ * @param contact Contact instance + */ + private void updateContactMobileNumbers (final Contact contact) { + // Parameter must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Id number is not valid + } + + // Is land-line set? + if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { + // Unique-add it + this.uniqueAddMobileNumber(contact.getContactMobileNumber()); + } + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/mobile/list/JobsMobileListWebViewController.java b/src/java/org/mxchange/jjobs/beans/mobile/list/JobsMobileListWebViewController.java new file mode 100644 index 00000000..12c0ab12 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/mobile/list/JobsMobileListWebViewController.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2016 - 2020 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.mobile.list; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; + +/** + * An interface for a request web controller (bean) for administrative phone + * number purposes. + *

+ * @author Roland Häder + */ +public interface JobsMobileListWebViewController extends Serializable { + + /** + * Returns a list of all mobile numbers. For performance reasons, the + * controller (bean) should be view-scoped as from user to user nothing + * changes. And the controller's post-construct method should load all + * numbers and cache it in the controller. + *

+ * @return List of all mobile numbers + */ + List getAllMobileNumbers (); + + /** + * Finds a mobile entry by given id number + *

+ * @param mobileNumberId Mobile entry id number + *

+ * @return A valid mobile instance + *

+ * @throws MobileEntityNotFoundException If the entity was not found + */ + DialableMobileNumber findMobileNumberById (Long mobileNumberId) throws MobileEntityNotFoundException; + +} diff --git a/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsAdminMobileProviderWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsAdminMobileProviderWebRequestBean.java index f8e4b262..73310ac1 100644 --- a/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsAdminMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsAdminMobileProviderWebRequestBean.java @@ -27,13 +27,13 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jjobs.beans.mobileprovider.list.FinancialsMobileProviderListWebViewController; import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent; import org.mxchange.jphone.events.mobileprovider.added.AdminMobileProviderAddedEvent; import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderAlreadyAddedException; import org.mxchange.jphone.model.phonenumbers.mobileprovider.AdminMobileProviderSessionBeanRemote; import org.mxchange.jphone.model.phonenumbers.mobileprovider.CellphoneProvider; import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jjobs.beans.mobileprovider.list.JobsMobileProviderListWebViewController; /** * Administrative controller (bean) for mobile provider @@ -59,7 +59,7 @@ public class JobsAdminMobileProviderWebRequestBean extends BaseJobsBean implemen * Mobile provider list view */ @Inject - private FinancialsMobileProviderListWebViewController mobileProviderListController; + private JobsMobileProviderListWebViewController mobileProviderListController; /** * Event being fired when the mobile provider was added diff --git a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewBean.java deleted file mode 100644 index ab20ff88..00000000 --- a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewBean.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.mobileprovider.list; - -import fish.payara.cdi.jsr107.impl.NamedCache; -import java.text.MessageFormat; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import javax.annotation.PostConstruct; -import javax.cache.Cache; -import javax.ejb.EJB; -import javax.enterprise.event.Observes; -import javax.faces.view.ViewScoped; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent; -import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderNotFoundException; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote; - -/** - * A views-scoped bean for mobile providers - *

- * @author Roland Häder - */ -@Named ("mobileProviderListController") -@ViewScoped -public class FinancialsMobileProviderListWebViewBean extends BaseJobsBean implements FinancialsMobileProviderListWebViewController { - - /** - * Serial number - */ - private static final long serialVersionUID = 15_869_423_671_950_277L; - - /** - * A list of all mobile providers - */ - private final List allMobileProviders; - - /** - * A list of filtered mobile providers - */ - private List filteredMobileProviders; - - /** - * Remote EJB for mobile providers (regular) - */ - @EJB (lookup = "java:global/jjobs-ejb/mobileProvider!org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote") - private MobileProviderSingletonBeanRemote mobileProviderBean; - - /** - * "Cached" list of mobile providers - */ - @Inject - @NamedCache (cacheName = "mobileProviderCache") - private transient Cache mobileProviderCache; - - /** - * Selected mobile provider instance - */ - private MobileProvider selectedMobileProvider; - - /** - * Default constructor - */ - public FinancialsMobileProviderListWebViewBean () { - // Call super constructor - super(); - - // Init list - this.allMobileProviders = new LinkedList<>(); - } - - /** - * Observes events being fired after the administrator has added a new - * mobile provider - *

- * @param event Event being fired - */ - public void afterAdminAddedMobileProviderEvent (@Observes final AdminAddedMobileProviderEvent event) { - // Is all valid? - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedMobileProvider() == null) { - // Throw again ... - throw new NullPointerException("event.addedMobileProvider is null"); //NOI18N - } else if (event.getAddedMobileProvider().getProviderId() == null) { - // And again ... - throw new NullPointerException("event.addedMobileProvider.providerId is null"); //NOI18N - } else if (event.getAddedMobileProvider().getProviderId() < 1) { - // Id is invalid - throw new IllegalArgumentException(MessageFormat.format("event.addedMobileProvider.providerId={0} is not valid.", event.getAddedMobileProvider().getProviderId())); //NOI18N - } - - // Add it to the list - this.mobileProviderCache.put(event.getAddedMobileProvider().getProviderId(), event.getAddedMobileProvider()); - this.getAllMobileProviders().add(event.getAddedMobileProvider()); - } - - @Override - public MobileProvider findMobileProviderById (final Long mobileProviderId) throws MobileProviderNotFoundException { - // Validate parameter - if (null == mobileProviderId) { - // Throw NPE - throw new NullPointerException("mobileProviderId is null"); //NOI18N - } else if (mobileProviderId < 1) { - // Throw IAE - throw new IllegalArgumentException("mobileProviderId=" + mobileProviderId + " is invalid."); //NOI18N - } else if (!this.mobileProviderCache.containsKey(mobileProviderId)) { - // Not found - throw new MobileProviderNotFoundException(mobileProviderId); - } - - // Get it from cache - final MobileProvider mobileProvider = this.mobileProviderCache.get(mobileProviderId); - - // Return it - return mobileProvider; - } - - @Override - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getAllMobileProviders () { - // Return it - return this.allMobileProviders; - } - - /** - * Getter for filtered mobile provider list - *

- * @return Filtered mobile providers - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredMobileProviders () { - return this.filteredMobileProviders; - } - - /** - * Getter for filtered mobile provider list - *

- * @param filteredMobileProviders Filtered mobile providers - */ - @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredMobileProviders (final List filteredMobileProviders) { - this.filteredMobileProviders = filteredMobileProviders; - } - - /** - * Getter for selected mobile provider instance - *

- * @return Selected mobile provider instance - */ - public MobileProvider getSelectedMobileProvider () { - return this.selectedMobileProvider; - } - - /** - * Setter for selected mobile provider instance - *

- * @param selectedMobileProvider Selected mobile provider instance - */ - public void setSelectedMobileProvider (final MobileProvider selectedMobileProvider) { - this.selectedMobileProvider = selectedMobileProvider; - } - - /** - * Post-construction method - */ - @PostConstruct - public void initializeList () { - // Is cache there? - if (!this.mobileProviderCache.iterator().hasNext()) { - // Add all - for (final MobileProvider mobileProvider : this.mobileProviderBean.fetchAllMobileProviders()) { - // Add it to cache - this.mobileProviderCache.put(mobileProvider.getProviderId(), mobileProvider); - } - } - - // Is the list empty, but filled cache? - if (this.getAllMobileProviders().isEmpty() && this.mobileProviderCache.iterator().hasNext()) { - // Build up list - for (final Cache.Entry currentEntry : this.mobileProviderCache) { - // Add to list - this.getAllMobileProviders().add(currentEntry.getValue()); - } - - // Sort list - this.getAllMobileProviders().sort(new Comparator() { - @Override - public int compare (final MobileProvider mobileProvider1, final MobileProvider mobileProvider2) { - return mobileProvider1.getProviderId() > mobileProvider2.getProviderId() ? 1 : mobileProvider1.getProviderId() < mobileProvider2.getProviderId() ? -1 : 0; - } - }); - } - } -} diff --git a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewController.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewController.java deleted file mode 100644 index f1e4568e..00000000 --- a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewController.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.mobileprovider.list; - -import java.io.Serializable; -import java.util.List; -import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderNotFoundException; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; - -/** - * An interface for general mobile provider controller - *

- * @author Roland Häder - */ -public interface FinancialsMobileProviderListWebViewController extends Serializable { - - /** - * Returns a mobile provider instance by given primary key. If not found, a - * proper exception is thrown. - *

- * @param mobileProviderId Primary key - *

- * @return Mobile provider instance - *

- * @throws MobileProviderNotFoundException If the primary key could not be - * found - */ - MobileProvider findMobileProviderById (final Long mobileProviderId) throws MobileProviderNotFoundException; - - /** - * Returns a list of all mobile providers - *

- * @return A list of all mobile providers - */ - List getAllMobileProviders (); - -} diff --git a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/JobsMobileProviderListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/JobsMobileProviderListWebViewBean.java new file mode 100644 index 00000000..d1e56e21 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/JobsMobileProviderListWebViewBean.java @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2016 - 2020 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.mobileprovider.list; + +import fish.payara.cdi.jsr107.impl.NamedCache; +import java.text.MessageFormat; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import javax.annotation.PostConstruct; +import javax.cache.Cache; +import javax.ejb.EJB; +import javax.enterprise.event.Observes; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent; +import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderNotFoundException; +import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote; + +/** + * A views-scoped bean for mobile providers + *

+ * @author Roland Häder + */ +@Named ("mobileProviderListController") +@ViewScoped +public class JobsMobileProviderListWebViewBean extends BaseJobsBean implements JobsMobileProviderListWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 15_869_423_671_950_277L; + + /** + * A list of all mobile providers + */ + private final List allMobileProviders; + + /** + * A list of filtered mobile providers + */ + private List filteredMobileProviders; + + /** + * Remote EJB for mobile providers (regular) + */ + @EJB (lookup = "java:global/jjobs-ejb/mobileProvider!org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote") + private MobileProviderSingletonBeanRemote mobileProviderBean; + + /** + * "Cached" list of mobile providers + */ + @Inject + @NamedCache (cacheName = "mobileProviderCache") + private transient Cache mobileProviderCache; + + /** + * Selected mobile provider instance + */ + private MobileProvider selectedMobileProvider; + + /** + * Default constructor + */ + public JobsMobileProviderListWebViewBean () { + // Call super constructor + super(); + + // Init list + this.allMobileProviders = new LinkedList<>(); + } + + /** + * Observes events being fired after the administrator has added a new + * mobile provider + *

+ * @param event Event being fired + */ + public void afterAdminAddedMobileProviderEvent (@Observes final AdminAddedMobileProviderEvent event) { + // Is all valid? + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedMobileProvider() == null) { + // Throw again ... + throw new NullPointerException("event.addedMobileProvider is null"); //NOI18N + } else if (event.getAddedMobileProvider().getProviderId() == null) { + // And again ... + throw new NullPointerException("event.addedMobileProvider.providerId is null"); //NOI18N + } else if (event.getAddedMobileProvider().getProviderId() < 1) { + // Id is invalid + throw new IllegalArgumentException(MessageFormat.format("event.addedMobileProvider.providerId={0} is not valid.", event.getAddedMobileProvider().getProviderId())); //NOI18N + } + + // Add it to the list + this.mobileProviderCache.put(event.getAddedMobileProvider().getProviderId(), event.getAddedMobileProvider()); + this.getAllMobileProviders().add(event.getAddedMobileProvider()); + } + + @Override + public MobileProvider findMobileProviderById (final Long mobileProviderId) throws MobileProviderNotFoundException { + // Validate parameter + if (null == mobileProviderId) { + // Throw NPE + throw new NullPointerException("mobileProviderId is null"); //NOI18N + } else if (mobileProviderId < 1) { + // Throw IAE + throw new IllegalArgumentException("mobileProviderId=" + mobileProviderId + " is invalid."); //NOI18N + } else if (!this.mobileProviderCache.containsKey(mobileProviderId)) { + // Not found + throw new MobileProviderNotFoundException(mobileProviderId); + } + + // Get it from cache + final MobileProvider mobileProvider = this.mobileProviderCache.get(mobileProviderId); + + // Return it + return mobileProvider; + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllMobileProviders () { + // Return it + return this.allMobileProviders; + } + + /** + * Getter for filtered mobile provider list + *

+ * @return Filtered mobile providers + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredMobileProviders () { + return this.filteredMobileProviders; + } + + /** + * Getter for filtered mobile provider list + *

+ * @param filteredMobileProviders Filtered mobile providers + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredMobileProviders (final List filteredMobileProviders) { + this.filteredMobileProviders = filteredMobileProviders; + } + + /** + * Getter for selected mobile provider instance + *

+ * @return Selected mobile provider instance + */ + public MobileProvider getSelectedMobileProvider () { + return this.selectedMobileProvider; + } + + /** + * Setter for selected mobile provider instance + *

+ * @param selectedMobileProvider Selected mobile provider instance + */ + public void setSelectedMobileProvider (final MobileProvider selectedMobileProvider) { + this.selectedMobileProvider = selectedMobileProvider; + } + + /** + * Post-construction method + */ + @PostConstruct + public void initializeList () { + // Is cache there? + if (!this.mobileProviderCache.iterator().hasNext()) { + // Add all + for (final MobileProvider mobileProvider : this.mobileProviderBean.fetchAllMobileProviders()) { + // Add it to cache + this.mobileProviderCache.put(mobileProvider.getProviderId(), mobileProvider); + } + } + + // Is the list empty, but filled cache? + if (this.getAllMobileProviders().isEmpty() && this.mobileProviderCache.iterator().hasNext()) { + // Build up list + for (final Cache.Entry currentEntry : this.mobileProviderCache) { + // Add to list + this.getAllMobileProviders().add(currentEntry.getValue()); + } + + // Sort list + this.getAllMobileProviders().sort(new Comparator() { + @Override + public int compare (final MobileProvider mobileProvider1, final MobileProvider mobileProvider2) { + return mobileProvider1.getProviderId() > mobileProvider2.getProviderId() ? 1 : mobileProvider1.getProviderId() < mobileProvider2.getProviderId() ? -1 : 0; + } + }); + } + } +} diff --git a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/JobsMobileProviderListWebViewController.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/JobsMobileProviderListWebViewController.java new file mode 100644 index 00000000..17567c4f --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/JobsMobileProviderListWebViewController.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 - 2020 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.mobileprovider.list; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderNotFoundException; +import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; + +/** + * An interface for general mobile provider controller + *

+ * @author Roland Häder + */ +public interface JobsMobileProviderListWebViewController extends Serializable { + + /** + * Returns a mobile provider instance by given primary key. If not found, a + * proper exception is thrown. + *

+ * @param mobileProviderId Primary key + *

+ * @return Mobile provider instance + *

+ * @throws MobileProviderNotFoundException If the primary key could not be + * found + */ + MobileProvider findMobileProviderById (final Long mobileProviderId) throws MobileProviderNotFoundException; + + /** + * Returns a list of all mobile providers + *

+ * @return A list of all mobile providers + */ + List getAllMobileProviders (); + +} diff --git a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java index 07edf159..64d04d32 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java @@ -30,7 +30,6 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jjobs.beans.phone.list.FinancialsPhoneListWebViewController; import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent; import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent; import org.mxchange.jphone.events.fax.deleted.AdminFaxNumberDeletedEvent; @@ -51,6 +50,7 @@ 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.jphone.model.phonenumbers.phone.AdminPhoneSessionBeanRemote; +import org.mxchange.jjobs.beans.phone.list.JobsPhoneListWebViewController; /** * Administrative controller (bean) for phone numbers @@ -139,7 +139,7 @@ public class JobsAdminPhoneWebRequestBean extends BaseJobsBean implements JobsAd * Generic hone controller */ @Inject - private FinancialsPhoneListWebViewController phoneListController; + private JobsPhoneListWebViewController phoneListController; /** * Phone number diff --git a/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewBean.java deleted file mode 100644 index 8c68bcdb..00000000 --- a/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewBean.java +++ /dev/null @@ -1,636 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.phone.list; - -import fish.payara.cdi.jsr107.impl.NamedCache; -import java.text.MessageFormat; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import javax.annotation.PostConstruct; -import javax.cache.Cache; -import javax.ejb.EJB; -import javax.enterprise.event.Observes; -import javax.faces.view.ViewScoped; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; -import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; -import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent; -import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent; -import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent; -import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent; -import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent; -import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent; -import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException; -import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote; - -/** - * Administrative listing controller (bean) for phone numbers - *

- * @author Roland Häder - */ -@Named ("phoneListController") -@ViewScoped -public class FinancialsPhoneListWebViewBean extends BaseJobsBean implements FinancialsPhoneListWebViewController { - - /** - * Serial number - */ - private static final long serialVersionUID = 491_058_674_675_690_107L; - - /** - * A list of all fax numbers - */ - private final List allFaxNumbers; - - /** - * A list of all land-line numbers - */ - private final List allLandLineNumbers; - - /** - * All fax numbers - */ - @Inject - @NamedCache (cacheName = "faxNumberCache") - private transient Cache faxNumberCache; - - /** - * A list of filtered fax numbers - */ - private List filteredFaxNumbers; - - /** - * A list of filtered land-line numbers - */ - private List filteredLandLineNumbers; - - /** - * All land-line numbers - */ - @Inject - @NamedCache (cacheName = "landLineNumberCache") - private transient Cache landLineNumberCache; - - /** - * General EJB for phone numbers - */ - @EJB (lookup = "java:global/jjobs-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote") - private PhoneSessionBeanRemote phoneBean; - - /** - * Default constructor - */ - public FinancialsPhoneListWebViewBean () { - // Call super constructor - super(); - - // Initialize lists - this.allFaxNumbers = new LinkedList<>(); - this.allLandLineNumbers = new LinkedList<>(); - } - - /** - * Observes events being fired when an administrator has added a new - * contact. - *

- * @param event Event being fired - */ - public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { - // The event must be valid - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedContact() == null) { - // Throw again ... - throw new NullPointerException("event.addedContact is null"); //NOI18N - } else if (event.getAddedContact().getContactId() == null) { - // ... and again - throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N - } else if (event.getAddedContact().getContactId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N - } - - // Update contact's mobile, land-line and fax number - this.updateContactPhoneNumbers(event.getAddedContact()); - - // Clear this bean - this.clear(); - } - - /** - * Observes events being fired when an administrator has deleted a fax - * number - *

- * @param event Event being fired - */ - public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent 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.getDeletedFaxNumber() == null) { - // Throw NPE again - throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N - } else if (event.getDeletedFaxNumber().getPhoneId() == null) { - // phoneId is null - throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N - } else if (event.getDeletedFaxNumber().getPhoneId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N - } - - // Update contact's mobile, land-line and fax number - this.getAllFaxNumbers().remove(event.getDeletedFaxNumber()); - - // Clear all data - this.clear(); - } - - /** - * Observes events being fired when an administrator has deleted a land-line - * number - *

- * @param event Event being fired - */ - public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent 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.getDeletedLandLineNumber() == null) { - // Throw NPE again - throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N - } else if (event.getDeletedLandLineNumber().getPhoneId() == null) { - // phoneId is null - throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N - } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N - } - - // Update contact's mobile, land-line and fax number - this.getAllLandLineNumbers().remove(event.getDeletedLandLineNumber()); - - // Clear all data - this.clear(); - } - - /** - * Observes events being fired when an administrator has a linked a fax - * number - *

- * @param event Event being fired - */ - public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) { - // Is the event fine? - if (event == null) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getContact() == null) { - // Throw again ... - throw new NullPointerException("event.contact is null"); //NOI18N - } else if (event.getContact().getContactId() == null) { - // Throw again ... - throw new NullPointerException("event.contact.contactId is null"); //NOI18N - } else if (event.getContact().getContactId() < 1) { - // Throw again ... - throw new NullPointerException(MessageFormat.format("event.contact.contactId={0} is invalid", event.getContact().getContactId())); //NOI18N - } else if (event.getContact().getContactFaxNumber() == null) { - // Throw again ... - throw new NullPointerException("event.contact.contactFaxNumber is null"); //NOI18N - } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) { - // Throw again ... - throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null"); //NOI18N - } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) { - // Throw again ... - throw new NullPointerException(MessageFormat.format("event.contact.contactFaxNumber.phoneId={0} is invalid", event.getContact().getContactFaxNumber().getPhoneId())); //NOI18N - } else if (event.getLinkedFaxNumber() == null) { - // Throw again ... - throw new NullPointerException("event.linkedFaxNumer is null"); //NOI18N - } - - // Is the id number in linked number not set? - if (event.getLinkedFaxNumber().getPhoneId() == null) { - // Then it is a new number, so add it from contact as there the id number has been set - this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber()); - } - } - - /** - * Observes events being fired when an administrator has a linked a - * land-line number - *

- * @param event Event being fired - */ - public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) { - // Is the event fine? - if (event == null) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getContact() == null) { - // Throw again ... - throw new NullPointerException("event.contact is null"); //NOI18N - } else if (event.getContact().getContactId() == null) { - // Throw again ... - throw new NullPointerException("event.contact.contactId is null"); //NOI18N - } else if (event.getContact().getContactId() < 1) { - // Throw again ... - throw new NullPointerException(MessageFormat.format("event.contact.contactId={0} is invalid", event.getContact().getContactId())); //NOI18N - } else if (event.getContact().getContactLandLineNumber() == null) { - // Throw again ... - throw new NullPointerException("event.contact.contactLandLineNumber is null"); //NOI18N - } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) { - // Throw again ... - throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null"); //NOI18N - } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) { - // Throw again ... - throw new NullPointerException(MessageFormat.format("event.contact.contactLandLineNumber.phoneId={0} is invalid", event.getContact().getContactLandLineNumber().getPhoneId())); //NOI18N - } else if (event.getLinkedLandLineNumber() == null) { - // Throw again ... - throw new NullPointerException("event.linkedLandLineNumer is null"); //NOI18N - } - - // Is the id number in linked number not set? - if (event.getLinkedLandLineNumber().getPhoneId() == null) { - // Then it is a new number, so add it from contact as there the id number has been set - this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber()); - } - } - - /** - * Observes events being fired when an administrator has updated contact - * data. - *

- * @param event Event being fired - */ - public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent 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) { - // phoneId 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 - } - - // Update contact's mobile, land-line and fax number - this.updateContactPhoneNumbers(event.getUpdatedContact()); - - // Clear all data - this.clear(); - } - - /** - * Observes events being fired when an administrator has updated a fax - * number. - *

- * @param event Event being fired - */ - public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent 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.getUpdatedFaxNumber() == null) { - // Throw NPE again - throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N - } else if (event.getUpdatedFaxNumber().getPhoneId() == null) { - // phoneId is null - throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N - } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N - } - - // Uniquely add it - this.uniqueAddFaxNumber(event.getUpdatedFaxNumber()); - - // Clear it - this.clear(); - } - - /** - * Observes events being fired when an administrator has updated a land-line - * number. - *

- * @param event Event being fired - */ - public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent 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.getUpdatedLandLineNumber() == null) { - // Throw NPE again - throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N - } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) { - // phoneId is null - throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N - } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N - } - - // Uniquely add it - this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber()); - - // Clear it - this.clear(); - } - - @Override - public DialableFaxNumber findFaxNumberById (final Long phoneId) throws PhoneEntityNotFoundException { - // Validate paramter - if (null == phoneId) { - // Throw NPE - throw new NullPointerException("phoneId is null"); //NOI18N - } else if (phoneId < 1) { - // Throw IAE - throw new IllegalArgumentException("phoneId=" + phoneId + " is invalid."); //NOI18N - } else if (!this.faxNumberCache.containsKey(phoneId)) { - // Not found - throw new PhoneEntityNotFoundException(phoneId); - } - - // Get it from cache - final DialableFaxNumber faxNumber = this.faxNumberCache.get(phoneId); - - // Return it - return faxNumber; - } - - @Override - public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException { - // Validate paramter - if (null == landLineNumberId) { - // Throw NPE - throw new NullPointerException("landLineNumberId is null"); //NOI18N - } else if (landLineNumberId < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("landLineNumberId={0} is invalid.", landLineNumberId)); //NOI18N - } else if (!this.landLineNumberCache.containsKey(landLineNumberId)) { - // Not found - throw new PhoneEntityNotFoundException(landLineNumberId); - } - - // Get it from cache - final DialableLandLineNumber landLineNumber = this.landLineNumberCache.get(landLineNumberId); - - // Return it - return landLineNumber; - } - - @Override - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getAllFaxNumbers () { - return this.allFaxNumbers; - } - - @Override - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getAllLandLineNumbers () { - return this.allLandLineNumbers; - } - - /** - * Getter for filtered fax number list - *

- * @return Filtered fax number list - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredFaxNumbers () { - return this.filteredFaxNumbers; - } - - /** - * Setter for filtered fax number list - * - * @param filteredFaxNumbers Filtered fax number list - */ - @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredFaxNumbers (final List filteredFaxNumbers) { - this.filteredFaxNumbers = filteredFaxNumbers; - } - - /** - * Getter for filtered land-line number list - *

- * @return Filtered land-line number list - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredLandLineNumbers () { - return this.filteredLandLineNumbers; - } - - /** - * Setter for filtered land-line number list - * - * @param filteredLandLineNumbers Filtered land-line number list - */ - @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredLandLineNumbers (final List filteredLandLineNumbers) { - this.filteredLandLineNumbers = filteredLandLineNumbers; - } - - /** - * Post-construction method - */ - @PostConstruct - public void initializeList () { - // Is cache there? - if (!this.faxNumberCache.iterator().hasNext()) { - // Add all - for (final DialableFaxNumber currentNumber : this.phoneBean.fetchAllFaxNumbers()) { - // Add it to cache - this.faxNumberCache.put(currentNumber.getPhoneId(), currentNumber); - } - } - - // Is cache there? - if (!this.landLineNumberCache.iterator().hasNext()) { - // Add all - for (final DialableLandLineNumber currentNumber : this.phoneBean.fetchAllLandLineNumbers()) { - // Add it to cache - this.landLineNumberCache.put(currentNumber.getPhoneId(), currentNumber); - } - } - - // Is cache filled and list is empty - if ((this.faxNumberCache.iterator().hasNext()) && (this.getAllFaxNumbers().isEmpty())) { - // Build up list - for (final Cache.Entry currentEntry : this.faxNumberCache) { - // Add to list - this.getAllFaxNumbers().add(currentEntry.getValue()); - } - - // Sort list - this.getAllFaxNumbers().sort(new Comparator() { - @Override - public int compare (final DialableFaxNumber faxNumber1, final DialableFaxNumber faxNumber2) { - return faxNumber1.getPhoneId() > faxNumber2.getPhoneId() ? 1 : faxNumber1.getPhoneId() < faxNumber2.getPhoneId() ? -1 : 0; - } - }); - - // Set full list - this.setFilteredFaxNumbers(this.getAllFaxNumbers()); - } - - // Is cache filled and list is empty - if ((this.landLineNumberCache.iterator().hasNext()) && (this.getAllLandLineNumbers().isEmpty())) { - // Build up list - for (final Cache.Entry currentEntry : this.landLineNumberCache) { - // Add to list - this.getAllLandLineNumbers().add(currentEntry.getValue()); - } - - // Sort list - this.getAllLandLineNumbers().sort(new Comparator() { - @Override - public int compare (final DialableLandLineNumber landLineNumber1, final DialableLandLineNumber landLineNumber2) { - return landLineNumber1.getPhoneId() > landLineNumber2.getPhoneId() ? 1 : landLineNumber1.getPhoneId() < landLineNumber2.getPhoneId() ? -1 : 0; - } - }); - - // Set full list - this.setFilteredLandLineNumbers(this.getAllLandLineNumbers()); - } - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all data - } - - /** - * Uniquely add given fax number to this bean's list. First remove the old - * instance (by id number), then re-add it again. - *

- * @param faxNumber number to add - */ - private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) { - // Make sure the parameter is valid - if (null == faxNumber) { - // Throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (faxNumber.getPhoneId() == null) { - // Throw again ... - throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N - } else if (faxNumber.getPhoneId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId())); //NOI18N - } - - // First remove it - if (!this.getAllFaxNumbers().remove(faxNumber)) { - // Did not work, try by id number - for (final DialableFaxNumber currentNumber : this.getAllFaxNumbers()) { - // Is id number the same? - if (Objects.equals(currentNumber.getPhoneId(), faxNumber.getPhoneId())) { - // Found it - this.getAllFaxNumbers().remove(currentNumber); - break; - } - } - } - - // ... then add it - this.getAllFaxNumbers().add(faxNumber); - } - - /** - * Uniquely add given land-line number to this bean's list. First remove the - * old instance (by id number), then re-add it again. - *

- * @param landLineNumber Land-line number to add - */ - private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) { - // Make sure the parameter is valid - if (null == landLineNumber) { - // Throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneId() == null) { - // Throw again ... - throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N - } else if (landLineNumber.getPhoneId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId())); //NOI18N - } - - // First remove it - if (!this.getAllLandLineNumbers().remove(landLineNumber)) { - // Did not work, try by id number - for (final DialableLandLineNumber currentNumber : this.getAllLandLineNumbers()) { - // Is id number the same? - if (Objects.equals(currentNumber.getPhoneId(), landLineNumber.getPhoneId())) { - // Found it - this.getAllLandLineNumbers().remove(currentNumber); - break; - } - } - } - - // ... then add it - this.getAllLandLineNumbers().add(landLineNumber); - } - - /** - * Updates given contact's mobile, land-line and fax number - *

- * @param contact Contact instance - */ - private void updateContactPhoneNumbers (final Contact contact) { - // Parameter must be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Id number is not valid - } - - // Is land-line set? - if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Unique-add it - this.uniqueAddLandLineNumber(contact.getContactLandLineNumber()); - } - - // Is fax set? - if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Unique-add it - this.uniqueAddFaxNumber(contact.getContactFaxNumber()); - } - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewController.java b/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewController.java deleted file mode 100644 index 421c5723..00000000 --- a/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewController.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.phone.list; - -import java.io.Serializable; -import java.util.List; -import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException; -import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; - -/** - * An interface for a request web controller (bean) for administrative phone - * number purposes. - *

- * @author Roland Häder - */ -public interface FinancialsPhoneListWebViewController extends Serializable { - - /** - * Returns a list of all fax numbers. For performance reasons, the - * controller (bean) should be view-scoped as from user to user nothing - * changes. And the controller's post-construct method should load all - * numbers and cache it in the controller. - *

- * @return List of all fax numbers - */ - List getAllFaxNumbers (); - - /** - * Returns a list of all land-line numbers. For performance reasons, the - * controller (bean) should be view-scoped as from user to user nothing - * changes. And the controller's post-construct method should load all - * numbers and cache it in the controller. - *

- * @return List of all land-line numbers - */ - List getAllLandLineNumbers (); - - /** - * Finds a fax entry by given id number - *

- * @param faxNumberId Fax entry id number - *

- * @return A valid fax instance - *

- * @throws PhoneEntityNotFoundException If the entity was not found - */ - DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException; - - /** - * Finds a land-line entry by given id number - *

- * @param landLineNumberId Land-line entry id number - *

- * @return A valid land-line instance - *

- * @throws PhoneEntityNotFoundException If the entity was not found - */ - DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException; - -} diff --git a/src/java/org/mxchange/jjobs/beans/phone/list/JobsPhoneListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/phone/list/JobsPhoneListWebViewBean.java new file mode 100644 index 00000000..398fbdb5 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/phone/list/JobsPhoneListWebViewBean.java @@ -0,0 +1,636 @@ +/* + * Copyright (C) 2016 - 2020 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.phone.list; + +import fish.payara.cdi.jsr107.impl.NamedCache; +import java.text.MessageFormat; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import javax.annotation.PostConstruct; +import javax.cache.Cache; +import javax.ejb.EJB; +import javax.enterprise.event.Observes; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent; +import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent; +import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent; +import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent; +import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote; + +/** + * Administrative listing controller (bean) for phone numbers + *

+ * @author Roland Häder + */ +@Named ("phoneListController") +@ViewScoped +public class JobsPhoneListWebViewBean extends BaseJobsBean implements JobsPhoneListWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 491_058_674_675_690_107L; + + /** + * A list of all fax numbers + */ + private final List allFaxNumbers; + + /** + * A list of all land-line numbers + */ + private final List allLandLineNumbers; + + /** + * All fax numbers + */ + @Inject + @NamedCache (cacheName = "faxNumberCache") + private transient Cache faxNumberCache; + + /** + * A list of filtered fax numbers + */ + private List filteredFaxNumbers; + + /** + * A list of filtered land-line numbers + */ + private List filteredLandLineNumbers; + + /** + * All land-line numbers + */ + @Inject + @NamedCache (cacheName = "landLineNumberCache") + private transient Cache landLineNumberCache; + + /** + * General EJB for phone numbers + */ + @EJB (lookup = "java:global/jjobs-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote") + private PhoneSessionBeanRemote phoneBean; + + /** + * Default constructor + */ + public JobsPhoneListWebViewBean () { + // Call super constructor + super(); + + // Initialize lists + this.allFaxNumbers = new LinkedList<>(); + this.allLandLineNumbers = new LinkedList<>(); + } + + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedContact() == null) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N + } + + // Update contact's mobile, land-line and fax number + this.updateContactPhoneNumbers(event.getAddedContact()); + + // Clear this bean + this.clear(); + } + + /** + * Observes events being fired when an administrator has deleted a fax + * number + *

+ * @param event Event being fired + */ + public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent 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.getDeletedFaxNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N + } else if (event.getDeletedFaxNumber().getPhoneId() == null) { + // phoneId is null + throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N + } else if (event.getDeletedFaxNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N + } + + // Update contact's mobile, land-line and fax number + this.getAllFaxNumbers().remove(event.getDeletedFaxNumber()); + + // Clear all data + this.clear(); + } + + /** + * Observes events being fired when an administrator has deleted a land-line + * number + *

+ * @param event Event being fired + */ + public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent 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.getDeletedLandLineNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N + } else if (event.getDeletedLandLineNumber().getPhoneId() == null) { + // phoneId is null + throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N + } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N + } + + // Update contact's mobile, land-line and fax number + this.getAllLandLineNumbers().remove(event.getDeletedLandLineNumber()); + + // Clear all data + this.clear(); + } + + /** + * Observes events being fired when an administrator has a linked a fax + * number + *

+ * @param event Event being fired + */ + public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) { + // Is the event fine? + if (event == null) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getContact() == null) { + // Throw again ... + throw new NullPointerException("event.contact is null"); //NOI18N + } else if (event.getContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactId is null"); //NOI18N + } else if (event.getContact().getContactId() < 1) { + // Throw again ... + throw new NullPointerException(MessageFormat.format("event.contact.contactId={0} is invalid", event.getContact().getContactId())); //NOI18N + } else if (event.getContact().getContactFaxNumber() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactFaxNumber is null"); //NOI18N + } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null"); //NOI18N + } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) { + // Throw again ... + throw new NullPointerException(MessageFormat.format("event.contact.contactFaxNumber.phoneId={0} is invalid", event.getContact().getContactFaxNumber().getPhoneId())); //NOI18N + } else if (event.getLinkedFaxNumber() == null) { + // Throw again ... + throw new NullPointerException("event.linkedFaxNumer is null"); //NOI18N + } + + // Is the id number in linked number not set? + if (event.getLinkedFaxNumber().getPhoneId() == null) { + // Then it is a new number, so add it from contact as there the id number has been set + this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber()); + } + } + + /** + * Observes events being fired when an administrator has a linked a + * land-line number + *

+ * @param event Event being fired + */ + public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) { + // Is the event fine? + if (event == null) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getContact() == null) { + // Throw again ... + throw new NullPointerException("event.contact is null"); //NOI18N + } else if (event.getContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactId is null"); //NOI18N + } else if (event.getContact().getContactId() < 1) { + // Throw again ... + throw new NullPointerException(MessageFormat.format("event.contact.contactId={0} is invalid", event.getContact().getContactId())); //NOI18N + } else if (event.getContact().getContactLandLineNumber() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactLandLineNumber is null"); //NOI18N + } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null"); //NOI18N + } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) { + // Throw again ... + throw new NullPointerException(MessageFormat.format("event.contact.contactLandLineNumber.phoneId={0} is invalid", event.getContact().getContactLandLineNumber().getPhoneId())); //NOI18N + } else if (event.getLinkedLandLineNumber() == null) { + // Throw again ... + throw new NullPointerException("event.linkedLandLineNumer is null"); //NOI18N + } + + // Is the id number in linked number not set? + if (event.getLinkedLandLineNumber().getPhoneId() == null) { + // Then it is a new number, so add it from contact as there the id number has been set + this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber()); + } + } + + /** + * Observes events being fired when an administrator has updated contact + * data. + *

+ * @param event Event being fired + */ + public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent 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) { + // phoneId 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 + } + + // Update contact's mobile, land-line and fax number + this.updateContactPhoneNumbers(event.getUpdatedContact()); + + // Clear all data + this.clear(); + } + + /** + * Observes events being fired when an administrator has updated a fax + * number. + *

+ * @param event Event being fired + */ + public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent 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.getUpdatedFaxNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N + } else if (event.getUpdatedFaxNumber().getPhoneId() == null) { + // phoneId is null + throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N + } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N + } + + // Uniquely add it + this.uniqueAddFaxNumber(event.getUpdatedFaxNumber()); + + // Clear it + this.clear(); + } + + /** + * Observes events being fired when an administrator has updated a land-line + * number. + *

+ * @param event Event being fired + */ + public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent 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.getUpdatedLandLineNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N + } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) { + // phoneId is null + throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N + } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N + } + + // Uniquely add it + this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber()); + + // Clear it + this.clear(); + } + + @Override + public DialableFaxNumber findFaxNumberById (final Long phoneId) throws PhoneEntityNotFoundException { + // Validate paramter + if (null == phoneId) { + // Throw NPE + throw new NullPointerException("phoneId is null"); //NOI18N + } else if (phoneId < 1) { + // Throw IAE + throw new IllegalArgumentException("phoneId=" + phoneId + " is invalid."); //NOI18N + } else if (!this.faxNumberCache.containsKey(phoneId)) { + // Not found + throw new PhoneEntityNotFoundException(phoneId); + } + + // Get it from cache + final DialableFaxNumber faxNumber = this.faxNumberCache.get(phoneId); + + // Return it + return faxNumber; + } + + @Override + public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException { + // Validate paramter + if (null == landLineNumberId) { + // Throw NPE + throw new NullPointerException("landLineNumberId is null"); //NOI18N + } else if (landLineNumberId < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("landLineNumberId={0} is invalid.", landLineNumberId)); //NOI18N + } else if (!this.landLineNumberCache.containsKey(landLineNumberId)) { + // Not found + throw new PhoneEntityNotFoundException(landLineNumberId); + } + + // Get it from cache + final DialableLandLineNumber landLineNumber = this.landLineNumberCache.get(landLineNumberId); + + // Return it + return landLineNumber; + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllFaxNumbers () { + return this.allFaxNumbers; + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllLandLineNumbers () { + return this.allLandLineNumbers; + } + + /** + * Getter for filtered fax number list + *

+ * @return Filtered fax number list + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredFaxNumbers () { + return this.filteredFaxNumbers; + } + + /** + * Setter for filtered fax number list + * + * @param filteredFaxNumbers Filtered fax number list + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredFaxNumbers (final List filteredFaxNumbers) { + this.filteredFaxNumbers = filteredFaxNumbers; + } + + /** + * Getter for filtered land-line number list + *

+ * @return Filtered land-line number list + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredLandLineNumbers () { + return this.filteredLandLineNumbers; + } + + /** + * Setter for filtered land-line number list + * + * @param filteredLandLineNumbers Filtered land-line number list + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredLandLineNumbers (final List filteredLandLineNumbers) { + this.filteredLandLineNumbers = filteredLandLineNumbers; + } + + /** + * Post-construction method + */ + @PostConstruct + public void initializeList () { + // Is cache there? + if (!this.faxNumberCache.iterator().hasNext()) { + // Add all + for (final DialableFaxNumber currentNumber : this.phoneBean.fetchAllFaxNumbers()) { + // Add it to cache + this.faxNumberCache.put(currentNumber.getPhoneId(), currentNumber); + } + } + + // Is cache there? + if (!this.landLineNumberCache.iterator().hasNext()) { + // Add all + for (final DialableLandLineNumber currentNumber : this.phoneBean.fetchAllLandLineNumbers()) { + // Add it to cache + this.landLineNumberCache.put(currentNumber.getPhoneId(), currentNumber); + } + } + + // Is cache filled and list is empty + if ((this.faxNumberCache.iterator().hasNext()) && (this.getAllFaxNumbers().isEmpty())) { + // Build up list + for (final Cache.Entry currentEntry : this.faxNumberCache) { + // Add to list + this.getAllFaxNumbers().add(currentEntry.getValue()); + } + + // Sort list + this.getAllFaxNumbers().sort(new Comparator() { + @Override + public int compare (final DialableFaxNumber faxNumber1, final DialableFaxNumber faxNumber2) { + return faxNumber1.getPhoneId() > faxNumber2.getPhoneId() ? 1 : faxNumber1.getPhoneId() < faxNumber2.getPhoneId() ? -1 : 0; + } + }); + + // Set full list + this.setFilteredFaxNumbers(this.getAllFaxNumbers()); + } + + // Is cache filled and list is empty + if ((this.landLineNumberCache.iterator().hasNext()) && (this.getAllLandLineNumbers().isEmpty())) { + // Build up list + for (final Cache.Entry currentEntry : this.landLineNumberCache) { + // Add to list + this.getAllLandLineNumbers().add(currentEntry.getValue()); + } + + // Sort list + this.getAllLandLineNumbers().sort(new Comparator() { + @Override + public int compare (final DialableLandLineNumber landLineNumber1, final DialableLandLineNumber landLineNumber2) { + return landLineNumber1.getPhoneId() > landLineNumber2.getPhoneId() ? 1 : landLineNumber1.getPhoneId() < landLineNumber2.getPhoneId() ? -1 : 0; + } + }); + + // Set full list + this.setFilteredLandLineNumbers(this.getAllLandLineNumbers()); + } + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all data + } + + /** + * Uniquely add given fax number to this bean's list. First remove the old + * instance (by id number), then re-add it again. + *

+ * @param faxNumber number to add + */ + private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) { + // Make sure the parameter is valid + if (null == faxNumber) { + // Throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId())); //NOI18N + } + + // First remove it + if (!this.getAllFaxNumbers().remove(faxNumber)) { + // Did not work, try by id number + for (final DialableFaxNumber currentNumber : this.getAllFaxNumbers()) { + // Is id number the same? + if (Objects.equals(currentNumber.getPhoneId(), faxNumber.getPhoneId())) { + // Found it + this.getAllFaxNumbers().remove(currentNumber); + break; + } + } + } + + // ... then add it + this.getAllFaxNumbers().add(faxNumber); + } + + /** + * Uniquely add given land-line number to this bean's list. First remove the + * old instance (by id number), then re-add it again. + *

+ * @param landLineNumber Land-line number to add + */ + private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) { + // Make sure the parameter is valid + if (null == landLineNumber) { + // Throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId())); //NOI18N + } + + // First remove it + if (!this.getAllLandLineNumbers().remove(landLineNumber)) { + // Did not work, try by id number + for (final DialableLandLineNumber currentNumber : this.getAllLandLineNumbers()) { + // Is id number the same? + if (Objects.equals(currentNumber.getPhoneId(), landLineNumber.getPhoneId())) { + // Found it + this.getAllLandLineNumbers().remove(currentNumber); + break; + } + } + } + + // ... then add it + this.getAllLandLineNumbers().add(landLineNumber); + } + + /** + * Updates given contact's mobile, land-line and fax number + *

+ * @param contact Contact instance + */ + private void updateContactPhoneNumbers (final Contact contact) { + // Parameter must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Id number is not valid + } + + // Is land-line set? + if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { + // Unique-add it + this.uniqueAddLandLineNumber(contact.getContactLandLineNumber()); + } + + // Is fax set? + if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { + // Unique-add it + this.uniqueAddFaxNumber(contact.getContactFaxNumber()); + } + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/phone/list/JobsPhoneListWebViewController.java b/src/java/org/mxchange/jjobs/beans/phone/list/JobsPhoneListWebViewController.java new file mode 100644 index 00000000..0ad5190f --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/phone/list/JobsPhoneListWebViewController.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2016 - 2020 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 + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.phone.list; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; + +/** + * An interface for a request web controller (bean) for administrative phone + * number purposes. + *

+ * @author Roland Häder + */ +public interface JobsPhoneListWebViewController extends Serializable { + + /** + * Returns a list of all fax numbers. For performance reasons, the + * controller (bean) should be view-scoped as from user to user nothing + * changes. And the controller's post-construct method should load all + * numbers and cache it in the controller. + *

+ * @return List of all fax numbers + */ + List getAllFaxNumbers (); + + /** + * Returns a list of all land-line numbers. For performance reasons, the + * controller (bean) should be view-scoped as from user to user nothing + * changes. And the controller's post-construct method should load all + * numbers and cache it in the controller. + *

+ * @return List of all land-line numbers + */ + List getAllLandLineNumbers (); + + /** + * Finds a fax entry by given id number + *

+ * @param faxNumberId Fax entry id number + *

+ * @return A valid fax instance + *

+ * @throws PhoneEntityNotFoundException If the entity was not found + */ + DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException; + + /** + * Finds a land-line entry by given id number + *

+ * @param landLineNumberId Land-line entry id number + *

+ * @return A valid land-line instance + *

+ * @throws PhoneEntityNotFoundException If the entity was not found + */ + DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException; + +} diff --git a/src/java/org/mxchange/jjobs/beans/profile/JobsUserProfileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/profile/JobsUserProfileWebRequestBean.java index a943ba2c..322a0055 100644 --- a/src/java/org/mxchange/jjobs/beans/profile/JobsUserProfileWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/profile/JobsUserProfileWebRequestBean.java @@ -22,7 +22,7 @@ import javax.faces.FacesException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jjobs.beans.user.JobsUserWebRequestController; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController; import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; @@ -46,7 +46,7 @@ public class JobsUserProfileWebRequestBean extends BaseJobsBean implements JobsU * User list controller */ @Inject - private JobsUserWebRequestController userListController; + private JobsUserListWebViewController userListController; /** * Login controller diff --git a/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebRequestBean.java index 0d8a6707..18f64575 100644 --- a/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebRequestBean.java @@ -26,7 +26,7 @@ import javax.inject.Named; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController; -import org.mxchange.jjobs.beans.user.JobsUserWebRequestController; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController; import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; @@ -72,7 +72,7 @@ public class JobsResendLinkWebRequestBean extends BaseJobsBean implements JobsRe * Regular user controller */ @Inject - private JobsUserWebRequestController userListController; + private JobsUserListWebViewController userListController; /** * Event being fired after confirmation link is being sent diff --git a/src/java/org/mxchange/jjobs/converter/business/employee/JobsEmployeeConverter.java b/src/java/org/mxchange/jjobs/converter/business/employee/JobsEmployeeConverter.java index 2c895c62..b0fbf809 100644 --- a/src/java/org/mxchange/jjobs/converter/business/employee/JobsEmployeeConverter.java +++ b/src/java/org/mxchange/jjobs/converter/business/employee/JobsEmployeeConverter.java @@ -24,8 +24,8 @@ import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeNotFoundException; import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jjobs.beans.business.employee.JobsEmployeeWebRequestBean; -import org.mxchange.jjobs.beans.business.employee.JobsEmployeeWebRequestController; +import org.mxchange.jjobs.beans.business.employee.list.JobsEmployeeListWebViewBean; +import org.mxchange.jjobs.beans.business.employee.list.JobsEmployeeListWebViewController; /** * Converter for converting company employee to and from id number @@ -38,21 +38,12 @@ public class JobsEmployeeConverter implements Converter { /** * Employable EJB */ - private static JobsEmployeeWebRequestController EMPLOYEE_LIST_CONTROLLER; + private static JobsEmployeeListWebViewController EMPLOYEE_LIST_CONTROLLER; @Override public Employable getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the instance there? - if (null == EMPLOYEE_LIST_CONTROLLER) { - // Get bean from CDI directly - EMPLOYEE_LIST_CONTROLLER = CDI.current().select(JobsEmployeeWebRequestBean.class).get(); - } - // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N - // Return null return null; } @@ -64,6 +55,12 @@ public class JobsEmployeeConverter implements Converter { // Try to parse the value as long final Long employeeId = Long.valueOf(submittedValue); + // Is the instance there? + if (null == EMPLOYEE_LIST_CONTROLLER) { + // Get bean from CDI directly + EMPLOYEE_LIST_CONTROLLER = CDI.current().select(JobsEmployeeListWebViewBean.class).get(); + } + // Try to get user instance from it companyEmployee = EMPLOYEE_LIST_CONTROLLER.findEmployeeById(employeeId); } catch (final NumberFormatException ex) { diff --git a/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java b/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java index c5f3f1b9..51387181 100644 --- a/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java +++ b/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java @@ -22,6 +22,8 @@ import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; +import org.mxchange.jjobs.beans.phone.list.JobsPhoneListWebViewBean; +import org.mxchange.jjobs.beans.phone.list.JobsPhoneListWebViewController; import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; diff --git a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java index 2a64a37a..5c808704 100644 --- a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java +++ b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java @@ -22,6 +22,8 @@ import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; +import org.mxchange.jjobs.beans.phone.list.JobsPhoneListWebViewBean; +import org.mxchange.jjobs.beans.phone.list.JobsPhoneListWebViewController; import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; diff --git a/src/java/org/mxchange/jjobs/converter/mobile/JobsMobileNumberConverter.java b/src/java/org/mxchange/jjobs/converter/mobile/JobsMobileNumberConverter.java index 69472ec4..60b3ee62 100644 --- a/src/java/org/mxchange/jjobs/converter/mobile/JobsMobileNumberConverter.java +++ b/src/java/org/mxchange/jjobs/converter/mobile/JobsMobileNumberConverter.java @@ -22,6 +22,9 @@ import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; +import org.mxchange.jjobs.beans.mobile.list.JobsMobileListWebViewBean; +import org.mxchange.jjobs.beans.mobile.list.JobsMobileListWebViewController; +import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException; import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; /** diff --git a/src/java/org/mxchange/jjobs/converter/mobileprovider/JobsMobileProviderConverter.java b/src/java/org/mxchange/jjobs/converter/mobileprovider/JobsMobileProviderConverter.java index c70f9059..b26acae5 100644 --- a/src/java/org/mxchange/jjobs/converter/mobileprovider/JobsMobileProviderConverter.java +++ b/src/java/org/mxchange/jjobs/converter/mobileprovider/JobsMobileProviderConverter.java @@ -22,6 +22,8 @@ import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; +import org.mxchange.jjobs.beans.mobileprovider.list.JobsMobileProviderListWebViewBean; +import org.mxchange.jjobs.beans.mobileprovider.list.JobsMobileProviderListWebViewController; import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderNotFoundException; import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; diff --git a/src/java/org/mxchange/jjobs/converter/user/JobsUserConverter.java b/src/java/org/mxchange/jjobs/converter/user/JobsUserConverter.java index 5050ed42..241e1c28 100644 --- a/src/java/org/mxchange/jjobs/converter/user/JobsUserConverter.java +++ b/src/java/org/mxchange/jjobs/converter/user/JobsUserConverter.java @@ -22,8 +22,8 @@ import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; -import org.mxchange.jjobs.beans.user.JobsUserWebRequestBean; -import org.mxchange.jjobs.beans.user.JobsUserWebRequestController; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewBean; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; @@ -38,14 +38,14 @@ public class JobsUserConverter implements Converter { /** * User backing bean */ - private static JobsUserWebRequestController USER_LIST_CONTROLLER; + private static JobsUserListWebViewController USER_LIST_CONTROLLER; @Override public User getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { // Is the instance there? if (null == USER_LIST_CONTROLLER) { // Get bean from CDI directly - USER_LIST_CONTROLLER = CDI.current().select(JobsUserWebRequestBean.class).get(); + USER_LIST_CONTROLLER = CDI.current().select(JobsUserListWebViewBean.class).get(); } // Is the value null or empty? diff --git a/src/java/org/mxchange/jjobs/validator/emailaddress/employee/JobsEmployeeEmailAddressValidator.java b/src/java/org/mxchange/jjobs/validator/emailaddress/employee/JobsEmployeeEmailAddressValidator.java index 55d2c37f..e1525642 100644 --- a/src/java/org/mxchange/jjobs/validator/emailaddress/employee/JobsEmployeeEmailAddressValidator.java +++ b/src/java/org/mxchange/jjobs/validator/emailaddress/employee/JobsEmployeeEmailAddressValidator.java @@ -25,8 +25,8 @@ import javax.faces.context.FacesContext; import javax.faces.validator.FacesValidator; import javax.faces.validator.ValidatorException; import org.mxchange.jcoreee.validator.string.BaseStringValidator; -import org.mxchange.jjobs.beans.business.employee.JobsEmployeeWebRequestBean; -import org.mxchange.jjobs.beans.business.employee.JobsEmployeeWebRequestController; +import org.mxchange.jjobs.beans.business.employee.list.JobsEmployeeListWebViewBean; +import org.mxchange.jjobs.beans.business.employee.list.JobsEmployeeListWebViewController; /** * A validator for employee email address validation @@ -44,7 +44,7 @@ public class JobsEmployeeEmailAddressValidator extends BaseStringValidator { /** * Employee backing bean */ - private static JobsEmployeeWebRequestController EMPLOYEE_LIST_CONTROLLER; + private static JobsEmployeeListWebViewController EMPLOYEE_LIST_CONTROLLER; /** * Pattern matcher @@ -117,7 +117,7 @@ public class JobsEmployeeEmailAddressValidator extends BaseStringValidator { // Is the instance there? if (null == EMPLOYEE_LIST_CONTROLLER) { // Get bean from CDI directly - EMPLOYEE_LIST_CONTROLLER = CDI.current().select(JobsEmployeeWebRequestBean.class).get(); + EMPLOYEE_LIST_CONTROLLER = CDI.current().select(JobsEmployeeListWebViewBean.class).get(); } // Is it registered? diff --git a/src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java b/src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java index 2e0a6692..f11b3684 100644 --- a/src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java +++ b/src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java @@ -24,8 +24,8 @@ import javax.faces.context.FacesContext; import javax.faces.validator.FacesValidator; import javax.faces.validator.ValidatorException; import org.mxchange.jcoreee.validator.number.BaseNumberValidator; -import org.mxchange.jjobs.beans.user.JobsUserWebRequestBean; -import org.mxchange.jjobs.beans.user.JobsUserWebRequestController; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewBean; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController; /** * A validator for user ids @@ -38,7 +38,7 @@ public class JobsUserIdValidator extends BaseNumberValidator { /** * User backing bean */ - private static JobsUserWebRequestController USER_LIST_CONTROLLER; + private static JobsUserListWebViewController USER_LIST_CONTROLLER; /** * Serial number @@ -56,7 +56,7 @@ public class JobsUserIdValidator extends BaseNumberValidator { // Is the instance there? if (null == USER_LIST_CONTROLLER) { // Get bean from CDI directly - USER_LIST_CONTROLLER = CDI.current().select(JobsUserWebRequestBean.class).get(); + USER_LIST_CONTROLLER = CDI.current().select(JobsUserListWebViewBean.class).get(); } // Cast value