From f8e33ab8f44c2c8429a94e9d24ce670f04ef6e65 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 2 Apr 2020 18:29:54 +0200 Subject: [PATCH] Please cherry-pick: - rewrote admin-headquarters-list to have filters and sorting (newer approach) - added p:panelGrid around reset/submit buttons, still administrative contact list is not being updated on record insert - used beanHelper.renderEmployee() to render department leader (employee instance again) - fixed some wrong references due to last rewrite for departments - added missing i18n key MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...ancialsAdminHeadquarterWebRequestBean.java | 46 +-- .../FinancialsHeadquarterWebRequestBean.java | 201 ------------ ...ncialsHeadquarterWebRequestController.java | 40 --- .../FinancialsHeadquarterListWebViewBean.java | 306 ++++++++++++++++++ ...cialsHeadquarterListWebViewController.java | 79 +++++ .../FinancialsHeadquarterConverter.java | 19 +- ...ncialsHeadquarterCompanyNameValidator.java | 20 +- ...cialsHeadquarterEmailAddressValidator.java | 13 +- .../localization/generic_de_DE.properties | 1 + .../localization/generic_en_US.properties | 1 + .../basic_data/admin_form_basic_data.tpl | 2 +- .../department/admin_form_department_data.tpl | 2 +- .../employee/admin_form_employee_data.tpl | 4 +- web/admin/contact/admin_contact_list.xhtml | 24 +- .../department/admin_department_list.xhtml | 4 +- .../headquarter/admin_headquarter_list.xhtml | 73 ++++- 16 files changed, 504 insertions(+), 331 deletions(-) create mode 100644 src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewBean.java create mode 100644 src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewController.java diff --git a/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsAdminHeadquarterWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsAdminHeadquarterWebRequestBean.java index dd287dc2..4dd51a1a 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsAdminHeadquarterWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsAdminHeadquarterWebRequestBean.java @@ -33,12 +33,12 @@ import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.headquarter.AdminHeadquarterSessionBeanRemote; import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; -import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters; import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.business.headquarter.list.FinancialsHeadquarterListWebViewController; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; @@ -107,12 +107,6 @@ public class FinancialsAdminHeadquarterWebRequestBean extends BaseFinancialsBean */ private Employable headquarterContactEmployee; - /** - * A general headquarter controller (backing bean) - */ - @Inject - private FinancialsHeadquarterWebRequestController headquarterController; - /** * Country */ @@ -138,6 +132,12 @@ public class FinancialsAdminHeadquarterWebRequestBean extends BaseFinancialsBean */ private Short headquarterLastHouseNumber; + /** + * A general headquarter controller (backing bean) + */ + @Inject + private FinancialsHeadquarterListWebViewController headquarterListController; + /** * Store */ @@ -222,7 +222,7 @@ public class FinancialsAdminHeadquarterWebRequestBean extends BaseFinancialsBean final Headquarter headquarter = this.createHeadquarter(); // Is the headquarter not created yet? - if (this.isHeadquarterCreatedByRequiredData(headquarter)) { + if (this.headquarterListController.isHeadquarterCreatedByRequiredData(headquarter)) { // Then show proper faces message this.showFacesMessage("form-admin-add-headquarter-office:headquarterStreet", "ADMIN_HEADQUARTER_ALREADY_CREATED"); //NOI18N return; @@ -847,36 +847,6 @@ public class FinancialsAdminHeadquarterWebRequestBean extends BaseFinancialsBean return openingTime; } - /** - * Checks whether the given headquarter' 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 headquarter Headquarter to check it's address - *

- * @return Whether the address has been found - */ - private boolean isHeadquarterCreatedByRequiredData (final Headquarter headquarter) { - // Get full list from other bean - final List allHeadquarter = this.headquarterController.allHeadquarter(); - - // Default is not found - boolean isFound = false; - - // Now check each entry - for (final Headquarter hq : allHeadquarter) { - // Is same address? - if (Headquarters.isSameAddress(hq, headquarter)) { - // Found one - isFound = true; - break; - } - } - - // Return flag - return isFound; - } - /** * Checks if given opening time is already added *

diff --git a/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestBean.java index 15c9d8ff..4bb7a2c6 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestBean.java @@ -16,22 +16,9 @@ */ package org.mxchange.jfinancials.beans.business.headquarter; -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.context.RequestScoped; -import javax.enterprise.event.Observes; -import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.jcontactsbusiness.events.headquarter.added.ObservableHeadquarterAddedEvent; -import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterNotFoundException; -import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; import org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote; import org.mxchange.jfinancials.beans.BaseFinancialsBean; @@ -49,206 +36,18 @@ public class FinancialsHeadquarterWebRequestBean extends BaseFinancialsBean impl */ private static final long serialVersionUID = 5_028_697_360_465L; - /** - * A list of all headquarter - */ - private final List allHeadquarter; - - /** - * A list of filtered headquarter - */ - private List filteredHeadquarter; - /** * EJB for administrative purposes */ @EJB (lookup = "java:global/jfinancials-ejb/headquarter!org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote") private HeadquarterSessionBeanRemote headquarterBean; - /** - * A list of all headquarter (globally) - */ - @Inject - @NamedCache (cacheName = "headquarterCache") - private Cache headquarterCache; - /** * Default constructor */ public FinancialsHeadquarterWebRequestBean () { // Call super constructor super(); - - // Init list - this.allHeadquarter = new LinkedList<>(); - } - - /** - * Observes events being fired when a branch office has been added. - *

- * @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 - */ - public void afterHeadquarterAddedEvent (@Observes final ObservableHeadquarterAddedEvent event) { - // Validate parameter - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getHeadquarter() == null) { - // Throw NPE again - throw new NullPointerException("event.headquarter is null"); //NOI18N - } else if (event.getHeadquarter().getHeadquarterId() == null) { - // Throw it again - throw new NullPointerException("event.headquarter.branchId is null"); //NOI18N - } else if (event.getHeadquarter().getHeadquarterId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("event.headquarter.branchId={0} is not valid", event.getHeadquarter().getHeadquarterId())); //NOI18N - } - - // Add instance to cache - this.headquarterCache.put(event.getHeadquarter().getHeadquarterId(), event.getHeadquarter()); - this.allHeadquarter.add(event.getHeadquarter()); - } - - @Override - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List allHeadquarter () { - return this.allHeadquarter; - } - - @Override - public Headquarter findHeadquarterById (final Long headquarterId) throws HeadquarterNotFoundException { - // Validate parameter - if (null == headquarterId) { - // Throw NPE - throw new NullPointerException("headquarterId is null"); //NOI18N - } else if (headquarterId < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("headquarterId={0} is invalid", headquarterId)); //NOI18N - } else if (!this.headquarterCache.containsKey(headquarterId)) { - // Not found - throw new HeadquarterNotFoundException(headquarterId); - } - - // Get it from cache - final Headquarter headquarter = this.headquarterCache.get(headquarterId); - - // Return it - return headquarter; - } - - /** - * Getter for a list of filtered headquarter - *

- * @return Filtered headquarter - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredHeadquarter () { - return this.filteredHeadquarter; - } - - /** - * Setter for a list of filtered headquarter - *

- * @param filteredHeadquarter Filtered headquarter - */ - @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredHeadquarter (final List filteredHeadquarter) { - this.filteredHeadquarter = filteredHeadquarter; - } - - /** - * Initializer method - */ - @PostConstruct - public void initializeList () { - // Is cache there? - if (!this.headquarterCache.iterator().hasNext()) { - // Get whole list from EJB - final List Headquarter = this.headquarterBean.allHeadquarters(); - - // Add all - for (final Headquarter headquarter : Headquarter) { - // Add it to cache - this.headquarterCache.put(headquarter.getHeadquarterId(), headquarter); - } - } - - // Is the list empty, but filled cache? - if (this.allHeadquarter.isEmpty() && this.headquarterCache.iterator().hasNext()) { - // Build up list - for (final Cache.Entry currentEntry : this.headquarterCache) { - // Add to list - this.allHeadquarter.add(currentEntry.getValue()); - } - - // Sort list - this.allHeadquarter.sort(new Comparator() { - @Override - public int compare (final Headquarter headquarter1, final Headquarter headquarter2) { - return headquarter1.getHeadquarterId() > headquarter2.getHeadquarterId() ? 1 : headquarter1.getHeadquarterId() < headquarter2.getHeadquarterId() ? -1 : 0; - } - }); - } - } - - @Override - public Boolean isCompanyNameUsed (final String companyName) { - // Validate parameter - if (null == companyName) { - // Throw NPE - throw new NullPointerException("companyName is null"); //NOI18N - } else if (companyName.isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("companyName is empty"); //NOI18N - } - - // Default is not found - boolean isFound = false; - - // Check all entries - for (final Headquarter headquarter : this.allHeadquarter()) { - // Is same company name? - if (Objects.equals(headquarter.getHeadquarterCompanyName(), companyName)) { - // Found it - isFound = true; - break; - } - } - - // Return flag - return isFound; - } - - @Override - public Boolean isEmailAddressRegistered (final String emailAddress) { - // Validate parameter - if (null == emailAddress) { - // Throw NPE - throw new NullPointerException("emailAddress is null"); //NOI18N - } else if (emailAddress.isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("emailAddress is empty"); //NOI18N - } - - // Default is not found - boolean isFound = false; - - // Check all entries - for (final Headquarter headquarter : this.allHeadquarter()) { - // Is email address used? - if (Objects.equals(headquarter.getHeadquarterEmailAddress(), emailAddress)) { - // Found it - isFound = true; - break; - } - } - - // Return flag - return isFound; } } diff --git a/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestController.java index c844692c..f03e91ac 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestController.java @@ -17,9 +17,6 @@ package org.mxchange.jfinancials.beans.business.headquarter; import java.io.Serializable; -import java.util.List; -import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterNotFoundException; -import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; /** * An interface for general Headquarter controller @@ -28,41 +25,4 @@ import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; */ public interface FinancialsHeadquarterWebRequestController extends Serializable { - /** - * Checks whether given company name already exists - *

- * @param companyName Company name to check - *

- * @return Whether the company name exists - */ - Boolean isCompanyNameUsed (final String companyName); - - /** - * Checks if given email address is already registered by an other - * headquarter - *

- * @param emailAddress Email address - *

- * @return Whether the email address has been already registered - */ - Boolean isEmailAddressRegistered (final String emailAddress); - - /** - * Returns a list of all headquarter - *

- * @return A list of all headquarter - */ - List allHeadquarter (); - - /** - * Tries to find a headquarter with given id number - *

- * @param headquarterId Headquarter id - *

- * @return A headquarter instance - *

- * @throws HeadquarterNotFoundException If the headquarter was not found - */ - Headquarter findHeadquarterById (final Long headquarterId) throws HeadquarterNotFoundException; - } diff --git a/src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewBean.java new file mode 100644 index 00000000..b5bce36b --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewBean.java @@ -0,0 +1,306 @@ +/* + * Copyright (C) 2017 - 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.jfinancials.beans.business.headquarter.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.jcontactsbusiness.events.headquarter.added.ObservableHeadquarterAddedEvent; +import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterNotFoundException; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; +import org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; + +/** + * A list bean for headquarter + *

+ * @author Roland Häder + */ +@Named ("headquarterListController") +@ViewScoped +public class FinancialsHeadquarterListWebViewBean extends BaseFinancialsBean implements FinancialsHeadquarterListWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 5_028_697_360_466L; + + /** + * A list of all headquarter + */ + private final List allHeadquarters; + + /** + * A list of filtered headquarter + */ + private List filteredHeadquarters; + + /** + * EJB for administrative purposes + */ + @EJB (lookup = "java:global/jfinancials-ejb/headquarter!org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote") + private HeadquarterSessionBeanRemote headquarterBean; + + /** + * A list of all headquarter (globally) + */ + @Inject + @NamedCache (cacheName = "headquarterCache") + private transient Cache headquarterCache; + + /** + * Currently selected headquarter + */ + private Headquarter selectedHeadquarter; + + /** + * Default constructor + */ + public FinancialsHeadquarterListWebViewBean () { + // Call super constructor + super(); + + // Init list + this.allHeadquarters = new LinkedList<>(); + } + + /** + * Observes events being fired when a branch office has been added. + *

+ * @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 + */ + public void afterHeadquarterAddedEvent (@Observes final ObservableHeadquarterAddedEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getHeadquarter() == null) { + // Throw NPE again + throw new NullPointerException("event.headquarter is null"); //NOI18N + } else if (event.getHeadquarter().getHeadquarterId() == null) { + // Throw it again + throw new NullPointerException("event.headquarter.branchId is null"); //NOI18N + } else if (event.getHeadquarter().getHeadquarterId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("event.headquarter.branchId={0} is not valid", event.getHeadquarter().getHeadquarterId())); //NOI18N + } + + // Add instance to cache + this.headquarterCache.put(event.getHeadquarter().getHeadquarterId(), event.getHeadquarter()); + this.getAllHeadquarters().add(event.getHeadquarter()); + } + + @Override + public Headquarter findHeadquarterById (final Long headquarterId) throws HeadquarterNotFoundException { + // Validate parameter + if (null == headquarterId) { + // Throw NPE + throw new NullPointerException("headquarterId is null"); //NOI18N + } else if (headquarterId < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("headquarterId={0} is invalid", headquarterId)); //NOI18N + } else if (!this.headquarterCache.containsKey(headquarterId)) { + // Not found + throw new HeadquarterNotFoundException(headquarterId); + } + + // Get it from cache + final Headquarter headquarter = this.headquarterCache.get(headquarterId); + + // Return it + return headquarter; + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllHeadquarters () { + return this.allHeadquarters; + } + + /** + * Getter for a list of filtered headquarter + *

+ * @return Filtered headquarter + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredHeadquarters () { + return this.filteredHeadquarters; + } + + /** + * Setter for a list of filtered headquarter + *

+ * @param filteredHeadquarters Filtered headquarter + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredHeadquarters (final List filteredHeadquarters) { + this.filteredHeadquarters = filteredHeadquarters; + } + + /** + * Getter for selected headquarter + *

+ * @return Selected headquarter + */ + public Headquarter getSelectedHeadquarter () { + return this.selectedHeadquarter; + } + + /** + * Setter for selected headquarter + *

+ * @param selectedHeadquarter Selected headquarter + */ + public void setSelectedHeadquarter (final Headquarter selectedHeadquarter) { + this.selectedHeadquarter = selectedHeadquarter; + } + + /** + * Initializer method + */ + @PostConstruct + public void initializeList () { + // Is cache there? + if (!this.headquarterCache.iterator().hasNext()) { + // Get whole list from EJB + final List Headquarter = this.headquarterBean.allHeadquarters(); + + // Add all + for (final Headquarter headquarter : Headquarter) { + // Add it to cache + this.headquarterCache.put(headquarter.getHeadquarterId(), headquarter); + } + } + + // Is the list empty, but filled cache? + if (this.getAllHeadquarters().isEmpty() && this.headquarterCache.iterator().hasNext()) { + // Build up list + for (final Cache.Entry currentEntry : this.headquarterCache) { + // Add to list + this.getAllHeadquarters().add(currentEntry.getValue()); + } + + // Sort list + this.getAllHeadquarters().sort(new Comparator() { + @Override + public int compare (final Headquarter headquarter1, final Headquarter headquarter2) { + return headquarter1.getHeadquarterId() > headquarter2.getHeadquarterId() ? 1 : headquarter1.getHeadquarterId() < headquarter2.getHeadquarterId() ? -1 : 0; + } + }); + } + } + + @Override + public Boolean isCompanyNameUsed (final String companyName) { + // Validate parameter + if (null == companyName) { + // Throw NPE + throw new NullPointerException("companyName is null"); //NOI18N + } else if (companyName.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("companyName is empty"); //NOI18N + } + + // Default is not found + boolean isFound = false; + + // Check all entries + for (final Headquarter headquarter : this.getAllHeadquarters()) { + // Is same company name? + if (Objects.equals(headquarter.getHeadquarterCompanyName(), companyName)) { + // Found it + isFound = true; + break; + } + } + + // Return flag + return isFound; + } + + @Override + public Boolean isEmailAddressRegistered (final String emailAddress) { + // Validate parameter + if (null == emailAddress) { + // Throw NPE + throw new NullPointerException("emailAddress is null"); //NOI18N + } else if (emailAddress.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("emailAddress is empty"); //NOI18N + } + + // Default is not found + boolean isFound = false; + + // Check all entries + for (final Headquarter headquarter : this.getAllHeadquarters()) { + // Is email address used? + if (Objects.equals(headquarter.getHeadquarterEmailAddress(), emailAddress)) { + // Found it + isFound = true; + break; + } + } + + // Return flag + return isFound; + } + + /** + * Checks whether the given headquarter' 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 headquarter Headquarter to check it's address + *

+ * @return Whether the address has been found + */ + @Override + public boolean isHeadquarterCreatedByRequiredData (final Headquarter headquarter) { + // Default is not found + boolean isFound = false; + + // Now check each entry + for (final Headquarter hq : this.getAllHeadquarters()) { + // Is same address? + if (Headquarters.isSameAddress(hq, headquarter)) { + // Found one + isFound = true; + break; + } + } + + // Return flag + return isFound; + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewController.java b/src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewController.java new file mode 100644 index 00000000..f2d0e057 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewController.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2017 - 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.jfinancials.beans.business.headquarter.list; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterNotFoundException; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; + +/** + * An interface for general Headquarter controller + *

+ * @author Roland Häder + */ +public interface FinancialsHeadquarterListWebViewController extends Serializable { + + /** + * Checks whether given company name already exists + *

+ * @param companyName Company name to check + *

+ * @return Whether the company name exists + */ + Boolean isCompanyNameUsed (final String companyName); + + /** + * Checks if given email address is already registered by an other + * headquarter + *

+ * @param emailAddress Email address + *

+ * @return Whether the email address has been already registered + */ + Boolean isEmailAddressRegistered (final String emailAddress); + + /** + * Returns a list of all headquarter + *

+ * @return A list of all headquarter + */ + List getAllHeadquarters (); + + /** + * Tries to find a headquarter with given id number + *

+ * @param headquarterId Headquarter id + *

+ * @return A headquarter instance + *

+ * @throws HeadquarterNotFoundException If the headquarter was not found + */ + Headquarter findHeadquarterById (final Long headquarterId) throws HeadquarterNotFoundException; + + /** + * Checks whether the given headquarter' 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 headquarter Headquarter to check it's address + *

+ * @return Whether the address has been found + */ + boolean isHeadquarterCreatedByRequiredData (final Headquarter headquarter); + +} diff --git a/src/java/org/mxchange/jfinancials/converter/business/headquarter/FinancialsHeadquarterConverter.java b/src/java/org/mxchange/jfinancials/converter/business/headquarter/FinancialsHeadquarterConverter.java index fcc005ab..7b07d312 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/headquarter/FinancialsHeadquarterConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/headquarter/FinancialsHeadquarterConverter.java @@ -24,8 +24,8 @@ import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterNotFoundException; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; -import org.mxchange.jfinancials.beans.business.headquarter.FinancialsHeadquarterWebRequestBean; -import org.mxchange.jfinancials.beans.business.headquarter.FinancialsHeadquarterWebRequestController; +import org.mxchange.jfinancials.beans.business.headquarter.list.FinancialsHeadquarterListWebViewBean; +import org.mxchange.jfinancials.beans.business.headquarter.list.FinancialsHeadquarterListWebViewController; /** * Converter for converting company headquarter to and from id number @@ -38,15 +38,10 @@ public class FinancialsHeadquarterConverter implements Converter { /** * Headquarter backing bean */ - private static FinancialsHeadquarterWebRequestController HEADQUARTER_CONTROLLER; + private static FinancialsHeadquarterListWebViewController HEADQUARTER_LIST_CONTROLLER; @Override public Headquarter getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the instance there? - if (null == HEADQUARTER_CONTROLLER) { - HEADQUARTER_CONTROLLER = CDI.current().select(FinancialsHeadquarterWebRequestBean.class).get(); - } - // Init instance Headquarter headquarter = null; @@ -54,8 +49,14 @@ public class FinancialsHeadquarterConverter implements Converter { // Try to parse the value as long final Long headquarterId = Long.valueOf(submittedValue); + // Is the instance there? + if (null == HEADQUARTER_LIST_CONTROLLER) { + // Set it now + HEADQUARTER_LIST_CONTROLLER = CDI.current().select(FinancialsHeadquarterListWebViewBean.class).get(); + } + // Try to get user instance from it - headquarter = HEADQUARTER_CONTROLLER.findHeadquarterById(headquarterId); + headquarter = HEADQUARTER_LIST_CONTROLLER.findHeadquarterById(headquarterId); } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); diff --git a/src/java/org/mxchange/jfinancials/validator/business/headquarter/FinancialsHeadquarterCompanyNameValidator.java b/src/java/org/mxchange/jfinancials/validator/business/headquarter/FinancialsHeadquarterCompanyNameValidator.java index 0e71efa3..367337f6 100644 --- a/src/java/org/mxchange/jfinancials/validator/business/headquarter/FinancialsHeadquarterCompanyNameValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/business/headquarter/FinancialsHeadquarterCompanyNameValidator.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.string.BaseStringValidator; -import org.mxchange.jfinancials.beans.business.headquarter.FinancialsHeadquarterWebRequestBean; -import org.mxchange.jfinancials.beans.business.headquarter.FinancialsHeadquarterWebRequestController; +import org.mxchange.jfinancials.beans.business.headquarter.list.FinancialsHeadquarterListWebViewBean; +import org.mxchange.jfinancials.beans.business.headquarter.list.FinancialsHeadquarterListWebViewController; /** * A validator for headquarter company names @@ -38,7 +38,7 @@ public class FinancialsHeadquarterCompanyNameValidator extends BaseStringValidat /** * Headquarter backing bean */ - private static FinancialsHeadquarterWebRequestController HEADQUARTER_CONTROLLER; + private static FinancialsHeadquarterListWebViewController HEADQUARTER_LIST_CONTROLLER; /** * Serial number @@ -47,12 +47,6 @@ public class FinancialsHeadquarterCompanyNameValidator extends BaseStringValidat @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { - // Is the instance there? - if (null == HEADQUARTER_CONTROLLER) { - // Get bean from CDI directly - HEADQUARTER_CONTROLLER = CDI.current().select(FinancialsHeadquarterWebRequestBean.class).get(); - } - // All accepted, required fields final String[] requiredFields = {"companyName"}; //NOI18N @@ -80,8 +74,14 @@ public class FinancialsHeadquarterCompanyNameValidator extends BaseStringValidat checkExisting = Boolean.parseBoolean((String) attribute); } + // Is the instance there? + if (null == HEADQUARTER_LIST_CONTROLLER) { + // Get bean from CDI directly + HEADQUARTER_LIST_CONTROLLER = CDI.current().select(FinancialsHeadquarterListWebViewBean.class).get(); + } + // Check if name is already used - final Boolean nameExists = HEADQUARTER_CONTROLLER.isCompanyNameUsed(companyName); + final Boolean nameExists = HEADQUARTER_LIST_CONTROLLER.isCompanyNameUsed(companyName); // Is the user id valid? if ((!nameExists) && (checkExisting)) { diff --git a/src/java/org/mxchange/jfinancials/validator/emailaddress/headquarter/FinancialsHeadquarterEmailAddressValidator.java b/src/java/org/mxchange/jfinancials/validator/emailaddress/headquarter/FinancialsHeadquarterEmailAddressValidator.java index f70ba190..7da59a89 100644 --- a/src/java/org/mxchange/jfinancials/validator/emailaddress/headquarter/FinancialsHeadquarterEmailAddressValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/emailaddress/headquarter/FinancialsHeadquarterEmailAddressValidator.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.jfinancials.beans.business.headquarter.FinancialsHeadquarterWebRequestBean; -import org.mxchange.jfinancials.beans.business.headquarter.FinancialsHeadquarterWebRequestController; +import org.mxchange.jfinancials.beans.business.headquarter.list.FinancialsHeadquarterListWebViewBean; +import org.mxchange.jfinancials.beans.business.headquarter.list.FinancialsHeadquarterListWebViewController; /** * A validator for headquarter's email address validation @@ -44,7 +44,7 @@ public class FinancialsHeadquarterEmailAddressValidator extends BaseStringValida /** * Headquarter backing bean */ - private static FinancialsHeadquarterWebRequestController HEADQUARTER_CONTROLLER; + private static FinancialsHeadquarterListWebViewController HEADQUARTER_LIST_CONTROLLER; /** * Pattern matcher @@ -65,6 +65,7 @@ public class FinancialsHeadquarterEmailAddressValidator extends BaseStringValida * Default constructor */ public FinancialsHeadquarterEmailAddressValidator () { + // Default is not allowed this.allowEmptyRequiredData = Boolean.FALSE; } @@ -115,13 +116,13 @@ public class FinancialsHeadquarterEmailAddressValidator extends BaseStringValida final String clientId = component.getClientId(); // Is the instance there? - if (null == HEADQUARTER_CONTROLLER) { + if (null == HEADQUARTER_LIST_CONTROLLER) { // Get bean from CDI directly - HEADQUARTER_CONTROLLER = CDI.current().select(FinancialsHeadquarterWebRequestBean.class).get(); + HEADQUARTER_LIST_CONTROLLER = CDI.current().select(FinancialsHeadquarterListWebViewBean.class).get(); } // Is it registered? - final Boolean isRegistered = HEADQUARTER_CONTROLLER.isEmailAddressRegistered(emailAddress); + final Boolean isRegistered = HEADQUARTER_LIST_CONTROLLER.isEmailAddressRegistered(emailAddress); // Is the email address already registered? if ((!clientId.endsWith("resendEmailAddress")) && (isRegistered)) { //NOI18N diff --git a/src/java/org/mxchange/localization/generic_de_DE.properties b/src/java/org/mxchange/localization/generic_de_DE.properties index 1339124d..86d78d02 100644 --- a/src/java/org/mxchange/localization/generic_de_DE.properties +++ b/src/java/org/mxchange/localization/generic_de_DE.properties @@ -1213,3 +1213,4 @@ ADMIN_ASSIGNED_MANUFACTURER_LABEL=Zugewiesener Hersteller: BARCODE=Barcode: ADMIN_CONTACT_DETAILS_HEADER=Kontaktdaten zu {0} {1} {2}: ADMIN_DEPARTMENT_DETAILS_HEADER=Daten der Abteilung {0} (Id {1}): +ADMIN_HEADQUARTER_DETAILS_HEADER=Haupstelle von {0} (Id {1})): diff --git a/src/java/org/mxchange/localization/generic_en_US.properties b/src/java/org/mxchange/localization/generic_en_US.properties index b80ddb53..2997970b 100644 --- a/src/java/org/mxchange/localization/generic_en_US.properties +++ b/src/java/org/mxchange/localization/generic_en_US.properties @@ -1124,3 +1124,4 @@ ADMIN_ASSIGNED_MANUFACTURER_LABEL=Assigned manufacturer: BARCODE=Barcode: ADMIN_CONTACT_DETAILS_HEADER=Contact data of {0} {1} {2}: ADMIN_DEPARTMENT_DETAILS_HEADER=Data of department {0} (Id {1}): +ADMIN_HEADQUARTER_DETAILS_HEADER=Headquarter of {0} (Id {1})): diff --git a/web/WEB-INF/templates/admin/basic_data/admin_form_basic_data.tpl b/web/WEB-INF/templates/admin/basic_data/admin_form_basic_data.tpl index e4ab9379..126dbca0 100644 --- a/web/WEB-INF/templates/admin/basic_data/admin_form_basic_data.tpl +++ b/web/WEB-INF/templates/admin/basic_data/admin_form_basic_data.tpl @@ -149,7 +149,7 @@ - - + + + + diff --git a/web/admin/department/admin_department_list.xhtml b/web/admin/department/admin_department_list.xhtml index 4f724549..d3a51bee 100644 --- a/web/admin/department/admin_department_list.xhtml +++ b/web/admin/department/admin_department_list.xhtml @@ -210,7 +210,7 @@ @@ -307,7 +307,7 @@ - + diff --git a/web/admin/headquarter/admin_headquarter_list.xhtml b/web/admin/headquarter/admin_headquarter_list.xhtml index bc94fcd9..089a71f1 100644 --- a/web/admin/headquarter/admin_headquarter_list.xhtml +++ b/web/admin/headquarter/admin_headquarter_list.xhtml @@ -18,29 +18,49 @@ - + - - + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + @@ -228,7 +281,7 @@ type="submit" value="#{msg.BUTTON_ADMIN_ADD_HEADQUARTER}" action="#{adminHeadquarterController.addHeadquarter()}" - update=":master:form-list-Headquarter:headquarterList" + update=":master:form-list-headquarters:headquarterList" /> -- 2.39.5