WIP more reports API refactoring plus api docs

This commit is contained in:
John Woodlock
2012-05-15 22:59:17 +10:00
parent 06fa7ff146
commit 3fe1fe761e
5 changed files with 206 additions and 60 deletions
+125 -28
View File
@@ -32,8 +32,8 @@
<h3>&nbsp;</h3>
<h4>Reports</h4>
<ul>
<li><a href="#reports">Reports</a></li>
<li><a href="#reports">Reports</a></li>
<li><a href="#listreports">List Reports</a></li>
<li><a href="#runreport">Run a Report</a></li>
</ul>
</div>
@@ -305,10 +305,10 @@ error is parameter-specific. You can use this to display a message near
<div class="method-description">
<h3>Reports</h3>
<p>
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.
</p>
<p>
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.
</p>
<p>Add examples showing links to client listing report producing json, then csv, then a pentaho report producing html, pdf, csv</p>
@@ -320,39 +320,133 @@ The Mifos X Individual Lending client application uses a JQuery plugin called st
</div>
</div>
<div class="method-section">
<div class="method-description">
<h4>Parameters</h4>
<p>Note: the prefix R_ below stands for Reporting</p>
<dl class="argument-list">
<dt>R_Name</dt>
<dd>mandatory</dd>
<dd>Report Name. One of the standard or user-defined Mifos X reports.</dd>
<dt>R_'parameter names' ...</dt>
<dd>optional, <span>No defaults</span></dd>
<dd>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.</dd>
<dt>R_parameterType</dt>
<dd>optional, The only valid value is 'true'. If any other value is provided the parameter will be ignored</span></span></dd>
<dd>Determines whether the request looks for reports or paraters that have been configured.</dd>
<dt>exportCSV</dt>
<dd>optional, <span>The only valid value is 'true'. If any other value is provided the parameter will be ignored</span></dd>
<dd>Output will be delivered as a CSV file instead of JSON. Doesn't apply to Pentaho reports.</dd>
</dl>
<a id="listreports" name="listreports" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>List Reports</h4>
<p>
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.
</p>
<h5>Arguments</h5>
<dl class="argument-list">
<dt>exportCSV</dt>
<dd>optional, <span>The only valid value is 'true'. If any other value is provided the argument will be ignored</span></dd>
<dd>Output will be delivered as a CSV file instead of JSON.</dd>
</dl>
<p>Example Request:
<a style="word-wrap: break-word;" href="http://localhost:8080/mifosng-provider/api/v1/reports/Client%20Listing?FR_officeId=1">http://localhost:8080/mifosng-provider/api/v1/reports/Client%20Listing?FR_officeId=1</a>
<a style="word-wrap: break-word;" href="http://localhost:8080/mifosng-provider/api/v1/reports">http://localhost:8080/mifosng-provider/api/v1/reports</a>
</p>
</div>
<div class="method-example">
<code class="method-declaration">GET https://thedomainname/v1/reports</code>
<code class="method-response">{
"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
]
}</code>
</div>
</div>
<a id="runreport" name="runreport" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>Running a Report</h4>
<p>
Runs a report and returns the report output.
</p>
<h5>Arguments</h5>
<dl class="argument-list">
<dt>R_'parameter names' ...</dt>
<dd>optional, <span>No defaults</span></dd>
<dd>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.</dd>
<dd>Note: the prefix R_ stands for Reporting</dd>
<dt>parameterType</dt>
<dd>optional, <span>The only valid value is 'true'. If any other value is provided the argument will be ignored</span></dd>
<dd>Determines whether the request looks in the list of reports or the list of parameters for its data.</dd>
<dt>exportCSV</dt>
<dd>optional, <span>The only valid value is 'true'. If any other value is provided the argument will be ignored</span></dd>
<dd>Output will be delivered as a CSV file instead of JSON. Doesn't apply to Pentaho reports.</dd>
</dl>
<p>Example Request:
<a style="word-wrap: break-word;" href="http://localhost:8080/mifosng-provider/api/v1/reports/Client%20Listing?R_officeId=1">http://localhost:8080/mifosng-provider/api/v1/reports/Client%20Listing?R_officeId=1</a>
</p>
</div>
<div class="method-example">
<code class="method-declaration">GET https://thedomainname/v1/reports/{REPORTNAME}</code>
<code class="method-response">{
"columnHeaders": [
{
"columnName": "Office/Branch",
@@ -404,6 +498,9 @@ The Mifos X Individual Lending client application uses a JQuery plugin called st
</div>
</div>
<a id="create_customer" name="create_customer" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
@@ -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 = '<table><tr>';
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 += "&parameterType=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 += "&parameterType=true";
var fullExportUrl = RESTUrl + "/" + rptName + inQueryParameters;
showMsg("full export url: " + fullExportUrl);
@@ -16,6 +16,6 @@
<script type="text/javascript" src="${resValue}/libs/DataTables-1.8.2/extras/TableTools/media/js/TableTools.min.js"></script>
<script type="text/javascript" src="${resValue}/libs/jquery.i18n.properties-min-1.0.9.js"></script>
<script type="text/javascript" src="${resValue}/libs/OAuthSimple.js"></script>
<script type="text/javascript" src="${resValue}/stretchyreporting/stretchyreporting-0.968.js"></script>
<script type="text/javascript" src="${resValue}/stretchyreporting/stretchyreporting-0.97.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
@@ -55,7 +55,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
final String type, final Map<String, String> 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 {
@@ -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<String, String> queryParams = uriInfo
.getQueryParameters();
String type = queryParams.getFirst("R_Type");
Map<String, String> extractedQueryParams = new HashMap<String, String>();
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<String, String> 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<String, String> extractedQueryParams = new HashMap<String, String>();
@@ -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()