From 09bddb7bf7beaae715294b621c005c3fd039ea43 Mon Sep 17 00:00:00 2001 From: John Woodlock Date: Sun, 28 Apr 2013 03:05:14 +0100 Subject: [PATCH] wip mifosx-195 add list of parameters to reports template --- .../dataqueries/api/ReportsApiResource.java | 16 +- .../dataqueries/data/ReportData.java | 141 ++++++++++-------- .../dataqueries/data/ReportParameterData.java | 24 +-- .../service/ReadReportingService.java | 21 ++- .../service/ReadReportingServiceImpl.java | 30 ++++ 5 files changed, 142 insertions(+), 90 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/ReportsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/ReportsApiResource.java index 549efe454..98c17aa10 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/ReportsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/ReportsApiResource.java @@ -49,19 +49,19 @@ public class ReportsApiResource { private final String resourceNameForPermissions = "REPORT"; private final PlatformSecurityContext context; private final ToApiJsonSerializer toApiJsonSerializer; - private final ReadReportingService readExtraDataAndReportingService; + private final ReadReportingService readReportingService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final ApiRequestParameterHelper apiRequestParameterHelper; @Autowired public ReportsApiResource( final PlatformSecurityContext context, - final ReadReportingService readExtraDataAndReportingService, + final ReadReportingService readReportingService, final ToApiJsonSerializer toApiJsonSerializer, PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final ApiRequestParameterHelper apiRequestParameterHelper) { this.context = context; - this.readExtraDataAndReportingService = readExtraDataAndReportingService; + this.readReportingService = readReportingService; this.toApiJsonSerializer = toApiJsonSerializer; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.apiRequestParameterHelper = apiRequestParameterHelper; @@ -75,7 +75,7 @@ public class ReportsApiResource { context.authenticatedUser().validateHasReadPermission( resourceNameForPermissions); - final Collection result = this.readExtraDataAndReportingService + final Collection result = this.readReportingService .retrieveReportList(); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper @@ -94,14 +94,15 @@ public class ReportsApiResource { context.authenticatedUser().validateHasReadPermission( resourceNameForPermissions); - final ReportData result = this.readExtraDataAndReportingService + final ReportData result = this.readReportingService .retrieveReport(id); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper .process(uriInfo.getQueryParameters()); if (settings.isTemplate()) { - result.appendedTemplate(); + result.appendedTemplate(this.readReportingService + .getAllowedParameters()); } return this.toApiJsonSerializer.serialize(settings, result, RESPONSE_DATA_PARAMETERS); @@ -117,7 +118,8 @@ public class ReportsApiResource { resourceNameForPermissions); ReportData result = new ReportData(); - result.appendedTemplate(); + result.appendedTemplate(this.readReportingService + .getAllowedParameters()); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper .process(uriInfo.getQueryParameters()); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ReportData.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ReportData.java index 47b8d13e2..9ef690acb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ReportData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ReportData.java @@ -11,76 +11,87 @@ import java.util.List; final public class ReportData { - @SuppressWarnings("unused") - private final Long id; - @SuppressWarnings("unused") - private final String reportName; - @SuppressWarnings("unused") - private final String reportType; - @SuppressWarnings("unused") - private final String reportSubType; - @SuppressWarnings("unused") - private final String reportCategory; - @SuppressWarnings("unused") - private final String description; - @SuppressWarnings("unused") - private final String reportSql; - @SuppressWarnings("unused") - private final Boolean coreReport; - @SuppressWarnings("unused") - private final Boolean useReport; - @SuppressWarnings("unused") - private final Collection reportParameters; + @SuppressWarnings("unused") + private final Long id; + @SuppressWarnings("unused") + private final String reportName; + @SuppressWarnings("unused") + private final String reportType; + @SuppressWarnings("unused") + private final String reportSubType; + @SuppressWarnings("unused") + private final String reportCategory; + @SuppressWarnings("unused") + private final String description; + @SuppressWarnings("unused") + private final String reportSql; + @SuppressWarnings("unused") + private final Boolean coreReport; + @SuppressWarnings("unused") + private final Boolean useReport; + @SuppressWarnings("unused") + private final Collection reportParameters; - @SuppressWarnings("unused") - private List allowedReportTypes; - @SuppressWarnings("unused") - private List allowedReportSubTypes; + @SuppressWarnings("unused") + private List allowedReportTypes; + @SuppressWarnings("unused") + private List allowedReportSubTypes; + @SuppressWarnings("unused") + private Collection allowedParameters; - public ReportData(final Long id, final String reportName, final String reportType, final String reportSubType, - final String reportCategory, final String description, final String reportSql, final Boolean coreReport, - final Boolean useReport, final Collection reportParameters) { - this.id = id; - this.reportName = reportName; - this.reportType = reportType; - this.reportSubType = reportSubType; - this.reportCategory = reportCategory; - this.description = description; - this.reportParameters = reportParameters; - this.reportSql = reportSql; - this.coreReport = coreReport; - this.useReport = useReport; - this.allowedReportTypes = null; - this.allowedReportSubTypes = null; - } + public ReportData(final Long id, final String reportName, + final String reportType, final String reportSubType, + final String reportCategory, final String description, + final String reportSql, final Boolean coreReport, + final Boolean useReport, + final Collection reportParameters) { + this.id = id; + this.reportName = reportName; + this.reportType = reportType; + this.reportSubType = reportSubType; + this.reportCategory = reportCategory; + this.description = description; + this.reportParameters = reportParameters; + this.reportSql = reportSql; + this.coreReport = coreReport; + this.useReport = useReport; + this.allowedReportTypes = null; + this.allowedReportSubTypes = null; + this.allowedParameters = null; + } - public ReportData() { - this.id = null; - this.reportName = null; - this.reportType = null; - this.reportSubType = null; - this.reportCategory = null; - this.description = null; - this.reportParameters = null; - this.reportSql = null; - this.coreReport = null; - this.useReport = null; - this.allowedReportTypes = null; - this.allowedReportSubTypes = null; - } + public ReportData() { + this.id = null; + this.reportName = null; + this.reportType = null; + this.reportSubType = null; + this.reportCategory = null; + this.description = null; + this.reportParameters = null; + this.reportSql = null; + this.coreReport = null; + this.useReport = null; + this.allowedReportTypes = null; + this.allowedReportSubTypes = null; + this.allowedParameters = null; + } - public void appendedTemplate() { + public void appendedTemplate( + final Collection allowedParameters) { - List reportTypes = new ArrayList(); - reportTypes.add("Table"); - reportTypes.add("Pentaho"); - reportTypes.add("Chart"); - this.allowedReportTypes = reportTypes; + List reportTypes = new ArrayList(); + reportTypes.add("Table"); + reportTypes.add("Pentaho"); + reportTypes.add("Chart"); + this.allowedReportTypes = reportTypes; - List reportSubTypes = new ArrayList(); - reportSubTypes.add("Bar"); - reportSubTypes.add("Pie"); - this.allowedReportSubTypes = reportSubTypes; - } + List reportSubTypes = new ArrayList(); + reportSubTypes.add("Bar"); + reportSubTypes.add("Pie"); + this.allowedReportSubTypes = reportSubTypes; + + this.allowedParameters = allowedParameters; + + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ReportParameterData.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ReportParameterData.java index 55676dcd5..5030fc1f3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ReportParameterData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ReportParameterData.java @@ -5,18 +5,20 @@ */ package org.mifosplatform.infrastructure.dataqueries.data; +/* used to show list of parameters used by a report and also for getting a list of parameters available (the reportParameterName is left null */ final public class ReportParameterData { - @SuppressWarnings("unused") - private final Long id; - @SuppressWarnings("unused") - private final String reportParameterName; - @SuppressWarnings("unused") - private final String parameterName; + @SuppressWarnings("unused") + private final Long id; + @SuppressWarnings("unused") + private final String reportParameterName; + @SuppressWarnings("unused") + private final String parameterName; - public ReportParameterData(final Long id, final String reportParameterName, final String parameterName) { - this.id = id; - this.reportParameterName = reportParameterName; - this.parameterName = parameterName; - } + public ReportParameterData(final Long id, final String reportParameterName, + final String parameterName) { + this.id = id; + this.reportParameterName = reportParameterName; + this.parameterName = parameterName; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingService.java index ad76bee12..f96e697d5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingService.java @@ -13,20 +13,27 @@ import javax.ws.rs.core.StreamingOutput; import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData; import org.mifosplatform.infrastructure.dataqueries.data.ReportData; +import org.mifosplatform.infrastructure.dataqueries.data.ReportParameterData; public interface ReadReportingService { - StreamingOutput retrieveReportCSV(String name, String type, Map extractedQueryParams); + StreamingOutput retrieveReportCSV(String name, String type, + Map extractedQueryParams); - GenericResultsetData retrieveGenericResultset(String name, String type, Map extractedQueryParams); + GenericResultsetData retrieveGenericResultset(String name, String type, + Map extractedQueryParams); - Response processPentahoRequest(String reportName, String outputType, Map queryParams); + Response processPentahoRequest(String reportName, String outputType, + Map queryParams); - String retrieveReportPDF(String name, String type, Map extractedQueryParams); + String retrieveReportPDF(String name, String type, + Map extractedQueryParams); - String getReportType(String reportName); + String getReportType(String reportName); - Collection retrieveReportList(); + Collection retrieveReportList(); - ReportData retrieveReport(final Long id); + Collection getAllowedParameters(); + + ReportData retrieveReport(final Long id); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java index 9ba167280..8f4c9c73a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java @@ -499,6 +499,17 @@ public class ReadReportingServiceImpl implements ReadReportingService { return reportList; } + + @Override + public Collection getAllowedParameters() { + + ReportParameterMapper rm = new ReportParameterMapper(); + String sql = rm.schema(); + Collection parameters = this.jdbcTemplate.query(sql, rm, new Object[] {}); + return parameters; + } + + private static final class ReportParameterJoinMapper implements RowMapper { public String schema(final Long reportId) { @@ -560,4 +571,23 @@ public class ReadReportingServiceImpl implements ReadReportingService { coreReport, useReport, reportParameterId, reportParameterName, parameterName); } } + + private static final class ReportParameterMapper implements RowMapper { + + public String schema() { + + return "select p.id as id, p.parameter_name as parameterName from stretchy_parameter p where ifnull(p.special,'') != 'Y' order by p.id"; + + } + + @Override + public ReportParameterData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + + final Long id = rs.getLong("id"); + final String parameterName = rs.getString("parameterName"); + + return new ReportParameterData(id, null, parameterName); + } + } + } \ No newline at end of file