Search in sources :

Example 6 with SendingAttachment

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;
}
Also used : SendingAttachment(com.haulmont.cuba.core.entity.SendingAttachment)

Example 7 with 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;
}
Also used : SendingAttachment(com.haulmont.cuba.core.entity.SendingAttachment) SendingMessage(com.haulmont.cuba.core.entity.SendingMessage)

Example 8 with SendingAttachment

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();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) SendingAttachment(com.haulmont.cuba.core.entity.SendingAttachment)

Example 9 with SendingAttachment

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;
}
Also used : SendingAttachment(com.haulmont.cuba.core.entity.SendingAttachment) SendingMessage(com.haulmont.cuba.core.entity.SendingMessage)

Aggregations

SendingAttachment (com.haulmont.cuba.core.entity.SendingAttachment)9 SendingMessage (com.haulmont.cuba.core.entity.SendingMessage)3 EntityManager (com.haulmont.cuba.core.EntityManager)2 Transaction (com.haulmont.cuba.core.Transaction)2 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)1 Test (org.junit.Test)1