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