use of com.haulmont.cuba.core.entity.SendingAttachment in project cuba by cuba-platform.
the class Emailer method toSendingAttachment.
protected SendingAttachment toSendingAttachment(EmailAttachment ea) {
SendingAttachment sendingAttachment = metadata.create(SendingAttachment.class);
sendingAttachment.setContent(ea.getData());
sendingAttachment.setContentId(ea.getContentId());
sendingAttachment.setName(ea.getName());
sendingAttachment.setEncoding(ea.getEncoding());
sendingAttachment.setDisposition(ea.getDisposition());
return sendingAttachment;
}
use of com.haulmont.cuba.core.entity.SendingAttachment in project cuba by cuba-platform.
the class Emailer method convertToSendingMessage.
protected SendingMessage convertToSendingMessage(String address, String from, String caption, String body, @Nullable List<EmailHeader> headers, @Nullable EmailAttachment[] attachments, @Nullable Integer attemptsCount, @Nullable Date deadline) {
SendingMessage sendingMessage = metadata.create(SendingMessage.class);
sendingMessage.setAddress(address);
sendingMessage.setFrom(from);
sendingMessage.setContentText(body);
sendingMessage.setCaption(caption);
sendingMessage.setAttemptsCount(attemptsCount);
sendingMessage.setDeadline(deadline);
sendingMessage.setAttemptsMade(0);
if (attachments != null && attachments.length > 0) {
StringBuilder attachmentsName = new StringBuilder();
List<SendingAttachment> sendingAttachments = new ArrayList<>(attachments.length);
for (EmailAttachment ea : attachments) {
attachmentsName.append(ea.getName()).append(";");
SendingAttachment sendingAttachment = toSendingAttachment(ea);
sendingAttachment.setMessage(sendingMessage);
sendingAttachments.add(sendingAttachment);
}
sendingMessage.setAttachments(sendingAttachments);
sendingMessage.setAttachmentsName(attachmentsName.toString());
} else {
sendingMessage.setAttachments(Collections.<SendingAttachment>emptyList());
}
if (headers != null && !headers.isEmpty()) {
StringBuilder headersLine = new StringBuilder();
for (EmailHeader header : headers) {
headersLine.append(header.toString()).append(SendingMessage.HEADERS_SEPARATOR);
}
sendingMessage.setHeaders(headersLine.toString());
} else {
sendingMessage.setHeaders(null);
}
replaceRecipientIfNecessary(sendingMessage);
return sendingMessage;
}
use of com.haulmont.cuba.core.entity.SendingAttachment in project cuba by cuba-platform.
the class Emailer method migrateAttachmentsToFileStorage.
@Override
public void migrateAttachmentsToFileStorage(List<SendingAttachment> attachments) {
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
for (SendingAttachment attachment : attachments) {
migrateAttachment(em, attachment);
}
tx.commit();
}
}
use of com.haulmont.cuba.core.entity.SendingAttachment in project cuba by cuba-platform.
the class Emailer method createClone.
protected SendingMessage createClone(SendingMessage srcMessage) {
SendingMessage clonedMessage = metadata.getTools().copy(srcMessage);
List<SendingAttachment> clonedList = new ArrayList<>();
for (SendingAttachment srcAttach : srcMessage.getAttachments()) {
SendingAttachment clonedAttach = (SendingAttachment) metadata.getTools().copy(srcAttach);
clonedAttach.setMessage(null);
clonedAttach.setMessage(clonedMessage);
clonedList.add(clonedAttach);
}
clonedMessage.setAttachments(clonedList);
return clonedMessage;
}
Aggregations