From 6c08da515b29c399b1b52162812a47e70d4a7c0b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 12 Mar 2016 18:08:59 +0100 Subject: [PATCH] Continued a bit: - 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 | Bin 37613 -> 38450 bytes lib/juser-lib.jar | Bin 4887 -> 5111 bytes .../email_address/EmailChangeSessionBean.java | 88 ++++++++++++------ .../jusercore/model/user/UserSessionBean.java | 52 ++++++++++- 4 files changed, 112 insertions(+), 28 deletions(-) diff --git a/lib/juser-core.jar b/lib/juser-core.jar index 8488d71d29bac0c83be02e3c7e5e3129e0b51f47..1924b0bcb057c30248932d2d3e5063b69db3e4ce 100644 GIT binary patch delta 3979 zcma)93sjWH6~6z!FLqf#76l2fHHu*u6+}!T3RyxxkcTLWMtmWxfDt3C#;C0eRZvk7 zoM?)z)}F-J8e2)%XLAy5jg6j@#2V9j($-q@(Ad_VHs|y-CoyTiJO82!SB5Tr%$}n-MF<-=F+FfQMy+UymDrGz+NSR1U zM5K@%rAnh71e;mJzwQgIj3VM+o``I)i*jAKNXoH^!=e~m-=x^;z7@UTA#F*o@byhSspt?Xp_E05=K1N~krnRh=9>C|@ISd;Dhe6E zqf?pPk~KAPsVBYn$C3kHcP4 zRNUW`C0iU;Dy1?Ly=bNHQ$miFvI)gQ6lbM8ddfPj$X`e#5BC;S=+}IU8)=JB$ z#za4`QYHP+O3%?cD=nt|R+_-Z>Fk?HlYRfnj#a!-SS|(25`sQQP&Dc>a$k(Z-oPl( z1mXQ9;VSnG=`EH8q0;sWc&^e(mil+0Cc)3mBztW$G+qH-MrEd zy#7DGw0=M7hMD-?Vh8fWw)W6O%2+^?(15uH^!_NO^BDBU-86-=y#2G8%Cng^pnF6* zz%O9>atcob*t%ec3Fgw17!J$gcN-5aUz>12fc11hg*8+}GpZ;?aZ@psXo0oC4~va*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h@`;0R{LP8Z;Bl}3Z%6V+Bk%EL`fS3Jyl@?+u6V+8>J zGrUd%{$3yBUyQ&wqQM~z4r@>z8fJ&&toY8=l=YeqMG`6B)Ek9-oT9Q2cGwbI6Ef?u zX!y=LL5RV>=2+d6-tth8u8J~_LuuFBLG(swUfJs*@7uCT+xB^E%TK$3IOa(4rZa=H zEoTn#!&yeO+)IcT?h@j=yYPP>=e!QCy!Fboo#72y;Z8Q-PkkTNnqQ_Xx=^e9zCRW0 hD~Is8_ia65rabZk@+>JJHb@b1LKYFP#6_g(JfcqLtU-Ne$!UMJI|QIZ_$}SkEd~aIAOn-% zNEu!+r+8HUC{USz3;_T^1ql?GUsccq6(AtG`rVvY3s{nH@*1itnP_$YwlUF?09t&{ zSkWB@V+@iEQr@%CBz)gY@NLcYuFVu78o#r)axvdw#IJEk{P>Kb51}z>I0n8RDvCMq zqfiNxJ%y$bvh9a=?FGCY+RKPXyM~wyR}j15HN-=B_5UdHktQl<5r-bgylaeeiz@s@ zN%B@Sf{GS(=rQw^3e|W?&!Ce26H`Q;6+I8vRrf*{AKZAg98mDl68l^RXjpjr2C3$E A2><{9 diff --git a/src/java/org/mxchange/jusercore/model/email_address/EmailChangeSessionBean.java b/src/java/org/mxchange/jusercore/model/email_address/EmailChangeSessionBean.java index ba17695..b7958d6 100644 --- a/src/java/org/mxchange/jusercore/model/email_address/EmailChangeSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/email_address/EmailChangeSessionBean.java @@ -17,11 +17,13 @@ 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; /** @@ -50,52 +52,84 @@ public class EmailChangeSessionBean extends BaseDatabaseBean implements EmailCha } @Override - public void enqueueEmailAddressForChange (final User user) { + public List 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)); //NOI18N // 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("updateEmailAddress: user={0} - CALLED!", user)); + 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: emailAddress={0} - CALLED!", emailAddress)); //NOI18N // 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. diff --git a/src/java/org/mxchange/jusercore/model/user/UserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/UserSessionBean.java index 2502c7c..f438600 100644 --- a/src/java/org/mxchange/jusercore/model/user/UserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/UserSessionBean.java @@ -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 } -- 2.39.5