Search in sources :

Example 1 with StringTemplateStaticImpl

use of org.summerb.utils.stringtemplate.impl.StringTemplateStaticImpl in project summerb by skarpushin.

the class SecurityMailsMessageBuilderFactoryImpl method createEmailMessageBuilderFromArticle.

@Override
public EmailMessageBuilder createEmailMessageBuilderFromArticle(String articleKey, User sender) {
    try {
        Map<Locale, Article> options = articleService.findArticleLocalizations(articleKey);
        if (options == null || options.size() == 0) {
            log.error("Emails will not be sent! Article not found: " + articleKey);
        }
        LocaleAwareEmailMessageBuilderImpl ret = new LocaleAwareEmailMessageBuilderImpl();
        for (Entry<Locale, Article> entry : options.entrySet()) {
            EmailMessageBuilderImpl builder = new EmailMessageBuilderImpl();
            builder.setLocale(entry.getKey());
            builder.setFromNameTemplate(new StringTemplateStaticImpl(sender.getDisplayName()));
            builder.setToNameTemplate(stringTemplateCompiler.compile("${to.displayName}"));
            builder.setSubjectTemplate(new StringTemplateStaticImpl(entry.getValue().getTitle()));
            builder.setBodyTemplate(stringTemplateCompiler.compile(entry.getValue().getContent()));
            ret.getLocaleSpecificBuilders().add(builder);
        }
        return ret;
    } catch (Throwable t) {
        throw new RuntimeException("Failed to create email message builder using article id: " + articleKey, t);
    }
}
Also used : Locale(java.util.Locale) EmailMessageBuilderImpl(org.summerb.microservices.emailsender.impl.EmailMessageBuilderImpl) LocaleAwareEmailMessageBuilderImpl(org.summerb.microservices.emailsender.impl.LocaleAwareEmailMessageBuilderImpl) Article(org.summerb.microservices.articles.api.dto.Article) StringTemplateStaticImpl(org.summerb.utils.stringtemplate.impl.StringTemplateStaticImpl) LocaleAwareEmailMessageBuilderImpl(org.summerb.microservices.emailsender.impl.LocaleAwareEmailMessageBuilderImpl)

Aggregations

Locale (java.util.Locale)1 Article (org.summerb.microservices.articles.api.dto.Article)1 EmailMessageBuilderImpl (org.summerb.microservices.emailsender.impl.EmailMessageBuilderImpl)1 LocaleAwareEmailMessageBuilderImpl (org.summerb.microservices.emailsender.impl.LocaleAwareEmailMessageBuilderImpl)1 StringTemplateStaticImpl (org.summerb.utils.stringtemplate.impl.StringTemplateStaticImpl)1