log.warn("generateReport: request : " + reportInput.getRequestId() + " : " + reportOutput.getContentMessage());
return reportOutput;
}
ReportUser user = userProvider.getUser(reportInput.getUser().getUserName(), reportInput.getUser().getPassword());
if (user == null)
{
reportOutput.setContentMessage("Invalid ReportInput - User not found: " + reportInput.getUser().getUserName());
log.warn("generateReport: request : " + reportInput.getRequestId() + " : " + reportOutput.getContentMessage());
return reportOutput;
}
if (!user.isValidReport(report))
{
reportOutput.setContentMessage("Invalid ReportInput - "
+ user.getName() + " not authorized to run: "
+ reportInput.getReportName());
log.warn("generateReport: request : " + reportInput.getRequestId() + " : " + reportOutput.getContentMessage());
return reportOutput;
}
log.info("generateReport: received request : " + reportInput.getRequestId() + " : for report : " + report.getName() + " : from : " + user.getName());
if (reportInput.getDeliveryMethods() == null || reportInput.getDeliveryMethods().length < 1)
{
ReportLog reportLog = null;
try
{
reportLog = new ReportLog(user, report, new Date());
reportLog.setExportType(reportInput.getExportType().getCode());
reportLog = reportLogProvider.insertReportLog(reportLog);
ReportEngine reportEngine = ReportEngineHelper.getReportEngine(report,
dataSourceProvider, directoryProvider, propertiesProvider);
ReportEngineInput engineInput = new ReportEngineInput(report, buildParameterMap(reportInput, report));
engineInput.setExportType(reportInput.getExportType());
engineInput.setXmlInput(reportInput.getXmlInput());
engineInput.setLocale(ORUtil.getLocale(reportInput.getLocale()));
ReportEngineOutput reportEngineOutput = reportEngine.generateReport(engineInput);
reportOutput.setContent(reportEngineOutput.getContent());
reportOutput.setContentType(reportEngineOutput.getContentType());
reportOutput.setContentExtension(reportEngineOutput.getContentExtension());
//convert List of Dynabeans to XML so that it can be serialized
if (reportEngineOutput instanceof QueryEngineOutput)
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
xStream.toXML(((QueryEngineOutput)reportEngineOutput).getResults(), out);
reportOutput.setContent(out.toByteArray());
reportOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_XML);
out.close();
}
reportLog.setStatus(ReportLog.STATUS_SUCCESS);
reportLog.setEndTime(new Date());
reportLogProvider.updateReportLog(reportLog);
}
catch(Exception e)
{
if (reportLog != null && reportLog.getId() != null)
{
reportLog.setStatus(ReportLog.STATUS_FAILURE);
reportLog.setMessage(e.getMessage());
reportLog.setEndTime(new Date());
try
{
reportLogProvider.updateReportLog(reportLog);
}
catch (Exception ex)
{
log.error("Unable to update ReportLog: " + ex.getMessage());
}
}
}
}
else
{
ReportSchedule schedule = new ReportSchedule();
schedule.setReport(report);
schedule.setUser(user);
schedule.setReportParameters(buildParameterMap(reportInput, report));
schedule.setExportType(reportInput.getExportType().getCode());
schedule.setScheduleName(report.getId() + "|" + new Date().getTime());
schedule.setScheduleDescription(reportInput.getScheduleDescription());
schedule.setScheduleType(ReportSchedule.ONCE);
schedule.setXmlInput(reportInput.getXmlInput());
schedule.setDeliveryReturnAddress(reportInput.getDeliveryReturnAddress());
schedule.setRequestId(reportInput.getRequestId());
schedule.setSchedulePriority(reportInput.getSchedulePriority());
schedule.setDeliveryMethods(convertDeliveryMethodsToNames(reportInput.getDeliveryMethods()));
schedule.setLocale(ORUtil.getLocale(reportInput.getLocale()));
if (reportInput.getDeliveryAddress() != null)
{
schedule.setRecipients(reportInput.getDeliveryAddress());
}
else
{
schedule.setRecipients(user.getEmail());
}
// advanced scheduling
if (reportInput.getStartDate() != null)
{
if (!user.isAdvancedScheduler())
{
throw new ProviderException("Not Authorized: Advanced Scheduling permission required");
}
schedule.setScheduleType(reportInput.getScheduleType().getCode());