From 0d25cbaaf30913ad0bd592cc883fcfe07983c16f 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 --- ...ssbookAdminBusinessDataWebRequestBean.java | 4 +- .../AddressbookContactWebRequestBean.java | 83 +++++++++++-------- .../AddressbookBusinessContactConverter.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/addressbook/beans/business/basicdata/AddressbookAdminBusinessDataWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookAdminBusinessDataWebRequestBean.java index ff365ab9..8bcd570c 100644 --- a/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookAdminBusinessDataWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookAdminBusinessDataWebRequestBean.java @@ -26,7 +26,7 @@ import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; 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 AddressbookAdminBusinessDataWebRequestBean extends BaseAddressbookC // 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/addressbook/beans/contact/AddressbookContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java index 24a6bcd8..39b3a48e 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java @@ -18,7 +18,6 @@ package org.mxchange.addressbook.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 AddressbookContactWebRequestBean extends BaseAddressbookController /** * A list of all selectable contacts */ - private List selectableContacts; + @Inject + @NamedCache (cacheName = "selectableContactsCache") + private Cache selectableContactsCache; /** * Street @@ -271,7 +272,7 @@ public class AddressbookContactWebRequestBean extends BaseAddressbookController 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 AddressbookContactWebRequestBean extends BaseAddressbookController } // 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 AddressbookContactWebRequestBean extends BaseAddressbookController */ @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 AddressbookContactWebRequestBean extends BaseAddressbookController * @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/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java b/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java index e718939d..f5cc9a9f 100644 --- a/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java +++ b/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java @@ -26,9 +26,9 @@ import javax.faces.validator.ValidatorException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; -import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote; +import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicCompanyDataNotFoundException; /** * Converter for contact id <-> valid business contact instance @@ -80,7 +80,7 @@ public class AddressbookBusinessContactConverter 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