]> git.mxchange.org Git - addressbook-war.git/blobdiff - src/java/org/mxchange/addressbook/beans/email_address/EmailChangeWebSessionBean.java
fixed copyright and added stuff for localization support (unfinished)
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / email_address / EmailChangeWebSessionBean.java
index aadf4ba3af873e4eb02e8342426afbb1f59b5266..337199c8f3abf1377e2372774209aa1d210ad24a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 quix0r
+ * Copyright (C) 2016 Roland Haeder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,7 +17,6 @@
 package org.mxchange.addressbook.beans.email_address;
 
 import java.text.MessageFormat;
-import java.util.GregorianCalendar;
 import java.util.List;
 import java.util.Objects;
 import javax.enterprise.context.SessionScoped;
@@ -123,14 +122,20 @@ public class EmailChangeWebSessionBean implements EmailChangeWebSessionControlle
                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
 
+               // Get dummy email address
+               String dummyEmail = this.getEmailAddress1();
+
+               // Unset all so the user is forced to re-enter it
+               this.clear();
+
                // Check if the email address is already enqueued
-               if (this.isEmailAddressQueued()) {
+               if (this.isEmailAddressQueued(dummyEmail)) {
                        // Yes, then abort here
                        return "login_email_already_added"; //NOI18N
                }
 
                // Create change object, to save EJB calls, the hash is not generated here
-               ChangeableEmailAddress emailAddress = new EmailAddressChange(user, this.getEmailAddress1(), new GregorianCalendar());
+               ChangeableEmailAddress emailAddress = new EmailAddressChange(user, dummyEmail);
 
                // Call EJB
                this.emailBean.enqueueEmailAddressForChange(emailAddress);
@@ -166,30 +171,41 @@ public class EmailChangeWebSessionBean implements EmailChangeWebSessionControlle
        }
 
        /**
-        * 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.
+        * Clears email address fields so the user has to re-enter them
+        */
+       private void clear () {
+               // Clear fields
+               this.setEmailAddress1(null);
+               this.setEmailAddress2(null);
+       }
+
+       /**
+        * Checks if given email address 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>
+        * @param emailAddress Email address to verify
         * <p>
         * @return Whether the email address in field emailAddress1 is already queued
         */
-       private boolean isEmailAddressQueued () {
+       private boolean isEmailAddressQueued (final String emailAddress) {
                // 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
+               assert (emailAddress != null) : "emailAddress should not be null"; //NOI18N
+               assert (!emailAddress.trim().isEmpty()) : "emailAddress should not be empty"; //NOI18N
 
                // Check list
-               if (this.emailAddresses.contains(this.getEmailAddress1())) {
+               if (this.emailAddresses.contains(emailAddress)) {
                        // Okay, found it
                        return true;
                }
 
                // Check EJB
-               boolean isQueued = this.emailBean.isEmailAddressEnqueued(this.getEmailAddress1());
+               boolean isQueued = this.emailBean.isEmailAddressEnqueued(emailAddress);
 
                // Is it there?
                if (isQueued) {
                        // Add to list
-                       this.emailAddresses.add(this.getEmailAddress1());
+                       this.emailAddresses.add(emailAddress);
                }
 
                // Return status