From 04c68d76f87e76208fca8aac626387efeb98d1ab Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 16 Apr 2020 22:04:23 +0200 Subject: [PATCH] Please cherry-pick: - renamed allFoos() to fetchAllFoos() - cleanup of deprecated/no longer needed business methods as fetchAllFoos() can be used instead - splitted mobile number relevant business methods into separate EJB, this allows better load-balancing on servers with many CPU cores - UserLoginSessionBean is now superflous and can be removed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../AddressbookAdminContactSessionBean.java | 2 +- .../AddressbookContactSessionBean.java | 55 +--- ...dressbookAdminBusinessDataSessionBean.java | 4 +- .../AddressbookBusinessDataSessionBean.java | 2 +- ...dressbookAdminBranchOfficeSessionBean.java | 4 +- .../AddressbookBranchOfficeSessionBean.java | 2 +- ...AddressbookAdminDepartmentSessionBean.java | 2 +- .../AddressbookDepartmentSessionBean.java | 2 +- .../AddressbookAdminEmployeeSessionBean.java | 4 +- .../AddressbookEmployeeSessionBean.java | 2 +- ...ddressbookAdminHeadquarterSessionBean.java | 2 +- .../AddressbookHeadquarterSessionBean.java | 2 +- ...dressbookAdminOpeningTimesSessionBean.java | 6 +- .../AddressbookOpeningTimesSessionBean.java | 2 +- .../AddressbookAdminCountrySingletonBean.java | 2 +- .../data/AddressbookCountrySingletonBean.java | 2 +- .../FinancialsAdminMobileSessionBean.java | 139 +++++++++ .../mobile/FinancialsMobileSessionBean.java | 65 +++++ ...ddressbookMobileProviderSingletonBean.java | 2 +- .../AddressbookAdminPhoneSessionBean.java | 96 ------- .../phone/AddressbookPhoneSessionBean.java | 25 +- .../user/AddressbookUserSessionBean.java | 264 ++++-------------- ...AddressbookUserEmailChangeSessionBean.java | 88 +++--- ...essbookUserPasswordHistorySessionBean.java | 2 +- 24 files changed, 324 insertions(+), 452 deletions(-) create mode 100644 src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsAdminMobileSessionBean.java create mode 100644 src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsMobileSessionBean.java diff --git a/src/java/org/mxchange/jcontacts/model/contact/AddressbookAdminContactSessionBean.java b/src/java/org/mxchange/jcontacts/model/contact/AddressbookAdminContactSessionBean.java index 247e541..f4c558a 100644 --- a/src/java/org/mxchange/jcontacts/model/contact/AddressbookAdminContactSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/contact/AddressbookAdminContactSessionBean.java @@ -129,7 +129,7 @@ public class AddressbookAdminContactSessionBean extends BaseAddressbookEnterpris boolean isFound = false; // Fest all entries and iterate over them - for (final Contact currentContact : this.contactBean.allContacts()) { + for (final Contact currentContact : this.contactBean.fetchAllContacts()) { // Is found? if (Objects.equals(contact, currentContact)) { // Yes, found the same diff --git a/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java b/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java index ff63176..7def32a 100644 --- a/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java @@ -18,7 +18,6 @@ package org.mxchange.jcontacts.model.contact; import java.text.MessageFormat; import java.util.List; -import java.util.Objects; import javax.ejb.Stateless; import javax.persistence.NoResultException; import javax.persistence.Query; @@ -48,7 +47,7 @@ public class AddressbookContactSessionBean extends BaseAddressbookEnterpriseBean @Override @SuppressWarnings ("unchecked") - public List allContacts () { + public List fetchAllContacts () { // Log trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts - CALLED!", this.getClass().getSimpleName())); //NOI18N @@ -65,58 +64,6 @@ public class AddressbookContactSessionBean extends BaseAddressbookEnterpriseBean return contacts; } - @Override - public Contact lookupContact (final Contact contact) { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Parameter should be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() > 0) { - try { - // Id set, ask other method - return this.findContactById(contact.getContactId()); - } catch (final ContactNotFoundException ex) { - // Not found, should not happen - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is set, but not found.", contact.getContactId()), ex); //NOI18N - } - } - - // Default is not found - Contact foundContact = null; - - // Get whole list - final List contacts = this.allContacts(); - - // Is the list empty? - if (contacts.isEmpty()) { - // Then abort here - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: No contacts registered, returning NULL ...", this.getClass().getSimpleName())); //NOI18N - return null; - } - - // Loop through all - for (final Contact currentContact : contacts) { - // Is same contact? - if ((Objects.equals(contact, currentContact)) || (Contacts.isSameContact(contact, currentContact))) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isContactFound: Found same contact: contactId={1}", this.getClass().getSimpleName(), currentContact.getContactId())); //NOI18N - - // Found it - foundContact = currentContact; - break; - } - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: foundContact={1} - EXIT!", this.getClass().getSimpleName(), foundContact)); //NOI18N - - // Return found contact - return foundContact; - } - @Override public Contact updateContactData (final Contact contact, final boolean isCellphoneUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) { // Log trace message diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java index 0dc78c3..912d626 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java @@ -147,7 +147,7 @@ public class AddressbookAdminBusinessDataSessionBean extends BaseAddressbookEnte boolean isFound = false; // Then check each entry - for (final BasicData currentBasicData : this.businessDataBean.allBusinessBasicData()) { + for (final BasicData currentBasicData : this.businessDataBean.fetchAllBusinessBasicData()) { // Is the company name matching? if (Objects.equals(currentBasicData.getCompanyName(), basicData.getCompanyName())) { // Found match @@ -171,7 +171,7 @@ public class AddressbookAdminBusinessDataSessionBean extends BaseAddressbookEnte boolean isFound = false; // Then check each entry - for (final BasicData currentBasicData : this.businessDataBean.allBusinessBasicData()) { + for (final BasicData currentBasicData : this.businessDataBean.fetchAllBusinessBasicData()) { // Is the company name matching? if (Objects.equals(currentBasicData.getCompanyShortName(), basicData.getCompanyShortName())) { // Found match diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookBusinessDataSessionBean.java index 1ca10a2..3e545b1 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookBusinessDataSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookBusinessDataSessionBean.java @@ -45,7 +45,7 @@ public class AddressbookBusinessDataSessionBean extends BaseAddressbookEnterpris @Override @SuppressWarnings ("unchecked") - public List allBusinessBasicData () { + public List fetchAllBusinessBasicData () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: CALLED!", this.getClass().getSimpleName())); //NOI18N diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java index 331e988..e27b296 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java @@ -73,7 +73,7 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookEnte } // Add created timestamp - branchOffice.setBranchCreated(new Date()); + branchOffice.setBranchEntryCreated(new Date()); // Is user instance set? if (branchOffice.getBranchCompany() instanceof BasicData) { @@ -141,7 +141,7 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookEnte */ private boolean isBranchOfficeFound (final BranchOffice branchOffice) { // Get whole list - final List branchOffices = this.branchOfficeBean.allBranchOffices(); + final List branchOffices = this.branchOfficeBean.fetchAllBranchOffices(); // Default is not found boolean isFound = false; diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java index 4209f13..cb8cfbe 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java @@ -37,7 +37,7 @@ public class AddressbookBranchOfficeSessionBean extends BaseAddressbookEnterpris @Override @SuppressWarnings ("unchecked") - public List allBranchOffices () { + public List fetchAllBranchOffices () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: CALLED!", this.getClass().getSimpleName())); //NOI18N diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java index 55bc8bd..18d5bfa 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java @@ -154,7 +154,7 @@ public class AddressbookAdminDepartmentSessionBean extends BaseAddressbookEnterp */ private boolean isDepartmentFound (final Department department) { // Get whole list - final List departments = this.departmentBean.allDepartments(); + final List departments = this.departmentBean.fetchAllDepartments(); // Default is not found boolean isFound = false; diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java index d86f4df..e2921d0 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java @@ -37,7 +37,7 @@ public class AddressbookDepartmentSessionBean extends BaseAddressbookEnterpriseB @Override @SuppressWarnings ("unchecked") - public List allDepartments () { + public List fetchAllDepartments () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allDepartments: CALLED!", this.getClass().getSimpleName())); //NOI18N diff --git a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminEmployeeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminEmployeeSessionBean.java index 96fb26d..0ee1245 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminEmployeeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminEmployeeSessionBean.java @@ -207,7 +207,7 @@ public class AddressbookAdminEmployeeSessionBean extends BaseAddressbookEnterpri } // Set created timestamp - employee.setEmployeeCreated(new Date()); + employee.setEmployeeEntryCreated(new Date()); // Persist it this.getEntityManager().persist(employee); @@ -231,7 +231,7 @@ public class AddressbookAdminEmployeeSessionBean extends BaseAddressbookEnterpri boolean isFound = false; // Check all entries - for (final Employable otherEmployee : this.employeeBean.allEmployees()) { + for (final Employable otherEmployee : this.employeeBean.fetchAllEmployees()) { // Is same found? if (Employees.isSameEmployeeFound(employee, otherEmployee)) { // Found it diff --git a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookEmployeeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookEmployeeSessionBean.java index 89fdadb..48f2b5d 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookEmployeeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookEmployeeSessionBean.java @@ -44,7 +44,7 @@ public class AddressbookEmployeeSessionBean extends BaseAddressbookEnterpriseBea @Override @SuppressWarnings ("unchecked") - public List allEmployees () { + public List fetchAllEmployees () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allEmployees(): CALLED!", this.getClass().getSimpleName())); //NOI18N diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookAdminHeadquarterSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookAdminHeadquarterSessionBean.java index 88261ac..cc7738a 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookAdminHeadquarterSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookAdminHeadquarterSessionBean.java @@ -131,7 +131,7 @@ public class AddressbookAdminHeadquarterSessionBean extends BaseAddressbookEnter */ private boolean isHeadquarterFound (final Headquarter headquarter) { // Get whole list - final List headquarters = this.headquarterBean.allHeadquarters(); + final List headquarters = this.headquarterBean.fetchAllHeadquarters(); // Default is not found boolean isFound = false; diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookHeadquarterSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookHeadquarterSessionBean.java index a309bd0..c74aab7 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookHeadquarterSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookHeadquarterSessionBean.java @@ -39,7 +39,7 @@ public class AddressbookHeadquarterSessionBean extends BaseAddressbookEnterprise @Override @SuppressWarnings ("unchecked") - public List allHeadquarters () { + public List fetchAllHeadquarters () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: CALLED!", this.getClass().getSimpleName())); //NOI18N diff --git a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java index 24de287..a9848c8 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java @@ -51,7 +51,7 @@ public class AddressbookAdminOpeningTimesSessionBean extends BaseAddressbookEnte if (null == openingTime) { // Throw NPE throw new NullPointerException("openingTime is null"); //NOI18N - } else if (openingTime.getOpeningId() instanceof Long) { + } else if (openingTime.getOpeningTimeId() instanceof Long) { // Should not happen throw new IllegalArgumentException("openingTime.openingId should not be set."); //NOI18N } else if (openingTime.getOpeningStartDay()== null) { @@ -69,13 +69,13 @@ public class AddressbookAdminOpeningTimesSessionBean extends BaseAddressbookEnte } // Set created timestamp - openingTime.setOpeningCreated(new Date()); + openingTime.setOpeningTimeEntryCreated(new Date()); // Persist it this.getEntityManager().persist(openingTime); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addOpeningTimes(): openingTime.openingId={1} - EXIT!", this.getClass().getSimpleName(), openingTime.getOpeningId())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addOpeningTimes(): openingTime.openingId={1} - EXIT!", this.getClass().getSimpleName(), openingTime.getOpeningTimeId())); //NOI18N // Return updated instance return openingTime; diff --git a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java index 44cf877..1b163e7 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java @@ -37,7 +37,7 @@ public class AddressbookOpeningTimesSessionBean extends BaseAddressbookEnterpris @Override @SuppressWarnings ("unchecked") - public List allOpeningTimes () { + public List fetchAllOpeningTimes () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allOpeningTimes: CALLED!", this.getClass().getSimpleName())); //NOI18N diff --git a/src/java/org/mxchange/jcountry/model/data/AddressbookAdminCountrySingletonBean.java b/src/java/org/mxchange/jcountry/model/data/AddressbookAdminCountrySingletonBean.java index aba5a02..42878bd 100644 --- a/src/java/org/mxchange/jcountry/model/data/AddressbookAdminCountrySingletonBean.java +++ b/src/java/org/mxchange/jcountry/model/data/AddressbookAdminCountrySingletonBean.java @@ -114,7 +114,7 @@ public class AddressbookAdminCountrySingletonBean extends BaseAddressbookEnterpr boolean isAdded = false; // Try to match code/i18n key (should be both unique!) - for (final Country currentCountry : this.countryBean.allCountries()) { + for (final Country currentCountry : this.countryBean.fetchAllCountries()) { // Is it matching if (Objects.equals(country, currentCountry)) { // Yes, then set flag and abort loop diff --git a/src/java/org/mxchange/jcountry/model/data/AddressbookCountrySingletonBean.java b/src/java/org/mxchange/jcountry/model/data/AddressbookCountrySingletonBean.java index 99ff1d6..b8b1a75 100644 --- a/src/java/org/mxchange/jcountry/model/data/AddressbookCountrySingletonBean.java +++ b/src/java/org/mxchange/jcountry/model/data/AddressbookCountrySingletonBean.java @@ -47,7 +47,7 @@ public class AddressbookCountrySingletonBean extends BaseAddressbookEnterpriseBe @Override @SuppressWarnings ("unchecked") - public List allCountries () { + public List fetchAllCountries () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCountries: CALLED!", this.getClass().getSimpleName())); //NOI18N diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsAdminMobileSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsAdminMobileSessionBean.java new file mode 100644 index 0000000..5040db6 --- /dev/null +++ b/src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsAdminMobileSessionBean.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2016 - 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.jphone.model.phonenumbers.mobile; + +import java.text.MessageFormat; +import java.util.Date; +import javax.ejb.Stateless; +import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean; + +/** + * An EJB for administrative mobile number purposes + *

+ * @author Roland Häder + */ +@Stateless (name = "adminMobile", description = "An administrative bean handling mobile number data") +public class FinancialsAdminMobileSessionBean extends BaseFinancialsEnterpriseBean implements AdminMobileSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 18_597_165_817_401_854L; + + /** + * Default constructor + */ + public FinancialsAdminMobileSessionBean () { + // Call super constructor + super(); + } + + @Override + public void deleteMobileData (final DialableMobileNumber mobileNumber) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); + + // Is all data set + if (null == mobileNumber) { + // Not set, throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getMobileId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getMobileId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getMobileId())); //NOI18N + } else if (mobileNumber.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N + } else if (mobileNumber.getMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N + } else if (mobileNumber.getMobileNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", mobileNumber.getMobileNumber())); //NOI18N + } + + // Get a managed instance + final DialableMobileNumber managedNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getMobileId()); + + // Remove it from database + this.getEntityManager().remove(managedNumber); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); + } + + @Override + public DialableMobileNumber updateMobileData (final DialableMobileNumber mobileNumber) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); + + // Is all data set + if (null == mobileNumber) { + // Not set, throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getMobileId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getMobileId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getMobileId())); //NOI18N + } else if (mobileNumber.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N + } else if (mobileNumber.getMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N + } else if (mobileNumber.getMobileNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", mobileNumber.getMobileNumber())); //NOI18N + } + + // Get contact from it and find it + final DialableMobileNumber managedNumber = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getMobileId()); + + // Should be found + assert (managedNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getMobileId()); //NOI18N + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateMobileData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getMobileId())); //NOI18N + + // Set updated timestamp + MobileNumbers.copyMobileNumber(mobileNumber, managedNumber); + managedNumber.setMobileEntryUpdated(new Date()); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N + + // Return it + return managedNumber; + } + +} diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsMobileSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsMobileSessionBean.java new file mode 100644 index 0000000..8e2e899 --- /dev/null +++ b/src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsMobileSessionBean.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016 - 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.jphone.model.phonenumbers.mobile; + +import java.text.MessageFormat; +import java.util.List; +import javax.ejb.Stateless; +import javax.persistence.Query; +import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean; + +/** + * A general mobile number EJB + *

+ * @author Roland Häder + */ +@Stateless (name = "mobile", description = "A bean handling mobile number data") +public class FinancialsMobileSessionBean extends BaseFinancialsEnterpriseBean implements MobileSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 134_945_698_127_602L; + + /** + * Default constructor + */ + public FinancialsMobileSessionBean () { + // Call super constructor + super(); + } + + @SuppressWarnings ("unchecked") + @Override + public List fetchAllMobileNumbers () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Get query + final Query query = this.getEntityManager().createNamedQuery("AllMobileNumbers", MobileNumber.class); //NOI18N + + // Get list from it + final List list = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + + // Return it + return list; + } + +} diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java index d377b4a..f6f53ce 100644 --- a/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java +++ b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java @@ -47,7 +47,7 @@ public class AddressbookMobileProviderSingletonBean extends BaseAddressbookEnter @Override @SuppressWarnings ("unchecked") - public List allMobileProviders () { + public List fetchAllMobileProviders () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileProvider: CALLED!", this.getClass().getSimpleName())); //NOI18N diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java index b27dc98..ca0be6d 100644 --- a/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java +++ b/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java @@ -24,8 +24,6 @@ import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers; /** * An EJB for administrative phone purposes @@ -144,48 +142,6 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookEnterpriseB this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); } - @Override - public void deleteMobileData (final DialableMobileNumber mobileNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); - - // Is all data set - if (null == mobileNumber) { - // Not set, throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getMobileId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N - } else if (mobileNumber.getMobileId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getMobileId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // ... throw again - throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } else if (mobileNumber.getMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N - } else if (mobileNumber.getMobileNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", mobileNumber.getMobileNumber())); //NOI18N - } - - // Get a managed instance - final DialableMobileNumber managedNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getMobileId()); - - // Remove it from database - this.getEntityManager().remove(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); - } - @Override public DialableFaxNumber updateFaxData (final DialableFaxNumber faxNumber) { // Trace message @@ -302,56 +258,4 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookEnterpriseB return managedNumber; } - @Override - public DialableMobileNumber updateMobileData (final DialableMobileNumber mobileNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); - - // Is all data set - if (null == mobileNumber) { - // Not set, throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getMobileId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N - } else if (mobileNumber.getMobileId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getMobileId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // ... throw again - throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } else if (mobileNumber.getMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N - } else if (mobileNumber.getMobileNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", mobileNumber.getMobileNumber())); //NOI18N - } - - // Get contact from it and find it - final DialableMobileNumber managedNumber = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getMobileId()); - - // Should be found - assert (managedNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getMobileId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateMobileData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getMobileId())); //NOI18N - - // Set updated timestamp - MobileNumbers.copyMobileNumber(mobileNumber, managedNumber); - managedNumber.setMobileEntryUpdated(new Date()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - } diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookPhoneSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookPhoneSessionBean.java index a937bde..5fd38db 100644 --- a/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookPhoneSessionBean.java +++ b/src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookPhoneSessionBean.java @@ -25,8 +25,6 @@ import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; /** * A general phone EJB @@ -51,7 +49,7 @@ public class AddressbookPhoneSessionBean extends BaseAddressbookEnterpriseBean i @SuppressWarnings ("unchecked") @Override - public List allFaxNumbers () { + public List fetchAllFaxNumbers () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N @@ -70,7 +68,7 @@ public class AddressbookPhoneSessionBean extends BaseAddressbookEnterpriseBean i @SuppressWarnings ("unchecked") @Override - public List allLandLineNumbers () { + public List fetchAllLandLineNumbers () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N @@ -87,23 +85,4 @@ public class AddressbookPhoneSessionBean extends BaseAddressbookEnterpriseBean i return list; } - @SuppressWarnings ("unchecked") - @Override - public List allMobileNumbers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - final Query query = this.getEntityManager().createNamedQuery("AllMobileNumbers", MobileNumber.class); //NOI18N - - // Get list from it - final List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - } diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java index 962da34..f0d38d1 100644 --- a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java @@ -19,11 +19,10 @@ package org.mxchange.jusercore.model.user; import java.text.MessageFormat; import java.util.Date; import java.util.List; +import java.util.Objects; import javax.ejb.EJB; import javax.ejb.EJBException; import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.PersistenceException; import javax.persistence.Query; import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean; import org.mxchange.jcontacts.model.contact.Contact; @@ -70,45 +69,6 @@ public class AddressbookUserSessionBean extends BaseAddressbookEnterpriseBean im super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N } - @Override - @SuppressWarnings ("unchecked") - @Deprecated - public List allUserNames () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - final Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N - - // Get result list - final List userNameList = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: userNameList.size()={1} - EXIT!", this.getClass().getSimpleName(), userNameList.size())); //NOI18N - - // Return it - return userNameList; - } - - @Override - @SuppressWarnings ("unchecked") - public List allUsers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get named query - final Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N - - // Get result - final List users = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N - - // Return full list - return users; - } - @Override public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException { // Trace message @@ -154,79 +114,25 @@ public class AddressbookUserSessionBean extends BaseAddressbookEnterpriseBean im } @Override - @Deprecated - public User fillUserData (final User user) throws UserNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserName() == null) { - // Throw NPE - throw new NullPointerException("user.userName is null"); - } else if (user.getUserName().isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("user.userName is empty"); - } else if (!this.ifUserExists(user)) { - // User does not exist - throw new UserNotFoundException(user); - } - - // Try to locate it - final Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("userName", user.getUserName()); //NOI18N - - // Initialize variable - final User foundUser; - - // Try it - try { - // Try to get single result - foundUser = (User) query.getSingleResult(); - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logException(ex); - return null; - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: foundUser={1} - EXIT!", this.getClass().getSimpleName(), foundUser)); //NOI18N - - // Return prepared instance - return foundUser; - } - - @Override - @Deprecated - public String generateRandomUserName () { + @SuppressWarnings ("unchecked") + public List fetchAllUsers () { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get full list - final List userList = this.allUserNames(); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N - // Init variable - String userName = null; + // Get named query + final Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N - // Loop until a user name is found - while ((userName == null) || (userList.contains(userName))) { - // Generate random name - userName = Users.generateRandomUserName(); - } + // Get result + final List users = query.getResultList(); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName: userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N - // Found one, so return it - return userName; + // Return full list + return users; } @Override - @Deprecated public boolean ifUserExists (final User user) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N @@ -243,38 +149,24 @@ public class AddressbookUserSessionBean extends BaseAddressbookEnterpriseBean im throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N } - // Generate query - final Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("id", user.getUserId()); //NOI18N - - // Try this - try { - // Try to get single result - final User dummy = (User) query.getSingleResult(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: getSingleResult() returned no result: {0}", ex)); //NOI18N - - // User name does not exist - return false; - } catch (final PersistenceException ex) { - // Something bad happened - this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user {0} found.", user, ex)); //NOI18N - - // Throw again - throw ex; + // Default is not found + boolean isFound = false; + + // Fetch whole list + for (final User currentUser : this.fetchAllUsers()) { + // Is found? + if (Objects.equals(user, currentUser)) { + // Yes, then set flag and exit iteration + isFound = true; + break; + } } // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: Found user {1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N - // Found it - return true; + // Return flag + return isFound; } @Override @@ -291,29 +183,21 @@ public class AddressbookUserSessionBean extends BaseAddressbookEnterpriseBean im throw new NullPointerException("userName is empty"); //NOI18N } - // Generate query - final Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("userName", userName); //NOI18N - - // Try this - try { - // Try to get single result - final User dummy = (User) query.getSingleResult(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N - - // User name does not exist - return false; + // Default is not registered + boolean isRegistered = false; + + // Iterate over all records + for (final User currentUser : this.fetchAllUsers()) { + // Does the username match? + if (userName.equals(currentUser.getUserName())) { + // Yes, then set flag and exit iteration + isRegistered = true; + break; + } } // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: Found userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: isRegistered={1} - EXIT!", this.getClass().getSimpleName(), isRegistered)); //NOI18N // Found it return true; @@ -330,38 +214,24 @@ public class AddressbookUserSessionBean extends BaseAddressbookEnterpriseBean im throw new NullPointerException("user is null"); //NOI18N } - // Generate query - final Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("emailAddress", user.getUserContact().getContactEmailAddress()); //NOI18N - - // Search for it - try { - // Try to get single result - final User dummy = (User) query.getSingleResult(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N - - // Email address does not exist - return false; - } catch (final PersistenceException ex) { - // Something bad happened - this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N - - // Throw again - throw ex; + // Default is not registered + boolean isRegistered = false; + + // Iterate over all records + for (final User currentUser : this.fetchAllUsers()) { + // Does the email address match? + if (user.getUserContact().getContactEmailAddress().equals(currentUser.getUserContact().getContactEmailAddress())) { + // Yes, then set flag and exit iteration + isRegistered = true; + break; + } } // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: isRegistered={1} - EXIT!", this.getClass().getSimpleName(), isRegistered)); //NOI18N // Found it - return true; + return isRegistered; } @Override @@ -375,38 +245,14 @@ public class AddressbookUserSessionBean extends BaseAddressbookEnterpriseBean im throw new NullPointerException("user is null"); //NOI18N } - // Generate query - final Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("userName", user.getUserName()); //NOI18N - - // Try this - try { - // Try to get single result - final User dummy = (User) query.getSingleResult(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N - - // User name does not exist - return false; - } catch (final PersistenceException ex) { - // Something bad happened - this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N - - // Throw again - throw ex; - } + // Ask other method + final boolean isRegistered = this.ifUserNameExists(user.getUserName()); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: isRegistered={1} - EXIT!", this.getClass().getSimpleName(), isRegistered)); //NOI18N - // Found it - return true; + // Return flag + return isRegistered; } @Override diff --git a/src/java/org/mxchange/jusercore/model/user/email_address/AddressbookUserEmailChangeSessionBean.java b/src/java/org/mxchange/jusercore/model/user/email_address/AddressbookUserEmailChangeSessionBean.java index 6bc4100..cbd4be8 100644 --- a/src/java/org/mxchange/jusercore/model/user/email_address/AddressbookUserEmailChangeSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/email_address/AddressbookUserEmailChangeSessionBean.java @@ -57,25 +57,6 @@ public class AddressbookUserEmailChangeSessionBean extends BaseAddressbookEnterp super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N } - @Override - @SuppressWarnings ("unchecked") - public List allQueuedAddresses () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get named query - final Query query = this.getEntityManager().createNamedQuery("AllEmailAddressChanges", String.class); //NOI18N - - // Get all entries - final List emailAddresses = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: emailAddresses.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddresses.size())); //NOI18N - - // Return it - return emailAddresses; - } - @Override public void enqueueEmailAddressForChange (final ChangeableEmailAddress emailChange, final String baseUrl) { // Trace message @@ -94,9 +75,6 @@ public class AddressbookUserEmailChangeSessionBean extends BaseAddressbookEnterp } else if (emailChange.getEmailChangeUser().getUserId() < 1) { // Not valid id throw new IllegalArgumentException(MessageFormat.format("emailChange.emailChangeUser.userId={0} is invalid.", emailChange.getEmailChangeUser().getUserId())); //NOI18N - } else if (!this.userBean.ifUserExists(emailChange.getEmailChangeUser())) { - // User does not exist - throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailChange.getEmailChangeId())); //NOI18N } else if (emailChange.getEmailAddress().trim().isEmpty()) { // Email address is empty throw new IllegalArgumentException("emailChange.emaiLAddress is empty."); //NOI18N @@ -119,36 +97,22 @@ public class AddressbookUserEmailChangeSessionBean extends BaseAddressbookEnterp } @Override - public boolean isEmailAddressEnqueued (final String emailAddress) { + @SuppressWarnings ("unchecked") + public List fetchAllQueuedAddressChanges () { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressEnqueued: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N - - // Create query instance - final Query query = this.getEntityManager().createNamedQuery("SearchEmailChangeByEmail"); //NOI18N - - // Add email address as parameter - query.setParameter("email", emailAddress); //NOI18N - - // Initialize variable - boolean isFound = false; + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: CALLED!", this.getClass().getSimpleName())); //NOI18N - // Try it - try { - // Try to get single result - final ChangeableEmailAddress dummy = (ChangeableEmailAddress) query.getSingleResult(); + // Get named query + final Query query = this.getEntityManager().createNamedQuery("AllEmailAddressChanges", ChangeableEmailAddress.class); //NOI18N - // Found it - isFound = true; - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logException(ex); - } + // Get all entries + final List emailAddresses = query.getResultList(); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressEnqueued: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: emailAddresses.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddresses.size())); //NOI18N // Return it - return isFound; + return emailAddresses; } @Override @@ -169,9 +133,6 @@ public class AddressbookUserEmailChangeSessionBean extends BaseAddressbookEnterp } else if (emailAddress.getEmailAddress().trim().isEmpty()) { // Email address is empty throw new IllegalArgumentException("emailAddress.emaiLAddress is empty."); //NOI18N - } else if (!this.userBean.ifUserExists(emailAddress.getEmailChangeUser())) { - // User does not exist - throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailAddress.getEmailChangeId())); //NOI18N } else if (!this.isEmailAddressEnqueued(emailAddress.getEmailAddress())) { // Email address is not enqueued throw new EJBException(MessageFormat.format("Email address {0} is not enqueued.", emailAddress.getEmailAddress())); //NOI18N @@ -231,4 +192,35 @@ public class AddressbookUserEmailChangeSessionBean extends BaseAddressbookEnterp emailAddress.setEmailChangeHash(hash); } + /** + * Checks whether given email address is already enqueued + *

+ * @param emailAddress Email address to check + *

+ * @return Whether the email address has already been enqueued + */ + private boolean isEmailAddressEnqueued (final String emailAddress) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressEnqueued: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N + + // Default is not found + boolean isFound = false; + + // Fetch all records + for (final ChangeableEmailAddress address : this.fetchAllQueuedAddressChanges()) { + // Is it found? + if (address.getEmailAddress().equals(emailAddress)) { + // Yes, set flag, skip further iterations + isFound = true; + break; + } + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressEnqueued: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N + + // Return it + return isFound; + } + } diff --git a/src/java/org/mxchange/jusercore/model/user/password_history/AddressbookUserPasswordHistorySessionBean.java b/src/java/org/mxchange/jusercore/model/user/password_history/AddressbookUserPasswordHistorySessionBean.java index 7734e09..96c1afa 100644 --- a/src/java/org/mxchange/jusercore/model/user/password_history/AddressbookUserPasswordHistorySessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/password_history/AddressbookUserPasswordHistorySessionBean.java @@ -46,7 +46,7 @@ public class AddressbookUserPasswordHistorySessionBean extends BaseAddressbookEn @Override @SuppressWarnings ("unchecked") - public List getUserPasswordHistory (final User user) { + public List fetchPasswordHistoryByUser (final User user) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N -- 2.39.5