Search in sources :

Example 1 with OutputFormat

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;
}
Also used : CKEditorEmailField(au.com.vaadinutils.fields.CKEditorEmailField) FormLayout(com.vaadin.ui.FormLayout) ReportEmailSender(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailSender) TabSheet(com.vaadin.ui.TabSheet) TopVerticalLayout(au.com.vaadinutils.layout.TopVerticalLayout) ReportEmailScheduleEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity) OutputFormat(au.com.vaadinutils.jasper.JasperManager.OutputFormat) TopVerticalLayout(au.com.vaadinutils.layout.TopVerticalLayout) VerticalLayout(com.vaadin.ui.VerticalLayout) FormHelper(au.com.vaadinutils.crud.FormHelper)

Example 2 with OutputFormat

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;
}
Also used : AttachmentType(au.com.vaadinutils.jasper.AttachmentType) ReportParameter(au.com.vaadinutils.jasper.parameter.ReportParameter) ReportEmailRecipient(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient) JasperManager(au.com.vaadinutils.jasper.JasperManager) OutputFormat(au.com.vaadinutils.jasper.JasperManager.OutputFormat) RenderedReport(au.com.vaadinutils.jasper.RenderedReport) JasperEmailBuilder(au.com.vaadinutils.jasper.JasperEmailBuilder) JasperReportPropertiesAlternateFile(au.com.vaadinutils.jasper.ui.JasperReportPropertiesAlternateFile)

Example 3 with OutputFormat

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();
        }
    });
}
Also used : StreamResource(com.vaadin.server.StreamResource) ReportParameter(au.com.vaadinutils.jasper.parameter.ReportParameter) OutputFormat(au.com.vaadinutils.jasper.JasperManager.OutputFormat) JasperManager(au.com.vaadinutils.jasper.JasperManager) PollListener(com.vaadin.event.UIEvents.PollListener) SimpleDateFormat(java.text.SimpleDateFormat) PollEvent(com.vaadin.event.UIEvents.PollEvent) Date(java.util.Date)

Aggregations

OutputFormat (au.com.vaadinutils.jasper.JasperManager.OutputFormat)3 JasperManager (au.com.vaadinutils.jasper.JasperManager)2 ReportParameter (au.com.vaadinutils.jasper.parameter.ReportParameter)2 FormHelper (au.com.vaadinutils.crud.FormHelper)1 CKEditorEmailField (au.com.vaadinutils.fields.CKEditorEmailField)1 AttachmentType (au.com.vaadinutils.jasper.AttachmentType)1 JasperEmailBuilder (au.com.vaadinutils.jasper.JasperEmailBuilder)1 RenderedReport (au.com.vaadinutils.jasper.RenderedReport)1 ReportEmailRecipient (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient)1 ReportEmailScheduleEntity (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity)1 ReportEmailSender (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailSender)1 JasperReportPropertiesAlternateFile (au.com.vaadinutils.jasper.ui.JasperReportPropertiesAlternateFile)1 TopVerticalLayout (au.com.vaadinutils.layout.TopVerticalLayout)1 PollEvent (com.vaadin.event.UIEvents.PollEvent)1 PollListener (com.vaadin.event.UIEvents.PollListener)1 StreamResource (com.vaadin.server.StreamResource)1 FormLayout (com.vaadin.ui.FormLayout)1 TabSheet (com.vaadin.ui.TabSheet)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 SimpleDateFormat (java.text.SimpleDateFormat)1