Search in sources :

Example 1 with ReportEmailScheduleEntity

use of au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity 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 ReportEmailScheduleEntity

use of au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity 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 3 with ReportEmailScheduleEntity

use of au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity in project VaadinUtils by rlsutton1.

the class JasperReportScheduleLayout method dateParamsHandleRowChange.

private void dateParamsHandleRowChange(EntityItem<ReportEmailScheduleEntity> item) {
    paramForm.removeAllComponents();
    paramForm.setSpacing(true);
    paramForm.setSizeFull();
    paramForm.setMargin(true);
    updaters.clear();
    if (item != null) {
        ReportEmailScheduleEntity entity = item.getEntity();
        List<DateParameterOffsetType> offsetTypes = new LinkedList<DateParameterOffsetType>();
        for (DateParameterOffsetType offsetType : DateParameterOffsetType.values()) {
            offsetTypes.add(offsetType);
        }
        for (final ScheduledDateParameter dateParam : entity.getDateParameters()) {
            HorizontalLayout dateLayout = new HorizontalLayout();
            dateLayout.setSizeFull();
            dateLayout.setSpacing(true);
            dateLayout.setHeight("55");
            final ComboBox offsetType = new ComboBox(dateParam.getLabel(), offsetTypes);
            offsetType.setImmediate(true);
            offsetType.setNullSelectionAllowed(false);
            offsetType.setWidth("140");
            final DateField startDateField = new DateField("From", dateParam.getStartDate());
            startDateField.setResolution(Resolution.DAY);
            startDateField.setDateFormat("yyyy/MM/dd");
            // pickers visability doesn't change, it's determined by the
            // parameter type which can't be changed here
            final TimePicker startTimePicker = new TimePicker("");
            startTimePicker.setValues(dateParam.getStartDate());
            startTimePicker.setVisible(dateParam.getType() == DateParameterType.DATE_TIME);
            final DateField endDateField = new DateField("To", dateParam.getEndDate());
            endDateField.setResolution(Resolution.DAY);
            endDateField.setDateFormat("yyyy/MM/dd");
            // pickers visability doesn't change, it's determined by the
            // parameter type which can't be changed here
            final TimePicker endTimePicker = new TimePicker("");
            endTimePicker.setValues(dateParam.getStartDate());
            endTimePicker.setVisible(dateParam.getType() == DateParameterType.DATE_TIME);
            offsetType.addValueChangeListener(new ValueChangeListener() {

                private static final long serialVersionUID = 7081417825842355432L;

                @Override
                public void valueChange(ValueChangeEvent event) {
                    DateParameterOffsetType offsetTypeValue = (DateParameterOffsetType) event.getProperty().getValue();
                    startDateField.setVisible(offsetTypeValue == DateParameterOffsetType.CONSTANT);
                    endDateField.setVisible(offsetTypeValue == DateParameterOffsetType.CONSTANT);
                }
            });
            offsetType.setValue(dateParam.getOffsetType());
            dateLayout.addComponent(offsetType);
            dateLayout.addComponent(startDateField);
            dateLayout.addComponent(startTimePicker);
            dateLayout.addComponent(endDateField);
            dateLayout.addComponent(endTimePicker);
            paramForm.addComponent(dateLayout);
            updaters.add(new EntityParamUpdater(dateParam.getLabel(), offsetType, startDateField, startTimePicker, endDateField, endTimePicker));
        }
    }
}
Also used : TimePicker(au.com.vaadinutils.layout.TimePicker) ComboBox(com.vaadin.ui.ComboBox) ReportEmailScheduleEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity) DateParameterOffsetType(au.com.vaadinutils.jasper.scheduler.entities.DateParameterOffsetType) LinkedList(java.util.LinkedList) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.data.Property.ValueChangeListener) DateField(com.vaadin.ui.DateField)

Example 4 with ReportEmailScheduleEntity

use of au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity in project VaadinUtils by rlsutton1.

the class JasperReportLayout method createScheduleButton.

private void createScheduleButton(String buttonHeight, HorizontalLayout buttonContainer) {
    scheduleButton = new NativeButton();
    JpaBaseDao<ReportEmailScheduleEntity, Long> dao = JpaBaseDao.getGenericDao(ReportEmailScheduleEntity.class);
    Long count = dao.getCount(ReportEmailScheduleEntity_.JasperReportPropertiesClassName, reportProperties.getReportClass().getCanonicalName());
    ScheduleIconBuilder iconBuilder = new ScheduleIconBuilder();
    String baseIconFileName = "Call Calendar_32";
    String path = VaadinServlet.getCurrent().getServletContext().getRealPath("templates/images/seanau/");
    // then search in the /images/seanau director.
    if (path == null || !new File(path).exists()) {
        path = VaadinServlet.getCurrent().getServletContext().getRealPath("/images/seanau/");
    }
    String targetFileName = baseIconFileName + "-" + count + ".png";
    iconBuilder.buildLogo(count.intValue(), new File(path), baseIconFileName + ".png", targetFileName);
    scheduleButton.setIcon(new ExternalResource("images/seanau/" + targetFileName));
    scheduleButton.setDescription("Schedule");
    scheduleButton.setWidth("50");
    scheduleButton.setHeight(buttonHeight);
    scheduleButton.addClickListener(new ClickEventLogged.ClickListener() {

        private static final long serialVersionUID = 7207441556779172217L;

        @Override
        public void clicked(ClickEvent event) {
            new JasperReportSchedulerWindow(reportProperties, builder.getReportParameters());
        }
    });
    buttonContainer.addComponent(scheduleButton);
}
Also used : NativeButton(com.vaadin.ui.NativeButton) JasperReportSchedulerWindow(au.com.vaadinutils.jasper.scheduler.JasperReportSchedulerWindow) ClickEventLogged(au.com.vaadinutils.listener.ClickEventLogged) ScheduleIconBuilder(au.com.vaadinutils.jasper.scheduler.ScheduleIconBuilder) ClickEvent(com.vaadin.ui.Button.ClickEvent) ReportEmailScheduleEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity) ExternalResource(com.vaadin.server.ExternalResource) File(java.io.File)

Example 5 with ReportEmailScheduleEntity

use of au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity in project VaadinUtils by rlsutton1.

the class JasperReportScheduleLayout method paramsHandleRowChange.

private void paramsHandleRowChange(EntityItem<ReportEmailScheduleEntity> item) {
    try {
        builder = null;
        reportProperties = null;
        if (item != null) {
            ReportEmailScheduleEntity entity = item.getEntity();
            reportProperties = entity.getJasperReportPropertiesClass().newInstance();
            builder = reportProperties.getFilterBuilder();
            List<ExpanderComponent> paramComponents = builder.buildLayout(true);
            for (ExpanderComponent componet : paramComponents) {
                paramForm.addComponent(componet.getComponent());
                if (componet.shouldExpand()) {
                    paramForm.setExpandRatio(componet.getComponent(), 1);
                }
            }
            for (ReportParameter<?> builtParam : builder.getReportParameters()) {
                for (ReportEmailParameter schedParam : entity.getReportParameters()) {
                    for (String parameterName : builtParam.getParameterNames()) {
                        if (schedParam.getName().equalsIgnoreCase(parameterName)) {
                            builtParam.setValueAsString(schedParam.getValue(), parameterName);
                            break;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.error(e, e);
    }
}
Also used : ExpanderComponent(au.com.vaadinutils.jasper.filter.ExpanderComponent) ReportEmailScheduleEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity) InvalidValueException(com.vaadin.data.Validator.InvalidValueException)

Aggregations

ReportEmailScheduleEntity (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity)8 ReportEmailRecipient (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient)3 ReportEmailSender (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailSender)2 InvalidValueException (com.vaadin.data.Validator.InvalidValueException)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 EntityTable (au.com.vaadinutils.crud.EntityTable)1 FormHelper (au.com.vaadinutils.crud.FormHelper)1 CKEditorEmailField (au.com.vaadinutils.fields.CKEditorEmailField)1 OutputFormat (au.com.vaadinutils.jasper.JasperManager.OutputFormat)1 ExpanderComponent (au.com.vaadinutils.jasper.filter.ExpanderComponent)1 ReportChooser (au.com.vaadinutils.jasper.parameter.ReportChooser)1 JasperReportSchedulerWindow (au.com.vaadinutils.jasper.scheduler.JasperReportSchedulerWindow)1 ScheduleIconBuilder (au.com.vaadinutils.jasper.scheduler.ScheduleIconBuilder)1 DateParameterOffsetType (au.com.vaadinutils.jasper.scheduler.entities.DateParameterOffsetType)1 ReportEmailParameterEntity (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailParameterEntity)1 ReportEmailScheduledDateParameter (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduledDateParameter)1 TimePicker (au.com.vaadinutils.layout.TimePicker)1 TopVerticalLayout (au.com.vaadinutils.layout.TopVerticalLayout)1 ClickEventLogged (au.com.vaadinutils.listener.ClickEventLogged)1