From 32c4f7095b98123c15a69ca925ba7aa9be34abd4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 9 Sep 2017 12:54:16 +0200 Subject: [PATCH] Please cherry-pick: - renamed companyDataId -> basicDataId (already done in underlaying entity) - implemented addBranchOffice() which will call newly added private methods to create a BranchOffice instance and validate if the address is already found in an other bean's cache - for this, allBranchOffices() needs to be published in interface - implemented afterBranchOfficeAddedEvent() event observer which will add the newly added branch office to the backing bean's cache - now displaying link to company's website correctly or, if not provided, a replacement message - same with email link, maybe one day I move this out to a custom JSF tag? - added missing i18n strings - generalized duplicate i18n strings - added missing navigation cases MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../FinancialsBusinessDataWebRequestBean.java | 12 +- ...ncialsAdminBranchOfficeWebRequestBean.java | 163 ++++++++++++++++++ .../FinancialsBranchOfficeWebRequestBean.java | 32 +++- ...cialsBranchOfficeWebRequestController.java | 9 + .../FinancialsBasicCompanyDataConverter.java | 2 +- .../localization/bundle_de_DE.properties | 63 ++++--- .../localization/bundle_en_US.properties | 63 ++++--- web/WEB-INF/faces-config.xml | 36 +++- .../columns/admin_contact_data_columns.tpl | 2 +- .../admin_contact_data_columns_mini.tpl | 2 +- .../contact/admin_form_contact_data.tpl | 2 +- .../form_data/fax/admin_form_fax_data.tpl | 2 +- .../landline/admin_form_landline_data.tpl | 2 +- .../mobile/admin_form_mobile_data.tpl | 2 +- .../admin/panel_grids/fax/admin_fax_data.tpl | 2 +- .../landline/admin_landline_data.tpl | 2 +- .../panel_grids/mobile/admin_mobile_data.tpl | 2 +- .../admin_form_basic_company_data.tpl | 26 +-- .../admin_form_branch_offices_data.tpl | 16 +- .../admin_basic_company_data_list.xhtml | 16 +- .../admin_branch_offices_list.xhtml | 34 ++-- web/admin/contact/admin_contact_list.xhtml | 2 +- web/admin/country/admin_country_list.xhtml | 2 +- web/admin/fax/admin_fax_list.xhtml | 2 +- web/admin/fax/admin_fax_show.xhtml | 2 +- web/admin/landline/admin_landline_list.xhtml | 2 +- web/admin/landline/admin_landline_show.xhtml | 2 +- web/admin/mobile/admin_mobile_list.xhtml | 2 +- web/admin/mobile/admin_mobile_show.xhtml | 2 +- .../admin_mobile_provider_list.xhtml | 4 +- web/admin/user/admin_user_list.xhtml | 2 +- 31 files changed, 381 insertions(+), 131 deletions(-) diff --git a/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsBusinessDataWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsBusinessDataWebRequestBean.java index de1192ae..ec9df6db 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsBusinessDataWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsBusinessDataWebRequestBean.java @@ -142,12 +142,12 @@ public class FinancialsBusinessDataWebRequestBean extends BaseFinancialsControll } else if (event.getBasicData() == null) { // Throw NPE again throw new NullPointerException("event.basicData is null"); - } else if (event.getBasicData().getCompanyDataId() == null) { + } else if (event.getBasicData().getBasicDataId() == null) { // Throw NPE again - throw new NullPointerException("event.basicData.companyDataId is null"); - } else if (event.getBasicData().getCompanyDataId() < 1) { + throw new NullPointerException("event.basicData.basicDataId is null"); + } else if (event.getBasicData().getBasicDataId() < 1) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("event.basicData.companyDataId={0} is invalid", event.getBasicData().getCompanyDataId())); + throw new IllegalArgumentException(MessageFormat.format("event.basicData.basicDataId={0} is invalid", event.getBasicData().getBasicDataId())); } else if (event.getBasicData().getCompanyName() == null) { // Throw NPE again throw new NullPointerException("event.basicData.companyName is null"); @@ -157,7 +157,7 @@ public class FinancialsBusinessDataWebRequestBean extends BaseFinancialsControll } // Add it to list - this.basicDataCache.put(event.getBasicData().getCompanyDataId(), event.getBasicData()); + this.basicDataCache.put(event.getBasicData().getBasicDataId(), event.getBasicData()); } /** @@ -364,7 +364,7 @@ public class FinancialsBusinessDataWebRequestBean extends BaseFinancialsControll final BusinessBasicData next = iterator.next(); // Add it to cache - this.basicDataCache.put(next.getCompanyDataId(), next); + this.basicDataCache.put(next.getBasicDataId(), next); } } } diff --git a/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsAdminBranchOfficeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsAdminBranchOfficeWebRequestBean.java index 94d88e7b..4bb7fd5f 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsAdminBranchOfficeWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsAdminBranchOfficeWebRequestBean.java @@ -16,14 +16,28 @@ */ package org.mxchange.jfinancials.beans.business.branchoffice; +import java.util.List; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.branchoffice.AdminBranchOfficeSessionBeanRemote; +import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.branchoffice.BranchOfficeUtils; +import org.mxchange.jcontactsbusiness.branchoffice.CompanyBranchOffice; import org.mxchange.jcontactsbusiness.employee.Employee; +import org.mxchange.jcontactsbusiness.events.branchoffice.added.BranchOfficeAddedEvent; +import org.mxchange.jcontactsbusiness.events.branchoffice.added.ObservableBranchOfficeAddedEvent; +import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException; import org.mxchange.jcountry.data.Country; import org.mxchange.jfinancials.beans.BaseFinancialsController; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.fax.FaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; import org.mxchange.jusercore.model.user.User; /** @@ -76,6 +90,19 @@ public class FinancialsAdminBranchOfficeWebRequestBean extends BaseFinancialsCon */ private Short branchHouseNumber; + /** + * An event being fired when a branch office has been successfully added + */ + @Inject + @Any + private Event branchOfficeAddedEvent; + + /** + * A general branch office controller (backing bean) + */ + @Inject + private FinancialsBranchOfficeWebRequestController branchOfficeController; + /** * Store */ @@ -139,6 +166,43 @@ public class FinancialsAdminBranchOfficeWebRequestBean extends BaseFinancialsCon super(); } + /** + * Adds branch office with all data from this backing bean. First this + * action method will validate if the branch office's address is already + * registered and if found, it will output a proper faces message. + *

+ * @return Redirect outcome + */ + public String addBranchOffice () { + // Get instance + final BranchOffice branchOffice = this.createBranchOffice(); + + // Is the branch office not created yet? + if (this.isBranchOfficeCreatedByRequiredData(branchOffice)) { + // Then show proper faces message + this.showFacesMessage("form_admin_add_branch_office:branchStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED"); //NOI18N + return ""; //NOI18N + } + + // Delcare updated instance + final BranchOffice updatedOffice; + + try { + // Try to call EJB + updatedOffice = this.adminBranchOfficeBean.addBranchOffice(branchOffice); + } catch (final BranchOfficeAlreadyAddedException ex) { + // Output message + this.showFacesMessage("form_admin_add_branch_office:branchStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED"); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.branchOfficeAddedEvent.fire(new BranchOfficeAddedEvent(updatedOffice)); + + // Redirect to list + return "admin_list_branch_offices"; //NOI18N + } + /** * Getter for city *

@@ -445,4 +509,103 @@ public class FinancialsAdminBranchOfficeWebRequestBean extends BaseFinancialsCon this.landLineNumber = landLineNumber; } + /** + * Prepares an instance of a BranchOffice object (entity) with all data from + * this bean. If a complete fax number or land-line number was provided, it + * will be set in the instance as well. + *

+ * @return An instance of a BranchOffice class (entity) + */ + private BranchOffice createBranchOffice () { + // Create new branch office instance + final BranchOffice branchOffice = new CompanyBranchOffice(this.getBranchCity(), this.getBranchCompany(), this.getBranchCountry(), this.getBranchStreet(), this.getBranchZipCode(), this.getBranchHouseNumber()); + + // Add all other fields, too + branchOffice.setBranchContactEmployee(this.getBranchContactEmployee()); + branchOffice.setBranchEmailAddress(this.getBranchEmailAddress()); + branchOffice.setBranchStore(this.getBranchStore()); + branchOffice.setBranchSuiteNumber(this.getBranchSuiteNumber()); + branchOffice.setBranchUserOwner(this.getBranchUserOwner()); + + // Generate phone number + final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber()); + final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); + + // Don't set null or wrong references + if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) { + // Now the number must be given + if (landLine.getPhoneAreaCode() == null) { + // Is null + throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N + } else if (landLine.getPhoneAreaCode() < 1) { + // Abort here + throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N + } else if (landLine.getPhoneNumber() == null) { + // Is null + throw new NullPointerException("phone.phoneNumber is null"); //NOI18N + } else if (landLine.getPhoneNumber() < 1) { + // Abort here + throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N + } + + // Set phone number + branchOffice.setBranchLandLineNumber(landLine); + } + + // Don't set null or wrong references + if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) { + // Now the number must be given + if (fax.getPhoneAreaCode() == null) { + // Is null + throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N + } else if (fax.getPhoneAreaCode() < 1) { + // Abort here + throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N + } else if (fax.getPhoneNumber() == null) { + // Is null + throw new NullPointerException("fax.phoneNumber is null"); //NOI18N + } else if (fax.getPhoneNumber() < 1) { + // Abort here + throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N + } + + // Set fax number + branchOffice.setBranchFaxNumber(fax); + } + + // Return fully prepared instance + return branchOffice; + } + + /** + * Checks whether the given branch office's address is already found in + * local cache. Please note that this method fully relies on the cache, so + * you must always fire proper events that add/update/delete entries in + * cache. + *

+ * @param branchOffice Branch office to check it's address + *

+ * @return Whether the address has been found + */ + private boolean isBranchOfficeCreatedByRequiredData (final BranchOffice branchOffice) { + // Get full list from other bean + final List branchOffices = this.branchOfficeController.allBranchOffices(); + + // Default is not found + boolean isFound = false; + + // Now check each entry + for (final BranchOffice bo : branchOffices) { + // Is same address? + if (BranchOfficeUtils.isSameAddress(bo, branchOffice)) { + // Found one + isFound = true; + break; + } + } + + // Return flag + return isFound; + } + } diff --git a/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsBranchOfficeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsBranchOfficeWebRequestBean.java index 46be69a0..6d26c698 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsBranchOfficeWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsBranchOfficeWebRequestBean.java @@ -17,6 +17,7 @@ package org.mxchange.jfinancials.beans.business.branchoffice; import fish.payara.cdi.jsr107.impl.NamedCache; +import java.text.MessageFormat; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -24,10 +25,12 @@ import javax.annotation.PostConstruct; import javax.cache.Cache; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Observes; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.branchoffice.BranchOfficeSessionBeanRemote; +import org.mxchange.jcontactsbusiness.events.branchoffice.added.ObservableBranchOfficeAddedEvent; import org.mxchange.jfinancials.beans.BaseFinancialsController; /** @@ -66,11 +69,34 @@ public class FinancialsBranchOfficeWebRequestBean extends BaseFinancialsControll } /** - * Returns a list of all branch offices + * Observes events being fired when a branch office has been added. *

- * @return A list of all branch offices + * @param event Event being fired + *

+ * @throws NullPointerException If the parameter or it's carried instance is null + * @throws IllegalArgumentException If the branchId is zero or lower */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public void afterBranchOfficeAddedEvent (@Observes final ObservableBranchOfficeAddedEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getBranchOffice() == null) { + // Throw NPE again + throw new NullPointerException("event.branchOffice is null"); //NOI18N + } else if (event.getBranchOffice().getBranchId() == null) { + // Throw it again + throw new NullPointerException("event.branchOffice.branchId is null"); //NOI18N + } else if (event.getBranchOffice().getBranchId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("event.branchOffice.branchId={0} is not valid", event.getBranchOffice().getBranchId())); //NOI18N + } + + // Add instance to cache + this.branchOfficeCache.put(event.getBranchOffice().getBranchId(), event.getBranchOffice()); + } + + @Override public List allBranchOffices () { // Init list final List list = new LinkedList<>(); diff --git a/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsBranchOfficeWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsBranchOfficeWebRequestController.java index ddacb392..e6b9ed5f 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsBranchOfficeWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/business/branchoffice/FinancialsBranchOfficeWebRequestController.java @@ -17,6 +17,8 @@ package org.mxchange.jfinancials.beans.business.branchoffice; import java.io.Serializable; +import java.util.List; +import org.mxchange.jcontactsbusiness.branchoffice.BranchOffice; /** * An interface for general branch office controller @@ -25,4 +27,11 @@ import java.io.Serializable; */ public interface FinancialsBranchOfficeWebRequestController extends Serializable { + /** + * Returns a list of all branch offices + *

+ * @return A list of all branch offices + */ + List allBranchOffices (); + } diff --git a/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java index 924b91cf..0414610d 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java @@ -98,7 +98,7 @@ public class FinancialsBasicCompanyDataConverter implements Converter /admin/basic_company_data/admin_basic_company_data_list.xhtml - admin_show_basic_company_data - /admin/basic_company_data/admin_basic_company_data_assign.xhtml + admin_show_basic_data + /admin/basic_company_data/admin_basic_company_data_show.xhtml admin_assign_basic_company_data_contact @@ -728,9 +728,41 @@ admin_assign_basic_company_data_owner /admin/basic_company_data/admin_basic_company_data_assign_owner.xhtml + + admin_show_business_employee + /admin/company_employee/admin_company_employee_show.xhtml + + + admin_assign_basic_company_data_employee + /admin/basic_company_data/admin_basic_company_data_assign_employee.xhtml + /admin/branch_offices/admin_branch_offices_list.xhtml + + admin_show_branch_office + /admin/branch_offices/admin_branch_office_show.xhtml + + + admin_show_user + /admin/user/admin_user_show.xhtml + + + admin_assign_branch_office_owner + /admin/branch_offices/admin_branch_office_assign_owner.xhtml + + + admin_show_basic_data + /admin/basic_company_data/admin_basic_company_data_show.xhtml + + + admin_show_business_employee + /admin/company_employee/admin_company_employee_show.xhtml + + + admin_assign_branch_office_employee + /admin/branch_offices/admin_branch_office_assign_employee.xhtml +