Search in sources :

Example 91 with MailerResult

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

the class MailManagerTest method testGetOutbox.

@Test
public void testGetOutbox() {
    // send a mail
    Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-5-" + UUID.randomUUID().toString());
    Identity toId = JunitTestHelper.createAndPersistIdentityAsUser("mail-6-" + UUID.randomUUID().toString());
    MailBundle bundle = new MailBundle();
    bundle.setFromId(fromId);
    bundle.setToId(toId);
    bundle.setContent("Hello outbox", "Content of outbox");
    MailerResult result = mailManager.sendMessage(bundle);
    Assert.assertNotNull(result);
    Assert.assertEquals(MailerResult.OK, result.getReturnCode());
    dbInstance.commitAndCloseSession();
    // retrieve the outbox of toId (with lazy loading)
    List<DBMailLight> sendedMails = mailManager.getOutbox(fromId, 0, -1, false);
    Assert.assertNotNull(sendedMails);
    Assert.assertEquals(1, sendedMails.size());
    DBMailLight sendedMail = sendedMails.get(0);
    Assert.assertNotNull(sendedMail);
    Assert.assertEquals("Hello outbox", sendedMail.getSubject());
    dbInstance.commitAndCloseSession();
    // retrieve the outbox of toId (with fetch)
    List<DBMailLight> sendedMailsWithFetch = mailManager.getOutbox(fromId, 0, -1, true);
    Assert.assertNotNull(sendedMailsWithFetch);
    Assert.assertEquals(1, sendedMailsWithFetch.size());
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 92 with MailerResult

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

the class MailManagerTest method testGetInbox.

@Test
public void testGetInbox() {
    // send a mail
    Identity fromId = JunitTestHelper.createAndPersistIdentityAsRndUser("mail-3");
    Identity toId = JunitTestHelper.createAndPersistIdentityAsRndUser("mail-4");
    MailBundle bundle = new MailBundle();
    bundle.setFromId(fromId);
    bundle.setToId(toId);
    bundle.setContent("Hello inbox", "Content of inbox");
    MailerResult result = mailManager.sendMessage(bundle);
    Assert.assertNotNull(result);
    Assert.assertEquals(MailerResult.OK, result.getReturnCode());
    dbInstance.commitAndCloseSession();
    // retrieve the inbox of toId
    List<DBMailLight> incomingMails = mailManager.getInbox(toId, Boolean.TRUE, Boolean.TRUE, null, 0, -1);
    Assert.assertNotNull(incomingMails);
    Assert.assertEquals(1, incomingMails.size());
    DBMailLight incomingMail = incomingMails.get(0);
    Assert.assertNotNull(incomingMail);
    Assert.assertEquals("Hello inbox", incomingMail.getSubject());
}
Also used : MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 93 with MailerResult

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

the class MailManagerTest method testDeleteUserData_groupedMail.

@Test
public void testDeleteUserData_groupedMail() {
    // send a mail to three ids
    String metaId = UUID.randomUUID().toString();
    Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-7-" + UUID.randomUUID().toString());
    Identity toId_1 = JunitTestHelper.createAndPersistIdentityAsUser("mail-8-" + UUID.randomUUID().toString());
    Identity toId_2 = JunitTestHelper.createAndPersistIdentityAsUser("mail-9-" + UUID.randomUUID().toString());
    Identity toId_3 = JunitTestHelper.createAndPersistIdentityAsUser("mail-10-" + UUID.randomUUID().toString());
    ContactList ccs = new ContactList("unit-test-cc");
    ccs.add(toId_1);
    ccs.add(toId_2);
    ccs.add(toId_3);
    ccs.add(fromId);
    MailBundle bundle = new MailBundle();
    bundle.setFromId(fromId);
    bundle.setContactList(ccs);
    bundle.setMetaId(metaId);
    bundle.setContent("Hello delList", "Content of delList");
    MailerResult result = mailManager.sendMessage(bundle);
    Assert.assertNotNull(result);
    Assert.assertEquals(MailerResult.OK, result.getReturnCode());
    dbInstance.commitAndCloseSession();
    // delete the 4 users datas
    mailBoxExtension.deleteUserData(toId_1, "lalala", null);
    mailBoxExtension.deleteUserData(toId_2, "lalala", null);
    mailBoxExtension.deleteUserData(toId_3, "lalala", null);
    mailBoxExtension.deleteUserData(fromId, "lalala", null);
    dbInstance.commitAndCloseSession();
    // check inbox / outbox
    List<DBMailLight> deletedMails_1 = mailManager.getInbox(toId_1, null, null, null, 0, -1);
    Assert.assertNotNull(deletedMails_1);
    Assert.assertTrue(deletedMails_1.isEmpty());
    List<DBMailLight> deletedMails_2 = mailManager.getInbox(toId_2, null, null, null, 0, -1);
    Assert.assertNotNull(deletedMails_2);
    Assert.assertTrue(deletedMails_2.isEmpty());
    List<DBMailLight> deletedMails_3 = mailManager.getInbox(toId_3, null, null, null, 0, -1);
    Assert.assertNotNull(deletedMails_3);
    Assert.assertTrue(deletedMails_3.isEmpty());
    List<DBMailLight> deletedMails_4 = mailManager.getOutbox(fromId, 0, -1, true);
    Assert.assertNotNull(deletedMails_4);
    Assert.assertTrue(deletedMails_4.isEmpty());
    // check mail by meta id
    List<DBMailLight> deletedMails = mailManager.getEmailsByMetaId(metaId);
    Assert.assertNotNull(deletedMails);
    Assert.assertTrue(deletedMails.isEmpty());
}
Also used : 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) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Test(org.junit.Test)

Example 94 with MailerResult

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

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

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