int fromMonth, int fromDay, int fromHour, int fromMinute, boolean toNone, int toYear, int toMonth,
int toDay, int toHour, int toMinute, boolean schedule, int schedulePeriod, int runDelayMinutes,
String scheduleCron, boolean email, boolean includeData, boolean zipData,
List<RecipientListEntryBean> recipients) {
ProcessResult response = new ProcessResult();
// Basic validation
validateData(response, name, points, dateRangeType, relativeDateType, previousPeriodCount, pastPeriodCount);
if (schedule) {
if (schedulePeriod == ReportVO.SCHEDULE_CRON) {
// Check the cron pattern.
try {
new CronTimerTrigger(scheduleCron);
}
catch (Exception e) {
response.addContextualMessage("scheduleCron", "reports.validate.cron", e.getMessage());
}
}
else {
if (runDelayMinutes < 0)
response.addContextualMessage("runDelayMinutes", "reports.validate.lessThan0");
else if (runDelayMinutes > 59)
response.addContextualMessage("runDelayMinutes", "reports.validate.greaterThan59");
}
}
if (schedule && email && recipients.isEmpty())
response.addContextualMessage("recipients", "reports.validate.needRecip");
if (response.getHasMessages())
return response;
User user = Common.getUser();
ReportDao reportDao = new ReportDao();
ReportVO report;
if (id == Common.NEW_ID) {
report = new ReportVO();
report.setUserId(user.getId());
}
else
report = reportDao.getReport(id);
ReportCommon.ensureReportPermission(user, report);
// Update the new values.
report.setXid(xid);
report.setName(name);
report.setPoints(points);
report.setTemplate(template);
report.setIncludeEvents(includeEvents);
report.setIncludeUserComments(includeUserComments);
report.setDateRangeType(dateRangeType);
report.setRelativeDateType(relativeDateType);
report.setPreviousPeriodCount(previousPeriodCount);
report.setPreviousPeriodType(previousPeriodType);
report.setPastPeriodCount(pastPeriodCount);
report.setPastPeriodType(pastPeriodType);
report.setFromNone(fromNone);
report.setFromYear(fromYear);
report.setFromMonth(fromMonth);
report.setFromDay(fromDay);
report.setFromHour(fromHour);
report.setFromMinute(fromMinute);
report.setToNone(toNone);
report.setToYear(toYear);
report.setToMonth(toMonth);
report.setToDay(toDay);
report.setToHour(toHour);
report.setToMinute(toMinute);
report.setSchedule(schedule);
report.setSchedulePeriod(schedulePeriod);
report.setRunDelayMinutes(runDelayMinutes);
report.setScheduleCron(scheduleCron);
report.setEmail(email);
report.setIncludeData(includeData);
report.setZipData(zipData);
report.setRecipients(recipients);
// Save the report
reportDao.saveReport(report);
// Conditionally schedule the report.
ReportJob.scheduleReportJob(report);
// Send back the report id in case this was new.
response.addData("reportId", report.getId());
response.addData("report", report);
return response;
}