]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 7 Jul 2017 22:27:02 +0000 (00:27 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 7 Jul 2017 22:34:50 +0000 (00:34 +0200)
- rewrote email delivery as EmailDeliveryWrapper() has now a constructor with all required fields
- also saved one parameter (one lesser = easier code)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jmailee/model/delivery/PizzaEmailDeliveryMessageBean.java
src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java
src/java/org/mxchange/jusercore/model/user/register/PizzaUserRegistrationSessionBean.java
src/java/org/mxchange/jusercore/model/user/resendlink/PizzaResendLinkSessionBean.java
src/java/org/mxchange/pizzaaplication/database/BasePizzaDatabaseBean.java

index a1353c10eed0c37384f10aaed32e9e60b5db5ae9..6a56ec51fc0c5d3330cde90471d468d945ece2cd 100644 (file)
@@ -28,6 +28,7 @@ import javax.jms.Message;
 import javax.jms.MessageListener;
 import javax.jms.ObjectMessage;
 import javax.mail.MessagingException;
+import javax.naming.NamingException;
 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
 import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
 import org.mxchange.pizzaapplication.mailer.model.delivery.DeliverablePizzaEmail;
@@ -65,8 +66,10 @@ public class PizzaEmailDeliveryMessageBean extends BasePizzaDatabaseBean impleme
 
        /**
         * Default constructor
+        * <p>
+        * @throws javax.naming.NamingException If a JNDI name could not be found
         */
-       public PizzaEmailDeliveryMessageBean () {
+       public PizzaEmailDeliveryMessageBean () throws NamingException {
                // Call super constructor
                super();
 
@@ -164,9 +167,9 @@ public class PizzaEmailDeliveryMessageBean extends BasePizzaDatabaseBean impleme
                if (wrapper.getLocale() == null) {
                        // Throw NPE
                        throw new NullPointerException("wrapper.locale is null"); //NOI18N
-               } else if (wrapper.getRecipient() == null) {
+               } else if (wrapper.getRecipientAddress()== null) {
                        // Throw again ...
-                       throw new NullPointerException("wrapper.recipient is null"); //NOI18N
+                       throw new NullPointerException("wrapper.recipientAddress is null"); //NOI18N
                } else if (wrapper.getSubjectLine() == null) {
                        // ... and again
                        throw new NullPointerException("wrapper.subjectLine is null"); //NOI18N
index 34bc29bbac01a3d35eb06461df5e48f42025b885..8747f100637aa412ce37d665a48776af6c4ca4dc 100644 (file)
@@ -19,11 +19,7 @@ package org.mxchange.jusercore.model.user;
 import java.text.MessageFormat;
 import java.util.GregorianCalendar;
 import javax.ejb.EJB;
-import javax.ejb.EJBException;
 import javax.ejb.Stateless;
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
@@ -265,20 +261,11 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
                // Update user
                User updatedUser = this.userBean.updateUserData(user);
 
-               // Init variable
-               Address emailAddress;
-
-               try {
-                       // Create email address and set
-                       emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
-               } catch (final AddressException ex) {
-                       // Throw again
-                       throw new EJBException(ex);
-               }
+               // @TODO Create user lock history entry
 
                // Send out email
                // @TODO externalize subject line
-               this.sendEmail("User account locked", "user_account_locked", emailAddress, updatedUser, baseUrl, null); //NOI18N
+               this.sendEmail("User account locked", "user_account_locked", updatedUser, baseUrl, null); //NOI18N
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
@@ -334,20 +321,11 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements
                // Update user
                User updatedUser = this.userBean.updateUserData(user);
 
-               // Init variable
-               Address emailAddress;
-
-               try {
-                       // Create email address and set
-                       emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
-               } catch (final AddressException ex) {
-                       // Throw again
-                       throw new EJBException(ex);
-               }
+               // @TODO Create user lock history entry
 
                // Send out email
                // @TODO externalize subject line
-               this.sendEmail("User Account unlocked", "user_account_unlocked", emailAddress, updatedUser, baseUrl, null); //NOI18N
+               this.sendEmail("User account unlocked", "user_account_unlocked", updatedUser, baseUrl, null); //NOI18N
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
index 056491e073e23b85d84b3863da61b5a9ead6ef0b..4049040b1f5ae8afcfb82a0a8dea7c4491ae6570 100644 (file)
@@ -22,9 +22,6 @@ import java.util.List;
 import javax.ejb.EJB;
 import javax.ejb.EJBException;
 import javax.ejb.Stateless;
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
 import javax.persistence.NoResultException;
 import javax.persistence.PersistenceException;
 import javax.persistence.Query;
@@ -180,19 +177,8 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS
                // Update user account
                User updatedUser = this.updateUserData(user);
 
-               // Init variable
-               Address emailAddress;
-
-               try {
-                       // Create email address and set
-                       emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
-               } catch (final AddressException ex) {
-                       // Throw again
-                       throw new EJBException(ex);
-               }
-
                // Send out email
-               this.sendEmail("User account confirmed", "user_account_confirmed", emailAddress, updatedUser, baseUrl, null); //NOI18N
+               this.sendEmail("User account confirmed", "user_account_confirmed", updatedUser, baseUrl, null); //NOI18N
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
@@ -666,19 +652,8 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS
                // Flush it to get id number back
                this.getEntityManager().flush();
 
-               // Init variable
-               Address emailAddress;
-
-               try {
-                       // Create email address and set
-                       emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
-               } catch (final AddressException ex) {
-                       // Throw again
-                       throw new EJBException(ex);
-               }
-
                // Send email to user
-               this.sendEmail("User password change", "user_password_change", emailAddress, updatedUser, baseUrl, null); //NOI18N
+               this.sendEmail("User password change", "user_password_change", updatedUser, baseUrl, null); //NOI18N
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N
index 2e1a706a3cb3dc7dd529b615f1cc7ba680295ce8..97209b4a011dd871befbd885f83cfc721dc2a5ac 100644 (file)
@@ -22,9 +22,6 @@ import java.util.List;
 import javax.ejb.EJB;
 import javax.ejb.EJBException;
 import javax.ejb.Stateless;
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
 import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
@@ -117,19 +114,9 @@ public class PizzaUserEmailChangeSessionBean extends BasePizzaDatabaseBean imple
 
                // Persist it
                //@TODO Fix email delivery then allow this: this.getEntityManager().persist(emailChange);
-               // Init variable
-               Address emailAddress;
-
-               try {
-                       // Create email address and set
-                       emailAddress = new InternetAddress(emailChange.getEmailAddress());
-               } catch (final AddressException ex) {
-                       // Throw again
-                       throw new EJBException(ex);
-               }
 
                // Send email
-               this.sendEmail("User email change", "user_email_change", emailAddress, emailChange.getEmailChangeUser(), baseUrl, null); //NOI18N
+               this.sendEmail("User email change", "user_email_change", emailChange.getEmailChangeUser(), baseUrl, null); //NOI18N
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.enqueueEmailAddressForChange - EXIT!", this.getClass().getSimpleName())); //NOI18N
index aeda1c0b8627d0358383f01c0a62b8b57c0c2950..863d1c6562c26fb296b68fbb61aaf00fddba930b 100644 (file)
@@ -19,11 +19,7 @@ package org.mxchange.jusercore.model.user.register;
 import java.text.MessageFormat;
 import java.util.Objects;
 import javax.ejb.EJB;
-import javax.ejb.EJBException;
 import javax.ejb.Stateless;
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
 import org.mxchange.jcontacts.contact.Contact;
@@ -183,20 +179,18 @@ public class PizzaUserRegistrationSessionBean extends BasePizzaDatabaseBean impl
                // Call other EJB
                User addedUser = this.adminUserBean.addUser(user);
 
-               // Init variable
-               Address emailAddress;
+               // Default template is with no random password
+               String templateName = "user_registration"; //NOI18N
 
-               try {
-                       // Create email address and set
-                       emailAddress = new InternetAddress(addedUser.getUserContact().getContactEmailAddress());
-               } catch (final AddressException ex) {
-                       // Throw again
-                       throw new EJBException(ex);
+               // Is password set?
+               if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
+                       // Switch to other template
+                       templateName = "user_registration_random"; //NOI18N
                }
 
                // Send email
                // @TODO: Internationlize the subject line somehow
-               this.sendEmail("User registration", "user_registration", emailAddress, addedUser, baseUrl, randomPassword); //NOI18N
+               this.sendEmail("User registration", templateName, addedUser, baseUrl, randomPassword); //NOI18N
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: addedUser={1},addedUser.userId={2} - EXIT!", this.getClass().getSimpleName(), addedUser, addedUser.getUserId())); //NOI18N
index f8198f74b378ba21bf32185e99f770fe1778556b..82c21a6bbd652755ea055fe511c6edc0f60c73b1 100644 (file)
@@ -19,11 +19,7 @@ package org.mxchange.jusercore.model.user.resendlink;
 import java.text.MessageFormat;
 import java.util.Locale;
 import javax.ejb.EJB;
-import javax.ejb.EJBException;
 import javax.ejb.Stateless;
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
 import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
@@ -108,20 +104,9 @@ public class PizzaResendLinkSessionBean extends BasePizzaDatabaseBean implements
                // Set it in user
                managedUser.setUserConfirmKey(confirmationKey);
 
-               // Init variable
-               Address emailAddress;
-
-               try {
-                       // Create email address and set
-                       emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress());
-               } catch (final AddressException ex) {
-                       // Throw again
-                       throw new EJBException(ex);
-               }
-
                // Send email
                // @TODO: Internationlize the subject line somehow
-               this.sendEmail("Resend user confirmation link", "user_resend_confirmation_link", emailAddress, user, baseUrl, null); //NOI18N
+               this.sendEmail("Resend user confirmation link", "user_resend_confirmation_link",  user, baseUrl, null); //NOI18N
 
                // Log trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: EXIT!", this.getClass().getSimpleName())); //NOI18N
index 3f140addba32488d16e0b7145a334ccb19d60dbd..2382192c2c65ccd5d8abd4559535ea0f0a162846 100644 (file)
@@ -24,6 +24,8 @@ import javax.ejb.EJBException;
 import javax.jms.JMSException;
 import javax.jms.ObjectMessage;
 import javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactUtils;
 import org.mxchange.jcoreee.database.BaseDatabaseBean;
@@ -470,15 +472,14 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
         * <p>
         * @param subjectLine    Subject line
         * @param templateName   Template name
-        * @param emailAddress   Recipient's email address
         * @param user           User instance
         * @param baseUrl        Base URL
         * @param randomPassword A randomly-generated password or NULL if user had
         *                       to enter it.
         */
-       protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl, final String randomPassword) {
+       protected void sendEmail (final String subjectLine, final String templateName, final User user, final String baseUrl, final String randomPassword) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},user={2},baseUrl={3} - CALLED!", subjectLine, templateName, user, baseUrl)); //NOI18N
 
                // All should be set
                if (null == subjectLine) {
@@ -493,9 +494,6 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                } else if (templateName.isEmpty()) {
                        // No template name
                        throw new IllegalArgumentException("templateName is empty"); //NOI18N
-               } else if (null == emailAddress) {
-                       // Throw NPE
-                       throw new NullPointerException("emailAddress is null"); //NOI18N
                } else if (null == user) {
                        // Throw NPE
                        throw new NullPointerException("user is null"); //NOI18N
@@ -534,9 +532,6 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                        throw new NullPointerException("this.session is not set. Have you forgotten to call super(String, String) and called only super() ?"); //NOI18N
                }
 
-               // Prepare mail wrapper
-               WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
-
                // Set all values
                Properties variables = UserUtils.getAllUserFields(user);
 
@@ -549,13 +544,20 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                        variables.put("randomPassword", randomPassword); //NOI18N
                }
 
-               // Set all
+               // Init addresss
+               Address recipientAddress;
+
+               try {
+                       // Create email address and set
+                       recipientAddress = new InternetAddress(user.getUserContact().getContactEmailAddress());
+               } catch (final AddressException ex) {
+                       // Throw again
+                       throw new EJBException(ex);
+               }
+
+               // Prepare mail wrapper
                // @TODO Language from message bundle
-               emailWrapper.setRecipient(emailAddress);
-               emailWrapper.setLocale(user.getUserLocale());
-               emailWrapper.setSubjectLine(subjectLine);
-               emailWrapper.setTemplateName(templateName);
-               emailWrapper.setTemplateVariables(variables);
+               WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper(recipientAddress, subjectLine, templateName, variables, user.getUserLocale());
 
                try {
                        // Send out email change