diff --git a/APIFolder/api.htm b/APIFolder/api.htm index 7d3e5b872..283f3c798 100644 --- a/APIFolder/api.htm +++ b/APIFolder/api.htm @@ -32,8 +32,8 @@

 

Reports

@@ -305,10 +305,10 @@ error is parameter-specific. You can use this to display a message near

Reports

-This reports resource allows you to run and receive output from pre-defined Mifos X reports. A "Generic Resultset" containing Column Heading as well as Data information is returned and JSON is the default output format. However, you can export to CSV format by simply adding "&exportCSV=true" to the end of your URI. +The reports resource allows you to run and receive output from pre-defined Mifos X reports. The default output is a JSON formatted "Generic Resultset". The Generic Resultset contains Column Heading as well as Data information. However, you can export to CSV format by simply adding "&exportCSV=true" to the end of your URI.

-Pentaho reports can also be run from this resource. The Pentaho reports can return HTML, PDF or CSV formats. +If Pentaho reports have been pre-defined, they can also be run through this resource. Pentaho reports can return HTML, PDF or CSV formats.

Add examples showing links to client listing report producing json, then csv, then a pentaho report producing html, pdf, csv

@@ -320,39 +320,133 @@ The Mifos X Individual Lending client application uses a JQuery plugin called st
-
-
-

Parameters

-

Note: the prefix R_ below stands for Reporting

-
-
R_Name
-
mandatory
-
Report Name. One of the standard or user-defined Mifos X reports.
-
R_'parameter names' ...
-
optional, No defaults
-
The number and names of the parameters depend on the specific report and how it has been configured. FR_officeId is an example parameter name.
-
R_parameterType
-
optional, The only valid value is 'true'. If any other value is provided the parameter will be ignored
-
Determines whether the request looks for reports or paraters that have been configured.
-
exportCSV
-
optional, The only valid value is 'true'. If any other value is provided the parameter will be ignored
-
Output will be delivered as a CSV file instead of JSON. Doesn't apply to Pentaho reports.
-
+ +   +
+
+

List Reports

+

+ Lists all reports and their parameters. If a report has more than one parameter it will be listed the same number of times as it has parameters. +

+ +
Arguments
+
+
exportCSV
+
optional, The only valid value is 'true'. If any other value is provided the argument will be ignored
+
Output will be delivered as a CSV file instead of JSON.
+

Example Request: - http://localhost:8080/mifosng-provider/api/v1/reports/Client%20Listing?FR_officeId=1 + http://localhost:8080/mifosng-provider/api/v1/reports

- - - - -
GET https://thedomainname/v1/reports { + "columnHeaders": [ + { + "columnName": "report_id", + "columnType": "INT", + "columnLength": null, + "columnDisplayType": null, + "columnValues": [] + }, + { + "columnName": "report_name", + "columnType": "VARCHAR", + "columnLength": null, + "columnDisplayType": null, + "columnValues": [] + }, + { + "columnName": "report_type", + "columnType": "VARCHAR", + "columnLength": null, + "columnDisplayType": null, + "columnValues": [] + }, +... more "columnHeaders" entries + ], + "data": [ + { + "row": [ + "29", + "Client Listing", + "Table", + null, + null, + "5", + null, + "selectOfficeId" + ] + }, + { + "row": [ + "42", + "Client Listing - Additional and Unlikely", + "Table", + null, + null, + "5", + null, + "selectOfficeId" + ] + }, + { + "row": [ + "30", + "Client Loans Listing", + "Table", + null, + null, + "5", + null, + "selectOfficeId" + ] + }, +... more "Row" entries + ] +} +
+
+ + + + + + +   +
+
+

Running a Report

+

+ Runs a report and returns the report output. +

+
Arguments
+
+
R_'parameter names' ...
+
optional, No defaults
+
The number and names of the parameters depend on the specific report and how it has been configured. R_officeId is an example parameter name.
+
Note: the prefix R_ stands for Reporting
+
parameterType
+
optional, The only valid value is 'true'. If any other value is provided the argument will be ignored
+
Determines whether the request looks in the list of reports or the list of parameters for its data.
+
exportCSV
+
optional, The only valid value is 'true'. If any other value is provided the argument will be ignored
+
Output will be delivered as a CSV file instead of JSON. Doesn't apply to Pentaho reports.
+
+ +

Example Request: + http://localhost:8080/mifosng-provider/api/v1/reports/Client%20Listing?R_officeId=1 +

+ +
+ +
+ GET https://thedomainname/v1/reports/{REPORTNAME} + { "columnHeaders": [ { "columnName": "Office/Branch", @@ -404,6 +498,9 @@ The Mifos X Individual Lending client application uses a JQuery plugin called st
+ + +  
diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.968.js b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.97.js similarity index 96% rename from mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.968.js rename to mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.97.js index 56462db0e..3ecd465ce 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.968.js +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.97.js @@ -165,9 +165,7 @@ function initialiseReporting(params) { reportQuery = 'FullReportList'; if (params.reportQuery) reportQuery = params.reportQuery; - - var theParams = {Type: 'parameter'}; - getReportData(reportQuery, theParams, setupReportListSuccess) + getReportData(reportQuery, {}, setupReportListSuccess, true) } function setCurrentDate() { @@ -435,7 +433,7 @@ function runTheReport() return; } - var theParams = {Type: 'report'}; + var theParams = {}; var pValue; var reportParameterName; @@ -469,14 +467,14 @@ function runTheReport() switch(reportListing[reportListingIndex].type) { case "Table": - if (showOption == "XLS") getExportCSV(selectedRpt, theParams) + if (showOption == "XLS") getExportCSV(selectedRpt, theParams, false) else { reportDataSuccess = function(data, textStatus, jqXHR){ createTable(data); showTableReport(); }; - getReportData(selectedRpt, theParams, reportDataSuccess); + getReportData(selectedRpt, theParams, reportDataSuccess, false); } break; case "Chart": @@ -485,7 +483,7 @@ function runTheReport() createChart(data); showChartReport(reportListing[reportListingIndex].subtype); }; - getReportData(selectedRpt, theParams, reportDataSuccess); + getReportData(selectedRpt, theParams, reportDataSuccess, false); break; case "Pentaho": getPentahoReport(selectedRpt, theParams); @@ -579,8 +577,7 @@ var parameterTableHtml = ''; eval(generateSelectSuccessVariable(listOfParameters[i].name, listOfParameters[i].label, selectOne, selectAll)); - var theParams = {Type: 'parameter'}; - getReportData(listOfParameters[i].name, theParams, selectSuccess) + getReportData(listOfParameters[i].name, {}, selectSuccess, true) } } @@ -612,8 +609,7 @@ setupParameterListSuccess = function(data, textStatus, jqXHR){ setupReportListSuccess = function(data, textStatus, jqXHR){ showMsgE("In setupReportListSuccess"); - theParams = {Type: 'parameter'}; - getReportData('FullParameterList', theParams, setupParameterListSuccess); + getReportData('FullParameterList', {}, setupParameterListSuccess, true); var prevId = -1; var currId; @@ -973,13 +969,13 @@ var Rchart; } -function getReportData(rptName, inParams, successFunction) { - if (isAuthRequest == true) getReportDataAuth(rptName, inParams, successFunction) - else getReportDataNoAuth(rptName, inParams, successFunction); +function getReportData(rptName, inParams, successFunction, isParameterType) { + if (isAuthRequest == true) getReportDataAuth(rptName, inParams, successFunction, isParameterType) + else getReportDataNoAuth(rptName, inParams, successFunction, isParameterType); } -function getReportDataAuth(rptName, inParams, successFunction) { +function getReportDataAuth(rptName, inParams, successFunction, isParameterType) { alert("needs fixing up, dont rely on data") var inQueryParameters = {}; for (var i in inParams ) inQueryParameters["R_" + i] = inParams[i]; @@ -1039,9 +1035,15 @@ function buildReportParms(inParams) { return reportParams } -function getReportDataNoAuth(rptName, inParams, successFunction) { +function getReportDataNoAuth(rptName, inParams, successFunction, isParameterType) { var inQueryParameters = buildReportParms(inParams); + if (isParameterType == true) + { + if (inQueryParameters > "") inQueryParameters += "¶meterType=true" + else inQueryParameters = "parameterType=true" + } + showMsgE("getReportDataNoAuth: " + inQueryParameters); $.ajax({ url: RESTUrl + "/" + rptName, @@ -1066,11 +1068,12 @@ function getReportDataNoAuth(rptName, inParams, successFunction) { } -function getExportCSV(rptName, inParams) { +function getExportCSV(rptName, inParams, isParameterType) { var inQueryParameters = buildReportParms(inParams); if (inQueryParameters > "") inQueryParameters = "?" + inQueryParameters + "&exportCSV=true" - else inQueryParameters = "?exportCSV=true" + else inQueryParameters = "?exportCSV=true"; + if (isParameterType == true) inQueryParameters += "¶meterType=true"; var fullExportUrl = RESTUrl + "/" + rptName + inQueryParameters; showMsg("full export url: " + fullExportUrl); diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/common-head-stretchyreporting.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/common-head-stretchyreporting.jsp index a5c20fe15..a8835f39c 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/common-head-stretchyreporting.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/common-head-stretchyreporting.jsp @@ -16,6 +16,6 @@ - + diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingServiceImpl.java index b5fe3d229..0c566cc37 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingServiceImpl.java @@ -55,7 +55,7 @@ public class ReadExtraDataAndReportingServiceImpl implements final String type, final Map queryParams) { return new StreamingOutput() { - + @Override public void write(OutputStream out) throws IOException, WebApplicationException { @@ -159,14 +159,23 @@ public class ReadExtraDataAndReportingServiceImpl implements String orgId = "1"; String sql; - try { - sql = getSQLtoRun(name, type, orgId, queryParams); - } catch (SQLException e) { - logger.info(name + ": Failed in getSQLtoRun"); - throw new WebApplicationException(Response - .status(Status.BAD_REQUEST).entity(e.getMessage()).build()); + if (name.equals(".")) { + sql = "select r.report_id, r.report_name, r.report_type, r.report_subtype, r.report_category," + + " rp.parameter_id, rp.report_parameter_name, p.parameter_name" + + " from stretchy_report r" + + " left join stretchy_report_parameter rp on rp.report_id = r.report_id" + + " left join stretchy_parameter p on p.parameter_id = rp.parameter_id" + + " order by r.report_name, rp.parameter_id"; + } else { + try { + sql = getSQLtoRun(name, type, orgId, queryParams); + } catch (SQLException e) { + logger.info(name + ": Failed in getSQLtoRun"); + throw new WebApplicationException(Response + .status(Status.BAD_REQUEST).entity(e.getMessage()) + .build()); + } } - // logger.info(name + ": RUNNING SQL"); GenericResultset result = null; try { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java index fe47c06c8..3b8ec2cd0 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java @@ -36,14 +36,49 @@ public class ReportingApiResource { private ReadExtraDataAndReportingService ReadExtraDataAndReportingService; @GET - @Path("{reportName}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload" }) - public Response retrieveReport(@PathParam("reportName") final String reportName, @Context UriInfo uriInfo) { + public Response retrieveReportList(@Context UriInfo uriInfo) { MultivaluedMap queryParams = uriInfo .getQueryParameters(); - String type = queryParams.getFirst("R_Type"); + Map extractedQueryParams = new HashMap(); + + String exportCSV = queryParams.getFirst("exportCSV"); + + if ((exportCSV == null) || (!(exportCSV.equalsIgnoreCase("true")))) { + GenericResultset result = this.ReadExtraDataAndReportingService + .retrieveGenericResultset(".", ".", extractedQueryParams); + return Response.ok().entity(result).build(); + } + + StreamingOutput result = this.ReadExtraDataAndReportingService + .retrieveReportCSV(".", ".", extractedQueryParams); + + return Response + .ok() + .entity(result) + .header("Content-Disposition", + "attachment;filename=ReportList.csv").build(); + } + + @GET + @Path("{reportName}") + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload" }) + public Response retrieveReport( + @PathParam("reportName") final String reportName, + @Context UriInfo uriInfo) { + + MultivaluedMap queryParams = uriInfo + .getQueryParameters(); + String parameterType = queryParams.getFirst("parameterType"); + if ((parameterType == null) + || (!(parameterType.equalsIgnoreCase("true")))) { + parameterType = "report"; + } else { + parameterType = "parameter"; + } String exportCSV = queryParams.getFirst("exportCSV"); Map extractedQueryParams = new HashMap(); @@ -63,13 +98,15 @@ public class ReportingApiResource { if ((exportCSV == null) || (!(exportCSV.equalsIgnoreCase("true")))) { GenericResultset result = this.ReadExtraDataAndReportingService - .retrieveGenericResultset(reportName, type, extractedQueryParams); + .retrieveGenericResultset(reportName, parameterType, + extractedQueryParams); return Response.ok().entity(result).build(); } StreamingOutput result = this.ReadExtraDataAndReportingService - .retrieveReportCSV(reportName, type, extractedQueryParams); + .retrieveReportCSV(reportName, parameterType, + extractedQueryParams); return Response .ok()