]> git.mxchange.org Git - jjobs-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Sat, 12 Mar 2016 17:10:31 +0000 (18:10 +0100)
committerRoland Haeder <roland@mxchange.org>
Sat, 12 Mar 2016 17:10:31 +0000 (18:10 +0100)
- added local caching of all enqueued email addresses (this can become big)
- updated jar(s)

lib/juser-core.jar
lib/juser-lib.jar
src/java/org/mxchange/jjobs/beans/email_address/EmailChangeWebSessionBean.java
src/java/org/mxchange/jjobs/validators/password/UserPasswordValidator.java

index 8488d71d29bac0c83be02e3c7e5e3129e0b51f47..8ce84feb27b6c1ae7308aae243d964e112f069d6 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 4e01c8c85dc9d2bddf57017d4915c44c1650f4d2..5debda8a4bd004ec59c0e11175ca7f206698c5b7 100644 (file)
@@ -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<String> 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.
+        * <p>
+        * @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;
+       }
+
 }
index 3673c7cf5a7c3c810374103efcd53ea545f3b50b..d1a90c05d1c418d949e6db84a7b96f2695381617 100644 (file)
@@ -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);