Search in sources :

Example 1 with CallableUI

use of au.com.vaadinutils.dao.CallableUI in project VaadinUtils by rlsutton1.

the class SendEmailTask method sendMessages.

private void sendMessages(final List<JasperTransmission> targets, final JasperProxy proxy) {
    new EntityManagerThread<Void>(new CallableUI<Void>(UI.getCurrent()) {

        @Override
        protected Void call(UI ui) throws Exception {
            int sent = 0;
            try {
                for (JasperTransmission transmission : targets) {
                    if (cancel == true)
                        break;
                    try {
                        JasperManager manager = proxy.getManager();
                        RenderedReport renderedHtml = manager.export(OutputFormat.HTML, null);
                        RenderedReport renderedPDF = manager.export(OutputFormat.PDF, null);
                        JasperEmailBuilder builder = new JasperEmailBuilder(proxy.getEmailSettings());
                        builder.setFrom(proxy.getSenderEmailAddress()).setSubject(proxy.getSubject()).setHtmlBody(renderedHtml).addTo(transmission.getRecipientEmailAddress()).addAttachement(renderedPDF.getBodyAsDataSource("report.pdf", AttachmentType.PDF));
                        builder.send(false);
                    } catch (EmailException e) {
                        logger.error(e, e);
                        transmission.setException(e);
                        SendEmailTask.super.taskItemError(transmission);
                        VUNotification.show(e, Type.ERROR_MESSAGE);
                    }
                }
            } catch (Exception e) {
                VUNotification.show(e, Type.ERROR_MESSAGE);
                throw e;
            } finally {
                SendEmailTask.super.taskComplete(sent);
            }
            return null;
        }
    });
}
Also used : EntityManagerThread(au.com.vaadinutils.dao.EntityManagerThread) UI(com.vaadin.ui.UI) CallableUI(au.com.vaadinutils.dao.CallableUI) JasperManager(au.com.vaadinutils.jasper.JasperManager) RenderedReport(au.com.vaadinutils.jasper.RenderedReport) EmailException(org.apache.commons.mail.EmailException) JasperEmailBuilder(au.com.vaadinutils.jasper.JasperEmailBuilder) EmailException(org.apache.commons.mail.EmailException)

Aggregations

CallableUI (au.com.vaadinutils.dao.CallableUI)1 EntityManagerThread (au.com.vaadinutils.dao.EntityManagerThread)1 JasperEmailBuilder (au.com.vaadinutils.jasper.JasperEmailBuilder)1 JasperManager (au.com.vaadinutils.jasper.JasperManager)1 RenderedReport (au.com.vaadinutils.jasper.RenderedReport)1 UI (com.vaadin.ui.UI)1 EmailException (org.apache.commons.mail.EmailException)1