Search in sources :

Example 1 with AbstractPentahoParameter

use of org.mifos.reports.pentaho.params.AbstractPentahoParameter in project head by mifos.

the class PentahoParamParser method parseReportParams.

public List<AbstractPentahoParameter> parseReportParams(MasterReport report, HttpServletRequest request, Map<String, AbstractPentahoParameter> selectedValues, boolean update) {
    ParameterContext paramContext = null;
    try {
        paramContext = new DefaultParameterContext(report);
        ReportParameterDefinition paramDefinition = report.getParameterDefinition();
        List<AbstractPentahoParameter> result = new ArrayList<AbstractPentahoParameter>();
        for (ParameterDefinitionEntry paramDefEntry : paramDefinition.getParameterDefinitions()) {
            result.add(parseParam(paramDefEntry, paramContext, selectedValues, update));
        }
        return result;
    } catch (ReportDataFactoryException ex) {
        throw new JNDIException("Problem with Pentaho Reports", request);
    } catch (Exception ex) {
        throw new MifosRuntimeException(ex);
    } finally {
        if (paramContext != null) {
            try {
                paramContext.close();
            } catch (ReportDataFactoryException ex) {
                logger.error("Exception while closing parameter context", ex);
            }
        }
    }
}
Also used : ReportParameterDefinition(org.pentaho.reporting.engine.classic.core.parameters.ReportParameterDefinition) AbstractPentahoParameter(org.mifos.reports.pentaho.params.AbstractPentahoParameter) DefaultParameterContext(org.pentaho.reporting.engine.classic.core.parameters.DefaultParameterContext) ParameterDefinitionEntry(org.pentaho.reporting.engine.classic.core.parameters.ParameterDefinitionEntry) ArrayList(java.util.ArrayList) ReportDataFactoryException(org.pentaho.reporting.engine.classic.core.ReportDataFactoryException) DefaultParameterContext(org.pentaho.reporting.engine.classic.core.parameters.DefaultParameterContext) ParameterContext(org.pentaho.reporting.engine.classic.core.parameters.ParameterContext) ReportDataFactoryException(org.pentaho.reporting.engine.classic.core.ReportDataFactoryException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with AbstractPentahoParameter

use of org.mifos.reports.pentaho.params.AbstractPentahoParameter in project head by mifos.

the class PentahoReportsServiceImpl method addParametersToReport.

private void addParametersToReport(MasterReport report, Map<String, AbstractPentahoParameter> params) throws ReflectionException, IOException {
    ReportParameterValues rptParamValues = report.getParameterValues();
    ReportParameterDefinition paramsDefinition = report.getParameterDefinition();
    params.put("mifosLogoPath", getLogoParameterForReport());
    for (ParameterDefinitionEntry paramDefEntry : paramsDefinition.getParameterDefinitions()) {
        String paramName = paramDefEntry.getName();
        AbstractPentahoParameter parameter = params.get(paramName);
        if (parameter != null) {
            Object val = this.paramParser.parseParamValue(parameter, paramDefEntry);
            if (val != null && (!val.getClass().isArray() || Array.getLength(val) > 0)) {
                rptParamValues.put(paramName, val);
            }
        }
    }
}
Also used : ReportParameterDefinition(org.pentaho.reporting.engine.classic.core.parameters.ReportParameterDefinition) AbstractPentahoParameter(org.mifos.reports.pentaho.params.AbstractPentahoParameter) ParameterDefinitionEntry(org.pentaho.reporting.engine.classic.core.parameters.ParameterDefinitionEntry) ReportParameterValues(org.pentaho.reporting.engine.classic.core.util.ReportParameterValues)

Example 3 with AbstractPentahoParameter

use of org.mifos.reports.pentaho.params.AbstractPentahoParameter in project head by mifos.

the class PentahoReportFormBean method getAllParameteres.

public Map<String, AbstractPentahoParameter> getAllParameteres() {
    List<AbstractPentahoParameter> allParams = new ArrayList<AbstractPentahoParameter>();
    allParams.addAll(this.reportDateParams);
    allParams.addAll(this.reportInputParams);
    allParams.addAll(this.reportSingleSelectParams);
    allParams.addAll(this.reportMultiSelectParams);
    Map<String, AbstractPentahoParameter> result = new HashMap<String, AbstractPentahoParameter>();
    for (AbstractPentahoParameter param : allParams) {
        result.put(param.getParamName(), param);
    }
    return result;
}
Also used : AbstractPentahoParameter(org.mifos.reports.pentaho.params.AbstractPentahoParameter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 4 with AbstractPentahoParameter

use of org.mifos.reports.pentaho.params.AbstractPentahoParameter in project head by mifos.

the class PentahoReportFormBean method setReportParameters.

public void setReportParameters(List<AbstractPentahoParameter> params) {
    Map<String, AbstractPentahoParameter> formParams = getAllParameteres();
    for (AbstractPentahoParameter param : params) {
        String paramName = param.getParamName();
        if (formParams.containsKey(paramName)) {
            if (param instanceof PentahoSingleSelectParameter) {
                PentahoSingleSelectParameter singleSelectParam = (PentahoSingleSelectParameter) param;
                PentahoSingleSelectParameter singleSelectFormParam = (PentahoSingleSelectParameter) formParams.get(paramName);
                singleSelectFormParam.setPossibleValues(singleSelectParam.getPossibleValues());
            } else if (param instanceof PentahoMultiSelectParameter) {
                PentahoMultiSelectParameter multiSelectParam = (PentahoMultiSelectParameter) param;
                PentahoMultiSelectParameter multiSelectFormParam = (PentahoMultiSelectParameter) formParams.get(paramName);
                multiSelectFormParam.setPossibleValuesOptions(multiSelectParam.getPossibleValuesOptions());
                for (String val : multiSelectFormParam.getSelectedValues()) {
                    String text = multiSelectFormParam.getPossibleValuesOptions().get(val);
                    multiSelectFormParam.getPossibleValuesOptions().remove(val);
                    multiSelectFormParam.getSelectedValuesOptions().put(val, text);
                }
            }
        } else if (!param.getParamName().equals("mifosLogoPath")) {
            addParameter(param);
        }
    }
}
Also used : AbstractPentahoParameter(org.mifos.reports.pentaho.params.AbstractPentahoParameter) PentahoSingleSelectParameter(org.mifos.reports.pentaho.params.PentahoSingleSelectParameter) PentahoMultiSelectParameter(org.mifos.reports.pentaho.params.PentahoMultiSelectParameter)

Example 5 with AbstractPentahoParameter

use of org.mifos.reports.pentaho.params.AbstractPentahoParameter in project head by mifos.

the class PentahoReportsServiceIntegrationTest method testGetAdminReport.

@Test
public void testGetAdminReport() throws Exception {
    String adminDocumentUploadPath = viewOrganizationSettingsServiceFacade.getAdminDocumentStorageDirectory();
    String adminDocumentPath = "IntegrationTest_Loan_template.prpt";
    File adminDocumentSrc = new File(this.getClass().getResource("/Loan_template.prpt").toString().replace("file:", ""));
    File adminDocumentDst = new File(adminDocumentUploadPath + "/" + adminDocumentPath);
    try {
        FileUtils.copyFile(adminDocumentSrc, adminDocumentDst);
        AdminDocumentBO adminDocumentBO = new AdminDocumentBO();
        adminDocumentBO.setAdmindocId(Short.valueOf("1"));
        adminDocumentBO.setAdminDocumentName("IntegrationTest_Loan_template");
        adminDocumentBO.setIsActive(Short.valueOf("1"));
        adminDocumentBO.setAdminDocumentIdentifier(adminDocumentPath);
        AdminDocAccStateMixBO adminDocAccStateMixBO = new AdminDocAccStateMixBO();
        AccountStateEntity accountStateEntity = new AccountStateEntity(AccountState.LOAN_APPROVED);
        adminDocAccStateMixBO.setAccountStateID(accountStateEntity);
        adminDocAccStateMixBO.setAdminDocumentID(adminDocumentBO);
        legacyAdminDocumentDao.createOrUpdate(adminDocumentBO);
        Map<String, AbstractPentahoParameter> params = new HashMap<String, AbstractPentahoParameter>();
        PentahoInputParameter entityIdParameter = new PentahoInputParameter();
        entityIdParameter.setParamName("entity_id");
        entityIdParameter.setValue("000100000000002");
        params.put("entity_id", entityIdParameter);
        Integer adminDocId = Integer.parseInt(adminDocumentBO.getAdmindocId().toString());
        for (PentahoOutputType outputType : PentahoOutputType.values()) {
            PentahoReport report = pentahoReportsServiceImpl.getAdminReport(adminDocId, outputType.getId(), params);
            Assert.assertTrue(report.getFileExtension() == outputType.getFileExtension());
            Assert.assertTrue(report.getContentType() == outputType.getContentType());
            Assert.assertTrue(report.getErrors().isEmpty());
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (adminDocumentDst.exists()) {
            adminDocumentDst.delete();
        }
    }
}
Also used : PentahoReport(org.mifos.reports.pentaho.PentahoReport) AbstractPentahoParameter(org.mifos.reports.pentaho.params.AbstractPentahoParameter) HashMap(java.util.HashMap) AdminDocAccStateMixBO(org.mifos.reports.admindocuments.business.AdminDocAccStateMixBO) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) PentahoOutputType(org.mifos.reports.pentaho.util.PentahoOutputType) AdminDocumentBO(org.mifos.reports.admindocuments.business.AdminDocumentBO) PentahoInputParameter(org.mifos.reports.pentaho.params.PentahoInputParameter) File(java.io.File) Test(org.junit.Test)

Aggregations

AbstractPentahoParameter (org.mifos.reports.pentaho.params.AbstractPentahoParameter)8 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 PentahoReport (org.mifos.reports.pentaho.PentahoReport)2 PentahoInputParameter (org.mifos.reports.pentaho.params.PentahoInputParameter)2 DefaultListParameter (org.pentaho.reporting.engine.classic.core.parameters.DefaultListParameter)2 ParameterDefinitionEntry (org.pentaho.reporting.engine.classic.core.parameters.ParameterDefinitionEntry)2 ReportParameterDefinition (org.pentaho.reporting.engine.classic.core.parameters.ReportParameterDefinition)2 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.Test)1 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 AdminDocAccStateMixBO (org.mifos.reports.admindocuments.business.AdminDocAccStateMixBO)1 AdminDocumentBO (org.mifos.reports.admindocuments.business.AdminDocumentBO)1 PentahoMultiSelectParameter (org.mifos.reports.pentaho.params.PentahoMultiSelectParameter)1 PentahoSingleSelectParameter (org.mifos.reports.pentaho.params.PentahoSingleSelectParameter)1 PentahoOutputType (org.mifos.reports.pentaho.util.PentahoOutputType)1 ReportDataFactoryException (org.pentaho.reporting.engine.classic.core.ReportDataFactoryException)1 DefaultParameterContext (org.pentaho.reporting.engine.classic.core.parameters.DefaultParameterContext)1