import java.text.MessageFormat;
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;
if (null == user) {
// Abort here
throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userContact is null"); //NOI18N
+ } else if (user.getUserContact().getContactEmailAddress() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userContact.contactEmailAddress is null"); //NOI18N
+ } else if (user.getUserContact().getContactEmailAddress().isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("user.userContact.contactEmailAddress is empty"); //NOI18N
}
// Check if user is registered
// Call other EJB
User addedUser = this.userBean.addUser(user);
- // Create email
+ // 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
+ // TODO: Internationlize the subject line somehow
+ this.sendEmail("Registration", "registration", emailAddress, user); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: addedUser={0},addedUser.userId={1} - EXIT!", addedUser, addedUser.getUserId())); //NOI18N