]> git.mxchange.org Git - addressbook-mailer-ejb.git/blobdiff - src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkSessionBean.java
Continued:
[addressbook-mailer-ejb.git] / src / java / org / mxchange / addressbook / beans / resendlink / AddressbookResendLinkSessionBean.java
index 145100231d2fe230f897f65be8839d198ca59024..feb4cdef9cae32013c208b35288cff84d82af8bb 100644 (file)
  */
 package org.mxchange.addressbook.beans.resendlink;
 
+import de.chotime.landingpage.beans.resendlink.ResendLinkSessionBeanRemote;
+import java.text.MessageFormat;
+import java.util.Locale;
+import javax.annotation.PostConstruct;
 import javax.ejb.Stateless;
+import javax.faces.FacesException;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 
 /**
  * A session-based EJB for resending confirmation links
@@ -32,4 +49,95 @@ public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBea
         */
        private static final long serialVersionUID = 71_546_726_857_195_360L;
 
+       /**
+        * Connection
+        */
+       private Connection connection;
+
+       /**
+        * Object message
+        */
+       private ObjectMessage message;
+
+       /**
+        * Message producer
+        */
+       private MessageProducer messageProducer;
+
+       /**
+        * Mailer message queue
+        */
+       private Queue queue;
+
+       /**
+        * Session instance
+        */
+       private Session session;
+
+       /**
+        * Initialization of this bean
+        */
+       @PostConstruct
+       public void init () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
+
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Get factory from JMS resource
+                       QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
+
+                       // Lookup queue
+                       this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
+
+                       // Create connection
+                       this.connection = connectionFactory.createConnection();
+
+                       // Init session instance
+                       this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+                       // And message producer
+                       this.messageProducer = this.session.createProducer(this.queue);
+
+                       // Finally the message instance itself
+                       this.message = this.session.createObjectMessage();
+               } catch (final NamingException | JMSException e) {
+                       // Continued to throw
+                       throw new FacesException(e);
+               }
+       }
+
+       @Override
+       public String resendConfirmationLink (final User user, final Locale locale) {
+               // Log trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0} - CALLED!", user)); //NOI18N
+
+               // The user instance should be valid
+               if (null == user) {
+                       // 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
+               }
+
+               // @TODO Unfinished!
+               // All fine
+               return "resend_done"; //NOI18N
+       }
+
 }