use of org.mifos.reports.pentaho.PentahoValidationError in project head by mifos.
the class PentahoReportsServiceImpl method validate.
private void validate(MasterReport report, List<PentahoValidationError> errors) throws ReportProcessingException {
ReportParameterDefinition paramDefinition = report.getParameterDefinition();
ReportParameterValidator validator = paramDefinition.getValidator();
ParameterContext paramContext = new DefaultParameterContext(report);
ValidationResult validationResult = validator.validate(null, paramDefinition, paramContext);
for (ValidationMessage msg : validationResult.getErrors()) {
PentahoValidationError error = new PentahoValidationError(msg.getMessage());
errors.add(error);
}
String[] properties = validationResult.getProperties();
for (String prop : properties) {
for (ValidationMessage msg : validationResult.getErrors(prop)) {
PentahoValidationError error = new PentahoValidationError(prop, msg.getMessage());
errors.add(error);
}
}
}
use of org.mifos.reports.pentaho.PentahoValidationError in project head by mifos.
the class PentahoReportsServiceImpl method getReport.
@Override
public PentahoReport getReport(Integer reportId, Integer outputTypeId, Map<String, AbstractPentahoParameter> params) {
ByteArrayOutputStream baos = null;
if (!checkAccessToReport(reportId)) {
throw new AccessDeniedException("Access denied");
}
try {
String reportFileName = getReportFilename(reportId);
// load report definition
ResourceManager manager = new ResourceManager();
manager.registerDefaults();
URL url = PentahoReportLocator.getURLForReport(reportFileName);
Resource res = manager.createDirectly(url, MasterReport.class);
MasterReport report = (MasterReport) res.getResource();
PentahoReport result = new PentahoReport();
List<PentahoValidationError> errors = new ArrayList<PentahoValidationError>();
try {
addParametersToReport(report, params);
validate(report, errors);
} catch (ReflectionException ex) {
errors.add(new PentahoValidationError(ex.getMessage()));
}
result.setErrors(errors);
if (errors.isEmpty()) {
baos = new ByteArrayOutputStream();
PentahoOutputType outputType = PentahoOutputType.findById(outputTypeId);
switch(outputType) {
case XLS:
ExcelReportUtil.createXLS(report, baos);
break;
case RTF:
RTFReportUtil.createRTF(report, baos);
break;
case HTML:
HtmlReportUtil.createStreamHTML(report, baos);
break;
case CSV:
CSVReportUtil.createCSV(report, baos, "UTF-8");
break;
case XML:
XmlTableReportUtil.createFlowXML(report, baos);
break;
default:
// PDF
PdfReportUtil.createPDF(report, baos);
break;
}
result.setContentType(outputType.getContentType());
result.setFileExtension(outputType.getFileExtension());
result.setName(getReportName(reportId));
result.setContent(baos.toByteArray());
}
return result;
} catch (Exception e) {
throw new MifosRuntimeException(e);
} finally {
closeStream(baos);
}
}
use of org.mifos.reports.pentaho.PentahoValidationError in project head by mifos.
the class PentahoReportingController method executeReport.
@RequestMapping(value = "/execPentahoReport.ftl", method = RequestMethod.POST)
public ModelAndView executeReport(final HttpServletRequest request, HttpServletResponse response, @RequestParam(value = CANCEL_PARAM, required = false) String cancel, @Valid @ModelAttribute("pentahoReportFormBean") PentahoReportFormBean pentahoReportFormBean, BindingResult bindingResult) throws IOException {
if (!this.pentahoReportsService.checkAccessToReport(pentahoReportFormBean.getReportId())) {
throw new AccessDeniedException("Access denied");
}
ModelAndView mav = null;
Integer reportId = pentahoReportFormBean.getReportId();
if (StringUtils.isNotBlank(cancel)) {
mav = new ModelAndView("redirect:" + REPORTS_MAIN_URL);
} else if (bindingResult.hasErrors()) {
mav = new ModelAndView("viewPentahoReport");
initFormBean(pentahoReportFormBean, reportId, request);
} else {
Integer outputType = Integer.parseInt(pentahoReportFormBean.getOutputType());
Map<String, AbstractPentahoParameter> reportParams = pentahoReportFormBean.getAllParameteres();
PentahoReport report = this.pentahoReportsService.getReport(reportId, outputType, reportParams);
if (report.isInError()) {
for (PentahoValidationError error : report.getErrors()) {
addErrorToBindingResult(error, bindingResult);
}
mav = new ModelAndView("viewPentahoReport");
initFormBean(pentahoReportFormBean, reportId, request);
} else {
if (report.getContentType().equalsIgnoreCase("text/html")) {
HashMap<String, String> modelMap = new HashMap<String, String>();
modelMap.put("reportContent", new String(report.getContent()));
mav = new ModelAndView("viewHtmlReport", modelMap);
} else {
response.setHeader("Content-Disposition", "attachment; filename=\"" + report.getFilename() + "\"");
response.setContentType(report.getContentType());
response.setContentLength(report.getContentSize());
response.getOutputStream().write(report.getContent());
}
}
}
return mav;
}
use of org.mifos.reports.pentaho.PentahoValidationError in project head by mifos.
the class PentahoReportsServiceImpl method getAdminReport.
@Override
public PentahoReport getAdminReport(Integer adminReportId, Integer outputTypeId, Map<String, AbstractPentahoParameter> params) {
ByteArrayOutputStream baos = null;
try {
// load report definition
ResourceManager manager = new ResourceManager();
manager.registerDefaults();
String reportName = legacyAdminDocumentDao.getAdminDocumentById(adminReportId.shortValue()).getAdminDocumentName();
String filename = legacyAdminDocumentDao.getAdminDocumentById(adminReportId.shortValue()).getAdminDocumentIdentifier();
File file = new File(viewOrganizationSettingsServiceFacade.getAdminDocumentStorageDirectory(), filename);
StringBuilder path = new StringBuilder("file:");
path.append(file.getAbsolutePath());
URL url = new URL(path.toString());
Resource res = manager.createDirectly(url, MasterReport.class);
MasterReport report = (MasterReport) res.getResource();
PentahoReport result = new PentahoReport();
List<PentahoValidationError> errors = new ArrayList<PentahoValidationError>();
try {
addParametersToReport(report, params);
validate(report, errors);
} catch (ReflectionException ex) {
errors.add(new PentahoValidationError(ex.getMessage()));
}
result.setErrors(errors);
if (errors.isEmpty()) {
baos = new ByteArrayOutputStream();
PentahoOutputType outputType = PentahoOutputType.findById(outputTypeId);
switch(outputType) {
case XLS:
ExcelReportUtil.createXLS(report, baos);
break;
case RTF:
RTFReportUtil.createRTF(report, baos);
break;
case HTML:
HtmlReportUtil.createStreamHTML(report, baos);
break;
case CSV:
CSVReportUtil.createCSV(report, baos, "UTF-8");
break;
case XML:
XmlTableReportUtil.createFlowXML(report, baos);
break;
default:
// PDF
PdfReportUtil.createPDF(report, baos);
break;
}
result.setContentType(outputType.getContentType());
result.setFileExtension(outputType.getFileExtension());
result.setName(reportName);
result.setContent(baos.toByteArray());
}
return result;
} catch (Exception e) {
throw new MifosRuntimeException(e);
} finally {
closeStream(baos);
}
}
Aggregations