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;
}
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;
}
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();
}
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;
}
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;
}
Aggregations