]> git.mxchange.org Git - addressbook-ejb.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Wed, 18 May 2016 12:44:19 +0000 (14:44 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 21 May 2016 11:56:00 +0000 (13:56 +0200)
- EJBs cannot have access to faces context, better handle it over from the WAR project
- renamed method as "AsList" is superflous

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkSessionBean.java
src/java/org/mxchange/jusercore/model/email_address/AddressbookEmailChangeSessionBean.java
src/java/org/mxchange/jusercore/model/register/AddressbookUserRegistrationSessionBean.java

index 63790338c27370b057bcbd412e17b121701f565d..8b2f384935a606fe9813d51503dfa552ca320083 100644 (file)
  */
 package org.mxchange.addressbook.beans.resendlink;
 
-import java.io.Serializable;
 import java.text.MessageFormat;
+import java.util.Locale;
+import javax.ejb.EJBException;
 import javax.ejb.Stateless;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.ObjectMessage;
+import javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
-import org.mxchange.addressbook.mailer.model.delivery.AddressbookMailer;
-import org.mxchange.addressbook.mailer.model.delivery.DeliverableAddressbookEmail;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 
 /**
  * A session-based EJB for resending confirmation links
@@ -37,54 +38,56 @@ public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBea
        /**
         * Serial number
         */
-       private static final long serialVersionUID = 75_638_176_619_024L;
-
-       /**
-        * Mailer instance
-        */
-       private final DeliverableAddressbookEmail mailer;
-
-       /**
-        * Default constructor
-        */
-       public AddressbookResendLinkSessionBean () {
-               // Init mailer instance
-               this.mailer = new AddressbookMailer();
-       }
+       private static final long serialVersionUID = 71_546_726_857_195_360L;
 
        @Override
-       public void onMessage (final Message message) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N
-               // The parameter should be valid
-               if (null == message) {
+       public String resendConfirmationLink (final User user, final Locale locale, final String baseUrl) {
+               // Log trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0},locale={1},baseUrl={2} - CALLED!", user, locale, baseUrl)); //NOI18N
+
+               // The user instance should be valid
+               if (null == user) {
                        // Throw NPE
-                       throw new NullPointerException("message is null"); //NOI18N
-               } else if (!(message instanceof ObjectMessage)) {
-                       // Not implementing right interface
-                       throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+               } else if (user.getUserConfirmKey() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.userConfirmKey is null"); //NOI18N
+               } else if (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED) {
+                       // User account status is not UNCONFIRMED
+                       throw new IllegalStateException(MessageFormat.format("Account status from user.userId={0} is not UNCONFIRMED:{1}", user.getUserId(), user.getUserAccountStatus())); //NOI18N
+               } else if (null == locale) {
+                       // Locale should be set
+                       throw new NullPointerException("locale is null"); //NOI18N
                }
 
-               // Securely cast it
-               ObjectMessage objectMessage = (ObjectMessage) message;
+               // @TODO Unfinished: Change key + merge database
 
                // Init variable
-               Serializable serializable;
+               Address emailAddress;
 
                try {
-                       // Get object from message
-                       serializable = objectMessage.getObject();
-               } catch (final JMSException ex) {
-                       // Log it and don't continue any further
-                       this.getLoggerBeanLocal().logException(ex);
-                       return;
+                       // Create email address and set
+                       emailAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
+               } catch (final AddressException ex) {
+                       // Throw again
+                       throw new EJBException(ex);
                }
 
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N
+               // Send email
+               // TODO: Internationlize the subject line somehow
+               this.sendEmail("Resend confirmation link", "resend_confirmation_link", emailAddress, user, baseUrl); //NOI18N
+
+               // Log trace message
+               this.getLoggerBeanLocal().logTrace("resendConfirmationLink: CALLED!"); //NOI18N
 
-               // Trace message
-               this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N
+               // All fine
+               return "resend_done"; //NOI18N
        }
 
 }
index a77a00bc9f1db7e29803c56d7dcd515f24114709..65e2801539c33349fbcb9ac65170c35dafb234a4 100644 (file)
@@ -58,7 +58,7 @@ public class AddressbookEmailChangeSessionBean extends BaseAddressbookDatabaseBe
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<String> allQueuedAddressesAsList () {
+       public List<String> allQueuedAddresses () {
                // Trace message
                this.getLoggerBeanLocal().logTrace("allQueuedAddressesAsList: CALLED!"); //NOI18N
 
@@ -76,9 +76,9 @@ public class AddressbookEmailChangeSessionBean extends BaseAddressbookDatabaseBe
        }
 
        @Override
-       public void enqueueEmailAddressForChange (final ChangeableEmailAddress emailChange) {
+       public void enqueueEmailAddressForChange (final ChangeableEmailAddress emailChange, final String baseUrl) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("enqueueEmailAddressForChange: emailChange={0} - CALLED!", emailChange)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("enqueueEmailAddressForChange: emailChange={0},baseUrl={1} - CALLED!", emailChange, baseUrl)); //NOI18N
 
                // Email address change should be valid
                if (null == emailChange) {
@@ -123,7 +123,7 @@ public class AddressbookEmailChangeSessionBean extends BaseAddressbookDatabaseBe
                }
 
                // Send email
-               this.sendEmail("Email change", "email_change", emailAddress, emailChange.getEmailChangeUser()); //NOI18N
+               this.sendEmail("Email change", "email_change", emailAddress, emailChange.getEmailChangeUser(), baseUrl); //NOI18N
 
                // Trace message
                this.getLoggerBeanLocal().logTrace("enqueueEmailAddressForChange - EXIT!"); //NOI18N
index 54b0b09d99f1fbd615ee049029d07f886e6c6737..69a1c037093c63deaffe608dd639b68ad1197bd4 100644 (file)
@@ -136,9 +136,9 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
        }
 
        @Override
-       public User registerUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
+       public User registerUser (final User user, final String baseUrl) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: user={0} - CALLED!", user)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: user={0},baseUrl={1} - CALLED!", user, baseUrl)); //NOI18N
 
                // user should not be null
                if (null == user) {
@@ -180,7 +180,7 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
 
                // Send email
                // TODO: Internationlize the subject line somehow
-               this.sendEmail("Registration", "registration", emailAddress, addedUser); //NOI18N
+               this.sendEmail("Registration", "registration", emailAddress, addedUser, baseUrl); //NOI18N
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: addedUser={0},addedUser.userId={1} - EXIT!", addedUser, addedUser.getUserId())); //NOI18N