use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class ProjectBrokerMailerImpl method createMailTemplate.
/**
* Create default template which fill in context 'firstname' , 'lastname' and 'username'.
* @param subject
* @param body
* @return
*/
private MailTemplate createMailTemplate(Project project, Identity enrolledIdentity, String subject, String body, Locale locale) {
final String projectTitle = project.getTitle();
final String currentDate = Formatter.getInstance(locale).formatDateAndTime(new Date());
final String firstNameEnrolledIdentity = enrolledIdentity.getUser().getProperty(UserConstants.FIRSTNAME, null);
final String lastnameEnrolledIdentity = enrolledIdentity.getUser().getProperty(UserConstants.LASTNAME, null);
final String usernameEnrolledIdentity = enrolledIdentity.getName();
return new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
context.put("enrolled_identity_firstname", firstNameEnrolledIdentity);
context.put("enrolled_identity_lastname", lastnameEnrolledIdentity);
context.put("enrolled_identity_username", usernameEnrolledIdentity);
// Put variables from greater context
context.put("projectTitle", projectTitle);
context.put("currentDate", currentDate);
}
};
}
use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class UnpublishResourceCallback method execute.
@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
MailTemplate mailTemplate = (MailTemplate) runContext.get("mailTemplate");
if (mailTemplate != null) {
List<Identity> ownerList = new ArrayList<Identity>();
// owners
if (repositoryService.hasRole(ureq.getIdentity(), repositoryEntry, GroupRoles.owner.name())) {
ownerList = repositoryService.getMembers(repositoryEntry, GroupRoles.owner.name());
}
String businessPath = wControl.getBusinessControl().getAsString();
MailContext context = new MailContextImpl(businessPath);
String metaId = UUID.randomUUID().toString().replace("-", "");
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, ownerList, mailTemplate, ureq.getIdentity(), metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, ureq.getIdentity(), mailTemplate, ureq.getIdentity(), metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
StringBuilder errorMessage = new StringBuilder();
StringBuilder warningMessage = new StringBuilder();
MailHelper.appendErrorsAndWarnings(result, errorMessage, warningMessage, ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
if (warningMessage.length() > 0) {
wControl.setWarning(warningMessage.toString());
}
if (errorMessage.length() > 0) {
wControl.setError(errorMessage.toString());
}
ownerList.clear();
}
// update status
repositoryEntry = repositoryService.loadByKey(repositoryEntry.getKey());
repositoryEntry.setStatusCode(RepositoryEntryStatus.REPOSITORY_STATUS_CLOSED);
repositoryEntry = DBFactory.getInstance().getCurrentEntityManager().merge(repositoryEntry);
// clean catalog
Object cleanCatalog = runContext.get("cleanCatalog");
if (cleanCatalog != null && Boolean.TRUE.equals(cleanCatalog)) {
CoreSpringFactory.getImpl(CatalogManager.class).resourceableDeleted(repositoryEntry);
}
// clean groups
Object cleanGroups = runContext.get("cleanGroups");
if (cleanGroups != null && Boolean.TRUE.equals(cleanGroups)) {
doCleanGroups(ureq.getIdentity());
}
ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_CLOSE, getClass());
log.audit("Repository entry " + repositoryEntry.getDisplayname() + " ( " + repositoryEntry.getOlatResource() + " ) closed");
return StepsMainRunController.DONE_MODIFIED;
}
use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class MailTest method testMailToCcBccForEach.
/**
* Test for the mail template and the context variable methods
*/
@Test
public void testMailToCcBccForEach() {
String subject = "For Each Subject: Hello $firstname $lastname";
String body = "For Each Body: \n\n You ($login) should go to \n\n'$coursename' @ $courseURL$login";
final String coursename = "my course";
final String courseURL = "http://www.mytrashmail.com/myTrashMail_inbox.aspx?email=";
MailTemplate template = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
// Put user variables
User user = identity.getUser();
context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
context.put("login", identity.getName());
// Put variables from greater context, eg. course id, group name etc.
context.put("coursename", coursename);
context.put("courseURL", courseURL);
}
};
// some recipients data
List<Identity> recipients = new ArrayList<Identity>();
recipients.add(id1);
recipients.add(id2);
recipients.add(id3);
Identity recipientCC = id4;
// tests with / witthout CC and BCC
MailerResult result = new MailerResult();
result = sendMailAsSeparateMails(null, recipients, null, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
result = sendMailAsSeparateMails(null, recipients, recipientCC, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
result = sendMailAsSeparateMails(null, recipients, null, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
}
use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class MailTest method testMailToCcBccTogether.
/**
* Test for the mail template and the context variable methods
*/
@Test
public void testMailToCcBccTogether() {
String subject = "Together Subject: Hello everybody";
String body = "Together Body: \n\n You should go to \n\n'$coursename' @ $courseURL";
final String coursename = "my course";
final String courseURL = "http://www.mytrashmail.com/";
MailTemplate template = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
// identity is null in this mode - template parsed only once not for
// everybody
// Put variables from greater context, eg. course id, group name etc.
context.put("coursename", coursename);
context.put("courseURL", courseURL);
}
};
// some recipients data
List<Identity> recipients = new ArrayList<Identity>();
recipients.add(id1);
recipients.add(id2);
recipients.add(id3);
Identity recipientCC = id4;
// tests with / witthout CC and BCC
MailerResult result = new MailerResult();
result = sendMailAsSeparateMails(null, recipients, null, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
result = sendMailAsSeparateMails(null, recipients, recipientCC, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
result = sendMailAsSeparateMails(null, recipients, null, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
}
use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class EnrollmentManager method doCancelEnrollment.
public void doCancelEnrollment(final Identity identity, final BusinessGroup enrolledGroup, final ENCourseNode enNode, final CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
if (isLogDebugEnabled())
logDebug("doCancelEnrollment");
// 1. Remove group membership, fire events, do loggin etc.
// Remove participant. This will also check if a waiting-list with auto-close-ranks is configurated
// and move the users accordingly
MailPackage doNotSendmailPackage = new MailPackage(false);
businessGroupService.removeParticipants(identity, Collections.singletonList(identity), enrolledGroup, doNotSendmailPackage);
logInfo(" doCancelEnrollment in group " + enrolledGroup, identity.getName());
logInfo(" doCancelEnrollment in group " + enrolledGroup, identity.getName());
// 2. Remove enrollmentdate property
// only remove last time date, not firsttime
Property lastTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_ENROLLMENT_DATE);
if (lastTime != null) {
coursePropertyManager.deleteProperty(lastTime);
}
// 3. Send notification mail
MailTemplate mailTemplate = BGMailHelper.createRemoveMyselfMailTemplate(enrolledGroup, identity);
// fxdiff VCRP-16: intern mail system
MailContext context = new MailContextImpl(wControl.getBusinessControl().getAsString());
MailerResult result = new MailerResult();
MailBundle bundle = mailManager.makeMailBundle(context, identity, mailTemplate, null, null, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
MailHelper.printErrorsAndWarnings(result, wControl, false, trans.getLocale());
}
Aggregations