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;
}
});
}
Aggregations