From: Roland Häder Date: Tue, 17 May 2016 15:37:29 +0000 (+0200) Subject: Continued with rewrites, fixes: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;ds=sidebyside;h=ee9faa283aa4f3127e424866bcf91972e1a1b2c1;p=pizzaservice-ejb.git 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 Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jusercore/model/email_address/PizzaEmailChangeSessionBean.java b/src/java/org/mxchange/jusercore/model/email_address/PizzaEmailChangeSessionBean.java index 60d472d..35667b0 100644 --- a/src/java/org/mxchange/jusercore/model/email_address/PizzaEmailChangeSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/email_address/PizzaEmailChangeSessionBean.java @@ -19,33 +19,17 @@ 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.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; +import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; /** * A session bean for changing email addresses @@ -53,38 +37,13 @@ import org.mxchange.jusercore.model.user.UserUtils; * @author Roland Haeder */ @Stateless (name = "emailchange", description = "A bean handling email changes") -public class PizzaEmailChangeSessionBean extends BaseDatabaseBean implements EmailChangeSessionBeanRemote { +public class PizzaEmailChangeSessionBean extends BasePizzaDatabaseBean 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 */ @@ -152,78 +111,24 @@ public class PizzaEmailChangeSessionBean extends BaseDatabaseBean implements Ema // 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 PizzaEmailChangeSessionBean extends BaseDatabaseBean implements Ema 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/PizzaUserRegistrationSessionBean.java b/src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java index 60adced..26e63c3 100644 --- a/src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java @@ -154,6 +154,8 @@ public class PizzaUserRegistrationSessionBean extends BasePizzaDatabaseBean impl // 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 diff --git a/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkSessionBean.java index 643877c..d1fbc0c 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkSessionBean.java @@ -19,19 +19,11 @@ package org.mxchange.pizzaapplication.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.jusercore.model.user.User; import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; @@ -49,70 +41,10 @@ public class PizzaResendLinkSessionBean extends BasePizzaDatabaseBean implements */ 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 PizzaResendLinkSessionBean extends BasePizzaDatabaseBean implements 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 }