From 97d7104c93872c9eecf035f3dec979071223eb42 Mon Sep 17 00:00:00 2001 From: John Woodlock Date: Tue, 16 Apr 2013 03:22:37 +0100 Subject: [PATCH] WIP mifosx-195 read report api (has conflict --- .../dataqueries/api/ReportsApiResource.java | 30 +++++++++-- .../service/ReadReportingService.java | 2 + .../service/ReadReportingServiceImpl.java | 50 ++++++++++++------- 3 files changed, 59 insertions(+), 23 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 d2c6481f8..62ff42fc3 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 @@ -99,6 +99,25 @@ public class ReportsApiResource { RESPONSE_DATA_PARAMETERS); } + @GET + @Path("wip/{id}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String retrieveReport(@PathParam("id") final Long id, + @Context final UriInfo uriInfo) { + + context.authenticatedUser().validateHasReadPermission( + resourceNameForPermissions); + + final ReportData result = this.readExtraDataAndReportingService + .retrieveReport(id); + + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper + .process(uriInfo.getQueryParameters()); + return this.toApiJsonSerializer.serialize(settings, result, + RESPONSE_DATA_PARAMETERS); + } + @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @@ -114,10 +133,11 @@ public class ReportsApiResource { } @PUT - @Path("{id}") + @Path("{id}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String updateReport(@PathParam("id") final Long id, final String apiRequestBodyAsJson) { + public String updateReport(@PathParam("id") final Long id, + final String apiRequestBodyAsJson) { final CommandWrapper commandRequest = new CommandWrapperBuilder() .updateReport(id).withJson(apiRequestBodyAsJson).build(); @@ -127,9 +147,9 @@ public class ReportsApiResource { return this.toApiJsonSerializer.serialize(result); } - + @DELETE - @Path("{id}") + @Path("{id}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String deleteReport(@PathParam("id") final Long id) { @@ -148,7 +168,7 @@ public class ReportsApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload", "application/vnd.ms-excel", "application/pdf", "text/html" }) - public Response retrieveReport( + public Response runReport( @PathParam("reportName") final String reportName, @Context final UriInfo uriInfo) { 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 12ce25cac..c01fd5b56 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 @@ -31,4 +31,6 @@ public interface ReadReportingService { String getReportType(String reportName); Collection retrieveReportList(); + + 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 fa1db99c6..3ef351171 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 @@ -508,12 +508,26 @@ public class ReadReportingServiceImpl implements ReadReportingService { } } + @Override + public ReportData retrieveReport(Long id) { + Collection reports = retrieveReports(id); + + for (ReportData report : reports) { + return report; + } + return null; + } + @Override public Collection retrieveReportList() { + return retrieveReports(null); + } + + private Collection retrieveReports(final Long id) { ReportParameterJoinMapper rm = new ReportParameterJoinMapper(); - String sql = rm.schema(false, context.authenticatedUser().getId()); + String sql = rm.schema(context.authenticatedUser().getId(), id); Collection rpJoins = this.jdbcTemplate.query( sql, rm, new Object[] {}); @@ -546,16 +560,13 @@ public class ReadReportingServiceImpl implements ReadReportingService { } else { if (firstReport) { - firstReport = false; - } - else - { + firstReport = false; + } else { // write report entry - reportList - .add(new ReportData(reportId, reportName, - reportType, reportSubType, reportCategory, description, - reportSql, coreReport, useReport, - reportParameters)); + reportList.add(new ReportData(reportId, reportName, + reportType, reportSubType, reportCategory, + description, reportSql, coreReport, useReport, + reportParameters)); } prevReportId = rpJoin.getReportId(); @@ -585,8 +596,8 @@ public class ReadReportingServiceImpl implements ReadReportingService { } // write last report reportList.add(new ReportData(reportId, reportName, reportType, - reportSubType, reportCategory, description, reportSql, coreReport, - useReport, reportParameters)); + reportSubType, reportCategory, description, reportSql, + coreReport, useReport, reportParameters)); return reportList; } @@ -594,13 +605,13 @@ public class ReadReportingServiceImpl implements ReadReportingService { private static final class ReportParameterJoinMapper implements RowMapper { - public String schema(boolean includeSql, Long userId) { + public String schema(Long userId, Long reportId) { String sql = "select r.id as reportId, r.report_name as reportName, r.report_type as reportType, " + " r.report_subtype as reportSubType, r.report_category as reportCategory, r.description, r.core_report as coreReport, r.use_report as useReport, " + " rp.parameter_id as reportParameterId, rp.report_parameter_name as reportParameterName, p.parameter_name as parameterName"; - if (includeSql) + if (reportId != null) sql += ", r.report_sql as reportSql "; sql += " from stretchy_report r" @@ -614,8 +625,11 @@ public class ReadReportingServiceImpl implements ReadReportingService { + " left join m_permission p on p.id = rp.permission_id" + " where ur.appuser_id = " + userId - + " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', r.report_name))) " - + " order by r.id, rp.parameter_id"; + + " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', r.report_name))) "; + if (reportId != null) + sql += " and r.id = " + reportId; + else + sql += " order by r.id, rp.parameter_id"; return sql; } @@ -649,8 +663,8 @@ public class ReadReportingServiceImpl implements ReadReportingService { final String parameterName = rs.getString("parameterName"); return new ReportParameterJoinData(reportId, reportName, - reportType, reportSubType, reportCategory, description, reportSql, - coreReport, useReport, reportParameterId, + reportType, reportSubType, reportCategory, description, + reportSql, coreReport, useReport, reportParameterId, reportParameterName, parameterName); }