From: Roland Haeder Date: Sat, 12 Mar 2016 17:10:31 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f882aeef7f61f268812e35496dc151cf0866f2f0;p=jjobs-war.git Continued: - added local caching of all enqueued email addresses (this can become big) - updated jar(s) --- diff --git a/lib/juser-core.jar b/lib/juser-core.jar index 8488d71d..8ce84feb 100644 Binary files a/lib/juser-core.jar and b/lib/juser-core.jar differ diff --git a/lib/juser-lib.jar b/lib/juser-lib.jar index dd11c240..d70697aa 100644 Binary files a/lib/juser-lib.jar and b/lib/juser-lib.jar differ 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);