]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Wed, 18 May 2016 09:01:48 +0000 (11:01 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 21 May 2016 11:54:42 +0000 (13:54 +0200)
- renamed to have project name in it
- sending out mails over a message-driven bean is an asynchronous approach and will keep the other EJBs running fast
- use class, not interface everywhere

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

index 036e5d0ef6791a0e336f5a77eeb82974726e64d6..63790338c27370b057bcbd412e17b121701f565d 100644 (file)
  */
 package org.mxchange.addressbook.beans.resendlink;
 
-import de.chotime.landingpage.beans.resendlink.ResendLinkSessionBeanRemote;
+import java.io.Serializable;
 import java.text.MessageFormat;
-import java.util.Locale;
-import javax.ejb.EJBException;
 import javax.ejb.Stateless;
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.addressbook.mailer.model.delivery.AddressbookMailer;
+import org.mxchange.addressbook.mailer.model.delivery.DeliverableAddressbookEmail;
 
 /**
  * A session-based EJB for resending confirmation links
@@ -39,56 +37,54 @@ public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBea
        /**
         * Serial number
         */
-       private static final long serialVersionUID = 71_546_726_857_195_360L;
+       private static final long serialVersionUID = 75_638_176_619_024L;
 
-       @Override
-       public String resendConfirmationLink (final User user, final Locale locale) {
-               // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0},locale={1} - CALLED!", user, locale)); //NOI18N
+       /**
+        * Mailer instance
+        */
+       private final DeliverableAddressbookEmail mailer;
 
-               // The user instance should be valid
-               if (null == user) {
+       /**
+        * Default constructor
+        */
+       public AddressbookResendLinkSessionBean () {
+               // Init mailer instance
+               this.mailer = new AddressbookMailer();
+       }
+
+       @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) {
                        // Throw NPE
-                       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
+                       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
                }
 
-               // @TODO Unfinished: Change key + merge database
+               // Securely cast it
+               ObjectMessage objectMessage = (ObjectMessage) message;
 
                // Init variable
-               Address emailAddress;
+               Serializable serializable;
 
                try {
-                       // Create email address and set
-                       emailAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
-               } catch (final AddressException ex) {
-                       // Throw again
-                       throw new EJBException(ex);
+                       // Get object from message
+                       serializable = objectMessage.getObject();
+               } catch (final JMSException ex) {
+                       // Log it and don't continue any further
+                       this.getLoggerBeanLocal().logException(ex);
+                       return;
                }
 
-               // Send email
-               // TODO: Internationlize the subject line somehow
-               this.sendEmail("Resend confirmation link", "resend_confirmation_link", emailAddress, user); //NOI18N
-
-               // Log trace message
-               this.getLoggerBeanLocal().logTrace("resendConfirmationLink: CALLED!"); //NOI18N
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N
 
-               // All fine
-               return "resend_done"; //NOI18N
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N
        }
 
 }
index 4ca1d6e0342ff6303c2975aa97249c7f1c226a60..91c0156267aad6d0f752514a18e70306005dc863 100644 (file)
@@ -183,7 +183,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                }
 
                // Try to locate it
-               Query query = this.getEntityManager().createNamedQuery("SearchUserByName", User.class); //NOI18N
+               Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
 
                // Set parameter
                query.setParameter("param", user.getUserName()); //NOI18N
@@ -225,7 +225,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                }
 
                // Create query instance
-               Query query = this.getEntityManager().createNamedQuery("SearchUserById", User.class); //NOI18N
+               Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
 
                // Set user id
                query.setParameter("id", userId); //NOI18N
@@ -308,7 +308,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                }
 
                // Generate query
-               Query query = this.getEntityManager().createNamedQuery("SearchUserById", User.class); //NOI18N
+               Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
 
                // Set parameter
                query.setParameter("id", user.getUserId()); //NOI18N
@@ -355,7 +355,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                }
 
                // Generate query
-               Query query = this.getEntityManager().createNamedQuery("SearchUserById", User.class); //NOI18N
+               Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
 
                // Set parameter
                query.setParameter("id", userId); //NOI18N
@@ -402,7 +402,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                }
 
                // Generate query
-               Query query = this.getEntityManager().createNamedQuery("SearchUserByName", User.class); //NOI18N
+               Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
 
                // Set parameter
                query.setParameter("param", userName); //NOI18N
@@ -440,7 +440,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                }
 
                // Generate query
-               Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", User.class); //NOI18N
+               Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", LoginUser.class); //NOI18N
 
                // Set parameter
                query.setParameter("param", user.getUserContact().getContactEmailAddress()); //NOI18N
@@ -481,7 +481,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl
                }
 
                // Generate query
-               Query query = this.getEntityManager().createNamedQuery("SearchUserByName", User.class); //NOI18N
+               Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
 
                // Set parameter
                query.setParameter("param", user.getUserName()); //NOI18N