]> git.mxchange.org Git - addressbook-ejb.git/commitdiff
Continued with rewrites, fixes:
authorRoland Häder <roland@mxchange.org>
Tue, 17 May 2016 15:37:29 +0000 (17:37 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 21 May 2016 11:50:33 +0000 (13:50 +0200)
- used Base<Project-Name>DatabaseBean where possible
- use new sendEmail() which prepares the wrapper instance and then sending it
- the message object is now no longer created here as the Base<Project>DatabaseBean does it
- resendConfirmationLink() almost finished: changing confirmation key + merging database is unfinished

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 feb4cdef9cae32013c208b35288cff84d82af8bb..825f4efde2962f3ef79b8df29523a8bbb0cd52b8 100644 (file)
@@ -19,19 +19,11 @@ 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.EJBException;
 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 javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
@@ -49,70 +41,10 @@ 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
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0},locale={1} - CALLED!", user, locale)); //NOI18N
 
                // The user instance should be valid
                if (null == user) {
@@ -135,7 +67,25 @@ public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBea
                        throw new NullPointerException("locale is null"); //NOI18N
                }
 
-               // @TODO Unfinished!
+               // @TODO Unfinished: Change key + merge database
+
+               // Init variable
+               Address emailAddress;
+
+               try {
+                       // Create email address and set
+                       emailAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
+               } catch (final AddressException ex) {
+                       // Throw again
+                       throw new EJBException(ex);
+               }
+
+               // Send email
+               this.sendEmail("Resend confirmation link", "resend_confirmation_link", emailAddress, user); //NOI18N
+
+               // Log trace message
+               this.getLoggerBeanLocal().logTrace("resendConfirmationLink: CALLED!"); //NOI18N
+
                // All fine
                return "resend_done"; //NOI18N
        }
index f65a2ee4fdc40ae158860a87905d446fa363fbac..a77a00bc9f1db7e29803c56d7dcd515f24114709 100644 (file)
@@ -19,29 +19,15 @@ package org.mxchange.jusercore.model.email_address;
 import java.text.MessageFormat;
 import java.util.GregorianCalendar;
 import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-import javax.annotation.PostConstruct;
 import javax.ejb.EJB;
 import javax.ejb.EJBException;
 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.mail.Address;
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.jusercore.model.user.UserUtils;
 
@@ -51,38 +37,13 @@ import org.mxchange.jusercore.model.user.UserUtils;
  * @author Roland Haeder<roland@mxchange.org>
  */
 @Stateless (name = "emailchange", description = "A bean handling email changes")
-public class AddressbookEmailChangeSessionBean extends BaseDatabaseBean implements EmailChangeSessionBeanRemote {
+public class AddressbookEmailChangeSessionBean extends BaseAddressbookDatabaseBean implements EmailChangeSessionBeanRemote {
 
        /**
         * Serial number
         */
        private static final long serialVersionUID = 182_698_165_971_548L;
 
-       /**
-        * 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;
-
        /**
         * User bean
         */
@@ -150,78 +111,24 @@ public class AddressbookEmailChangeSessionBean extends BaseDatabaseBean implemen
                // Persist it
                //this.getEntityManager().persist(emailChange);
 
-               // Prepare mail wrapper
-               WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
+               // Init variable
+               Address emailAddress;
 
                try {
                        // Create email address and set
-                       Address emailAddress = new InternetAddress(emailChange.getEmailAddress());
-                       emailWrapper.setRecipient(emailAddress);
+                       emailAddress = new InternetAddress(emailChange.getEmailAddress());
                } catch (final AddressException ex) {
                        // Throw again
                        throw new EJBException(ex);
                }
 
-               // Set all values
-               Properties variables = UserUtils.getAllUserFields(emailChange.getEmailChangeUser());
-
-               // Set all
-               // @TODO Get locale from user + language from message bundle
-               emailWrapper.setLocale(Locale.GERMAN);
-               emailWrapper.setSubjectLine("Email change");
-               emailWrapper.setTemplateName("email_change"); //NOI18N
-               emailWrapper.setTemplateVariables(variables);
-
-               try {
-                       // Send out email change
-                       this.message.setObject(emailWrapper);
-
-                       // Send message
-                       this.sendMessage(this.message);
-               } catch (final JMSException ex) {
-                       // Throw again
-                       throw new EJBException(ex);
-               }
+               // Send email
+               this.sendEmail("Email change", "email_change", emailAddress, emailChange.getEmailChangeUser()); //NOI18N
 
                // Trace message
                this.getLoggerBeanLocal().logTrace("enqueueEmailAddressForChange - EXIT!"); //NOI18N
        }
 
-       /**
-        * 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 boolean isEmailAddressEnqueued (final String emailAddress) {
                // Trace message
@@ -335,22 +242,4 @@ public class AddressbookEmailChangeSessionBean extends BaseDatabaseBean implemen
                emailAddress.setEmailChangeHash(hash);
        }
 
-       /**
-        * Sends given message to configured queue
-        * <p>
-        * @param message Message to send
-        * <p>
-        * @throws JMSException if something went wrong
-        */
-       private void sendMessage (final ObjectMessage message) throws JMSException {
-               // The parameter should be valid
-               if (null == message) {
-                       // Throw NPE
-                       throw new NullPointerException("message is null"); //NOI18N
-               }
-
-               // Send it
-               this.messageProducer.send(message);
-       }
-
 }
index 1427119289b7a20df0025dff728642ebb576cd28..c5296216342f840bca228c65369faec078e5f0a6 100644 (file)
@@ -154,6 +154,8 @@ public class AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
                // Call other EJB
                User addedUser = this.userBean.addUser(user);
 
+               // Create email
+
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: addedUser={0},addedUser.userIdd={1} - EXIT!", addedUser, addedUser.getUserId())); //NOI18N