Search in sources :

Example 41 with MailTemplate

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

the class EnrollmentManager method doCancelEnrollmentInWaitingList.

public void doCancelEnrollmentInWaitingList(final Identity identity, final BusinessGroup enrolledWaitingListGroup, final ENCourseNode enNode, final CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
    // 1. Remove group membership, fire events, do loggin etc.
    businessGroupService.removeFromWaitingList(identity, Collections.singletonList(identity), enrolledWaitingListGroup, null);
    // 2. Remove enrollmentdate property
    // only remove last time date, not firsttime
    Property lastTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_WAITINGLIST_DATE);
    if (lastTime != null) {
        coursePropertyManager.deleteProperty(lastTime);
    }
    // 3. Send notification mail
    MailTemplate mailTemplate = BGMailHelper.createRemoveWaitinglistMailTemplate(enrolledWaitingListGroup, 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());
}
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 42 with MailTemplate

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

the class EnrollmentManager method addUserToParticipantList.

// /////////////////
// Private Methods
// /////////////////
private boolean addUserToParticipantList(Identity identity, BusinessGroup group, ENCourseNode enNode, CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
    // 2. Set first enrollment date
    String nowString = Long.toString(System.currentTimeMillis());
    Property firstTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_ENROLLMENT_DATE);
    if (firstTime == null) {
        // create firsttime
        firstTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_ENROLLMENT_DATE, null, null, nowString, null);
        coursePropertyManager.saveProperty(firstTime);
    }
    // 3. Set enrollmentdate property
    Property thisTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_ENROLLMENT_DATE);
    if (thisTime == null) {
        // create firsttime
        thisTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_ENROLLMENT_DATE, null, null, nowString, null);
        coursePropertyManager.saveProperty(thisTime);
    } else {
        thisTime.setStringValue(nowString);
        coursePropertyManager.updateProperty(thisTime);
    }
    // 4. Send notification mail
    MailTemplate mailTemplate = BGMailHelper.createAddMyselfMailTemplate(group, identity);
    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 43 with MailTemplate

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

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 44 with MailTemplate

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

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 45 with MailTemplate

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

the class GTAParticipantController method doSubmissionEmail.

private void doSubmissionEmail() {
    String body = config.getStringValue(GTACourseNode.GTASK_SUBMISSION_TEXT);
    if (StringHelper.containsNonWhitespace(body)) {
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        List<Identity> recipientsTO;
        File submitDirectory;
        if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
            recipientsTO = businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());
            submitDirectory = gtaManager.getSubmitDirectory(courseEnv, gtaNode, assessedGroup);
        } else {
            recipientsTO = Collections.singletonList(assessedIdentity);
            submitDirectory = gtaManager.getSubmitDirectory(courseEnv, gtaNode, assessedIdentity);
        }
        String subject = translate("submission.mail.subject");
        File[] files = TaskHelper.getDocuments(submitDirectory);
        MailTemplate template = new GTAMailTemplate(subject, body, files, getIdentity(), getTranslator());
        MailerResult result = new MailerResult();
        MailBundle[] bundles = mailManager.makeMailBundles(context, recipientsTO, template, null, UUID.randomUUID().toString(), result);
        mailManager.sendMessage(bundles);
    }
}
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) File(java.io.File)

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