Search in sources :

Example 21 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.

the class BGMailHelper method createMailTemplate.

/**
 * Internal helper - does all the magic
 *
 * @param group
 * @param actor
 * @param subjectKey
 * @param bodyKey
 * @return
 */
private static MailTemplate createMailTemplate(BusinessGroupShort group, Identity actor, String subjectKey, String bodyKey) {
    // get some data about the actor and fetch the translated subject / body via i18n module
    String[] bodyArgs = null;
    String lang = null;
    if (actor != null) {
        lang = actor.getUser().getPreferences().getLanguage();
    }
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(lang);
    if (actor != null) {
        bodyArgs = new String[] { actor.getUser().getProperty(UserConstants.FIRSTNAME, null), actor.getUser().getProperty(UserConstants.LASTNAME, null), UserManager.getInstance().getUserDisplayEmail(actor, locale), // 2x for compatibility with old i18m properties
        UserManager.getInstance().getUserDisplayEmail(actor, locale) };
    }
    Translator trans = Util.createPackageTranslator(BGMailHelper.class, locale, Util.createPackageTranslator(BusinessGroupListController.class, locale));
    String subject = trans.translate(subjectKey);
    String body = trans.translate(bodyKey, bodyArgs);
    // build learning resources as list of url as string
    final BGMailTemplateInfos infos;
    if (group != null) {
        BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
        List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
        infos = getTemplateInfos(group, repoEntries);
        subject = subject.replace("$groupname", infos.getGroupName());
        body = body.replace("$groupname", infos.getGroupNameWithUrl());
        body = body.replace("$groupdescription", infos.getGroupDescription());
        if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
            body = body.replace("$courselist", infos.getCourseList());
        } else {
            body = body.replace("$courselist", trans.translate("notification.mail.no.ressource", null));
        }
    } else {
        infos = new BGMailTemplateInfos("", "", "", "");
    }
    // create a mail template which all these data
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity identity) {
            // Put user variables into velocity context
            User user = identity.getUser();
            context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
            context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
            // the email of the user, needs to stay named 'login'
            context.put("login", user.getProperty(UserConstants.EMAIL, null));
            // Put variables from greater context
            context.put("groupname", infos.getGroupNameWithUrl());
            context.put("groupdescription", infos.getGroupDescription());
            if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
                context.put("courselist", infos.getCourseList());
            } else {
                context.put("courselist", trans.translate("notification.mail.no.ressource", null));
            }
            context.put("courselistempty", trans.translate("notification.mail.no.ressource", null));
        }
    };
    return mailTempl;
}
Also used : Locale(java.util.Locale) User(org.olat.core.id.User) RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) VelocityContext(org.apache.velocity.VelocityContext) Translator(org.olat.core.gui.translator.Translator) BusinessGroupService(org.olat.group.BusinessGroupService) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) BusinessGroupListController(org.olat.group.ui.main.BusinessGroupListController)

Example 22 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.

the class UserImportController method createMailTemplateForNewIdentity.

private MailTemplate createMailTemplateForNewIdentity(Identity identity, TransientIdentity transientIdentity) {
    // get some data about the actor and fetch the translated subject / body via i18n module
    String[] bodyArgs = new String[] { // {0}
    identity.getName(), // {1}
    identity.getUser().getProperty(UserConstants.FIRSTNAME, null), // {2}
    identity.getUser().getProperty(UserConstants.LASTNAME, null), // {3}
    UserManager.getInstance().getUserDisplayEmail(identity, getLocale()), // {4}
    Settings.getServerContextPathURI(), // {5}
    transientIdentity.getPassword() };
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
    Translator translator = Util.createPackageTranslator(UserImportController.class, locale);
    String subject = translator.translate("mail.new.identity.subject");
    String body = translator.translate("mail.new.identity.text", bodyArgs);
    // create a mail template which all these data
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity identity) {
            // Put user variables into velocity context
            User user = identity.getUser();
            context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
            context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
            // the email of the user, needs to stay named 'login'
            context.put("login", user.getProperty(UserConstants.EMAIL, null));
        }
    };
    return mailTempl;
}
Also used : Locale(java.util.Locale) User(org.olat.core.id.User) Translator(org.olat.core.gui.translator.Translator) VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Example 23 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.

the class DENManageParticipantsController method createNotificationMail.

private void createNotificationMail(UserRequest ureq, String subjectStr, String action) {
    MailTemplate mailTempl;
    if (action.equals(REMOVE_ACTION)) {
        mailTempl = denManager.getRemovedMailTemplate(ureq, subjectStr, getTranslator());
    } else {
        mailTempl = denManager.getAddedMailTemplate(ureq, subjectStr, getTranslator());
    }
    removeAsListenerAndDispose(notificationCtr);
    notificationCtr = new MailNotificationEditController(getWindowControl(), ureq, mailTempl, false, false, true);
    listenTo(notificationCtr);
    removeAsListenerAndDispose(notificationCmc);
    notificationCmc = new CloseableModalController(getWindowControl(), "close", notificationCtr.getInitialComponent());
    listenTo(notificationCmc);
    notificationCmc.activate();
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) MailTemplate(org.olat.core.util.mail.MailTemplate) MailNotificationEditController(org.olat.core.util.mail.MailNotificationEditController)

Example 24 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.

the class DENManager method getRemovedMailTemplate.

/**
 * Generates a mail template for users who were removed from a date
 * @param identity
 * @param event
 * @param trans
 * @return MailTemplate
 */
protected MailTemplate getRemovedMailTemplate(UserRequest ureq, String subjectStr, Translator trans) {
    Identity identity = ureq.getIdentity();
    String[] bodyArgs = new String[] { identity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale()), identity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()), UserManager.getInstance().getUserDisplayEmail(identity, ureq.getLocale()), "", subjectStr };
    String subject = trans.translate("mail.participants.remove.subject", bodyArgs);
    String body = trans.translate("mail.participants.remove.body", bodyArgs);
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity ident) {
        // 
        }
    };
    return mailTempl;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Example 25 with MailTemplate

use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.

the class DENManager method getAddedMailTemplate.

/**
 * Generates a mail template for users who were added to a date
 * @param identity
 * @param event
 * @param translator
 * @return MailTemplate
 */
protected MailTemplate getAddedMailTemplate(UserRequest ureq, String subjectStr, Translator translator) {
    Identity identity = ureq.getIdentity();
    String[] bodyArgs = new String[] { identity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale()), identity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()), UserManager.getInstance().getUserDisplayEmail(identity, ureq.getLocale()), "", subjectStr };
    String subject = translator.translate("mail.participants.add.subject", bodyArgs);
    String body = translator.translate("mail.participants.add.body", bodyArgs);
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity ident) {
        // 
        }
    };
    return mailTempl;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Aggregations

MailTemplate (org.olat.core.util.mail.MailTemplate)86 Identity (org.olat.core.id.Identity)62 MailerResult (org.olat.core.util.mail.MailerResult)46 MailBundle (org.olat.core.util.mail.MailBundle)32 MailContext (org.olat.core.util.mail.MailContext)30 MailContextImpl (org.olat.core.util.mail.MailContextImpl)30 VelocityContext (org.apache.velocity.VelocityContext)28 ArrayList (java.util.ArrayList)20 List (java.util.List)16 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)14 MailNotificationEditController (org.olat.core.util.mail.MailNotificationEditController)14 User (org.olat.core.id.User)12 Test (org.junit.Test)10 UserRequest (org.olat.core.gui.UserRequest)10 WindowControl (org.olat.core.gui.control.WindowControl)10 MailPackage (org.olat.core.util.mail.MailPackage)8 Property (org.olat.properties.Property)7 File (java.io.File)6 Locale (java.util.Locale)6 TableMultiSelectEvent (org.olat.core.gui.components.table.TableMultiSelectEvent)6