Search in sources :

Example 6 with MailTemplate

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

the class ProjectGroupController method handleCandidateGroupEvent.

private void handleCandidateGroupEvent(UserRequest urequest, Event event) {
    if (event instanceof IdentitiesAddEvent) {
        IdentitiesAddEvent identitiesAddEvent = (IdentitiesAddEvent) event;
        List<Identity> addedIdentities = projectGroupManager.addCandidates(identitiesAddEvent.getAddIdentities(), project);
        identitiesAddEvent.setIdentitiesAddedEvent(addedIdentities);
        fireEvent(urequest, Event.CHANGED_EVENT);
    } else if (event instanceof IdentitiesRemoveEvent) {
        projectGroupManager.removeCandidates(((IdentitiesRemoveEvent) event).getRemovedIdentities(), project);
        fireEvent(urequest, Event.CHANGED_EVENT);
    } else if (event instanceof IdentitiesMoveEvent) {
        final IdentitiesMoveEvent identitiesMoveEvent = (IdentitiesMoveEvent) event;
        // OLAT-6342: check identity not in group first!
        List<Identity> moveIdents = identitiesMoveEvent.getChosenIdentities();
        BusinessGroupAddResponse response = projectGroupManager.acceptCandidates(moveIdents, project, urequest.getIdentity(), projectBrokerModuleConfiguration.isAutoSignOut(), projectBrokerModuleConfiguration.isAcceptSelectionManually());
        identitiesMoveEvent.setMovedIdentities(response.getAddedIdentities());
        identitiesMoveEvent.setNotMovedIdentities(response.getIdentitiesAlreadyInGroup());
        // send mail for all of them
        MailTemplate mailTemplate = identitiesMoveEvent.getMailTemplate();
        if (mailTemplate != null) {
            MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
            String metaId = UUID.randomUUID().toString().replace("-", "");
            MailerResult result = new MailerResult();
            MailBundle[] bundles = mailManager.makeMailBundles(context, identitiesMoveEvent.getMovedIdentities(), mailTemplate, null, metaId, result);
            result.append(mailManager.sendMessage(bundles));
            if (mailTemplate.getCpfrom()) {
                MailBundle ccBundle = mailManager.makeMailBundle(context, urequest.getIdentity(), mailTemplate, null, metaId, result);
                result.append(mailManager.sendMessage(ccBundle));
            }
            MailHelper.printErrorsAndWarnings(result, getWindowControl(), urequest.getUserSession().getRoles().isOLATAdmin(), urequest.getLocale());
        }
        fireEvent(urequest, Event.CHANGED_EVENT);
        // Participant and waiting-list were changed => reload both
        projectMemberController.reloadData();
        // Do only reload data in case of IdentitiesMoveEvent (IdentitiesAddEvent and reload data resulting in doublicate values)
        projectCandidatesController.reloadData();
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) IdentitiesRemoveEvent(org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent) MailTemplate(org.olat.core.util.mail.MailTemplate) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) BusinessGroupAddResponse(org.olat.group.BusinessGroupAddResponse) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) IdentitiesMoveEvent(org.olat.admin.securitygroup.gui.IdentitiesMoveEvent)

Example 7 with MailTemplate

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

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);
        }
    };
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 8 with MailTemplate

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

the class ProjectBrokerMailerImpl method sendEmailProjectChanged.

private MailerResult sendEmailProjectChanged(List<Identity> group, Identity changer, Project project, String subject, String body, Locale locale) {
    MailTemplate enrolledMailTemplate = this.createProjectChangeMailTemplate(project, changer, subject, body, locale);
    // loop over all project manger
    StringBuilder identityNames = new StringBuilder();
    for (Identity identity : group) {
        if (identityNames.length() > 0)
            identityNames.append(",");
        identityNames.append(identity.getName());
    }
    MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
    MailerResult result = new MailerResult();
    MailBundle[] bundles = mailManager.makeMailBundles(context, group, enrolledMailTemplate, null, null, result);
    result.append(mailManager.sendMessage(bundles));
    log.audit("ProjectBroker: sendEmailToGroup: identities=" + identityNames.toString() + " , mailerResult.returnCode=" + result.getReturnCode());
    return 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) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 9 with MailTemplate

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

the class ProjectBrokerMailerImpl method sendEmailToGroup.

private MailerResult sendEmailToGroup(List<Identity> group, Identity enrolledIdentity, Project project, String subject, String body, Locale locale) {
    MailTemplate enrolledMailTemplate = this.createMailTemplate(project, enrolledIdentity, subject, body, locale);
    // loop over all project manger
    StringBuilder identityNames = new StringBuilder();
    for (Identity identity : group) {
        if (identityNames.length() > 0)
            identityNames.append(",");
        identityNames.append(identity.getName());
    }
    MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
    String metaId = UUID.randomUUID().toString().replace("-", "");
    MailerResult result = new MailerResult();
    MailBundle[] bundles = mailManager.makeMailBundles(context, group, enrolledMailTemplate, null, metaId, result);
    result.append(mailManager.sendMessage(bundles));
    log.audit("ProjectBroker: sendEmailToGroup: identities=" + identityNames.toString() + " , mailerResult.returnCode=" + result.getReturnCode());
    return 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) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 10 with MailTemplate

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

the class ProjectBrokerMailerImpl method createProjectChangeMailTemplate.

/**
 * Create default template which fill in context 'firstname' , 'lastname' and 'username'.
 * @param subject
 * @param body
 * @return
 */
private MailTemplate createProjectChangeMailTemplate(Project project, Identity changer, String subject, String body, Locale locale) {
    final String projectTitle = project.getTitle();
    final String currentDate = Formatter.getInstance(locale).formatDateAndTime(new Date());
    final String firstnameProjectManager = changer.getUser().getProperty(UserConstants.FIRSTNAME, null);
    final String lastnameProjectManager = changer.getUser().getProperty(UserConstants.LASTNAME, null);
    final String usernameProjectManager = changer.getName();
    return new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity identity) {
            // Put variables from greater context
            context.put("projectTitle", projectTitle);
            context.put("currentDate", currentDate);
            context.put("firstnameProjectManager", firstnameProjectManager);
            context.put("lastnameProjectManager", lastnameProjectManager);
            context.put("usernameProjectManager", usernameProjectManager);
        }
    };
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) Date(java.util.Date)

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