]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Thu, 16 Apr 2020 20:04:23 +0000 (22:04 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 16 Apr 2020 20:07:00 +0000 (22:07 +0200)
- 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

Signed-off-by: Roland Häder <roland@mxchange.org>
25 files changed:
src/java/org/mxchange/jcontacts/model/contact/FinancialsAdminContactSessionBean.java
src/java/org/mxchange/jcontacts/model/contact/FinancialsContactSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/basicdata/FinancialsAdminBusinessDataSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/basicdata/FinancialsBusinessDataSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsAdminBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/FinancialsBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsAdminDepartmentSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/FinancialsDepartmentSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/employee/FinancialsAdminEmployeeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/employee/FinancialsEmployeeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsAdminHeadquarterSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/headquarter/FinancialsHeadquarterSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsAdminOpeningTimesSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/opening_time/FinancialsOpeningTimesSessionBean.java
src/java/org/mxchange/jcountry/model/data/FinancialsAdminCountrySingletonBean.java
src/java/org/mxchange/jcountry/model/data/FinancialsCountrySingletonBean.java
src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsAdminMobileSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jphone/model/phonenumbers/mobile/FinancialsMobileSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/FinancialsMobileProviderSingletonBean.java
src/java/org/mxchange/jphone/model/phonenumbers/phone/FinancialsAdminPhoneSessionBean.java
src/java/org/mxchange/jphone/model/phonenumbers/phone/FinancialsPhoneSessionBean.java
src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/email_address/FinancialsUserEmailChangeSessionBean.java
src/java/org/mxchange/jusercore/model/user/password_history/FinancialsUserPasswordHistorySessionBean.java
src/java/org/mxchange/juserlogincore/model/user/login/FinancialsUserLoginSessionBean.java [deleted file]

index 043f5855e1f42d94f64cd388d597e7b09a58e26e..fdc3ea908ca3efb2985deda227642e02a2408108 100644 (file)
@@ -130,7 +130,7 @@ public class FinancialsAdminContactSessionBean extends BaseFinancialsEnterpriseB
                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
index a9d9cd35a1e7f7cf3da5461e14a69150ea3b6a85..8c9ad515a9da15e4b327cd455177af64b77f0cc0 100644 (file)
@@ -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 FinancialsContactSessionBean extends BaseFinancialsEnterpriseBean i
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<Contact> allContacts () {
+       public List<Contact> fetchAllContacts () {
                // Log trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts - CALLED!", this.getClass().getSimpleName())); //NOI18N
 
@@ -65,58 +64,6 @@ public class FinancialsContactSessionBean extends BaseFinancialsEnterpriseBean i
                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() instanceof Long) && (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<Contact> 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
index d9c2634896038abd43ade0157466cfab3895c134..b4f38cbb500c6603306f5726ee4e5970e167bd6c 100644 (file)
@@ -147,7 +147,7 @@ public class FinancialsAdminBusinessDataSessionBean extends BaseFinancialsEnterp
                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 FinancialsAdminBusinessDataSessionBean extends BaseFinancialsEnterp
                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
index bedbc1eb6943ec0d8a25f44fff99b9b1fbb6727c..67d5f707a0bd24e0cda1656456e35924f966a620 100644 (file)
@@ -45,7 +45,7 @@ public class FinancialsBusinessDataSessionBean extends BaseFinancialsEnterpriseB
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<BasicData> allBusinessBasicData () {
+       public List<BasicData> fetchAllBusinessBasicData () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
index 39e0d56fd379918faa99a4209f2fe49c5b2fffee..41584c2276a61f770c1adb8569c49e07199feed2 100644 (file)
@@ -73,7 +73,7 @@ public class FinancialsAdminBranchOfficeSessionBean extends BaseFinancialsEnterp
                }
 
                // 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 FinancialsAdminBranchOfficeSessionBean extends BaseFinancialsEnterp
         */
        private boolean isBranchOfficeFound (final BranchOffice branchOffice) {
                // Get whole list
-               final List<BranchOffice> branchOffices = this.branchOfficeBean.allBranchOffices();
+               final List<BranchOffice> branchOffices = this.branchOfficeBean.fetchAllBranchOffices();
 
                // Default is not found
                boolean isFound = false;
index 3d47c05408995ba62805c88e47bd67330e62e1af..ae95ba61f5347e1bf3b16d2106d3a9c67318cc00 100644 (file)
@@ -37,7 +37,7 @@ public class FinancialsBranchOfficeSessionBean extends BaseFinancialsEnterpriseB
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<BranchOffice> allBranchOffices () {
+       public List<BranchOffice> fetchAllBranchOffices () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
index e275285e897c6244a74386a11d8fc4ee97d33267..f23f267dc16e4590aab0547365b89e3130254f78 100644 (file)
@@ -154,7 +154,7 @@ public class FinancialsAdminDepartmentSessionBean extends BaseFinancialsEnterpri
         */
        private boolean isDepartmentFound (final Department department) {
                // Get whole list
-               final List<Department> departments = this.departmentBean.allDepartments();
+               final List<Department> departments = this.departmentBean.fetchAllDepartments();
 
                // Default is not found
                boolean isFound = false;
index ea9f9efa5303c9705508a4a77db03cfdbcac57c6..d64b7619bcfddcb34eb9d2f746f51d01fb82cad3 100644 (file)
@@ -37,7 +37,7 @@ public class FinancialsDepartmentSessionBean extends BaseFinancialsEnterpriseBea
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<Department> allDepartments () {
+       public List<Department> fetchAllDepartments () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allDepartments: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
index 480ebf025f35fd01aa9c9a777e1e2a7a1e145e8a..74ca845f6f50b66c2737eebf380242823e869f6a 100644 (file)
@@ -207,7 +207,7 @@ public class FinancialsAdminEmployeeSessionBean extends BaseFinancialsEnterprise
                }
 
                // Set created timestamp
-               employee.setEmployeeCreated(new Date());
+               employee.setEmployeeEntryCreated(new Date());
 
                // Persist it
                this.getEntityManager().persist(employee);
@@ -231,7 +231,7 @@ public class FinancialsAdminEmployeeSessionBean extends BaseFinancialsEnterprise
                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
index 0c8d816be27136321240d6d477e4baad014aab08..85aa625a9f5171a0539188103248d3290454a9ba 100644 (file)
@@ -44,7 +44,7 @@ public class FinancialsEmployeeSessionBean extends BaseFinancialsEnterpriseBean
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<Employable> allEmployees () {
+       public List<Employable> fetchAllEmployees () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allEmployees(): CALLED!", this.getClass().getSimpleName())); //NOI18N
 
index 9258b04a7d9f30333b2b63e0851a8c0002e27eff..307ca3754f1fa559962a949a013d205c07d4b00c 100644 (file)
@@ -131,7 +131,7 @@ public class FinancialsAdminHeadquarterSessionBean extends BaseFinancialsEnterpr
         */
        private boolean isHeadquarterFound (final Headquarter headquarter) {
                // Get whole list
-               final List<Headquarter> headquarters = this.headquarterBean.allHeadquarters();
+               final List<Headquarter> headquarters = this.headquarterBean.fetchAllHeadquarters();
 
                // Default is not found
                boolean isFound = false;
index 261e6b1884318417de08044c35ce864f7b1573d8..37094d7254a71f2cd8ef9674b0566d211e63a6f0 100644 (file)
@@ -39,7 +39,7 @@ public class FinancialsHeadquarterSessionBean extends BaseFinancialsEnterpriseBe
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<Headquarter> allHeadquarters () {
+       public List<Headquarter> fetchAllHeadquarters () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
index d2705505d5f58dbd86c226f84d3ac4774e20b258..ea9749bd3ef9e9b7d6016d190f096f3677d1f081 100644 (file)
@@ -51,7 +51,7 @@ public class FinancialsAdminOpeningTimesSessionBean extends BaseFinancialsEnterp
                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 FinancialsAdminOpeningTimesSessionBean extends BaseFinancialsEnterp
                }
 
                // 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;
index 713fef35d021706629887106552be09a41f286d7..c87d2ea0e1905828b772203fc7216344fec086d7 100644 (file)
@@ -37,7 +37,7 @@ public class FinancialsOpeningTimesSessionBean extends BaseFinancialsEnterpriseB
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<OpeningTime> allOpeningTimes () {
+       public List<OpeningTime> fetchAllOpeningTimes () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allOpeningTimes: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
index a0a608f167b420ff5f3c1cbc70ee2df181cdce7a..766d6556adbdafdb171368de4032022e0a0db5ce 100644 (file)
@@ -114,7 +114,7 @@ public class FinancialsAdminCountrySingletonBean extends BaseFinancialsEnterpris
                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
index 21b64380979dd2d974627b573d2fbd5d26f96839..6d51e08b73952a965fac9ca4804d10bd077ba23b 100644 (file)
@@ -47,7 +47,7 @@ public class FinancialsCountrySingletonBean extends BaseFinancialsEnterpriseBean
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<Country> allCountries () {
+       public List<Country> 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 (file)
index 0000000..5040db6
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@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 (file)
index 0000000..8e2e899
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@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<DialableMobileNumber> 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<DialableMobileNumber> 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;
+       }
+
+}
index 24d1a5524e3e5e95989d77055db657e83d605dde..343b1c48fde5b52b158a98dcc3ab274ba36c3762 100644 (file)
@@ -47,7 +47,7 @@ public class FinancialsMobileProviderSingletonBean extends BaseFinancialsEnterpr
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<MobileProvider> allMobileProviders () {
+       public List<MobileProvider> fetchAllMobileProviders () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileProvider: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
index 45a5438e7b37d00e5d91ab9c123a4d0c0b723bd4..b8dde265a0b88dff134e24887b1fe357b85e50be 100644 (file)
@@ -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 FinancialsAdminPhoneSessionBean extends BaseFinancialsEnterpriseBea
                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 FinancialsAdminPhoneSessionBean extends BaseFinancialsEnterpriseBea
                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;
-       }
-
 }
index 6452e8e8b21cbec050a36970ca7cdd4bf9ad18c5..653850be98f751122e3af01f96fb257d05249944 100644 (file)
@@ -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 FinancialsPhoneSessionBean extends BaseFinancialsEnterpriseBean imp
 
        @SuppressWarnings ("unchecked")
        @Override
-       public List<DialableFaxNumber> allFaxNumbers () {
+       public List<DialableFaxNumber> fetchAllFaxNumbers () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
@@ -70,7 +68,7 @@ public class FinancialsPhoneSessionBean extends BaseFinancialsEnterpriseBean imp
 
        @SuppressWarnings ("unchecked")
        @Override
-       public List<DialableLandLineNumber> allLandLineNumbers () {
+       public List<DialableLandLineNumber> fetchAllLandLineNumbers () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
@@ -87,23 +85,4 @@ public class FinancialsPhoneSessionBean extends BaseFinancialsEnterpriseBean imp
                return list;
        }
 
-       @SuppressWarnings ("unchecked")
-       @Override
-       public List<DialableMobileNumber> 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<DialableMobileNumber> 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;
-       }
-
 }
index eab8e52cdd2e446906647ea301242ada72cb4119..ffa3d2f7023671b4d34619c751ab8eea8892daf8 100644 (file)
@@ -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.jcontacts.model.contact.Contact;
 import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean;
@@ -69,45 +68,6 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                super("jms/jfinancials-queue-factory", "jms/jfinancials-email-queue"); //NOI18N
        }
 
-       @Override
-       @SuppressWarnings ("unchecked")
-       @Deprecated
-       public List<String> 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<String> 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<User> 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<User> 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
@@ -153,79 +113,25 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
        }
 
        @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<User> fetchAllUsers () {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get full list
-               final List<String> 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<User> 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
@@ -242,38 +148,24 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                        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
@@ -290,29 +182,21 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                        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;
@@ -329,38 +213,24 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                        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
@@ -374,38 +244,14 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                        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
index e69a58a239b48f2d0f3262b99d6ffaac92587192..f30de6ad835dc882c3a5e8cde7ededd948db9bbd 100644 (file)
@@ -57,25 +57,6 @@ public class FinancialsUserEmailChangeSessionBean extends BaseFinancialsEnterpri
                super("jms/jfinancials-queue-factory", "jms/jfinancials-email-queue"); //NOI18N
        }
 
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<String> 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<String> 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 FinancialsUserEmailChangeSessionBean extends BaseFinancialsEnterpri
                } 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 FinancialsUserEmailChangeSessionBean extends BaseFinancialsEnterpri
        }
 
        @Override
-       public boolean isEmailAddressEnqueued (final String emailAddress) {
+       @SuppressWarnings ("unchecked")
+       public List<ChangeableEmailAddress> 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<ChangeableEmailAddress> 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 FinancialsUserEmailChangeSessionBean extends BaseFinancialsEnterpri
                } 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 FinancialsUserEmailChangeSessionBean extends BaseFinancialsEnterpri
                emailAddress.setEmailChangeHash(hash);
        }
 
+       /**
+        * Checks whether given email address is already enqueued
+        * <p>
+        * @param emailAddress Email address to check
+        * <p>
+        * @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;
+       }
+
 }
index 1c25510a24a970ca1420ed4b36466531a903cfd5..1c6e45ed70e89ef8537562879151a300bd32a449 100644 (file)
@@ -46,7 +46,7 @@ public class FinancialsUserPasswordHistorySessionBean extends BaseFinancialsEnte
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<PasswordHistory> getUserPasswordHistory (final User user) {
+       public List<PasswordHistory> fetchPasswordHistoryByUser (final User user) {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
 
diff --git a/src/java/org/mxchange/juserlogincore/model/user/login/FinancialsUserLoginSessionBean.java b/src/java/org/mxchange/juserlogincore/model/user/login/FinancialsUserLoginSessionBean.java
deleted file mode 100644 (file)
index 3c7009a..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.juserlogincore.model.user.login;
-
-import java.text.MessageFormat;
-import javax.ejb.EJB;
-import javax.ejb.Stateless;
-import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.exceptions.UserStatusLockedException;
-import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.juserlogincore.container.login.LoginContainer;
-import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
-import org.mxchange.juserlogincore.login.UserLoginUtils;
-
-/**
- * A session EJB for user logins
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "userLogin", description = "A bean handling the application-specific user login")
-public class FinancialsUserLoginSessionBean extends BaseFinancialsEnterpriseBean implements UserLoginSessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 21_785_978_127_581_965L;
-
-       /**
-        * User EJB
-        */
-       @EJB (lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
-       private UserSessionBeanRemote userBean;
-
-       /**
-        * Default constructor
-        */
-       public FinancialsUserLoginSessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public User validateUserAccountStatus (final LoginContainer container) throws UserNotFoundException, UserStatusLockedException, UserStatusUnconfirmedException, UserPasswordMismatchException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.loginUser: container={1} - CALLED!", this.getClass().getSimpleName(), container)); //NOI18N
-
-               // user should not be null
-               if (null == container) {
-                       // Abort here
-                       throw new NullPointerException("container is null"); //NOI18N
-               } else if (container.getUser() == null) {
-                       // NPE again
-                       throw new NullPointerException("container.user is null"); //NOI18N
-               } else if (container.getUserPassword() == null) {
-                       // And yet again NPE
-                       throw new NullPointerException("container.userPassword is null"); //NOI18N
-               } else if (container.getUserPassword().isEmpty()) {
-                       // Empty password is not allowed, hardcoded.
-                       throw new IllegalArgumentException("container.userPassword is empty"); //NOI18N
-               }
-
-               // Is the account there?
-               if (!this.userBean.isUserNameRegistered(container.getUser())) {
-                       // Not registered
-                       throw new UserNotFoundException(container.getUser());
-               }
-
-               // Get user instance from persistance
-               // @TODO Rewrite this to use JCache instead
-               final User updatedUser = this.userBean.fillUserData(container.getUser());
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("loginUser: updatedUser={0}", updatedUser)); //NOI18N
-
-               // Is the user account unconfirmed?
-               if (updatedUser.getUserAccountStatus().equals(UserAccountStatus.UNCONFIRMED)) {
-                       // Is unconfirmed
-                       throw new UserStatusUnconfirmedException(container.getUser());
-               } else if (updatedUser.getUserAccountStatus().equals(UserAccountStatus.LOCKED)) {
-                       // Is locked
-                       throw new UserStatusLockedException(container.getUser());
-               } else if (!this.isPasswordMatching(container, updatedUser)) {
-                       // Not matcing passwords
-                       throw new UserPasswordMismatchException(container.getUser());
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.loginUser: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
-
-               // Return it
-               return updatedUser;
-       }
-
-       /**
-        * Checks if password matches of both instances. Both user instances must
-        * not match, the first one is the one from the calling bean/controller, the
-        * second is the from database.
-        * <p>
-        * @param container   Container instance holding the user instance and
-        *                    clear-text password
-        * @param updatedUser Updated user instance found for given user name
-        * <p>
-        * @return Whether the password matches
-        */
-       private boolean isPasswordMatching (final LoginContainer container, final User updatedUser) {
-               // First math both instances
-               if (null == container) {
-                       // Throw NPE
-                       throw new NullPointerException("container is null"); //NOI18N
-               } else if (null == updatedUser) {
-                       // Throw NPE
-                       throw new NullPointerException("updatedUser is null"); //NOI18N
-               } else if (container.getUser().equals(updatedUser)) {
-                       // Both same instance!
-                       throw new IllegalArgumentException(MessageFormat.format("container.user matches updatedUser: {0}", container.getUser())); //NOI18N
-               }
-
-               // Is it the same same password?
-               return UserLoginUtils.ifPasswordMatches(container, updatedUser);
-       }
-
-}