Search in sources :

Example 61 with MailerResult

use of org.olat.core.util.mail.MailerResult 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 62 with MailerResult

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

the class ContactFormController method doSend.

private void doSend(UserRequest ureq) {
    MailerResult result;
    try {
        File[] attachments = cntctForm.getAttachments();
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        MailBundle bundle = new MailBundle();
        bundle.setContext(context);
        if (emailFrom == null) {
            // in case the user provides his own email in form
            bundle.setFrom(cntctForm.getEmailFrom());
        } else {
            bundle.setFromId(emailFrom);
        }
        bundle.setContactLists(cntctForm.getEmailToContactLists());
        bundle.setContent(cntctForm.getSubject(), cntctForm.getBody(), attachments);
        result = mailService.sendMessage(bundle);
        if (cntctForm.isTcpFrom()) {
            MailBundle ccBundle = new MailBundle();
            ccBundle.setContext(context);
            if (emailFrom == null) {
                // in case the user provides his own email in form
                ccBundle.setFrom(cntctForm.getEmailFrom());
                ccBundle.setTo(cntctForm.getEmailFrom());
            } else {
                ccBundle.setFromId(emailFrom);
                ccBundle.setCc(emailFrom);
            }
            ccBundle.setContent(cntctForm.getSubject(), cntctForm.getBody(), attachments);
            MailerResult ccResult = mailService.sendMessage(ccBundle);
            result.append(ccResult);
        }
        if (result != null) {
            if (result.isSuccessful()) {
                showInfo("msg.send.ok");
                // do logging
                ThreadLocalUserActivityLogger.log(MailLoggingAction.MAIL_SENT, getClass());
                fireEvent(ureq, Event.DONE_EVENT);
            } else {
                showError(ureq, result);
                fireEvent(ureq, Event.FAILED_EVENT);
            }
        }
    } catch (Exception e) {
        logError("", e);
        showWarning("error.msg.send.nok");
    }
    cntctForm.setDisplayOnly(true);
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailerResult(org.olat.core.util.mail.MailerResult) MailContext(org.olat.core.util.mail.MailContext) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File)

Example 63 with MailerResult

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

the class LectureServiceImpl method sendReminder.

private void sendReminder(Identity teacher, LectureBlock lectureBlock) {
    RepositoryEntry entry = lectureBlock.getEntry();
    String language = teacher.getUser().getPreferences().getLanguage();
    Locale locale = i18nManager.getLocaleOrDefault(language);
    String startDate = Formatter.getInstance(locale).formatDate(lectureBlock.getStartDate());
    MailContext context = new MailContextImpl("[RepositoryEntry:" + entry.getKey() + "]");
    String url = Settings.getServerContextPathURI() + "/url/RepositoryEntry/" + entry.getKey() + "/LectureBlock/" + lectureBlock.getKey();
    String[] args = new String[] { // {0}
    lectureBlock.getTitle(), // {1}
    startDate, // {2}
    entry.getDisplayname(), // {3}
    url, // {4}
    userManager.getUserDisplayName(teacher) };
    Translator trans = Util.createPackageTranslator(LectureAdminController.class, locale);
    String subject = trans.translate("lecture.teacher.reminder.subject", args);
    String body = trans.translate("lecture.teacher.reminder.body", args);
    LectureReminderTemplate template = new LectureReminderTemplate(subject, body);
    MailerResult result = new MailerResult();
    MailBundle bundle = mailManager.makeMailBundle(context, teacher, template, null, null, result);
    MailerResult sendResult = mailManager.sendMessage(bundle);
    result.append(sendResult);
    String status;
    List<Identity> failedIdentities = result.getFailedIdentites();
    if (failedIdentities != null && failedIdentities.contains(teacher)) {
        status = "error";
    } else {
        status = "ok";
    }
    lectureBlockReminderDao.createReminder(lectureBlock, teacher, status);
}
Also used : Locale(java.util.Locale) MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) Translator(org.olat.core.gui.translator.Translator) MailerResult(org.olat.core.util.mail.MailerResult) RepositoryEntry(org.olat.repository.RepositoryEntry) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity)

Example 64 with MailerResult

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

the class CertificatesManagerImpl method doCertificate.

private void doCertificate(JmsCertificateWork workUnit) {
    CertificateImpl certificate = getCertificateById(workUnit.getCertificateKey());
    CertificateTemplate template = null;
    if (workUnit.getTemplateKey() != null) {
        template = getTemplateById(workUnit.getTemplateKey());
    }
    OLATResource resource = certificate.getOlatResource();
    Identity identity = certificate.getIdentity();
    RepositoryEntry entry = repositoryService.loadByResourceKey(resource.getKey());
    String dir = usersStorage.generateDir();
    File dirFile = new File(getCertificateRoot(), dir);
    dirFile.mkdirs();
    Float score = workUnit.getScore();
    String lang = identity.getUser().getPreferences().getLanguage();
    Locale locale = i18nManager.getLocaleOrDefault(lang);
    Boolean passed = workUnit.getPassed();
    Date dateCertification = certificate.getCreationDate();
    Date dateFirstCertification = getDateFirstCertification(identity, resource.getKey());
    Date dateNextRecertification = certificate.getNextRecertificationDate();
    File certificateFile;
    // File name with user name
    StringBuilder sb = new StringBuilder();
    sb.append(identity.getUser().getProperty(UserConstants.LASTNAME, locale)).append("_").append(identity.getUser().getProperty(UserConstants.FIRSTNAME, locale)).append("_").append(entry.getDisplayname()).append("_").append(Formatter.formatShortDateFilesystem(dateCertification));
    String filename = FileUtils.normalizeFilename(sb.toString()) + ".pdf";
    // External URL to certificate as short as possible for QR-Code
    sb = new StringBuilder();
    sb.append(Settings.getServerContextPathURI()).append("/certificate/").append(certificate.getUuid()).append("/certificate.pdf");
    String certUrl = sb.toString();
    if (template == null || template.getPath().toLowerCase().endsWith("pdf")) {
        CertificatePDFFormWorker worker = new CertificatePDFFormWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
        certificateFile = worker.fill(template, dirFile, filename);
        if (certificateFile == null) {
            certificate.setStatus(CertificateStatus.error);
        } else {
            certificate.setStatus(CertificateStatus.ok);
        }
    } else {
        CertificatePhantomWorker worker = new CertificatePhantomWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
        certificateFile = worker.fill(template, dirFile, filename);
        if (certificateFile == null) {
            certificate.setStatus(CertificateStatus.error);
        } else {
            certificate.setStatus(CertificateStatus.ok);
        }
    }
    certificate.setPath(dir + certificateFile.getName());
    if (dateFirstCertification != null) {
        // not the first certification, reset the last of the others certificates
        removeLastFlag(identity, resource.getKey());
    }
    MailerResult result = sendCertificate(identity, entry, certificateFile);
    if (result.isSuccessful()) {
        certificate.setEmailStatus(EmailStatus.ok);
    } else {
        certificate.setEmailStatus(EmailStatus.error);
    }
    dbInstance.getCurrentEntityManager().merge(certificate);
    dbInstance.commit();
    CertificateEvent event = new CertificateEvent(identity.getKey(), certificate.getKey(), resource.getKey());
    coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(event, ORES_CERTIFICATE_EVENT);
}
Also used : Locale(java.util.Locale) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) MailerResult(org.olat.core.util.mail.MailerResult) OLATResource(org.olat.resource.OLATResource) CertificateImpl(org.olat.course.certificate.model.CertificateImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) CertificateEvent(org.olat.course.certificate.CertificateEvent) Identity(org.olat.core.id.Identity) TransientIdentity(org.olat.admin.user.imp.TransientIdentity) File(java.io.File)

Example 65 with MailerResult

use of org.olat.core.util.mail.MailerResult 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

MailerResult (org.olat.core.util.mail.MailerResult)140 MailBundle (org.olat.core.util.mail.MailBundle)100 Identity (org.olat.core.id.Identity)82 MailContext (org.olat.core.util.mail.MailContext)66 MailContextImpl (org.olat.core.util.mail.MailContextImpl)66 MailTemplate (org.olat.core.util.mail.MailTemplate)46 Test (org.junit.Test)26 File (java.io.File)24 ArrayList (java.util.ArrayList)20 ContactList (org.olat.core.util.mail.ContactList)20 Locale (java.util.Locale)16 Translator (org.olat.core.gui.translator.Translator)16 VelocityContext (org.apache.velocity.VelocityContext)14 DBMailLight (org.olat.core.util.mail.model.DBMailLight)14 Date (java.util.Date)12 MailPackage (org.olat.core.util.mail.MailPackage)12 List (java.util.List)8 User (org.olat.core.id.User)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 Property (org.olat.properties.Property)7