]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Tue, 19 May 2020 23:28:45 +0000 (01:28 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 19 May 2020 23:28:45 +0000 (01:28 +0200)
- let's use createManaged() where possible to avoid some duplicate code. It may
  look a bit to much encapsulation or to fine-granulated, the createManaged()
  method contains some validation on the entity instance and that is a good
  reason to have it encapsulated away.

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/enterprise/BaseFinancialsEnterpriseBean.java
src/java/org/mxchange/jusercore/model/user/FinancialsAdminUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java
src/java/org/mxchange/juserlogincore/model/user/register/FinancialsUserRegistrationSessionBean.java

index 1178783a16f4bea0cad0055b014e26fc3ab4ea19..2a198076acd4956806a7e1b5616d9e02e5902f64 100644 (file)
@@ -809,10 +809,7 @@ public abstract class BaseFinancialsEnterpriseBean extends BaseEnterpriseBean {
                detachedContact.setContactEntryUpdated(new Date());
 
                // Get contact from it and find it
-               final Contact foundContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
-
-               // Should be found
-               assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
+               final Contact foundContact = this.createManaged(detachedContact);
 
                // Debug message
                this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeContactData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N
@@ -959,10 +956,7 @@ public abstract class BaseFinancialsEnterpriseBean extends BaseEnterpriseBean {
                detachedDepartment.setDepartmentEntryUpdated(new Date());
 
                // Get contact from it and find it
-               final Department foundDepartment = this.getEntityManager().find(detachedDepartment.getClass(), detachedDepartment.getDepartmentId());
-
-               // Should be found
-               assert (foundDepartment instanceof Department) : MessageFormat.format("Department with id {0} not found, but should be.", detachedDepartment.getDepartmentId()); //NOI18N
+               final Department foundDepartment = this.createManaged(detachedDepartment);
 
                // Debug message
                this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeDepartmentData: foundContact.contactId={0}", foundDepartment.getDepartmentId())); //NOI18N
index 431b19e567e1c6d539e57d888a91730a3029b97b..19b6eb36c18c6d955e133bea53ca3bb03910e8c4 100644 (file)
@@ -81,7 +81,7 @@ public class FinancialsAdminUserSessionBean extends BaseFinancialsEnterpriseBean
                }
 
                // Set created timestamp
-               user.setUserCreated(new Date());
+               user.setUserEntryCreated(new Date());
                user.getUserContact().setContactEntryCreated(new Date());
 
                // Update mobile, land-line and fax instance
@@ -178,7 +178,7 @@ public class FinancialsAdminUserSessionBean extends BaseFinancialsEnterpriseBean
                user.setUserContact(foundContact);
 
                // Set timestamp
-               user.setUserCreated(new Date());
+               user.setUserEntryCreated(new Date());
 
                // Perist it
                this.getEntityManager().persist(user);
index 755000f3559cee839e8bb8d62dbba78b287a38fb..231ea0fc6f273bd7f18dd5359bdf863bada6687f 100644 (file)
@@ -69,7 +69,7 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
        }
 
        @Override
-       public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
+       public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException, UserNotFoundException {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
 
@@ -100,7 +100,7 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                // Update user status and remove confirmation key
                managedUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
                managedUser.setUserConfirmKey(null);
-               managedUser.setUserUpdated(new Date());
+               managedUser.setUserEntryUpdated(new Date());
 
                // Send out email
                this.sendEmail("User account confirmed", "user_account_confirmed", managedUser, baseUrl, null); //NOI18N
@@ -255,7 +255,7 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
        }
 
        @Override
-       public User updateUserData (final User detachedUser) {
+       public User updateUserData (final User detachedUser) throws UserNotFoundException {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: detachedUser={1} - CALLED!", this.getClass().getSimpleName(), detachedUser)); //NOI18N
 
@@ -274,7 +274,7 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                        throw new NullPointerException("detachedUser.userAccountStatus is null"); //NOI18N
                } else if (!this.ifUserExists(detachedUser)) {
                        // User does not exist
-                       throw new EJBException(MessageFormat.format("User with id {0} does not exist.", detachedUser.getUserId())); //NOI18N
+                       throw new UserNotFoundException(detachedUser.getUserId());
                }
 
                // Remove contact instance as this is not updated
@@ -296,7 +296,7 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", managedUser.getUserId()); //NOI18N
 
                // Set as updated
-               managedUser.setUserUpdated(new Date());
+               managedUser.setUserEntryUpdated(new Date());
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - CALLED!", this.getClass().getSimpleName(), managedUser)); //NOI18N
@@ -356,7 +356,7 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                final User managedUser = this.updateUserData(user);
 
                // Update user account
-               managedUser.setUserUpdated(new Date());
+               managedUser.setUserEntryUpdated(new Date());
 
                // Create history entry
                PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), managedUser);
@@ -414,7 +414,7 @@ public class FinancialsUserSessionBean extends BaseFinancialsEnterpriseBean impl
                Users.copyUserData(user, managedUser);
 
                // Set as updated
-               managedUser.setUserUpdated(new Date());
+               managedUser.setUserEntryUpdated(new Date());
 
                // Update user data
                final Contact managedContact = this.mergeContactData(managedUser.getUserContact());
index 65d1a12b42377f9877dc2a86ee98fa0488805f5e..477ba3afe58dddc22cc9be833fe692e22f6b91d5 100644 (file)
 package org.mxchange.juserlogincore.model.user.register;
 
 import java.text.MessageFormat;
+import java.util.List;
 import java.util.Objects;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
 import org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.juserlogincore.login.UserLoginUtils;
@@ -76,8 +73,8 @@ public class FinancialsUserRegistrationSessionBean extends BaseFinancialsEnterpr
                        throw new NullPointerException("user is null"); //NOI18N
                }
 
-               // Create named instance
-               final Query query = this.getEntityManager().createNamedQuery("SearchUserByConfirmKey", LoginUser.class); //NOI18N
+               // Fetch whole list
+               final List<User> users = this.userBean.fetchAllUsers();
 
                // Init confirmation key
                String confirmationKey = null;
@@ -85,22 +82,16 @@ public class FinancialsUserRegistrationSessionBean extends BaseFinancialsEnterpr
                // Find a free one
                while (confirmationKey == null) {
                        // Create new one
-                       final String key = UserLoginUtils.generatedConfirmationKey(user);
-
-                       // Set key as parameter
-                       query.setParameter("confirmKey", key); //NOI18N
-
-                       // Try it
-                       try {
-                               // Get contact instance
-                               final Contact contact = (Contact) query.getSingleResult();
-
-                               // Warning message
-                               this.getLoggerBeanLocal().logWarning(MessageFormat.format("{0}.generateConfirmationKey: key {1} already found: contact.contactId={2}", this.getClass().getSimpleName(), key, contact.getContactId())); //NOI18N
-                       } catch (final NoResultException ex) {
-                               // Not found, normal case
-                               confirmationKey = key;
-                               break;
+                       confirmationKey = UserLoginUtils.generatedConfirmationKey(user);
+
+                       // Check all entries
+                       for (final User currentUser : users) {
+                               // Does the key match?
+                               if (Objects.equals(currentUser.getUserConfirmKey(), confirmationKey)) {
+                                       // Set key to null and exit loop
+                                       confirmationKey = null;
+                                       break;
+                               }
                        }
                }
 
@@ -148,7 +139,7 @@ public class FinancialsUserRegistrationSessionBean extends BaseFinancialsEnterpr
 
                // Is password set?
                if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
-                       // Switch to other template
+                       // Switch to template with random password exposed
                        templateName = "user_registration_random"; //NOI18N
                }