Search in sources :

Example 1 with MasterReport

use of org.pentaho.reporting.engine.classic.core.MasterReport in project head by mifos.

the class PentahoReportsServiceImpl method loadReport.

private MasterReport loadReport(String reportName) {
    ResourceManager manager = new ResourceManager();
    manager.registerDefaults();
    URL url = PentahoReportLocator.getURLForReport(reportName);
    try {
        Resource res = manager.createDirectly(url, MasterReport.class);
        MasterReport report = (MasterReport) res.getResource();
        return report;
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) Resource(org.pentaho.reporting.libraries.resourceloader.Resource) ResourceManager(org.pentaho.reporting.libraries.resourceloader.ResourceManager) URL(java.net.URL) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ReflectionException(org.mifos.reports.pentaho.util.ReflectionException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) IOException(java.io.IOException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with MasterReport

use of org.pentaho.reporting.engine.classic.core.MasterReport 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);
    }
}
Also used : PentahoReport(org.mifos.reports.pentaho.PentahoReport) ReflectionException(org.mifos.reports.pentaho.util.ReflectionException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Resource(org.pentaho.reporting.libraries.resourceloader.Resource) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceManager(org.pentaho.reporting.libraries.resourceloader.ResourceManager) URL(java.net.URL) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ReflectionException(org.mifos.reports.pentaho.util.ReflectionException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) IOException(java.io.IOException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) PentahoOutputType(org.mifos.reports.pentaho.util.PentahoOutputType) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) PentahoValidationError(org.mifos.reports.pentaho.PentahoValidationError) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with MasterReport

use of org.pentaho.reporting.engine.classic.core.MasterReport in project head by mifos.

the class PentahoReportsServiceImpl method getParametersForReport.

@Override
public List<AbstractPentahoParameter> getParametersForReport(Integer reportId, HttpServletRequest request, Map<String, AbstractPentahoParameter> selectedValues, boolean update) {
    if (!checkAccessToReport(reportId)) {
        throw new AccessDeniedException("Access denied");
    }
    String reportName = getReportFilename(reportId);
    MasterReport report = loadReport(reportName);
    return paramParser.parseReportParams(report, request, selectedValues, update);
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport)

Example 4 with MasterReport

use of org.pentaho.reporting.engine.classic.core.MasterReport 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);
    }
}
Also used : PentahoReport(org.mifos.reports.pentaho.PentahoReport) ReflectionException(org.mifos.reports.pentaho.util.ReflectionException) Resource(org.pentaho.reporting.libraries.resourceloader.Resource) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceManager(org.pentaho.reporting.libraries.resourceloader.ResourceManager) URL(java.net.URL) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ReflectionException(org.mifos.reports.pentaho.util.ReflectionException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) IOException(java.io.IOException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) PentahoOutputType(org.mifos.reports.pentaho.util.PentahoOutputType) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) PentahoValidationError(org.mifos.reports.pentaho.PentahoValidationError) File(java.io.File) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

MasterReport (org.pentaho.reporting.engine.classic.core.MasterReport)4 AccessDeniedException (org.springframework.security.access.AccessDeniedException)4 IOException (java.io.IOException)3 URL (java.net.URL)3 MifosRuntimeException (org.mifos.core.MifosRuntimeException)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 ReflectionException (org.mifos.reports.pentaho.util.ReflectionException)3 ReportProcessingException (org.pentaho.reporting.engine.classic.core.ReportProcessingException)3 Resource (org.pentaho.reporting.libraries.resourceloader.Resource)3 ResourceManager (org.pentaho.reporting.libraries.resourceloader.ResourceManager)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 PentahoReport (org.mifos.reports.pentaho.PentahoReport)2 PentahoValidationError (org.mifos.reports.pentaho.PentahoValidationError)2 PentahoOutputType (org.mifos.reports.pentaho.util.PentahoOutputType)2 File (java.io.File)1