Search in sources :

Example 16 with MailTemplate

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;
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) MailTemplate(org.olat.core.util.mail.MailTemplate) MailBundle(org.olat.core.util.mail.MailBundle) Property(org.olat.properties.Property)

Example 17 with MailTemplate

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);
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) MailTemplate(org.olat.core.util.mail.MailTemplate) MailManager(org.olat.core.util.mail.MailManager) Roles(org.olat.core.id.Roles) MailBundle(org.olat.core.util.mail.MailBundle) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 18 with MailTemplate

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);
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) BusinessGroupModule(org.olat.group.BusinessGroupModule) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) Roles(org.olat.core.id.Roles) BaseSecurity(org.olat.basesecurity.BaseSecurity) BusinessGroupService(org.olat.group.BusinessGroupService) MailTemplate(org.olat.core.util.mail.MailTemplate) MailManager(org.olat.core.util.mail.MailManager) List(java.util.List) MailBundle(org.olat.core.util.mail.MailBundle)

Example 19 with MailTemplate

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;
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 20 with MailTemplate

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);
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) MailTemplate(org.olat.core.util.mail.MailTemplate) BGUserMailTemplate(org.olat.group.ui.wizard.BGUserMailTemplate) BGMailNotificationEditController(org.olat.group.ui.wizard.BGMailNotificationEditController) BGUserMailTemplate(org.olat.group.ui.wizard.BGUserMailTemplate) MailType(org.olat.group.manager.BusinessGroupMailing.MailType) Component(org.olat.core.gui.components.Component)

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