From f882aeef7f61f268812e35496dc151cf0866f2f0 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 12 Mar 2016 18:10:31 +0100 Subject: [PATCH] Continued: - added local caching of all enqueued email addresses (this can become big) - updated jar(s) --- lib/juser-core.jar | Bin 37613 -> 38112 bytes lib/juser-lib.jar | Bin 4887 -> 5111 bytes .../EmailChangeWebSessionBean.java | 67 +++++++++++++++--- .../password/UserPasswordValidator.java | 4 +- 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/lib/juser-core.jar b/lib/juser-core.jar index 8488d71d29bac0c83be02e3c7e5e3129e0b51f47..8ce84feb27b6c1ae7308aae243d964e112f069d6 100644 GIT binary patch delta 3538 zcma)93s98T6+ZvJFLwDsSOFh^tc{r6<>{*lLQkNP;o0R3733 z!E0&aOfv0gs<9@TuBd67R+E^Rsg1FDIB6%f=513uZKgBLG^W$<+<(Ch!I{AP_uTW{ zbI$$#bMHO>-5bxSe|=Wf%8Ly~8&MchTmOLOQXlFcxa+6tP~X7&4sO48p%v4WSuCoQ z92N(Z0v1=5Y!>lq9*e04mpCy#MjTLWto{n>B{i12pQ>4ETR#luv$oMtrjO^c_^+Xu z#eAa&BG6~NuCQ!3H<(#|rWHwjX5>@@>&v1mq&yn4M&j1El`7-ji7SmPUrNZ5@+-$I zDbtcSO8Y0B$E94DdO^yV%z4J>w*H0%jZNF~bL~X@6o}}0hbT8hilkh-I6Qk?<)Dqm z)8kg!N`5QZX`2lVR6BKW^CNDyvq`6gx_GQRoUGJsqaND9YA>t3tnOsfUEJ)p&>jo* ziD;KQFlSD$QCTb$yGxw6*hTYC;93_iZc$PSQ>Czy-wzkFB+UjzY6crB-Wy=wlMhmFOLVGppr^GCc?j|&o zXtGARbgxF!=}wIXXrDs)BDyd|T-_TtRiibu)!53!yHsK872k*A6j9~IJkJz-IB z!}_6J2#&dMRv*Y%UlgY`w5MsC$O=flsw|}FhL%CLaJyrCQI7p(AT$HP1eixp`_`D#HdD)Y65!|ZGdctB z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D#Q#gz$a#laY1TMj0f#%|3{-;?kEsEV?--r3mukU;B`NXeDYq71U27nIm zZLne0=xDHU@)gEU0mdCv_yn0ktdLWPXJi)fnVdre^a3KHXYJ7-X&GkbLyH2mDBq?x zuH`lGH1IVzK%f|>%}y96(^1r8Y1-_r^;w@q1Paypd*Oqyo`l`i`jz!w++96gyH21K zCdp;FXZHw8r_=d3UFTKvDEF)yFDVsrk-yd}{J3iuXYPs%Sa>^O|GvX-DLZXdC7?nE zKrjm$5X=}TjET7crqnH@&~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/jjobs/beans/email_address/EmailChangeWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/email_address/EmailChangeWebSessionBean.java index 4e01c8c8..5debda8a 100644 --- a/src/java/org/mxchange/jjobs/beans/email_address/EmailChangeWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/email_address/EmailChangeWebSessionBean.java @@ -17,6 +17,8 @@ package org.mxchange.jjobs.beans.email_address; import java.text.MessageFormat; +import java.util.GregorianCalendar; +import java.util.List; import java.util.Objects; import javax.enterprise.context.SessionScoped; import javax.faces.view.facelets.FaceletException; @@ -28,6 +30,8 @@ import javax.naming.NamingException; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jjobs.beans.login.UserLoginWebSessionController; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; +import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; +import org.mxchange.jusercore.model.email_address.EmailAddressChange; import org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote; import org.mxchange.jusercore.model.user.User; @@ -55,6 +59,11 @@ public class EmailChangeWebSessionBean implements EmailChangeWebSessionControlle */ private String emailAddress2; + /** + * Local list of already queued email addresses + */ + private List emailAddresses; + /** * Remote email change bean */ @@ -77,6 +86,9 @@ public class EmailChangeWebSessionBean implements EmailChangeWebSessionControlle // Try to lookup this.emailBean = (EmailChangeSessionBeanRemote) context.lookup("ejb/stateless-jjobs-email-change"); //NOI18N + + // Init list + this.emailAddresses = this.emailBean.allQueuedAddressesAsList(); } catch (final NamingException e) { // Throw again throw new FaceletException(e); @@ -104,18 +116,24 @@ public class EmailChangeWebSessionBean implements EmailChangeWebSessionControlle User user = this.loginController.getLoggedInUser(); // It should be there, so run some tests on it - assert (user instanceof User) : "Instance loginController.loggedInUser is null"; - assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null"; - assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId()); - assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; - assert (user.getUserContact().getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; - assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); + assert (user instanceof User) : "Instance loginController.loggedInUser is null"; //NOI18N + assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null"; //NOI18N + assert (user.getUserId() > 0) : MessageFormat.format("loginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N + assert (user.getUserContact() instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N + assert (user.getUserContact().getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N + assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N + + // Check if the email address is already enqueued + if (this.isEmailAddressQueued()) { + // Yes, then abort here + return "login_email_already_added"; //NOI18N + } - // Update email address - user.getUserContact().setContactEmailAddress(this.getEmailAddress1()); + // Create change object + ChangeableEmailAddress emailAddress = new EmailAddressChange(user, this.getEmailAddress1(), new GregorianCalendar()); // Call EJB - this.emailBean.enqueueEmailAddressForChange(user); + this.emailBean.enqueueEmailAddressForChange(emailAddress); // All fine return "login_email_change_queued"; //NOI18N @@ -147,4 +165,35 @@ public class EmailChangeWebSessionBean implements EmailChangeWebSessionControlle (this.getEmailAddress2() != null)); } + /** + * Checks if current emailAddress1 has already been queued. First a local + * list is being checked, if not found, the EJB is called. Only if found, + * the result is "cached" in the list. + *

+ * @return Whether the email address in field emailAddress1 is already queued + */ + private boolean isEmailAddressQueued () { + // It should be there + assert (this.getEmailAddress1() != null) : "emailAddress1 should not be null"; //NOI18N + assert (!this.getEmailAddress1().trim().isEmpty()) : "emailAddress1 should not be empty"; //NOI18N + + // Check list + if (this.emailAddresses.contains(this.getEmailAddress1())) { + // Okay, found it + return true; + } + + // Check EJB + boolean isQueued = this.emailBean.isEmailAddressEnqueued(this.getEmailAddress1()); + + // Is it there? + if (isQueued) { + // Add to list + this.emailAddresses.add(this.getEmailAddress1()); + } + + // Return status + return isQueued; + } + } diff --git a/src/java/org/mxchange/jjobs/validators/password/UserPasswordValidator.java b/src/java/org/mxchange/jjobs/validators/password/UserPasswordValidator.java index 3673c7cf..d1a90c05 100644 --- a/src/java/org/mxchange/jjobs/validators/password/UserPasswordValidator.java +++ b/src/java/org/mxchange/jjobs/validators/password/UserPasswordValidator.java @@ -81,10 +81,10 @@ public class UserPasswordValidator extends BaseStringValidator implements Valida this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N // The required field - String[] requiredFileds = {"currentPassword"}; //NOI18N + String[] requiredFields = {"currentPassword"}; //NOI18N // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFileds, false); + super.preValidate(context, component, value, requiredFields, false); // value is known to be an entered password, so instance login container LoginContainer container = new UserLoginContainer(this.loginController.getLoggedInUser(), (String) value); -- 2.39.5