From: Roland Häder Date: Sat, 8 Jul 2017 18:12:23 +0000 (+0200) Subject: changed to jjobs X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=53ac14e9d3e6ed61c1f80ff5cf53680f12928196;p=jjobs-mailer-ejb.git changed to jjobs Signed-off-by: Roland Häder --- diff --git a/build.xml b/build.xml index 9ec25cf..bae9027 100644 --- a/build.xml +++ b/build.xml @@ -7,8 +7,8 @@ - - Builds, tests, and runs the project addressbook-mailer-ejb. + + Builds, tests, and runs the project jjobs-mailer-ejb. - + @@ -433,7 +433,7 @@ or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties f - + @@ -585,7 +585,7 @@ or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties f - + @@ -806,7 +806,7 @@ exists or setup the property manually. For example like this: COMPILATION SECTION --> - + @@ -814,7 +814,7 @@ exists or setup the property manually. For example like this: - + @@ -836,7 +836,7 @@ exists or setup the property manually. For example like this: - + @@ -844,7 +844,7 @@ exists or setup the property manually. For example like this: - + @@ -852,7 +852,7 @@ exists or setup the property manually. For example like this: - + @@ -861,7 +861,7 @@ exists or setup the property manually. For example like this: - + @@ -1246,7 +1246,7 @@ exists or setup the property manually. For example like this: CLEANUP SECTION --> - + diff --git a/nbproject/project.properties b/nbproject/project.properties index 7966925..2e22b0e 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -21,7 +21,7 @@ dist.jar=${dist.dir}/${jar.name} dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= -file.reference.addressbook-mailer.jar=lib/addressbook-mailer.jar +file.reference.jjobs-mailer.jar=lib/jjobs-mailer.jar file.reference.cdi-api.jar=lib/cdi-api.jar file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar file.reference.jcoreee.jar=lib/jcoreee.jar @@ -38,14 +38,14 @@ j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.ja j2ee.platform.wsit.classpath= j2ee.server.type=gfv3ee6 jar.compress=false -jar.name=addressbook-mailer-ejb.jar +jar.name=jjobs-mailer-ejb.jar jars.in.ejbjar=false javac.classpath=\ ${file.reference.jcoreee.jar}:\ ${file.reference.jcore-logger-lib.jar}:\ ${file.reference.jmailer-ee.jar}:\ ${file.reference.cdi-api.jar}:\ - ${reference.addressbook-mailer-lib.jar}:\ + ${reference.jjobs-mailer-lib.jar}:\ ${libs.velocity.classpath} javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.debug=true @@ -69,15 +69,15 @@ javadoc.private=true javadoc.splitindex=true javadoc.use=true javadoc.version=true -javadoc.windowtitle=addressbook EJBs +javadoc.windowtitle=jjobs EJBs meta.inf=${source.root}/conf meta.inf.excludes=sun-cmp-mappings.xml platform.active=default_platform -project.addressbook-mailer-lib=../addressbook-mailer-lib +project.jjobs-mailer-lib=../jjobs-mailer-lib project.juser-core=../juser-core project.license=agpl30 project.serviceLocator.class=de.chotime.landingpage.mailer.model.delivery.LandingMailer -reference.addressbook-mailer-lib.jar=${project.addressbook-mailer-lib}/dist/addressbook-mailer-lib.jar +reference.jjobs-mailer-lib.jar=${project.jjobs-mailer-lib}/dist/jjobs-mailer-lib.jar resource.dir=setup run.test.classpath=\ ${javac.test.classpath}:\ @@ -86,7 +86,7 @@ run.test.classpath=\ # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): runmain.jvmargs= source.encoding=UTF-8 -source.reference.addressbook-mailer.jar=../addressbook-mailer/src/ +source.reference.jjobs-mailer.jar=../jjobs-mailer/src/ source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/ source.reference.jcoreee.jar=../jcoreee/src/ source.reference.jmailer-ee.jar=../jmailer-ee/src/ diff --git a/nbproject/project.xml b/nbproject/project.xml index 0ee8b8e..b610c49 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -3,13 +3,13 @@ org.netbeans.modules.j2ee.ejbjarproject - addressbook-mailer-ejb + jjobs-mailer-ejb 1.6.5 file.reference.jcoreee.jar file.reference.jcore-logger-lib.jar file.reference.jmailer-ee.jar file.reference.cdi-api.jar - reference.addressbook-mailer-lib.jar + reference.jjobs-mailer-lib.jar libs.velocity.classpath @@ -23,7 +23,7 @@ - addressbook-mailer-lib + jjobs-mailer-lib jar jar diff --git a/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java b/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java deleted file mode 100644 index 31b6e0a..0000000 --- a/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.mailer.model.delivery; - -import java.io.Serializable; -import java.text.MessageFormat; -import javax.ejb.ActivationConfigProperty; -import javax.ejb.EJB; -import javax.ejb.MessageDriven; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.ObjectMessage; -import javax.mail.MessagingException; -import javax.naming.NamingException; -import org.mxchange.jcoreee.database.BaseDatabaseBean; -import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; - -/** - * A message-driven bean for sending out mails - *

- * @author Roland Häder - */ -@MessageDriven ( - name = "addressbookEmailDelivery", - description = "A message bean for email delivery", - activationConfig = { - @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/addressbook-email-queue"), - @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue") - }) -public class AddressbookEmailDeliveryMessageBean extends BaseDatabaseBean implements MessageListener { - - /** - * Serial number - */ - private static final long serialVersionUID = 75_638_176_619_024L; - - /** - * Mailer instance - */ - @EJB - private DeliverableAddressbookEmailLocal mailerBean; - - /** - * Default constructor - *

- * @throws javax.naming.NamingException If a JNDI name could not be found - */ - public AddressbookEmailDeliveryMessageBean () throws NamingException { - // Call super constructor - super(); - } - - @Override - public void onMessage (final Message message) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N - - // The parameter should be valid - if (null == message) { - // Throw NPE - throw new NullPointerException("message is null"); //NOI18N - } else if (!(message instanceof ObjectMessage)) { - // Not implementing right interface - throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N - } - - // Securely cast it - ObjectMessage objectMessage = (ObjectMessage) message; - - // Init variable - Serializable serializable; - - try { - // Get object from message - serializable = objectMessage.getObject(); - } catch (final JMSException ex) { - // Log it and don't continue any further - this.getLoggerBeanLocal().logException(ex); - return; - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N - - // Okay, is it the right interface? - if (null == serializable) { - // Throw NPE - throw new NullPointerException("serializable is null"); //NOI18N - } else if (!(serializable instanceof WrapableEmailDelivery)) { - // Not correct object send - throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement WrapableEmailDelivery", serializable)); //NOI18N - } - - // Securely cast it - WrapableEmailDelivery wrapper = (WrapableEmailDelivery) serializable; - - // Is all required set? - if (wrapper.getLocale() == null) { - // Throw NPE - throw new NullPointerException("wrapper.locale is null"); //NOI18N - } else if (wrapper.getRecipientAddress() == null) { - // Throw again ... - throw new NullPointerException("wrapper.recipientAddress is null"); //NOI18N - } else if (wrapper.getSubjectLine() == null) { - // ... and again - throw new NullPointerException("wrapper.subjectLine is null"); //NOI18N - } else if (wrapper.getSubjectLine().isEmpty()) { - // Is empty - throw new IllegalArgumentException("wrapper.subjectLine is empty"); //NOI18N - } else if (wrapper.getTemplateName() == null) { - // Throw NPE again - throw new NullPointerException("wrapper.templateName is null"); //NOI18N - } else if (wrapper.getTemplateName().isEmpty()) { - // Is empty - throw new IllegalArgumentException("wrapper.templateName is empty"); //NOI18N - } - - try { - // Send email out - this.mailerBean.sendDeliverableMail(wrapper); - } catch (final MessagingException ex) { - // Opps, something went wrong - this.getLoggerBeanLocal().logException(ex); - return; - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage - EXIT!", this.getClass().getSimpleName())); //NOI18N - } - -} diff --git a/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookMailerSingletonBean.java b/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookMailerSingletonBean.java deleted file mode 100644 index 895fbcd..0000000 --- a/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookMailerSingletonBean.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.mailer.model.delivery; - -import java.text.MessageFormat; -import java.util.Map; -import java.util.Properties; -import java.util.ResourceBundle; -import javax.annotation.PostConstruct; -import javax.annotation.Resource; -import javax.ejb.Singleton; -import javax.mail.MessagingException; -import javax.mail.Session; -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.mxchange.jmailee.model.delivery.BaseMailerBean; -import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; - -/** - * A singleton mailer EJB - *

- * @author Roland Häder - */ -@Singleton -public class AddressbookMailerSingletonBean extends BaseMailerBean implements DeliverableAddressbookEmailLocal { - - /** - * Serial number - */ - private static final long serialVersionUID = 17_857_816_596_030_918L; - - /** - * Configuration file - */ - private final String configFile = "org.mxchange.jmailer.config"; //NOI18N//NOI18N - - /** - * Email session - */ - @Resource (name = "addressbookSmtpSession", description = "A Java Mail session") - private Session mailSession; - - /** - * Default constructor - *

- */ - public AddressbookMailerSingletonBean () { - } - - /** - * Post-construction - */ - @PostConstruct - public void init () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Try to load bundle - ResourceBundle bundle = ResourceBundle.getBundle(this.configFile); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: bundle={1}", this.getClass().getSimpleName(), bundle)); //NOI18N - - // The bunble should be valid - if (null == bundle) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("bundle is null, maybe file {0} does not exist?", this.configFile)); //NOI18N - } - - // Init Properties - Properties properties = new Properties(); - - // Is the bundle not empty? - if (!bundle.keySet().isEmpty()) { - // Loop through all - for (final String key : bundle.keySet()) { - // Log debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: key={1}", this.getClass().getSimpleName(), key)); //NOI18N - - // Get string from bundle and set it in properties - properties.put(key, bundle.getString(key)); - } - } - - // Handle it over to the mailer - this.setProperties(properties); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - @Override - public void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendDeliverableMail: emailWrapper={0} - CALLED!", emailWrapper)); //NOI18N - - // The parameter must be valid - if (null == emailWrapper) { - // Throw NPE - throw new NullPointerException("emailWrapper is null"); //NOI18N - } else if (emailWrapper.getRecipientAddress() == null) { - // Throw NPE again - throw new NullPointerException("emailWrapper.recipientAddress is null"); //NOI18N - } else if (emailWrapper.getSubjectLine() == null) { - // ... and again - throw new NullPointerException("emailWrapper.subjectLine is null"); //NOI18N - } else if (emailWrapper.getSubjectLine().isEmpty()) { - // Is empty - throw new IllegalArgumentException("emailWrapper.subjectLine is empty"); //NOI18N - } else if (emailWrapper.getTemplateName() == null) { - // ... and again - throw new NullPointerException("emailWrapper.templateName is null"); //NOI18N - } else if (emailWrapper.getTemplateName().isEmpty()) { - // Is empty - throw new IllegalArgumentException("emailWrapper.templateName is empty"); //NOI18N - } else if (emailWrapper.getLocale() == null) { - // Throw NPE again - throw new NullPointerException("emailWrapper.locale is null"); //NOI18N - } else if (!emailWrapper.getTemplateVariables().containsKey("baseUrl")) { //NOI18N - // Not set - throw new IllegalArgumentException("emailWrapper.templateVariables.baseUrl is not set"); //NOI18N - } - - // All required data is set, load template - Template template = this.getTemplateEngine().getTemplate(String.format("templates/%s/%s.vm", emailWrapper.getLocale().getLanguage().toLowerCase(), emailWrapper.getTemplateName())); //NOI18N - - // Init context - VelocityContext context = new VelocityContext(); - - // Are some variables set? - if ((emailWrapper.getTemplateVariables() != null) && (!emailWrapper.getTemplateVariables().isEmpty())) { - // Add all variables - for (Map.Entry entry : emailWrapper.getTemplateVariables().entrySet()) { - // Get key/value - String key = (String) entry.getKey(); - String value = (String) entry.getValue(); - - // Both should not be empty - if (null == key) { - // Throw NPE - throw new NullPointerException("key is null"); //NOI18N - } else if (null == value) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("value for key={0} is null", key)); //NOI18N - } - - // Set it - context.put(key, value); - } - } - - // Send the email - this.deliverMailWithTemplate(template, context, emailWrapper, this.mailSession); - - // Trace message - this.getLoggerBeanLocal().logTrace("sendDeliverableMail: EXIT!"); //NOI18N - } - -} diff --git a/src/java/org/mxchange/jjobs/mailer/model/delivery/JobsEmailDeliveryMessageBean.java b/src/java/org/mxchange/jjobs/mailer/model/delivery/JobsEmailDeliveryMessageBean.java new file mode 100644 index 0000000..dd2a976 --- /dev/null +++ b/src/java/org/mxchange/jjobs/mailer/model/delivery/JobsEmailDeliveryMessageBean.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.mailer.model.delivery; + +import java.io.Serializable; +import java.text.MessageFormat; +import javax.ejb.ActivationConfigProperty; +import javax.ejb.EJB; +import javax.ejb.MessageDriven; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.ObjectMessage; +import javax.mail.MessagingException; +import javax.naming.NamingException; +import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; + +/** + * A message-driven bean for sending out mails + *

+ * @author Roland Häder + */ +@MessageDriven ( + name = "jjobsEmailDelivery", + description = "A message bean for email delivery", + activationConfig = { + @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jjobs-email-queue"), + @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue") + }) +public class JobsEmailDeliveryMessageBean extends BaseDatabaseBean implements MessageListener { + + /** + * Serial number + */ + private static final long serialVersionUID = 75_638_176_619_024L; + + /** + * Mailer instance + */ + @EJB + private DeliverableJobsEmailLocal mailerBean; + + /** + * Default constructor + *

+ * @throws javax.naming.NamingException If a JNDI name could not be found + */ + public JobsEmailDeliveryMessageBean () throws NamingException { + // Call super constructor + super(); + } + + @Override + public void onMessage (final Message message) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N + + // The parameter should be valid + if (null == message) { + // Throw NPE + throw new NullPointerException("message is null"); //NOI18N + } else if (!(message instanceof ObjectMessage)) { + // Not implementing right interface + throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N + } + + // Securely cast it + ObjectMessage objectMessage = (ObjectMessage) message; + + // Init variable + Serializable serializable; + + try { + // Get object from message + serializable = objectMessage.getObject(); + } catch (final JMSException ex) { + // Log it and don't continue any further + this.getLoggerBeanLocal().logException(ex); + return; + } + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N + + // Okay, is it the right interface? + if (null == serializable) { + // Throw NPE + throw new NullPointerException("serializable is null"); //NOI18N + } else if (!(serializable instanceof WrapableEmailDelivery)) { + // Not correct object send + throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement WrapableEmailDelivery", serializable)); //NOI18N + } + + // Securely cast it + WrapableEmailDelivery wrapper = (WrapableEmailDelivery) serializable; + + // Is all required set? + if (wrapper.getLocale() == null) { + // Throw NPE + throw new NullPointerException("wrapper.locale is null"); //NOI18N + } else if (wrapper.getRecipientAddress() == null) { + // Throw again ... + throw new NullPointerException("wrapper.recipientAddress is null"); //NOI18N + } else if (wrapper.getSubjectLine() == null) { + // ... and again + throw new NullPointerException("wrapper.subjectLine is null"); //NOI18N + } else if (wrapper.getSubjectLine().isEmpty()) { + // Is empty + throw new IllegalArgumentException("wrapper.subjectLine is empty"); //NOI18N + } else if (wrapper.getTemplateName() == null) { + // Throw NPE again + throw new NullPointerException("wrapper.templateName is null"); //NOI18N + } else if (wrapper.getTemplateName().isEmpty()) { + // Is empty + throw new IllegalArgumentException("wrapper.templateName is empty"); //NOI18N + } + + try { + // Send email out + this.mailerBean.sendDeliverableMail(wrapper); + } catch (final MessagingException ex) { + // Opps, something went wrong + this.getLoggerBeanLocal().logException(ex); + return; + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage - EXIT!", this.getClass().getSimpleName())); //NOI18N + } + +} diff --git a/src/java/org/mxchange/jjobs/mailer/model/delivery/JobsMailerSingletonBean.java b/src/java/org/mxchange/jjobs/mailer/model/delivery/JobsMailerSingletonBean.java new file mode 100644 index 0000000..b1ec48b --- /dev/null +++ b/src/java/org/mxchange/jjobs/mailer/model/delivery/JobsMailerSingletonBean.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.mailer.model.delivery; + +import java.text.MessageFormat; +import java.util.Map; +import java.util.Properties; +import java.util.ResourceBundle; +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import javax.ejb.Singleton; +import javax.mail.MessagingException; +import javax.mail.Session; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.mxchange.jmailee.model.delivery.BaseMailerBean; +import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; + +/** + * A singleton mailer EJB + *

+ * @author Roland Häder + */ +@Singleton +public class JobsMailerSingletonBean extends BaseMailerBean implements DeliverableJobsEmailLocal { + + /** + * Serial number + */ + private static final long serialVersionUID = 17_857_816_596_030_918L; + + /** + * Configuration file + */ + private final String configFile = "org.mxchange.jmailer.config"; //NOI18N//NOI18N + + /** + * Email session + */ + @Resource (name = "jjobsSmtpSession", description = "A Java Mail session") + private Session mailSession; + + /** + * Default constructor + *

+ */ + public JobsMailerSingletonBean () { + } + + /** + * Post-construction + */ + @PostConstruct + public void init () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Try to load bundle + ResourceBundle bundle = ResourceBundle.getBundle(this.configFile); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: bundle={1}", this.getClass().getSimpleName(), bundle)); //NOI18N + + // The bunble should be valid + if (null == bundle) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("bundle is null, maybe file {0} does not exist?", this.configFile)); //NOI18N + } + + // Init Properties + Properties properties = new Properties(); + + // Is the bundle not empty? + if (!bundle.keySet().isEmpty()) { + // Loop through all + for (final String key : bundle.keySet()) { + // Log debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: key={1}", this.getClass().getSimpleName(), key)); //NOI18N + + // Get string from bundle and set it in properties + properties.put(key, bundle.getString(key)); + } + } + + // Handle it over to the mailer + this.setProperties(properties); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: EXIT!", this.getClass().getSimpleName())); //NOI18N + } + + @Override + public void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendDeliverableMail: emailWrapper={0} - CALLED!", emailWrapper)); //NOI18N + + // The parameter must be valid + if (null == emailWrapper) { + // Throw NPE + throw new NullPointerException("emailWrapper is null"); //NOI18N + } else if (emailWrapper.getRecipientAddress() == null) { + // Throw NPE again + throw new NullPointerException("emailWrapper.recipientAddress is null"); //NOI18N + } else if (emailWrapper.getSubjectLine() == null) { + // ... and again + throw new NullPointerException("emailWrapper.subjectLine is null"); //NOI18N + } else if (emailWrapper.getSubjectLine().isEmpty()) { + // Is empty + throw new IllegalArgumentException("emailWrapper.subjectLine is empty"); //NOI18N + } else if (emailWrapper.getTemplateName() == null) { + // ... and again + throw new NullPointerException("emailWrapper.templateName is null"); //NOI18N + } else if (emailWrapper.getTemplateName().isEmpty()) { + // Is empty + throw new IllegalArgumentException("emailWrapper.templateName is empty"); //NOI18N + } else if (emailWrapper.getLocale() == null) { + // Throw NPE again + throw new NullPointerException("emailWrapper.locale is null"); //NOI18N + } else if (!emailWrapper.getTemplateVariables().containsKey("baseUrl")) { //NOI18N + // Not set + throw new IllegalArgumentException("emailWrapper.templateVariables.baseUrl is not set"); //NOI18N + } + + // All required data is set, load template + Template template = this.getTemplateEngine().getTemplate(String.format("templates/%s/%s.vm", emailWrapper.getLocale().getLanguage().toLowerCase(), emailWrapper.getTemplateName())); //NOI18N + + // Init context + VelocityContext context = new VelocityContext(); + + // Are some variables set? + if ((emailWrapper.getTemplateVariables() != null) && (!emailWrapper.getTemplateVariables().isEmpty())) { + // Add all variables + for (Map.Entry entry : emailWrapper.getTemplateVariables().entrySet()) { + // Get key/value + String key = (String) entry.getKey(); + String value = (String) entry.getValue(); + + // Both should not be empty + if (null == key) { + // Throw NPE + throw new NullPointerException("key is null"); //NOI18N + } else if (null == value) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("value for key={0} is null", key)); //NOI18N + } + + // Set it + context.put(key, value); + } + } + + // Send the email + this.deliverMailWithTemplate(template, context, emailWrapper, this.mailSession); + + // Trace message + this.getLoggerBeanLocal().logTrace("sendDeliverableMail: EXIT!"); //NOI18N + } + +}