Search in sources :

Example 21 with MailBundle

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

the class SendMailController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    ContactList contactList = new ContactList("");
    Collection<String> roleList = contactEl.getSelectedKeys();
    String[] roles = roleList.toArray(new String[roleList.size()]);
    List<Identity> identities = repositoryService.getMembers(repoEntries, RepositoryEntryRelationType.both, roles);
    if (identities.isEmpty()) {
        showWarning("error.contact.to.empty");
    } else {
        Set<Identity> deduplicates = new HashSet<>(identities);
        contactList.addAllIdentites(deduplicates);
        boolean success = false;
        try {
            File[] attachmentArr = getAttachments();
            MailContext context = null;
            if (repoEntries.size() == 1) {
                context = new MailContextImpl("[RepositoryEntry:" + repoEntries.get(0).getKey() + "]");
            }
            MailBundle bundle = new MailBundle();
            bundle.setContext(context);
            bundle.setFromId(getIdentity());
            bundle.setContactLists(Collections.singletonList(contactList));
            bundle.setContent(subjectEl.getValue(), bodyEl.getValue(), attachmentArr);
            MailerResult result = mailService.sendMessage(bundle);
            if (copyFromEl.isAtLeastSelected(1)) {
                MailBundle ccBundle = new MailBundle();
                ccBundle.setContext(context);
                ccBundle.setFromId(getIdentity());
                ccBundle.setCc(getIdentity());
                ccBundle.setContent(subjectEl.getValue(), bodyEl.getValue(), attachmentArr);
                MailerResult ccResult = mailService.sendMessage(ccBundle);
                result.append(ccResult);
            }
            success = result.isSuccessful();
        } catch (Exception e) {
            // error in recipient email address(es)
            handleAddressException(success);
        }
        if (success) {
            showInfo("msg.send.ok");
            // do logging
            ThreadLocalUserActivityLogger.log(MailLoggingAction.MAIL_SENT, getClass());
            fireEvent(ureq, Event.DONE_EVENT);
        } else {
            showInfo("error.msg.send.nok");
            fireEvent(ureq, Event.FAILED_EVENT);
        }
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File) HashSet(java.util.HashSet)

Example 22 with MailBundle

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

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 23 with MailBundle

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

the class EnrollmentManager method doCancelEnrollment.

public void doCancelEnrollment(final Identity identity, final BusinessGroup enrolledGroup, final ENCourseNode enNode, final CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
    if (isLogDebugEnabled())
        logDebug("doCancelEnrollment");
    // 1. Remove group membership, fire events, do loggin etc.
    // Remove participant. This will also check if a waiting-list with auto-close-ranks is configurated
    // and move the users accordingly
    MailPackage doNotSendmailPackage = new MailPackage(false);
    businessGroupService.removeParticipants(identity, Collections.singletonList(identity), enrolledGroup, doNotSendmailPackage);
    logInfo(" doCancelEnrollment in group " + enrolledGroup, identity.getName());
    logInfo(" doCancelEnrollment in group " + enrolledGroup, identity.getName());
    // 2. Remove enrollmentdate property
    // only remove last time date, not firsttime
    Property lastTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_ENROLLMENT_DATE);
    if (lastTime != null) {
        coursePropertyManager.deleteProperty(lastTime);
    }
    // 3. Send notification mail
    MailTemplate mailTemplate = BGMailHelper.createRemoveMyselfMailTemplate(enrolledGroup, 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) MailPackage(org.olat.core.util.mail.MailPackage) 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 24 with MailBundle

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

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 25 with MailBundle

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

Aggregations

MailBundle (org.olat.core.util.mail.MailBundle)126 MailerResult (org.olat.core.util.mail.MailerResult)100 Identity (org.olat.core.id.Identity)72 MailContextImpl (org.olat.core.util.mail.MailContextImpl)72 MailContext (org.olat.core.util.mail.MailContext)70 MailTemplate (org.olat.core.util.mail.MailTemplate)32 Translator (org.olat.core.gui.translator.Translator)28 ContactList (org.olat.core.util.mail.ContactList)28 Locale (java.util.Locale)20 File (java.io.File)18 Date (java.util.Date)16 Test (org.junit.Test)14 MailManager (org.olat.core.util.mail.MailManager)14 DBMailLight (org.olat.core.util.mail.model.DBMailLight)12 ArrayList (java.util.ArrayList)10 Property (org.olat.properties.Property)7 ContextEntry (org.olat.core.id.context.ContextEntry)6 AssertException (org.olat.core.logging.AssertException)6 TemporaryKey (org.olat.registration.TemporaryKey)6 UserManager (org.olat.user.UserManager)6