]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Continued a bit:
authorRoland Haeder <roland@mxchange.org>
Sat, 12 Mar 2016 17:08:52 +0000 (18:08 +0100)
committerRoland Haeder <roland@mxchange.org>
Sat, 12 Mar 2016 18:10:31 +0000 (19:10 +0100)
- added ifUserExists()
- rewrote enqueueEmailAddressForChange() which now takes ChangeableEmailAddress as instance
- also rewrote updateEmailAddress() with same parameter
- added isEmailAddressEnqueued()
- updated jar(s)

lib/juser-core.jar
lib/juser-lib.jar
src/java/org/mxchange/jusercore/model/email_address/EmailChangeSessionBean.java
src/java/org/mxchange/jusercore/model/user/UserSessionBean.java

index 8488d71d29bac0c83be02e3c7e5e3129e0b51f47..1924b0bcb057c30248932d2d3e5063b69db3e4ce 100644 (file)
Binary files a/lib/juser-core.jar and b/lib/juser-core.jar differ
index dd11c240493a216c77ed2b313e537ab78f64da1e..d70697aaa2ef33810501b060d2c314cca0e8cf1f 100644 (file)
Binary files a/lib/juser-lib.jar and b/lib/juser-lib.jar differ
index 2eddde855c2661ee42e599fc544324886b34cdcb..a049514509c546cb2d3f19c33a756e809a766e3b 100644 (file)
 package org.mxchange.jusercore.model.email_address;
 
 import java.text.MessageFormat;
+import java.util.List;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
 import javax.persistence.PersistenceException;
+import javax.persistence.Query;
 import org.mxchange.jcoreee.database.BaseDatabaseBean;
-import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 
 /**
@@ -32,6 +34,7 @@ import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 @Stateless (name = "email-change", mappedName = "ejb/stateless-addressbook-email-change", description = "A bean handling email changes")
 public class EmailChangeSessionBean extends BaseDatabaseBean implements EmailChangeSessionBeanRemote {
 
+
        /**
         * Serial number
         */
@@ -50,52 +53,84 @@ public class EmailChangeSessionBean extends BaseDatabaseBean implements EmailCha
        }
 
        @Override
-       public void enqueueEmailAddressForChange (final User user) {
+       public List<String> allQueuedAddressesAsList () {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       public void enqueueEmailAddressForChange (final ChangeableEmailAddress emailAddress) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("enqueueEmailAddressForChange: user={0} - CALLED!", user));
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("enqueueEmailAddressForChange: emailAddress={0} - CALLED!", emailAddress));
 
                // user should not be null
-               if (null == user) {
+               if (null == emailAddress) {
                        // Abort here
-                       throw new NullPointerException("user is null"); //NOI18N
-               } else if (user.getUserId() == null) {
+                       throw new NullPointerException("emailAddress is null"); //NOI18N
+               } else if (emailAddress.getEmailChangeId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("user.userId is null"); //NOI18N
-               } else if (user.getUserId() < 1) {
+                       throw new NullPointerException("emailAddress.emailChangeId is null"); //NOI18N
+               } else if (emailAddress.getEmailChangeId() < 1) {
                        // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
-               } else if (user.getUserAccountStatus() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
-               } else if (!this.userBean.ifUserIdExists(user.getUserId())) {
+                       throw new IllegalArgumentException(MessageFormat.format("emailAddress.emailChangeId={0} is not valid.", emailAddress.getEmailChangeId())); //NOI18N
+               } else if (!this.userBean.ifUserExists(emailAddress.getEmailChangeUser())) {
                        // User does not exist
-                       throw new PersistenceException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
+                       throw new PersistenceException(MessageFormat.format("Email change with id {0} does not exist.", emailAddress.getEmailChangeId())); //NOI18N
                }
 
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
 
        @Override
-       public void updateEmailAddress (final User user) {
+       public boolean isEmailAddressEnqueued (final String emailAddress) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressEnqueued: emailAddress={0} - CALLED!", emailAddress)); //NOI18N
+
+               // Create query instance
+               Query query = this.getEntityManager().createNamedQuery("SearchEmailChangeByEmail"); //NOI18N
+
+               // Add email address as parameter
+               query.setParameter("email", emailAddress); //NOI18N
+
+               // Initialize variable
+               boolean isFound = false;
+
+               // Try it
+               try {
+                       // Try to get single result
+                       ChangeableEmailAddress dummy = (ChangeableEmailAddress) query.getSingleResult();
+
+                       // Found it
+                       isFound = true;
+               } catch (final NoResultException ex) {
+                       // Log it
+                       this.getLoggerBeanLocal().logException(ex);
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressEnqueued: isFound={0} - EXIT!", isFound)); //NOI18N
+
+               // Return it
+               return isFound;
+       }
+
+       @Override
+       public void updateEmailAddress (final ChangeableEmailAddress emailAddress) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateEmailAddress: user={0} - CALLED!", user));
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateEmailAddress: emailAddress={0} - CALLED!", emailAddress));
 
                // user should not be null
-               if (null == user) {
+               if (null == emailAddress) {
                        // Abort here
-                       throw new NullPointerException("user is null"); //NOI18N
-               } else if (user.getUserId() == null) {
+                       throw new NullPointerException("emailAddress is null"); //NOI18N
+               } else if (emailAddress.getEmailChangeId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("user.userId is null"); //NOI18N
-               } else if (user.getUserId() < 1) {
+                       throw new NullPointerException("emailAddress.emailChangeId is null"); //NOI18N
+               } else if (emailAddress.getEmailChangeId() < 1) {
                        // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
-               } else if (user.getUserAccountStatus() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
-               } else if (!this.userBean.ifUserIdExists(user.getUserId())) {
+                       throw new IllegalArgumentException(MessageFormat.format("emailAddress.emailChangeId={0} is not valid.", emailAddress.getEmailChangeId())); //NOI18N
+               } else if (!this.userBean.ifUserExists(emailAddress.getEmailChangeUser())) {
                        // User does not exist
-                       throw new PersistenceException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
+                       throw new PersistenceException(MessageFormat.format("Email change with id {0} does not exist.", emailAddress.getEmailChangeId())); //NOI18N
                }
 
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
index 4795d84bec1f1295ca3a07df1e3c38fb7045cda5..59fe23ae2abbf00f98748cd256c3d7c3a3db7a9f 100644 (file)
@@ -159,6 +159,56 @@ public class UserSessionBean extends BaseDatabaseBean implements UserSessionBean
                return userNameList;
        }
 
+       @Override
+       public boolean ifUserExists (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: user={0} - CALLED!", user)); //NOI18N
+
+               // userId should not be null
+               if (null == user) {
+                       // Abort here
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // Abort here
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
+               }
+
+               // Generate query
+               Query query = this.getEntityManager().createNamedQuery("SearchUser", LoginUser.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("user", user); //NOI18N
+
+               // Try this
+               try {
+                       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;
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: Found user {0} - EXIT!", user)); //NOI18N
+
+               // Found it
+               return true;
+       }
+
        @Override
        public boolean ifUserIdExists (final Long userId) {
                // Trace message
@@ -306,7 +356,7 @@ public class UserSessionBean extends BaseDatabaseBean implements UserSessionBean
                } else if (user.getUserAccountStatus() == null) {
                        // Throw NPE again
                        throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
-               } else if (!this.ifUserIdExists(user.getUserId())) {
+               } else if (!this.ifUserExists(user)) {
                        // User does not exist
                        throw new PersistenceException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
                }