]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Thu, 2 Apr 2020 16:29:54 +0000 (18:29 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 2 Apr 2020 16:29:54 +0000 (18:29 +0200)
- 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

Signed-off-by: Roland Häder <roland@mxchange.org>
16 files changed:
src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsAdminHeadquarterWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/business/headquarter/FinancialsHeadquarterWebRequestController.java
src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/business/headquarter/list/FinancialsHeadquarterListWebViewController.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/converter/business/headquarter/FinancialsHeadquarterConverter.java
src/java/org/mxchange/jfinancials/validator/business/headquarter/FinancialsHeadquarterCompanyNameValidator.java
src/java/org/mxchange/jfinancials/validator/emailaddress/headquarter/FinancialsHeadquarterEmailAddressValidator.java
src/java/org/mxchange/localization/generic_de_DE.properties
src/java/org/mxchange/localization/generic_en_US.properties
web/WEB-INF/templates/admin/basic_data/admin_form_basic_data.tpl
web/WEB-INF/templates/admin/department/admin_form_department_data.tpl
web/WEB-INF/templates/admin/employee/admin_form_employee_data.tpl
web/admin/contact/admin_contact_list.xhtml
web/admin/department/admin_department_list.xhtml
web/admin/headquarter/admin_headquarter_list.xhtml

index dd287dc2944ba9043cdb5105c196e597df076c0f..4dd51a1a9d21f335da74de1d07c2e9b25a869cc9 100644 (file)
@@ -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.
-        * <p>
-        * @param headquarter Headquarter to check it's address
-        * <p>
-        * @return Whether the address has been found
-        */
-       private boolean isHeadquarterCreatedByRequiredData (final Headquarter headquarter) {
-               // Get full list from other bean
-               final List<Headquarter> 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
         * <p>
index 15c9d8ffb733b2667d39e69a5f97481f0bdbf8ee..4bb7a2c6d93ccbf2e3f046f0fba88e54d76a743f 100644 (file)
  */
 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<Headquarter> allHeadquarter;
-
-       /**
-        * A list of filtered headquarter
-        */
-       private List<Headquarter> 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<Long, Headquarter> 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.
-        * <p>
-        * @param event Event being fired
-        * <p>
-        * @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<Headquarter> 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
-        * <p>
-        * @return Filtered headquarter
-        */
-       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
-       public List<Headquarter> getFilteredHeadquarter () {
-               return this.filteredHeadquarter;
-       }
-
-       /**
-        * Setter for a list of filtered headquarter
-        * <p>
-        * @param filteredHeadquarter Filtered headquarter
-        */
-       @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
-       public void setFilteredHeadquarter (final List<Headquarter> 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> 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<Long, Headquarter> currentEntry : this.headquarterCache) {
-                               // Add to list
-                               this.allHeadquarter.add(currentEntry.getValue());
-                       }
-
-                       // Sort list
-                       this.allHeadquarter.sort(new Comparator<Headquarter>() {
-                               @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;
        }
 
 }
index c844692cc7c2919ca027f1a5da691b4f8763e6e8..f03e91ac6efcca05568da0288d390bc0833cb455 100644 (file)
@@ -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
-        * <p>
-        * @param companyName Company name to check
-        * <p>
-        * @return Whether the company name exists
-        */
-       Boolean isCompanyNameUsed (final String companyName);
-
-       /**
-        * Checks if given email address is already registered by an other
-        * headquarter
-        * <p>
-        * @param emailAddress Email address
-        * <p>
-        * @return Whether the email address has been already registered
-        */
-       Boolean isEmailAddressRegistered (final String emailAddress);
-
-       /**
-        * Returns a list of all headquarter
-        * <p>
-        * @return A list of all headquarter
-        */
-       List<Headquarter> allHeadquarter ();
-
-       /**
-        * Tries to find a headquarter with given id number
-        * <p>
-        * @param headquarterId Headquarter id
-        * <p>
-        * @return A headquarter instance
-        * <p>
-        * @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 (file)
index 0000000..b5bce36
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@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<Headquarter> allHeadquarters;
+
+       /**
+        * A list of filtered headquarter
+        */
+       private List<Headquarter> 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<Long, Headquarter> 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.
+        * <p>
+        * @param event Event being fired
+        * <p>
+        * @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<Headquarter> getAllHeadquarters () {
+               return this.allHeadquarters;
+       }
+
+       /**
+        * Getter for a list of filtered headquarter
+        * <p>
+        * @return Filtered headquarter
+        */
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+       public List<Headquarter> getFilteredHeadquarters () {
+               return this.filteredHeadquarters;
+       }
+
+       /**
+        * Setter for a list of filtered headquarter
+        * <p>
+        * @param filteredHeadquarters Filtered headquarter
+        */
+       @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+       public void setFilteredHeadquarters (final List<Headquarter> filteredHeadquarters) {
+               this.filteredHeadquarters = filteredHeadquarters;
+       }
+
+       /**
+        * Getter for selected headquarter
+        * <p>
+        * @return Selected headquarter
+        */
+       public Headquarter getSelectedHeadquarter () {
+               return this.selectedHeadquarter;
+       }
+
+       /**
+        * Setter for selected headquarter
+        * <p>
+        * @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> 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<Long, Headquarter> currentEntry : this.headquarterCache) {
+                               // Add to list
+                               this.getAllHeadquarters().add(currentEntry.getValue());
+                       }
+
+                       // Sort list
+                       this.getAllHeadquarters().sort(new Comparator<Headquarter>() {
+                               @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.
+        * <p>
+        * @param headquarter Headquarter to check it's address
+        * <p>
+        * @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 (file)
index 0000000..f2d0e05
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface FinancialsHeadquarterListWebViewController extends Serializable {
+
+       /**
+        * Checks whether given company name already exists
+        * <p>
+        * @param companyName Company name to check
+        * <p>
+        * @return Whether the company name exists
+        */
+       Boolean isCompanyNameUsed (final String companyName);
+
+       /**
+        * Checks if given email address is already registered by an other
+        * headquarter
+        * <p>
+        * @param emailAddress Email address
+        * <p>
+        * @return Whether the email address has been already registered
+        */
+       Boolean isEmailAddressRegistered (final String emailAddress);
+
+       /**
+        * Returns a list of all headquarter
+        * <p>
+        * @return A list of all headquarter
+        */
+       List<Headquarter> getAllHeadquarters ();
+
+       /**
+        * Tries to find a headquarter with given id number
+        * <p>
+        * @param headquarterId Headquarter id
+        * <p>
+        * @return A headquarter instance
+        * <p>
+        * @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.
+        * <p>
+        * @param headquarter Headquarter to check it's address
+        * <p>
+        * @return Whether the address has been found
+        */
+       boolean isHeadquarterCreatedByRequiredData (final Headquarter headquarter);
+
+}
index fcc005ab11245d7bbf0a81de269737adcf3e27a3..7b07d31267b8716ce90a497ceec1c0832bd108bc 100644 (file)
@@ -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> {
        /**
         * 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<Headquarter> {
                        // 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);
index 0e71efa35760412d0194043f8a51c99043d71335..367337f6381ca2aba4a43863d682ac733cb1d596 100644 (file)
@@ -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)) {
index f70ba190391511ecc6def2e86a702de20a654c63..7da59a891ff77dfdd77c051ba322672b593a2a4c 100644 (file)
@@ -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
index 1339124dd21874293f3e265fcb0c3796070a4c30..86d78d02f51e322254924eccc829f8386d685b64 100644 (file)
@@ -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})):
index b80ddb53f718be76d09c110345625e8e1cce90ea..2997970ba7f8dc13dd86297415bf08b5616692a5 100644 (file)
@@ -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})):
index e4ab9379bfe844184c640f212165456312edbc01..126dbca04f8a3aa6138177b5430e19739cedac83 100644 (file)
                                        <f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
 
                                        <f:selectItems
-                                               value="#{headquarterController.allHeadquarter()}"
+                                               value="#{headquarterListController.allHeadquarters}"
                                                var="headquarter"
                                                itemValue="#{headquarter}"
                                                itemLabel="#{beanHelper.renderHeadquarter(headquarter)}"
index 6d45042d116d1f84542a8dbaaae23c0d6edae082..502fcb9990aa8e8ee9e721da00c5674a32e99bd4 100644 (file)
@@ -79,7 +79,7 @@
                                <f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
 
                                <f:selectItems
-                                       value="#{headquarterController.allHeadquarter()}"
+                                       value="#{headquarterListController.allHeadquarters}"
                                        var="headquarter"
                                        itemValue="#{headquarter}"
                                        itemLabel="#{beanHelper.renderHeadquarter(headquarter)}"
index 91e7e1b7ff63aa5c19d854cf58641b4d91873ad4..66b46eb95ea2ec461948ae6303fe8ec3181b24cb 100644 (file)
                                <f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
 
                                <f:selectItems
-                                       value="#{departmentController.allDepartments()}"
+                                       value="#{departmentListController.allDepartments}"
                                        var="department"
                                        itemValue="#{department}"
                                        itemLabel="#{beanHelper.renderDepartment(department)}"
                                <f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
 
                                <f:selectItems
-                                       value="#{headquarterController.allHeadquarter()}"
+                                       value="#{headquarterListController.allHeadquarters}"
                                        var="headquarter"
                                        itemValue="#{headquarter}"
                                        itemLabel="#{beanHelper.renderHeadquarter(headquarter)}"
index be91835cd402f807c7016105d122ec23feeb6e43..9eb72bd3cff854172765616106c550adc9106370 100644 (file)
                                <core:outputAdminContactDataFormFields allowEmptyRequiredData="true" />
 
                                <f:facet name="footer">
-                                       <p:commandButton
-                                               styleClass="reset"
-                                               type="reset"
-                                               value="#{msg.BUTTON_RESET_FORM}"
-                                               />
-                                       <p:commandButton
-                                               type="submit"
-                                               value="#{msg.BUTTON_ADMIN_ADD_CONTACT}"
-                                               action="#{adminContactController.addContact()}"
-                                               update=":master:form-list-contacts:contactList"
-                                               />
+                                       <p:panelGrid columns="2" layout="grid">
+                                               <p:commandButton
+                                                       styleClass="reset"
+                                                       type="reset"
+                                                       value="#{msg.BUTTON_RESET_FORM}"
+                                                       />
+                                               <p:commandButton
+                                                       type="submit"
+                                                       value="#{msg.BUTTON_ADMIN_ADD_CONTACT}"
+                                                       action="#{adminContactController.addContact()}"
+                                                       update=":master:form-list-contacts:contactList"
+                                                       />
+                                       </p:panelGrid>
                                </f:facet>
                        </p:panelGrid>
                </h:form>
index 4f72454935a31c7d71dd264be5a698e8d717e72a..d3a51beea20219dabe6eef64d12859e0ffbe5c06 100644 (file)
 
                                        <p:link
                                                outcome="admin_show_employee"
-                                               value="#{department.departmentLead.employeeId}"
+                                               value="#{beanHelper.renderEmployee(department.departmentLead)}"
                                                title="#{msg.ADMIN_LINK_SHOW_DEPARTMENT_LEAD_EMPLOYEE_TITLE}"
                                                rendered="#{not empty department.departmentLead}"
                                                >
                                        <p:panelGrid columns="2" rendered="#{not empty departmentListController.selectedDepartment}">
                                                <f:facet name="header">
                                                        <h:outputFormat value="#{msg.ADMIN_DEPARTMENT_DETAILS_HEADER}">
-                                                               <f:param value="#{msg[departmentListController.selectedDepartment.departmentI18nKey]}" />
+                                                               <f:param value="#{local[departmentListController.selectedDepartment.departmentI18nKey]}" />
                                                                <f:param value="#{departmentListController.selectedDepartment.departmentId}" />
                                                        </h:outputFormat>
                                                </f:facet>
index bc94fcd92452102a22d58237d9f09766c3e27689..089a71f1b1127cfb934c8cbd3df4e78db83bae3f 100644 (file)
        </ui:define>
 
        <ui:define name="content">
-               <h:form id="form-list-Headquarter">
+               <h:form id="form-list-headquarters">
                        <p:dataTable
                                id="headquarterList"
                                var="headquarter"
-                               value="#{headquarterController.allHeadquarter()}"
+                               value="#{headquarterListController.allHeadquarters}"
                                paginator="true"
                                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
-                               filteredValue="#{headquarterController.filteredHeadquarter}"
+                               filteredValue="#{headquarterListController.filteredHeadquarters}"
                                rows="10"
+                               rowKey="#{headquarter.headquarterId}"
                                reflow="true"
                                resizableColumns="true"
                                rowsPerPageTemplate="5,10,20,50,100"
                                sortMode="multiple"
-                               summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_HEADQUARTER}"
-                               emptyMessage="#{msg.ADMIN_EMPTY_LIST_HEADQUARTER}"
+                               summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_BRANCH_OFFICES}"
+                               emptyMessage="#{msg.ADMIN_EMPTY_LIST_BRANCH_OFFICES}"
                                widgetVar="headquarterList"
+                               selectionMode="single"
+                               selection="#{headquarterListController.selectedHeadquarter}"
+                               skipChildren="true"
                                >
 
                                <f:facet name="header">
-                                       <p:panelGrid columns="2" columnClasses="ui-grid-col-10,ui-grid-col-2" layout="grid" styleClass="ui-noborder ui-transparent-widget">
-                                               <h:outputText value="#{msg.ADMIN_LIST_HEADQUARTER_HEADER}" />
+                                       <p:panelGrid
+                                               columns="3"
+                                               layout="grid"
+                                               columnClasses="ui-grid-col-4,ui-grid-col-6,ui-grid-col-2"
+                                               >
+                                               <p:spacer />
+
+                                               <p:panelGrid
+                                                       columns="2"
+                                                       columnClasses="ui-grid-4,ui-grid-8"
+                                                       layout="grid"
+                                                       styleClass="ui-noborder"
+                                                       >
+                                                       <p:outputLabel for="globalFilter" value="#{msg.SEARCH_ALL_FIELDS}" style="float: right" />
+                                                       <p:inputText id="globalFilter" onkeyup="PF('headquarterList').filter()" placeholder="#{msg.ENTER_KEYWORD}"/>
+                                               </p:panelGrid>
+
+                                               <p:outputPanel>
+                                                       <p:spacer height="4" />
 
-                                               <h:panelGroup>
                                                        <p:commandButton
                                                                id="toggler"
                                                                type="button"
                                                                />
 
                                                        <p:columnToggler datasource="headquarterList" trigger="toggler" />
-                                               </h:panelGroup>
+                                               </p:outputPanel>
                                        </p:panelGrid>
                                </f:facet>
 
+                               <p:ajax
+                                       event="rowSelect"
+                                       update=":master:form-list-headquarters:headquarter-details"
+                                       oncomplete="PF('headquarterDialog').show()"
+                                       />
+
                                <p:column
                                        headerText="#{msg.ID_HEADER}"
                                        sortBy="#{headquarter.headquarterId}"
                                        <links:outputHeadquarterAdminDropdownMenu headquarter="#{headquarter}" />
                                </p:column>
                        </p:dataTable>
+
+                       <p:dialog
+                               dynamic="true"
+                               modal="true"
+                               resizable="false"
+                               header="#{msg.ADMIN_SINGLE_HEADQUARTER_DETAILS_HEADER}"
+                               hideEffect="fade"
+                               showEffect="fade"
+                               widgetVar="headquarterDialog"
+                               position="top"
+                               responsive="true"
+                               closeOnEscape="true"
+                               >
+                               <p:outputPanel id="headquarter-details">
+                                       <p:panelGrid columns="2" rendered="#{not empty headquarterListController.selectedHeadquarter}">
+                                               <f:facet name="header">
+                                                       <h:outputFormat value="#{msg.ADMIN_HEADQUARTER_DETAILS_HEADER}">
+                                                               <f:param value="#{headquarterListController.selectedHeadquarter.headquarterCompanyName}" />
+                                                               <f:param value="#{headquarterListController.selectedHeadquarter.headquarterId}" />
+                                                       </h:outputFormat>
+                                               </f:facet>
+
+                                               <p:outputLabel value="#{msg.ID_HEADER}" title="#{msg.HEADQUARTER_ID_NUMBER_TITLE}" />
+                                               <h:outputText value="#{headquarterListController.selectedHeadquarter.headquarterId}" />
+                                       </p:panelGrid>
+                               </p:outputPanel>
+                       </p:dialog>
                </h:form>
 
                <h:form>
                                                        type="submit"
                                                        value="#{msg.BUTTON_ADMIN_ADD_HEADQUARTER}"
                                                        action="#{adminHeadquarterController.addHeadquarter()}"
-                                                       update=":master:form-list-Headquarter:headquarterList"
+                                                       update=":master:form-list-headquarters:headquarterList"
                                                        />
                                        </p:panelGrid>
                                </f:facet>