import java.text.MessageFormat;
import java.util.GregorianCalendar;
+import java.util.Locale;
import java.util.Objects;
+import java.util.Properties;
+import javax.ejb.EJBException;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.mail.Address;
import org.mxchange.jcontacts.contact.Contact;
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.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.utils.PhoneUtils;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserUtils;
/**
* A helper class for beans that access the database.
this.getLoggerBeanLocal().logTrace("mergeContactsCellphoneLandLineFaxNumbers: EXIT!"); //NOI18N
}
+ /**
+ * Sends an email with given subject line, template name to given recipient
+ * and user data
+ * <p>
+ * @param subjectLine Subject line
+ * @param templateName Template name
+ * @param emailAddress Recipient's email address
+ * @param user User instance
+ * @param session JMS Session
+ * @param messageProducer Message producer
+ */
+ protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final Session session, final MessageProducer messageProducer) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={3},user={4},session={5},messageProducer={6} - CALLED!", subjectLine, templateName, emailAddress, user, session, messageProducer));
+
+ // All should be set
+ if (null == subjectLine) {
+ // Throw NPE
+ throw new NullPointerException("subjectLine is null");
+ } else if (subjectLine.isEmpty()) {
+ // No subject line
+ throw new IllegalArgumentException("subjectLine is empty");
+ } else if (null == templateName) {
+ // Throw NPE
+ throw new NullPointerException("templateName is null");
+ } else if (templateName.isEmpty()) {
+ // No template name
+ throw new IllegalArgumentException("templateName is empty");
+ } else if (null == emailAddress) {
+ // Throw NPE
+ throw new NullPointerException("emailAddress is null");
+ }
+
+ // Prepare mail wrapper
+ WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
+
+ // Set all values
+ Properties variables = UserUtils.getAllUserFields(user);
+
+ // Set all
+ // @TODO Get locale from user + language from message bundle
+ emailWrapper.setRecipient(emailAddress);
+ emailWrapper.setLocale(Locale.GERMAN);
+ emailWrapper.setSubjectLine(subjectLine);
+ emailWrapper.setTemplateName(templateName); //NOI18N
+ emailWrapper.setTemplateVariables(variables);
+
+ try {
+ // Send out email change
+ ObjectMessage message = session.createObjectMessage();
+ message.setObject(emailWrapper);
+
+ // Send message
+ this.sendMessage(message, messageProducer);
+ } catch (final JMSException ex) {
+ // Throw again
+ throw new EJBException(ex);
+ }
+ }
+
/**
* Updates all contact's phone instances from other contact, both contacts
* should be the same.