Search in sources :

Example 6 with DBMailLight

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

the class MailManagerTest method testGetEmailByMetaId.

@Test
public void testGetEmailByMetaId() {
    // send a mail
    String metaId = UUID.randomUUID().toString();
    Identity fromId = JunitTestHelper.createAndPersistIdentityAsUser("mail-5-" + UUID.randomUUID().toString());
    Identity toId = JunitTestHelper.createAndPersistIdentityAsUser("mail-6-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    MailBundle bundle = new MailBundle();
    bundle.setFromId(fromId);
    bundle.setToId(toId);
    bundle.setMetaId(metaId);
    bundle.setContent("Hello meta ID", "Meta ID");
    MailerResult result = mailManager.sendMessage(bundle);
    Assert.assertNotNull(result);
    Assert.assertEquals(MailerResult.OK, result.getReturnCode());
    dbInstance.commitAndCloseSession();
    // retrieve the inbox of toId
    List<DBMailLight> mails = mailManager.getEmailsByMetaId(metaId);
    Assert.assertNotNull(mails);
    Assert.assertEquals(1, mails.size());
    DBMailLight mail = mails.get(0);
    Assert.assertNotNull(mail);
    Assert.assertEquals("Hello meta ID", mail.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 7 with DBMailLight

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

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 8 with DBMailLight

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

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 9 with DBMailLight

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

the class MailManagerTest method testDeleteUserData_separatedMail.

@Test
public void testDeleteUserData_separatedMail() {
    // send a mail as separated e-mails 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());
    MailBundle bundle_1 = new MailBundle();
    bundle_1.setFromId(fromId);
    bundle_1.setToId(toId_1);
    bundle_1.setMetaId(metaId);
    bundle_1.setContent("Hello ccList", "Content of ccList");
    MailerResult result1 = mailManager.sendMessage(bundle_1);
    Assert.assertNotNull(result1);
    Assert.assertEquals(MailerResult.OK, result1.getReturnCode());
    MailBundle bundle_2 = new MailBundle();
    bundle_2.setFromId(fromId);
    bundle_2.setToId(toId_2);
    bundle_2.setMetaId(metaId);
    bundle_2.setContent("Hello ccList", "Content of ccList");
    MailerResult result2 = mailManager.sendMessage(bundle_2);
    Assert.assertNotNull(result2);
    Assert.assertEquals(MailerResult.OK, result2.getReturnCode());
    MailBundle bundle_3 = new MailBundle();
    bundle_3.setFromId(fromId);
    bundle_3.setToId(toId_3);
    bundle_3.setMetaId(metaId);
    bundle_3.setContent("Hello ccList", "Content of ccList");
    MailerResult result3 = mailManager.sendMessage(bundle_3);
    Assert.assertNotNull(result3);
    Assert.assertEquals(MailerResult.OK, result3.getReturnCode());
    dbInstance.commitAndCloseSession();
    // delete the 4 users datas
    mailBoxExtension.deleteUserData(fromId, "lalala", null);
    mailBoxExtension.deleteUserData(toId_1, "lalala", null);
    mailBoxExtension.deleteUserData(toId_2, "lalala", null);
    mailBoxExtension.deleteUserData(toId_3, "lalala", null);
    dbInstance.commitAndCloseSession();
    // 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) 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 10 with DBMailLight

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

the class MailListController method reloadModel.

private void reloadModel() {
    List<DBMailLight> mails;
    if (outbox) {
        if (StringHelper.containsNonWhitespace(metaId)) {
            mails = mailManager.getEmailsByMetaId(metaId);
        } else {
            mails = mailManager.getOutbox(getIdentity(), 0, -1, true);
        }
        // strip meta emails
        Set<String> metaIds = new HashSet<>();
        for (Iterator<DBMailLight> it = mails.iterator(); it.hasNext(); ) {
            DBMailLight mail = it.next();
            if (StringHelper.containsNonWhitespace(mail.getMetaId())) {
                if (metaIds.contains(mail.getMetaId())) {
                    it.remove();
                } else {
                    metaIds.add(mail.getMetaId());
                }
            }
        }
    } else {
        mails = mailManager.getInbox(getIdentity(), null, Boolean.TRUE, null, 0, -1);
    }
    // extract contexts
    Map<String, String> bpToContexts = new HashMap<>();
    for (DBMailLight mail : mails) {
        String businessPath = mail.getContext().getBusinessPath();
        if (StringHelper.containsNonWhitespace(businessPath) && !bpToContexts.containsKey(businessPath)) {
            String contextName = contextResolver.getName(businessPath, getLocale());
            if (StringHelper.containsNonWhitespace(contextName)) {
                bpToContexts.put(businessPath, contextName);
            }
        }
    }
    if (!bpToContexts.isEmpty()) {
        List<ShortName> filters = new ArrayList<>();
        Map<String, MailContextShortName> uniqueNames = new HashMap<>();
        ShortName allContextFilter = new MailContextShortName("-");
        filters.add(allContextFilter);
        for (Map.Entry<String, String> entry : bpToContexts.entrySet()) {
            String businessPath = entry.getKey();
            String contextName = entry.getValue();
            if (!uniqueNames.containsKey(contextName)) {
                MailContextShortName cxt = new MailContextShortName(contextName, new HashSet<String>());
                filters.add(cxt);
                uniqueNames.put(contextName, cxt);
            }
            uniqueNames.get(contextName).getBusinessPaths().add(businessPath);
        }
        tableCtr.setFilters(filters, allContextFilter);
    }
    Formatter formatter = Formatter.getInstance(getLocale());
    MailDataModel dataModel = new MailDataModel(mails, bpToContexts, getIdentity(), getTranslator(), formatter, outbox);
    tableCtr.setTableDataModel(dataModel);
}
Also used : HashMap(java.util.HashMap) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList) ShortName(org.olat.core.gui.ShortName) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

DBMailLight (org.olat.core.util.mail.model.DBMailLight)22 MailerResult (org.olat.core.util.mail.MailerResult)14 Test (org.junit.Test)12 Identity (org.olat.core.id.Identity)12 MailBundle (org.olat.core.util.mail.MailBundle)12 HashSet (java.util.HashSet)6 ContactList (org.olat.core.util.mail.ContactList)4 DBMailRecipient (org.olat.core.util.mail.model.DBMailRecipient)4 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 Publisher (org.olat.core.commons.services.notifications.Publisher)2 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)2 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)2 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)2 ShortName (org.olat.core.gui.ShortName)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2