use of org.olat.core.util.mail.model.DBMailLight in project openolat by klemens.
the class MailDataModel method getValueAt.
@Override
public Object getValueAt(int row, int col) {
DBMailLight mail = filteredMails == null ? mails.get(row) : filteredMails.get(row);
Columns[] cols = Columns.values();
if (col < cols.length) {
switch(cols[col]) {
case read:
{
for (DBMailRecipient recipient : mail.getRecipients()) {
if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
return recipient.getRead();
}
}
return Boolean.FALSE;
}
case marked:
{
for (DBMailRecipient recipient : mail.getRecipients()) {
if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
return recipient.getMarked();
}
}
return Boolean.FALSE;
}
case context:
{
String businessPath = mail.getContext().getBusinessPath();
if (StringHelper.containsNonWhitespace(businessPath)) {
String contextName = bpToContexts.get(businessPath);
if (StringHelper.containsNonWhitespace(businessPath) && StringHelper.containsNonWhitespace(contextName)) {
return new ContextPair(contextName, businessPath);
}
}
return null;
}
case subject:
return mail.getSubject();
case receivedDate:
case sendDate:
{
return mail.getCreationDate();
}
case from:
{
DBMailRecipient from = mail.getFrom();
if (from != null) {
if (from.getRecipient() != null) {
return from.getRecipient();
} else if (StringHelper.containsNonWhitespace(from.getGroup())) {
return from.getGroup();
} else {
return UserManager.getInstance().getUserDisplayEmail(from.getEmailAddress(), translator.getLocale());
}
}
return "-";
}
case recipients:
{
if (StringHelper.containsNonWhitespace(mail.getMetaId())) {
return translator.translate("mail.from.miscellaneous");
}
StringBuilder sb = new StringBuilder();
Set<String> groupSet = new HashSet<>();
for (DBMailRecipient recipient : mail.getRecipients()) {
if (recipient != null && recipient.getGroup() != null) {
String group = recipient.getGroup();
if (!groupSet.contains(group)) {
if (sb.length() > 0)
sb.append(", ");
sb.append(group);
groupSet.add(group);
}
}
}
return sb.toString();
}
}
}
return mail;
}
use of org.olat.core.util.mail.model.DBMailLight in project OpenOLAT by OpenOLAT.
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());
}
use of org.olat.core.util.mail.model.DBMailLight in project OpenOLAT by OpenOLAT.
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());
}
use of org.olat.core.util.mail.model.DBMailLight 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());
}
use of org.olat.core.util.mail.model.DBMailLight 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());
}
Aggregations