use of au.com.vaadinutils.jasper.JasperManager.OutputFormat in project VaadinUtils by rlsutton1.
the class JasperReportScheduleLayout method buildEditor.
@Override
@SuppressWarnings("deprecation")
public TabSheet buildEditor(ValidatingFieldGroup<ReportEmailScheduleEntity> validatingFieldGroup) {
TabSheet tabsheet = new TabSheet();
tabsheet.setSizeFull();
VerticalLayout main = new VerticalLayout();
main.setSpacing(true);
main.setMargin(true);
main.setSizeFull();
tabsheet.addTab(main, "Email");
main.addComponent(emailTargetLayout);
FormHelper<ReportEmailScheduleEntity> helper = new FormHelper<ReportEmailScheduleEntity>(main, fieldGroup);
reportTitle = helper.bindTextField("Report", ReportEmailScheduleEntity_.reportTitle);
reportTitle.setReadOnly(true);
sender = helper.bindEntityField("From", ReportEmailScheduleEntity_.sender, ReportEmailSender.class, ReportEmailSender_.username);
sender.setReadOnly(true);
outputFormat = helper.bindEnumField("Output format", ReportEmailScheduleEntity_.outputFormat.getName(), OutputFormat.class);
outputFormat.removeItem(OutputFormat.HTML);
helper.bindTextField("Subject", ReportEmailScheduleEntity_.subject);
CKEditorEmailField message = helper.bindEditorField("Message", ReportEmailScheduleEntity_.message, false);
helper.bindTextField("Report Log", ReportEmailScheduleEntity_.reportLog.getName()).setReadOnly(true);
main.setExpandRatio(message, 1);
TopVerticalLayout scheduleWrapper = new TopVerticalLayout();
scheduleWrapper.setSizeFull();
tabsheet.addTab(scheduleWrapper, "Schedule");
FormLayout scheduleForm = new FormLayout();
scheduleForm.setSizeFull();
scheduleForm.setMargin(true);
scheduleWrapper.addComponent(scheduleForm);
buildScheduleTab(validatingFieldGroup, scheduleForm, helper);
VerticalLayout paramWrapper = new VerticalLayout();
paramWrapper.setSizeFull();
tabsheet.addTab(paramWrapper, "Parameters");
paramForm = new VerticalLayout();
paramForm.setSizeFull();
paramForm.setMargin(true);
paramWrapper.addComponent(paramForm);
return tabsheet;
}
use of au.com.vaadinutils.jasper.JasperManager.OutputFormat in project VaadinUtils by rlsutton1.
the class ReportEmailRunnerImpl method runReport.
// Logger logger = org.apache.logging.log4j.LogManager.getLogger();
@Override
public boolean runReport(ReportEmailSchedule schedule, Date scheduledTime, JasperEmailSettings emailSettings) throws InterruptedException, IOException, EmailException, InstantiationException, IllegalAccessException, AddressException, ClassNotFoundException {
Preconditions.checkNotNull(schedule.getSendersEmailAddress(), "Missing senders email address.");
Preconditions.checkNotNull(schedule.getRecipients(), "Missing recipient email address");
Preconditions.checkArgument(schedule.getRecipients().size() > 0, "Missing recipient email address");
Class<? extends JasperReportProperties> jrpClass = schedule.getJasperReportPropertiesClass();
jasperReportProperties = jrpClass.newInstance();
this.schedule = schedule;
jasperReportProperties = new JasperReportPropertiesAlternateFile(schedule.getReportTitle(), schedule.getReportFileName(), jasperReportProperties);
Collection<ReportParameter<?>> params = buildParams(schedule, scheduledTime, this);
JasperManager manager = new JasperManager(this);
if (manager.checkQueueSize() > 0) {
return false;
}
JasperEmailBuilder builder = new JasperEmailBuilder(emailSettings);
OutputFormat outputFormat = schedule.getOutputFormat();
RenderedReport export = manager.export(outputFormat, params);
try {
AttachmentType attachementType = outputFormat.getAttachementType();
builder.setFrom(schedule.getSendersEmailAddress().toString()).setSubject(schedule.subject()).setHtmlBody(schedule.message()).addAttachement(export.getBodyAsDataSource(schedule.getReportTitle() + attachementType.getFileExtension(), attachementType));
for (ReportEmailRecipient address : schedule.getRecipients()) {
switch(address.getVisibility()) {
case TO:
builder.addTo(address.getEmail());
break;
case CC:
builder.addCC(address.getEmail());
break;
case BCC:
builder.addBCC(address.getEmail());
break;
}
}
builder.send(false);
} finally {
export.close();
}
return true;
}
use of au.com.vaadinutils.jasper.JasperManager.OutputFormat in project VaadinUtils by rlsutton1.
the class JasperReportLayout method getStreamConnectorRefreshListener.
private void getStreamConnectorRefreshListener(final JasperManager.OutputFormat outputFormat) {
UI.getCurrent().setPollInterval(500);
UI.getCurrent().addPollListener(new PollListener() {
private static final long serialVersionUID = -5641305025399715756L;
@Override
public void poll(PollEvent event) {
logger.warn("Checking if report is ready...");
if (streamReady && !streamConnected) {
// jasper manager is ready, so get the report stream and set
// it as the source for the display panel
streamConnected = true;
StreamResource resource = new StreamResource(getReportStream(), "report");
resource.setMIMEType(outputFormat.getMimeType());
resource.setCacheTime(-1);
resource.setFilename(exportFileName(outputFormat));
if (outputFormat == OutputFormat.CSV) {
csv.setSource(resource);
showCsvSplash();
} else {
getDisplayPanel().setSource(resource);
}
UI.getCurrent().removePollListener(this);
}
}
private String exportFileName(final JasperManager.OutputFormat outputFormat) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String name = reportProperties.getReportTitle() + "At" + sdf.format(new Date());
for (ReportParameter<?> param : builder.getReportParameters()) {
if (param.showFilter()) {
name += "-" + param.getLabel("");
for (String parameterName : param.getParameterNames()) {
name += "-" + param.getDisplayValue(parameterName);
}
}
}
if (name.length() > MAX_FILENAME_LENGTH) {
name = name.substring(0, MAX_FILENAME_LENGTH);
}
name = name.replace("/", "-");
return name + outputFormat.getFileExtension();
}
});
}
Aggregations