wip mifosx-195 add list of parameters to reports template

This commit is contained in:
John Woodlock
2013-04-28 03:05:14 +01:00
parent a3a40f5a45
commit 09bddb7bf7
5 changed files with 142 additions and 90 deletions
@@ -49,19 +49,19 @@ public class ReportsApiResource {
private final String resourceNameForPermissions = "REPORT"; private final String resourceNameForPermissions = "REPORT";
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ToApiJsonSerializer<ReportData> toApiJsonSerializer; private final ToApiJsonSerializer<ReportData> toApiJsonSerializer;
private final ReadReportingService readExtraDataAndReportingService; private final ReadReportingService readReportingService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final ApiRequestParameterHelper apiRequestParameterHelper; private final ApiRequestParameterHelper apiRequestParameterHelper;
@Autowired @Autowired
public ReportsApiResource( public ReportsApiResource(
final PlatformSecurityContext context, final PlatformSecurityContext context,
final ReadReportingService readExtraDataAndReportingService, final ReadReportingService readReportingService,
final ToApiJsonSerializer<ReportData> toApiJsonSerializer, final ToApiJsonSerializer<ReportData> toApiJsonSerializer,
PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final ApiRequestParameterHelper apiRequestParameterHelper) { final ApiRequestParameterHelper apiRequestParameterHelper) {
this.context = context; this.context = context;
this.readExtraDataAndReportingService = readExtraDataAndReportingService; this.readReportingService = readReportingService;
this.toApiJsonSerializer = toApiJsonSerializer; this.toApiJsonSerializer = toApiJsonSerializer;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.apiRequestParameterHelper = apiRequestParameterHelper; this.apiRequestParameterHelper = apiRequestParameterHelper;
@@ -75,7 +75,7 @@ public class ReportsApiResource {
context.authenticatedUser().validateHasReadPermission( context.authenticatedUser().validateHasReadPermission(
resourceNameForPermissions); resourceNameForPermissions);
final Collection<ReportData> result = this.readExtraDataAndReportingService final Collection<ReportData> result = this.readReportingService
.retrieveReportList(); .retrieveReportList();
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper
@@ -94,14 +94,15 @@ public class ReportsApiResource {
context.authenticatedUser().validateHasReadPermission( context.authenticatedUser().validateHasReadPermission(
resourceNameForPermissions); resourceNameForPermissions);
final ReportData result = this.readExtraDataAndReportingService final ReportData result = this.readReportingService
.retrieveReport(id); .retrieveReport(id);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper
.process(uriInfo.getQueryParameters()); .process(uriInfo.getQueryParameters());
if (settings.isTemplate()) { if (settings.isTemplate()) {
result.appendedTemplate(); result.appendedTemplate(this.readReportingService
.getAllowedParameters());
} }
return this.toApiJsonSerializer.serialize(settings, result, return this.toApiJsonSerializer.serialize(settings, result,
RESPONSE_DATA_PARAMETERS); RESPONSE_DATA_PARAMETERS);
@@ -117,7 +118,8 @@ public class ReportsApiResource {
resourceNameForPermissions); resourceNameForPermissions);
ReportData result = new ReportData(); ReportData result = new ReportData();
result.appendedTemplate(); result.appendedTemplate(this.readReportingService
.getAllowedParameters());
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper
.process(uriInfo.getQueryParameters()); .process(uriInfo.getQueryParameters());
@@ -11,76 +11,87 @@ import java.util.List;
final public class ReportData { final public class ReportData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Long id; private final Long id;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String reportName; private final String reportName;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String reportType; private final String reportType;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String reportSubType; private final String reportSubType;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String reportCategory; private final String reportCategory;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String description; private final String description;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String reportSql; private final String reportSql;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Boolean coreReport; private final Boolean coreReport;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Boolean useReport; private final Boolean useReport;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Collection<ReportParameterData> reportParameters; private final Collection<ReportParameterData> reportParameters;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private List<String> allowedReportTypes; private List<String> allowedReportTypes;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private List<String> allowedReportSubTypes; private List<String> allowedReportSubTypes;
@SuppressWarnings("unused")
private Collection<ReportParameterData> allowedParameters;
public ReportData(final Long id, final String reportName, final String reportType, final String reportSubType, public ReportData(final Long id, final String reportName,
final String reportCategory, final String description, final String reportSql, final Boolean coreReport, final String reportType, final String reportSubType,
final Boolean useReport, final Collection<ReportParameterData> reportParameters) { final String reportCategory, final String description,
this.id = id; final String reportSql, final Boolean coreReport,
this.reportName = reportName; final Boolean useReport,
this.reportType = reportType; final Collection<ReportParameterData> reportParameters) {
this.reportSubType = reportSubType; this.id = id;
this.reportCategory = reportCategory; this.reportName = reportName;
this.description = description; this.reportType = reportType;
this.reportParameters = reportParameters; this.reportSubType = reportSubType;
this.reportSql = reportSql; this.reportCategory = reportCategory;
this.coreReport = coreReport; this.description = description;
this.useReport = useReport; this.reportParameters = reportParameters;
this.allowedReportTypes = null; this.reportSql = reportSql;
this.allowedReportSubTypes = null; this.coreReport = coreReport;
} this.useReport = useReport;
this.allowedReportTypes = null;
this.allowedReportSubTypes = null;
this.allowedParameters = null;
}
public ReportData() { public ReportData() {
this.id = null; this.id = null;
this.reportName = null; this.reportName = null;
this.reportType = null; this.reportType = null;
this.reportSubType = null; this.reportSubType = null;
this.reportCategory = null; this.reportCategory = null;
this.description = null; this.description = null;
this.reportParameters = null; this.reportParameters = null;
this.reportSql = null; this.reportSql = null;
this.coreReport = null; this.coreReport = null;
this.useReport = null; this.useReport = null;
this.allowedReportTypes = null; this.allowedReportTypes = null;
this.allowedReportSubTypes = null; this.allowedReportSubTypes = null;
} this.allowedParameters = null;
}
public void appendedTemplate() { public void appendedTemplate(
final Collection<ReportParameterData> allowedParameters) {
List<String> reportTypes = new ArrayList<String>(); List<String> reportTypes = new ArrayList<String>();
reportTypes.add("Table"); reportTypes.add("Table");
reportTypes.add("Pentaho"); reportTypes.add("Pentaho");
reportTypes.add("Chart"); reportTypes.add("Chart");
this.allowedReportTypes = reportTypes; this.allowedReportTypes = reportTypes;
List<String> reportSubTypes = new ArrayList<String>(); List<String> reportSubTypes = new ArrayList<String>();
reportSubTypes.add("Bar"); reportSubTypes.add("Bar");
reportSubTypes.add("Pie"); reportSubTypes.add("Pie");
this.allowedReportSubTypes = reportSubTypes; this.allowedReportSubTypes = reportSubTypes;
}
this.allowedParameters = allowedParameters;
}
} }
@@ -5,18 +5,20 @@
*/ */
package org.mifosplatform.infrastructure.dataqueries.data; 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 { final public class ReportParameterData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Long id; private final Long id;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String reportParameterName; private final String reportParameterName;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String parameterName; private final String parameterName;
public ReportParameterData(final Long id, final String reportParameterName, final String parameterName) { public ReportParameterData(final Long id, final String reportParameterName,
this.id = id; final String parameterName) {
this.reportParameterName = reportParameterName; this.id = id;
this.parameterName = parameterName; this.reportParameterName = reportParameterName;
} this.parameterName = parameterName;
}
} }
@@ -13,20 +13,27 @@ import javax.ws.rs.core.StreamingOutput;
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData; import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
import org.mifosplatform.infrastructure.dataqueries.data.ReportData; import org.mifosplatform.infrastructure.dataqueries.data.ReportData;
import org.mifosplatform.infrastructure.dataqueries.data.ReportParameterData;
public interface ReadReportingService { public interface ReadReportingService {
StreamingOutput retrieveReportCSV(String name, String type, Map<String, String> extractedQueryParams); StreamingOutput retrieveReportCSV(String name, String type,
Map<String, String> extractedQueryParams);
GenericResultsetData retrieveGenericResultset(String name, String type, Map<String, String> extractedQueryParams); GenericResultsetData retrieveGenericResultset(String name, String type,
Map<String, String> extractedQueryParams);
Response processPentahoRequest(String reportName, String outputType, Map<String, String> queryParams); Response processPentahoRequest(String reportName, String outputType,
Map<String, String> queryParams);
String retrieveReportPDF(String name, String type, Map<String, String> extractedQueryParams); String retrieveReportPDF(String name, String type,
Map<String, String> extractedQueryParams);
String getReportType(String reportName); String getReportType(String reportName);
Collection<ReportData> retrieveReportList(); Collection<ReportData> retrieveReportList();
ReportData retrieveReport(final Long id); Collection<ReportParameterData> getAllowedParameters();
ReportData retrieveReport(final Long id);
} }
@@ -499,6 +499,17 @@ public class ReadReportingServiceImpl implements ReadReportingService {
return reportList; return reportList;
} }
@Override
public Collection<ReportParameterData> getAllowedParameters() {
ReportParameterMapper rm = new ReportParameterMapper();
String sql = rm.schema();
Collection<ReportParameterData> parameters = this.jdbcTemplate.query(sql, rm, new Object[] {});
return parameters;
}
private static final class ReportParameterJoinMapper implements RowMapper<ReportParameterJoinData> { private static final class ReportParameterJoinMapper implements RowMapper<ReportParameterJoinData> {
public String schema(final Long reportId) { public String schema(final Long reportId) {
@@ -560,4 +571,23 @@ public class ReadReportingServiceImpl implements ReadReportingService {
coreReport, useReport, reportParameterId, reportParameterName, parameterName); coreReport, useReport, reportParameterId, reportParameterName, parameterName);
} }
} }
private static final class ReportParameterMapper implements RowMapper<ReportParameterData> {
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);
}
}
} }