Search in sources :

Example 1 with ReportChooser

use of au.com.vaadinutils.jasper.parameter.ReportChooser in project VaadinUtils by rlsutton1.

the class JasperReportEmailWindow method sendEmail.

private ReportEmailScheduleEntity sendEmail(Collection<ReportParameter<?>> params, JasperReportProperties reportProperties) {
    String errorMessage = "";
    boolean hasValidTargets = false;
    for (EmailTargetLine target : emailTargetLayout.getTargets()) {
        if (target.targetAddress.getValue() != null) {
            if (!target.targetAddress.isValid()) {
                errorMessage = target.targetAddress.getValue() + " is not a valid email address";
                Notification.show(errorMessage, Type.ERROR_MESSAGE);
                return null;
            }
            hasValidTargets = true;
        }
    }
    if (!hasValidTargets) {
        Notification.show("Set at least one Recipient.", Type.ERROR_MESSAGE);
        return null;
    }
    ReportEmailScheduleEntity schedule = new ReportEmailScheduleEntity();
    schedule.setTitle(reportProperties.getReportTitle());
    schedule.setReportFilename(reportProperties.getReportFileName());
    schedule.setReportTemplateIdentifier(reportProperties.getReportIdentifier());
    schedule.setMessage(message.getValue());
    schedule.setSubject(subject.getValue());
    schedule.setReportClass(reportProperties.getReportClass());
    schedule.setScheduleMode(ScheduleMode.ONE_TIME);
    schedule.setOneTimeRunTime(new Date());
    schedule.setEnabled(true);
    EntityManager entityManager = EntityManagerProvider.getEntityManager();
    List<ReportEmailParameterEntity> rparams = new LinkedList<ReportEmailParameterEntity>();
    List<ReportEmailScheduledDateParameter> dparams = new LinkedList<ReportEmailScheduledDateParameter>();
    for (ReportParameter<?> param : params) {
        // omit report choosers, as they would complicate and confuse
        // if (!(param instanceof ReportChooser))
        {
            if (param instanceof ReportChooser) {
                String[] names = param.getParameterNames().toArray(new String[] {});
                // add non date fields
                ReportEmailParameterEntity rparam = new ReportEmailParameterEntity();
                rparam.setName(names[0]);
                rparam.setValue(param.getValue(names[0]).toString(), param.getDisplayValue(names[0]));
                rparams.add(rparam);
                entityManager.persist(rparam);
            } else if (!param.isDateField()) {
                String[] names = param.getParameterNames().toArray(new String[] {});
                // add non date fields
                ReportEmailParameterEntity rparam = new ReportEmailParameterEntity();
                rparam.setName(names[0]);
                rparam.setValue(param.getValue(names[0]).toString(), param.getDisplayValue(names[0]));
                rparams.add(rparam);
                entityManager.persist(rparam);
            } else {
                // add date fields
                ReportEmailScheduledDateParameter rparam = new ReportEmailScheduledDateParameter();
                String[] names = param.getParameterNames().toArray(new String[] {});
                rparam.setStartName(names[0]);
                rparam.setStartDate(param.getStartDate());
                rparam.setEndName(names[1]);
                rparam.setEndDate(param.getEndDate());
                rparam.setType(param.getDateParameterType());
                rparam.setOffsetType(DateParameterOffsetType.CONSTANT);
                rparam.setLabel(param.getLabel(names[0]));
                dparams.add(rparam);
                entityManager.persist(rparam);
            }
        }
    }
    schedule.setParameters(rparams);
    schedule.setDateParameters(dparams);
    ReportEmailSender reportEmailSender = new ReportEmailSender();
    reportEmailSender.setUserName(reportProperties.getUsername());
    reportEmailSender.setEmailAddress(reportProperties.getUserEmailAddress());
    schedule.setSender(reportEmailSender);
    entityManager.persist(reportEmailSender);
    List<ReportEmailRecipient> recips = new LinkedList<ReportEmailRecipient>();
    for (EmailTargetLine target : emailTargetLayout.getTargets()) {
        ReportEmailRecipient recipient = new ReportEmailRecipient();
        recipient.setEmail((String) target.targetAddress.getValue());
        recipient.setVisibility((ReportEmailRecipientVisibility) target.targetTypeCombo.getValue());
        entityManager.persist(recipient);
        recips.add(recipient);
    }
    schedule.setRecipients(recips);
    schedule.setNextScheduledRunTime(schedule.getScheduleMode().getNextRuntime(schedule, new Date()));
    schedule.setOutputFormat(OutputFormat.PDF);
    entityManager.persist(schedule);
    entityManager.flush();
    reportEmailSender = entityManager.merge(reportEmailSender);
    return schedule;
}
Also used : ReportChooser(au.com.vaadinutils.jasper.parameter.ReportChooser) ReportEmailScheduleEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity) Date(java.util.Date) LinkedList(java.util.LinkedList) EntityManager(javax.persistence.EntityManager) ReportEmailSender(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailSender) ReportEmailScheduledDateParameter(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduledDateParameter) ReportEmailRecipient(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient) ReportEmailParameterEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailParameterEntity)

Example 2 with ReportChooser

use of au.com.vaadinutils.jasper.parameter.ReportChooser in project VaadinUtils by rlsutton1.

the class JasperReportLayout method generateReport.

private void generateReport(final JasperManager.OutputFormat outputFormat, final Collection<ReportParameter<?>> params) {
    streamConnected = false;
    streamReady = false;
    splitPanel.setSecondComponent(splash);
    manager = null;
    boolean validParams = true;
    // manager for the selected report.
    for (ReportParameter<?> p : params) {
        if (p instanceof ReportChooser) {
            ReportChooser chooser = (ReportChooser) p;
            manager = new JasperManager(chooser.getReportProperties(reportProperties));
            Preconditions.checkNotNull(manager, "chooser returned a NULL JasperManager.");
        } else {
            validParams &= p.validate();
        }
    }
    if (!validParams) {
        Notification.show("Please correct your filters and try again", Type.ERROR_MESSAGE);
        printButton.setEnabled(true);
        exportButton.setEnabled(true);
        showButton.setEnabled(true);
        for (ExpanderComponent componet : components) {
            componet.getComponent().setEnabled(true);
        }
        return;
    }
    if (manager == null) {
        this.manager = new JasperManager(reportProperties);
    }
    CancelListener cancelListener = getProgressDialogCancelListener();
    final WorkingDialog dialog = new WorkingDialog("Generating report, please be patient", "Please wait", cancelListener);
    dialog.setHeight("150");
    UI.getCurrent().addWindow(dialog);
    getProgressDialogRefreshListener(dialog);
    getStreamConnectorRefreshListener(outputFormat);
    JasperProgressListener listener = getJasperManagerProgressListener(UI.getCurrent(), dialog, outputFormat);
    manager.exportAsync(outputFormat, params, listener);
}
Also used : JasperProgressListener(au.com.vaadinutils.jasper.JasperProgressListener) WorkingDialog(au.com.vaadinutils.ui.WorkingDialog) ExpanderComponent(au.com.vaadinutils.jasper.filter.ExpanderComponent) ReportChooser(au.com.vaadinutils.jasper.parameter.ReportChooser) JasperManager(au.com.vaadinutils.jasper.JasperManager) CancelListener(au.com.vaadinutils.listener.CancelListener)

Example 3 with ReportChooser

use of au.com.vaadinutils.jasper.parameter.ReportChooser in project VaadinUtils by rlsutton1.

the class JasperReportScheduleLayout method changedReportProperties.

private void changedReportProperties(ReportEmailScheduleEntity entityItem, ReportParameter<?> bParam) {
    try {
        if (bParam instanceof ReportChooser) {
            ReportChooser chooser = (ReportChooser) bParam;
            JasperReportProperties props = entityItem.getJasperReportPropertiesClass().newInstance();
            JasperReportProperties newProps = chooser.getReportProperties(props);
            entityItem.setReportFilename(newProps.getReportFileName());
            entityItem.setTitle(newProps.getReportTitle());
            reportTitle.setReadOnly(false);
            reportTitle.setValue(newProps.getReportTitle());
            reportTitle.setReadOnly(true);
        }
    } catch (Exception e) {
        logger.error(e, e);
        throw new RuntimeException(e);
    }
}
Also used : JasperReportProperties(au.com.vaadinutils.jasper.ui.JasperReportProperties) ReportChooser(au.com.vaadinutils.jasper.parameter.ReportChooser) InvalidValueException(com.vaadin.data.Validator.InvalidValueException)

Aggregations

ReportChooser (au.com.vaadinutils.jasper.parameter.ReportChooser)3 JasperManager (au.com.vaadinutils.jasper.JasperManager)1 JasperProgressListener (au.com.vaadinutils.jasper.JasperProgressListener)1 ExpanderComponent (au.com.vaadinutils.jasper.filter.ExpanderComponent)1 ReportEmailParameterEntity (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailParameterEntity)1 ReportEmailRecipient (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient)1 ReportEmailScheduleEntity (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity)1 ReportEmailScheduledDateParameter (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduledDateParameter)1 ReportEmailSender (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailSender)1 JasperReportProperties (au.com.vaadinutils.jasper.ui.JasperReportProperties)1 CancelListener (au.com.vaadinutils.listener.CancelListener)1 WorkingDialog (au.com.vaadinutils.ui.WorkingDialog)1 InvalidValueException (com.vaadin.data.Validator.InvalidValueException)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 EntityManager (javax.persistence.EntityManager)1