use of com.qcadoo.report.api.ReportService.ReportType in project qcadoo by qcadoo.
the class ReportDevelopmentController method generateReport.
@RequestMapping(value = "developReport/generate", method = RequestMethod.POST)
public ModelAndView generateReport(@RequestParam(value = L_TEMPLATE) final String template, @RequestParam(value = "type") final String type, @RequestParam(value = L_LOCALE) final String locale, final HttpServletRequest request, final HttpServletResponse response) {
if (!showReportDevelopment) {
return new ModelAndView(new RedirectView("/"));
}
List<ReportParameter> params = null;
try {
params = getReportParameters(template);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return showException(L_QCADOO_REPORT_REPORT, e).addObject(L_TEMPLATE, template).addObject("isParameter", true).addObject(L_LOCALE, locale);
}
try {
ReportType reportType = ReportType.valueOf(type.toUpperCase(Locale.ENGLISH));
Locale reportLocale = new Locale(locale);
Map<String, Object> parameters = new HashMap<String, Object>();
for (ReportParameter param : params) {
param.setValue(request.getParameter("params[" + param.getName() + "]"));
parameters.put(param.getName(), param.getRawValue());
}
byte[] report = reportService.generateReport(template, reportType, parameters, reportLocale);
response.setContentLength(report.length);
response.setContentType(reportType.getMimeType());
response.setHeader("Content-disposition", "attachment; filename=report." + type);
response.addHeader("Expires", "Tue, 03 Jul 2001 06:00:00 GMT");
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.addHeader("Pragma", "no-cache");
OutputStream out = response.getOutputStream();
try {
IOUtils.copy(new ByteArrayInputStream(report), out);
} catch (IOException e) {
LOG.error(e.getMessage(), e);
throw new ReportException(ReportException.Type.ERROR_WHILE_COPYING_REPORT_TO_RESPONSE, e);
}
out.flush();
return null;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return showException(L_QCADOO_REPORT_REPORT, e).addObject(L_TEMPLATE, template).addObject("isParameter", true).addObject(L_PARAMS, params).addObject(L_LOCALE, locale);
}
}
Aggregations