use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class EnrollmentManager method addUserToWaitingList.
private boolean addUserToWaitingList(Identity identity, BusinessGroup group, ENCourseNode enNode, CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
// <- moved to bgs 1. Add user to group, fire events, do loggin etc.
// 2. Set first waiting-list date
String nowString = Long.toString(System.currentTimeMillis());
Property firstTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_WAITINGLIST_DATE);
if (firstTime == null) {
// create firsttime
firstTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_WAITINGLIST_DATE, null, null, nowString, null);
coursePropertyManager.saveProperty(firstTime);
}
// 3. Set waiting-list date property
Property thisTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_WAITINGLIST_DATE);
if (thisTime == null) {
// create firsttime
thisTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_WAITINGLIST_DATE, null, null, nowString, null);
coursePropertyManager.saveProperty(thisTime);
} else {
thisTime.setStringValue(nowString);
coursePropertyManager.updateProperty(thisTime);
}
// 4. Send notification mail
MailTemplate mailTemplate = BGMailHelper.createAddWaitinglistMailTemplate(group, 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());
return true;
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class RepositoryMailing method sendEmail.
public static void sendEmail(Identity ureqIdentity, Identity identity, RepositoryEntry re, Type type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
String email = identity.getUser().getProperty(UserConstants.EMAIL, null);
String emailAlt = identity.getUser().getProperty(UserConstants.INSTITUTIONALEMAIL, null);
if (!StringHelper.containsNonWhitespace(email) && !StringHelper.containsNonWhitespace(emailAlt)) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
RepositoryModule repositoryModule = CoreSpringFactory.getImpl(RepositoryModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!repositoryModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
template = getDefaultTemplate(type, re, ureqIdentity);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[RepositoryEntry:" + re.getKey() + "]");
}
String metaId = mailing == null ? null : mailing.getUuid();
MailerResult result = new MailerResult();
MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailManager.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class BusinessGroupMailing method sendEmail.
protected static void sendEmail(Identity ureqIdentity, Identity identity, BusinessGroupShort group, MailType type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
BusinessGroupModule groupModule = CoreSpringFactory.getImpl(BusinessGroupModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!groupModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
// booking by myself
if (type != null && type == MailType.addParticipant && ureqIdentity != null && ureqIdentity.equals(identity)) {
template = BGMailHelper.createAddMyselfMailTemplate(group, ureqIdentity);
} else {
template = getDefaultTemplate(type, group, ureqIdentity);
}
} else if (group != null && template.getContext() != null && needTemplateEnhancement(template)) {
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
template = new MailTemplateDelegate(template, group, repoEntries);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[BusinessGroup:" + group.getKey() + "]");
}
MailerResult result = new MailerResult();
String metaId = mailing != null ? mailing.getUuid() : null;
MailManager mailService = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailService.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailService.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceImpl method deleteBusinessGroupWithMail.
@Override
public MailerResult deleteBusinessGroupWithMail(BusinessGroup businessGroupTodelete, String businessPath, Identity deletedBy, Locale locale) {
List<Identity> users = businessGroupRelationDAO.getMembers(businessGroupTodelete, GroupRoles.coach.name(), GroupRoles.participant.name(), GroupRoles.waiting.name());
// now delete the group first
deleteBusinessGroup(businessGroupTodelete);
dbInstance.commit();
// finally send email
MailTemplate mailTemplate = BGMailHelper.createDeleteGroupMailTemplate(businessGroupTodelete, deletedBy);
if (mailTemplate != null) {
String metaId = UUID.randomUUID().toString();
MailContext context = new MailContextImpl(businessPath);
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, users, mailTemplate, null, metaId, result);
result.append(mailManager.sendMessage(bundles));
return result;
}
return null;
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class AbstractBusinessGroupListController method confirmUserManagementEmail.
private void confirmUserManagementEmail(UserRequest ureq, MembershipModification mod, List<BusinessGroup> groups) {
removeAsListenerAndDispose(cmc);
removeAsListenerAndDispose(userManagementSendMailController);
MailTemplate defaultTemplate = null;
int totalModification = (mod.size() * groups.size());
if (totalModification == 1) {
MailType type = BusinessGroupMailing.getDefaultTemplateType(mod);
if (type != null) {
defaultTemplate = BusinessGroupMailing.getDefaultTemplate(type, groups.get(0), ureq.getIdentity());
}
}
MailTemplate template = new BGUserMailTemplate(groups, mod, defaultTemplate);
boolean mandatoryEmail = !mod.getAddParticipants().isEmpty() && groupModule.isMandatoryEnrolmentEmail(ureq.getUserSession().getRoles());
userManagementSendMailController = new BGMailNotificationEditController(getWindowControl(), ureq, template, totalModification == 1, totalModification == 1, false, mandatoryEmail);
Component cmp = userManagementSendMailController.getInitialComponent();
listenTo(userManagementSendMailController);
cmc = new CloseableModalController(getWindowControl(), translate("close"), cmp, true, translate("users.group"));
cmc.activate();
listenTo(cmc);
}
Aggregations