use of org.olat.core.util.mail.model.DBMailRecipient in project OpenOLAT by OpenOLAT.
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.DBMailRecipient in project openolat by klemens.
the class MailManagerImpl method deleteMail.
private void deleteMail(DBMailLight mail, Identity identity, boolean forceRemoveRecipient) {
boolean delete = true;
List<DBMailRecipient> updates = new ArrayList<DBMailRecipient>();
if (mail.getFrom() != null && mail.getFrom().getRecipient() != null) {
if (identity.equalsByPersistableKey(mail.getFrom().getRecipient())) {
DBMailRecipient from = mail.getFrom();
from.setDeleted(Boolean.TRUE);
if (forceRemoveRecipient) {
from.setRecipient(null);
}
updates.add(from);
}
if (mail.getFrom().getDeleted() != null) {
delete &= mail.getFrom().getDeleted().booleanValue();
}
}
for (DBMailRecipient recipient : mail.getRecipients()) {
if (recipient == null)
continue;
if (recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
recipient.setDeleted(Boolean.TRUE);
if (forceRemoveRecipient) {
recipient.setRecipient(null);
}
updates.add(recipient);
}
if (recipient.getDeleted() != null) {
delete &= recipient.getDeleted().booleanValue();
}
}
if (delete) {
Set<String> paths = new HashSet<String>();
// all marked as deleted -> delete the mail
List<DBMailAttachment> attachments = getAttachments(mail);
for (DBMailAttachment attachment : attachments) {
// reload from the hibernate session
mail = attachment.getMail();
dbInstance.deleteObject(attachment);
if (StringHelper.containsNonWhitespace(attachment.getPath())) {
paths.add(attachment.getPath());
}
}
dbInstance.deleteObject(mail);
// try to remove orphans file
for (String path : paths) {
int count = countAttachment(path);
if (count == 0) {
VFSItem item = mailModule.getRootForAttachments().resolve(path);
if (item instanceof VFSLeaf) {
((VFSLeaf) item).delete();
}
}
}
} else {
for (DBMailRecipient update : updates) {
dbInstance.updateObject(update);
}
}
}
use of org.olat.core.util.mail.model.DBMailRecipient in project openolat by klemens.
the class MailManagerImpl method toggleMarked.
@Override
public DBMailLight toggleMarked(DBMailLight mail, Identity identity) {
Boolean marked = null;
for (DBMailRecipient recipient : mail.getRecipients()) {
if (recipient == null)
continue;
if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
if (marked == null) {
marked = recipient.getMarked() == null ? Boolean.FALSE : recipient.getMarked();
}
recipient.setMarked(marked.booleanValue() ? Boolean.FALSE : Boolean.TRUE);
dbInstance.updateObject(recipient);
}
}
return mail;
}
use of org.olat.core.util.mail.model.DBMailRecipient 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.DBMailRecipient in project OpenOLAT by OpenOLAT.
the class MailManagerImpl method toggleMarked.
@Override
public DBMailLight toggleMarked(DBMailLight mail, Identity identity) {
Boolean marked = null;
for (DBMailRecipient recipient : mail.getRecipients()) {
if (recipient == null)
continue;
if (recipient != null && recipient.getRecipient() != null && recipient.getRecipient().equalsByPersistableKey(identity)) {
if (marked == null) {
marked = recipient.getMarked() == null ? Boolean.FALSE : recipient.getMarked();
}
recipient.setMarked(marked.booleanValue() ? Boolean.FALSE : Boolean.TRUE);
dbInstance.updateObject(recipient);
}
}
return mail;
}
Aggregations