Search in sources :

Example 51 with MailContextImpl

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

the class ProjectBrokerMailerImpl method sendEmail.

// ////////////////
// Private Methods
// ////////////////
private MailerResult sendEmail(Identity enrolledIdentity, Project project, String subject, String body, Locale locale) {
    MailTemplate enrolledMailTemplate = createMailTemplate(project, enrolledIdentity, subject, body, locale);
    MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
    MailerResult result = new MailerResult();
    MailBundle bundle = mailManager.makeMailBundle(context, enrolledIdentity, enrolledMailTemplate, null, null, result);
    if (bundle != null) {
        mailManager.sendMessage(bundle);
    }
    log.audit("ProjectBroker: sendEmail to identity.name=" + enrolledIdentity.getName() + " , 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) MailBundle(org.olat.core.util.mail.MailBundle)

Example 52 with MailContextImpl

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

the class DENManageParticipantsController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableListParticipants) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent tableEvent = (TableEvent) event;
            // open window for choosen date to manage the enrolled users or manually add
            if (tableEvent.getActionId().equals(DENListTableDataModel.CHANGE_ACTION)) {
                selectedEvent = listTableData.getObject(tableEvent.getRowId());
                List<Identity> participants = denManager.getEventParticipants(selectedEvent);
                participantsTableData = new DENParticipantsTableDataModel(participants);
                removeAsListenerAndDispose(tableManageParticipants);
                tableManageParticipants = denManager.createParticipantsTable(ureq, getWindowControl(), getTranslator(), participantsTableData);
                listenTo(tableManageParticipants);
                participantsVC = createVelocityContainer("participants");
                DateFormat df = new SimpleDateFormat();
                participantsVC.contextPut("dateTitle", selectedEvent.getSubject());
                participantsVC.contextPut("dateTimeframe", df.format(selectedEvent.getBegin()) + " - " + df.format(selectedEvent.getEnd()));
                participantsVC.put("participantsTable", tableManageParticipants.getInitialComponent());
                addParticipantButton = LinkFactory.createButton("participants.add", participantsVC, this);
                removeAsListenerAndDispose(manageParticipantsModalCntrl);
                manageParticipantsModalCntrl = new CloseableModalController(getWindowControl(), "close", participantsVC, true, translate("dates.table.participant.manage"));
                listenTo(manageParticipantsModalCntrl);
                manageParticipantsModalCntrl.activate();
            }
        } else {
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            BitSet selection = tmse.getSelection();
            // delete all users from the selected dates
            if (tmse.getAction().equals(DENListTableDataModel.DELETE_ACTION) && selection.cardinality() > 0) {
                selectedIds = denManager.getSelectedEventParticipants(dateList, selection);
                dateList = denManager.deleteParticipants(ores, courseNode, denManager.getSelectedEventIDs(dateList, selection));
                listTableData.setObjects(dateList);
                // send notification mail
                createNotificationMail(ureq, courseNode.getShortTitle(), REMOVE_ACTION);
            } else if (tmse.getAction().equals(DENListTableDataModel.MAIL_ACTION) && selection.cardinality() > 0) {
                // send email to all users from the selected dates
                List<Identity> participants = denManager.getSelectedEventParticipants(dateList, selection);
                createParticipantsMail(ureq, participants);
            } else if (selection.cardinality() == 0) {
                showWarning("participants.message.empty");
            }
        }
    } else if (source == userSearchCntrl) {
        if (event == Event.CANCELLED_EVENT) {
            userSearchCMC.deactivate();
        } else {
            List<Identity> toAdd = null;
            selectedIds = new ArrayList<Identity>();
            if (event instanceof SingleIdentityChosenEvent) {
                SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event;
                Identity choosenIdentity = singleEvent.getChosenIdentity();
                toAdd = new ArrayList<Identity>();
                toAdd.add(choosenIdentity);
            } else if (event instanceof MultiIdentityChosenEvent) {
                MultiIdentityChosenEvent multiEvent = (MultiIdentityChosenEvent) event;
                toAdd = multiEvent.getChosenIdentities();
            }
            boolean showMessage = false;
            if (toAdd != null && toAdd.size() > 0) {
                for (Identity identity : toAdd) {
                    status = denManager.doEnroll(identity, selectedEvent, ores, courseNode, true);
                    if (!status.isEnrolled() && status.getErrorMessage().equals(DENStatus.ERROR_ALREADY_ENROLLED))
                        showMessage = true;
                    else
                        selectedIds.add(identity);
                }
                if (showMessage)
                    showWarning("enrollment.warning.manual");
                refreshTables();
            }
            userSearchCMC.deactivate();
            if (selectedIds.size() > 0) {
                // write notification mail
                createNotificationMail(ureq, selectedEvent.getSubject(), ADD_ACTION);
            }
        }
    } else if (source == tableManageParticipants) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent tableEvent = (TableEvent) event;
            // delete single user from event
            if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.REMOVE_ACTION)) {
                Identity identity = participantsTableData.getEntryAt(tableEvent.getRowId());
                status = denManager.cancelEnroll(identity, selectedEvent, ores);
                if (!status.isCancelled())
                    showError();
                else // send notification mail
                {
                    selectedIds.clear();
                    selectedIds.add(identity);
                    createNotificationMail(ureq, selectedEvent.getSubject(), REMOVE_ACTION);
                }
                refreshTables();
            // write email to single user
            } else if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.MAIL_ACTION)) {
                List<Identity> participants = new ArrayList<Identity>();
                participants.add(participantsTableData.getEntryAt(tableEvent.getRowId()));
                createParticipantsMail(ureq, participants);
            }
        }
    } else if (source == notificationCtr && event == Event.DONE_EVENT) {
        if (notificationCtr.getMailTemplate() != null) {
            Identity sender = ureq.getIdentity();
            MailerResult result = new MailerResult();
            String metaId = UUID.randomUUID().toString().replace("-", "");
            MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
            MailBundle[] bundles = mailManager.makeMailBundles(context, selectedIds, notificationCtr.getMailTemplate(), sender, metaId, result);
            result.append(mailManager.sendMessage(bundles));
            if (notificationCtr.getMailTemplate().getCpfrom()) {
                MailBundle ccBundles = mailManager.makeMailBundle(context, sender, notificationCtr.getMailTemplate(), sender, metaId, result);
                result.append(mailManager.sendMessage(ccBundles));
            }
            MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
        }
        notificationCmc.deactivate();
        selectedIds.clear();
    } else if (source == contactCtr) {
        notificationCmc.deactivate();
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailerResult(org.olat.core.util.mail.MailerResult) MailContext(org.olat.core.util.mail.MailContext) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) TableEvent(org.olat.core.gui.components.table.TableEvent) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) ArrayList(java.util.ArrayList) ContactList(org.olat.core.util.mail.ContactList) List(java.util.List) Identity(org.olat.core.id.Identity) MultiIdentityChosenEvent(org.olat.basesecurity.events.MultiIdentityChosenEvent) MailBundle(org.olat.core.util.mail.MailBundle) SimpleDateFormat(java.text.SimpleDateFormat)

Example 53 with MailContextImpl

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

the class GroupController method doAddIdentitiesToGroup.

/**
 * Add users from the identites array to the group if they are not guest users
 * and not already in the group
 *
 * @param ureq
 * @param choosenIdentities
 */
private void doAddIdentitiesToGroup(UserRequest ureq, List<Identity> choosenIdentities, MailTemplate mailTemplate) {
    // additional security check
    if (!mayModifyMembers)
        throw new AssertException("not allowed to add member!");
    IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(choosenIdentities);
    // process workflow to BusinessGroupManager via BusinessGroupEditController
    fireEvent(ureq, identitiesAddedEvent);
    if (!identitiesAddedEvent.getAddedIdentities().isEmpty()) {
        // update table model
        reloadData();
    }
    // build info message for identities which could be added.
    StringBuilder infoMessage = new StringBuilder();
    for (Identity identity : identitiesAddedEvent.getIdentitiesWithoutPermission()) {
        infoMessage.append(translate("msg.isingroupanonymous", userManager.getUserDisplayName(identity))).append("<br />");
    }
    for (Identity identity : identitiesAddedEvent.getIdentitiesAlreadyInGroup()) {
        infoMessage.append(translate("msg.subjectalreadyingroup", userManager.getUserDisplayName(identity))).append("<br />");
    }
    // send the notification mail fro added users
    StringBuilder errorMessage = new StringBuilder();
    if (mailTemplate != null) {
        // means no sender in footer
        Identity sender = null;
        if (showSenderInAddMailFooter) {
            sender = ureq.getIdentity();
        }
        String metaId = UUID.randomUUID().toString();
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        MailerResult result = new MailerResult();
        MailBundle[] bundles = mailManager.makeMailBundles(context, identitiesAddedEvent.getAddedIdentities(), mailTemplate, sender, metaId, result);
        result.append(mailManager.sendMessage(bundles));
        if (mailTemplate.getCpfrom()) {
            MailBundle ccBundle = mailManager.makeMailBundle(context, ureq.getIdentity(), mailTemplate, sender, metaId, result);
            result.append(mailManager.sendMessage(ccBundle));
        }
        MailHelper.appendErrorsAndWarnings(result, errorMessage, infoMessage, ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
    }
    // report any errors on screen
    if (infoMessage.length() > 0)
        getWindowControl().setWarning(infoMessage.toString());
    if (errorMessage.length() > 0)
        getWindowControl().setError(errorMessage.toString());
}
Also used : AssertException(org.olat.core.logging.AssertException) MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 54 with MailContextImpl

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

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)

Example 55 with MailContextImpl

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

the class IQEditReplaceWizard method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == mailCtr && event == Event.DONE_EVENT) {
        MailTemplate mailTemplate = mailCtr.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, learners, mailTemplate, getIdentity(), metaId, result);
            result.append(mailManager.sendMessage(bundles));
            if (mailTemplate.getCpfrom()) {
                MailBundle ccBundle = mailManager.makeMailBundle(context, getIdentity(), mailTemplate, getIdentity(), metaId, result);
                result.append(mailManager.sendMessage(ccBundle));
            }
        }
        fireEvent(ureq, Event.DONE_EVENT);
    } else if (source == searchCtr && event == ReferencableEntriesSearchController.EVENT_REPOSITORY_ENTRY_SELECTED) {
        selectedRepositoryEntry = searchCtr.getSelectedEntry();
        doStep2(ureq);
    }
}
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)

Aggregations

MailBundle (org.olat.core.util.mail.MailBundle)72 MailContextImpl (org.olat.core.util.mail.MailContextImpl)72 MailContext (org.olat.core.util.mail.MailContext)70 MailerResult (org.olat.core.util.mail.MailerResult)66 Identity (org.olat.core.id.Identity)44 MailTemplate (org.olat.core.util.mail.MailTemplate)30 ContactList (org.olat.core.util.mail.ContactList)20 File (java.io.File)14 ArrayList (java.util.ArrayList)8 Locale (java.util.Locale)8 MailManager (org.olat.core.util.mail.MailManager)8 Translator (org.olat.core.gui.translator.Translator)7 Property (org.olat.properties.Property)7 ContextEntry (org.olat.core.id.context.ContextEntry)6 HashSet (java.util.HashSet)4 List (java.util.List)4 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)4 IdentitiesRemoveEvent (org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)4 AssertException (org.olat.core.logging.AssertException)4