From 83bf59a1845de76547173b6191a6f35bf86c5aa6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 17 May 2016 17:37:29 +0200 Subject: [PATCH] Continued with rewrites, fixes: - used BaseDatabaseBean 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 BaseDatabaseBean does it - resendConfirmationLink() almost finished: changing confirmation key + merging database is unfinished MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../resendlink/JobsResendLinkSessionBean.java | 99 ++++---------- .../JobsEmailChangeSessionBean.java | 125 +----------------- .../JobsUserRegistrationSessionBean.java | 2 + 3 files changed, 32 insertions(+), 194 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkSessionBean.java b/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkSessionBean.java index cd10a18..290362c 100644 --- a/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkSessionBean.java @@ -16,22 +16,13 @@ */ package org.mxchange.jjobs.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.jjobs.database.BaseJobsDatabaseBean; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.status.UserAccountStatus; @@ -49,70 +40,10 @@ public class JobsResendLinkSessionBean extends BaseJobsDatabaseBean implements R */ 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 +66,25 @@ public class JobsResendLinkSessionBean extends BaseJobsDatabaseBean implements R 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 } diff --git a/src/java/org/mxchange/jusercore/model/email_address/JobsEmailChangeSessionBean.java b/src/java/org/mxchange/jusercore/model/email_address/JobsEmailChangeSessionBean.java index de9c2ca..d2451b0 100644 --- a/src/java/org/mxchange/jusercore/model/email_address/JobsEmailChangeSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/email_address/JobsEmailChangeSessionBean.java @@ -19,31 +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.jjobs.database.BaseJobsDatabaseBean; -import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper; -import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; import org.mxchange.jusercore.model.user.UserSessionBeanRemote; import org.mxchange.jusercore.model.user.UserUtils; @@ -52,7 +36,7 @@ import org.mxchange.jusercore.model.user.UserUtils; *

* @author Roland Haeder */ -@Stateless (name = "email-change", description = "A bean handling email changes") +@Stateless (name = "emailchange", description = "A bean handling email changes") public class JobsEmailChangeSessionBean extends BaseJobsDatabaseBean implements EmailChangeSessionBeanRemote { /** @@ -60,31 +44,6 @@ public class JobsEmailChangeSessionBean extends BaseJobsDatabaseBean implements */ 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 */ @@ -152,78 +111,24 @@ public class JobsEmailChangeSessionBean extends BaseJobsDatabaseBean implements // 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 @@ -337,22 +242,4 @@ public class JobsEmailChangeSessionBean extends BaseJobsDatabaseBean implements emailAddress.setEmailChangeHash(hash); } - /** - * Sends given message to configured queue - *

- * @param message Message to send - *

- * @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); - } - } diff --git a/src/java/org/mxchange/jusercore/model/register/JobsUserRegistrationSessionBean.java b/src/java/org/mxchange/jusercore/model/register/JobsUserRegistrationSessionBean.java index 935d351..b2014e8 100644 --- a/src/java/org/mxchange/jusercore/model/register/JobsUserRegistrationSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/register/JobsUserRegistrationSessionBean.java @@ -154,6 +154,8 @@ public class JobsUserRegistrationSessionBean extends BaseJobsDatabaseBean implem // 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 -- 2.39.5