From b4b1d8bbfa771d3c0d99579419ea1995404c9fd0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 12 Sep 2017 21:18:42 +0200 Subject: [PATCH] Please cherry-pick: - removed export of basic company data, one day, an other approach rather than "single entity" export will maybe come MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...ncialsAdminBusinessDataWebRequestBean.java | 4 +- .../FinancialsContactWebRequestBean.java | 83 +++++++++++-------- .../FinancialsBasicCompanyDataConverter.java | 4 +- .../localization/bundle_de_DE.properties | 2 - .../localization/bundle_en_US.properties | 2 - web/WEB-INF/faces-config.xml | 4 - web/WEB-INF/templates/admin/admin_menu.tpl | 1 - 7 files changed, 52 insertions(+), 48 deletions(-) diff --git a/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsAdminBusinessDataWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsAdminBusinessDataWebRequestBean.java index b5dc0503..f081680e 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsAdminBusinessDataWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsAdminBusinessDataWebRequestBean.java @@ -25,7 +25,7 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontactsbusiness.events.basicdata.added.AdminAddedBusinessBasicDataEvent; import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent; -import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataAlreadyAddedException; +import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicCompanyDataAlreadyAddedException; import org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData; @@ -232,7 +232,7 @@ public class FinancialsAdminBusinessDataWebRequestBean extends BaseFinancialsCon // Fire event this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData)); - } catch (final BusinessDataAlreadyAddedException e) { + } catch (final BasicCompanyDataAlreadyAddedException e) { // Does already exist throw new FacesException(e); } diff --git a/src/java/org/mxchange/jfinancials/beans/contact/FinancialsContactWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/contact/FinancialsContactWebRequestBean.java index a6527d58..1162fded 100644 --- a/src/java/org/mxchange/jfinancials/beans/contact/FinancialsContactWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/contact/FinancialsContactWebRequestBean.java @@ -18,7 +18,6 @@ package org.mxchange.jfinancials.beans.contact; import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; -import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.LinkedList; @@ -210,7 +209,9 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im /** * A list of all selectable contacts */ - private List selectableContacts; + @Inject + @NamedCache (cacheName = "selectableContactsCache") + private Cache selectableContactsCache; /** * Street @@ -271,7 +272,7 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im this.uniqueAddContact(event.getAddedContact()); // Add to selectable contacts - this.selectableContacts.add(event.getAddedContact()); + this.selectableContactsCache.put(event.getAddedContact().getContactId(), event.getAddedContact()); } /** @@ -325,7 +326,7 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im } // Remove contact from list available contacts list - this.selectableContacts.remove(event.getLinkedUser().getUserContact()); + this.selectableContactsCache.remove(event.getLinkedUser().getUserContact().getContactId()); // Clear all data this.clear(); @@ -1025,56 +1026,52 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im */ @PostConstruct public void init () { - // Get all contacts - final List selectable = new LinkedList<>(); - // Is cache there? if (!this.contactsCache.iterator().hasNext()) { // Get whole list - List list = this.contactBean.allContacts(); + final List contacts = this.contactBean.allContacts(); // Add all - for (final Iterator iterator = list.iterator(); iterator.hasNext();) { - // Get next element - final Contact next = iterator.next(); - + for (final Contact contact : contacts) { // Add it to cache - this.contactsCache.put(next.getContactId(), next); - this.emailAddressCache.put(next.getContactId(), next.getContactEmailAddress()); - selectable.add(next); + this.contactsCache.put(contact.getContactId(), contact); + this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress()); } + } else if (this.selectableContactsCache.iterator().hasNext()) { + // Has already entries, avoid executing below code + return; } // Get all users - List allUsers = this.userController.allUsers(); + final List allUsers = this.userController.allUsers(); - // Get iterator - Iterator iterator = selectable.iterator(); + // Get iterator from contacts cache + final Iterator> iterator = this.contactsCache.iterator(); - // Loop through it + // Loop through all contacts while (iterator.hasNext()) { // Get next element - Contact next = iterator.next(); - - // Get iterator - Iterator userIterator = allUsers.iterator(); + final Cache.Entry next = iterator.next(); - // Loop through all users - while (userIterator.hasNext()) { - // Get user instance - User nextUser = userIterator.next(); + // Default is not found + boolean isFound = false; - // Is contact same? - if (Objects.equals(next, nextUser.getUserContact())) { - // Found same - iterator.remove(); + // User list is not empty, check each entry, if contact is found + for (final User user : allUsers) { + // Is the contact the same? + if (Objects.equals(user.getUserContact(), next.getValue())) { + // Found one + isFound = true; break; } } - } - // Set contact list - this.selectableContacts = selectable; + // Is contact not found? + if (!isFound) { + // Add it as selectable + this.selectableContactsCache.put(next.getKey(), next.getValue()); + } + } } @Override @@ -1131,7 +1128,23 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im * @return A list of all selectable contacts */ public List selectableContacts () { - return Collections.unmodifiableList(this.selectableContacts); + // Init list + final List selectableContacts = new LinkedList<>(); + + // Get iterator from cache + final Iterator> iterator = this.contactsCache.iterator(); + + // Loop through all contacts + while (iterator.hasNext()) { + // Get next element + final Cache.Entry next = iterator.next(); + + // Add entry's value to list + selectableContacts.add(next.getValue()); + } + + // Return list + return selectableContacts; } @Override diff --git a/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java index 62e3f5b0..9dba03fd 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBasicCompanyDataConverter.java @@ -28,7 +28,7 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote; -import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException; +import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicCompanyDataNotFoundException; /** * Converter for contact id <-> valid basic company data instance @@ -80,7 +80,7 @@ public class FinancialsBasicCompanyDataConverter implements Converteradmin_list_basic_company_data /admin/basic_company_data/admin_basic_company_data_list.xhtml - - admin_export_basic_company_data - /admin/basic_company_data/admin_basic_company_data_export.xhtml - admin_list_branch_offices /admin/branch_offices/admin_branch_offices_list.xhtml diff --git a/web/WEB-INF/templates/admin/admin_menu.tpl b/web/WEB-INF/templates/admin/admin_menu.tpl index 8da86ec5..e980a377 100644 --- a/web/WEB-INF/templates/admin/admin_menu.tpl +++ b/web/WEB-INF/templates/admin/admin_menu.tpl @@ -40,7 +40,6 @@
  • -
-- 2.39.5