WIP refactor api - make rptDB parameter optional

This commit is contained in:
John Woodlock
2012-05-14 18:00:04 +10:00
parent 3ae70b06bc
commit 9ddaf4c003
4 changed files with 28 additions and 24 deletions
@@ -90,11 +90,9 @@ function selectNewThousandsSep(selectedVal) {
} }
var reportingParams = { var reportingParams = {
rptDB: "mifosngprovider", //rptDB: "mifosngproviderJ",
RESTUrl: "${baseUrl}api/v1/reports", RESTUrl: "${baseUrl}api/v1/reports",
pentahoUrl: "${baseUrl}pentahoreport", pentahoUrl: "${baseUrl}pentahoreport",
//old link exportUrl: "${rootContext}exportcsv",
//not needed now exportUrl: "${baseUrl}exportcsv",
bundleDir: "${resValue}/stretchyreporting/mifosngbundle/", bundleDir: "${resValue}/stretchyreporting/mifosngbundle/",
reportsListDiv: "myListOfReports", reportsListDiv: "myListOfReports",
runReportDiv: "myRunReportButton", runReportDiv: "myRunReportButton",
@@ -9,11 +9,11 @@ import org.mifosng.data.reports.GenericResultset;
public interface ReadExtraDataAndReportingService { public interface ReadExtraDataAndReportingService {
StreamingOutput retrieveReportCSV(String rptDB, String name, String type, StreamingOutput retrieveReportCSV(String name, String type,
Map<String, String> extractedQueryParams); Map<String, String> extractedQueryParams);
// @PreAuthorize(value = "hasAnyRole('REPORTING_SUPER_USER_ROLE')") // @PreAuthorize(value = "hasAnyRole('REPORTING_SUPER_USER_ROLE')")
GenericResultset retrieveGenericResultset(String rptDB, String name, GenericResultset retrieveGenericResultset(String name,
String type, Map<String, String> extractedQueryParams); String type, Map<String, String> extractedQueryParams);
ExtraDatasets retrieveExtraDatasetNames(String datasetType); ExtraDatasets retrieveExtraDatasetNames(String datasetType);
@@ -38,24 +38,29 @@ public class ReadExtraDataAndReportingServiceImpl implements
.getLogger(ReadExtraDataAndReportingServiceImpl.class); .getLogger(ReadExtraDataAndReportingServiceImpl.class);
private final DataSource dataSource; private final DataSource dataSource;
private final String reportingMetaDataDB;
@Autowired @Autowired
public ReadExtraDataAndReportingServiceImpl(final DataSource dataSource) { public ReadExtraDataAndReportingServiceImpl(final DataSource dataSource)
throws SQLException {
this.dataSource = dataSource; this.dataSource = dataSource;
Connection db_connection = dataSource.getConnection();
this.reportingMetaDataDB = db_connection.getCatalog();
db_connection.close();
db_connection = null;
} }
@Override @Override
public StreamingOutput retrieveReportCSV(final String rptDB, public StreamingOutput retrieveReportCSV(final String name,
final String name, final String type, final String type, final Map<String, String> queryParams) {
final Map<String, String> queryParams) {
return new StreamingOutput() { return new StreamingOutput() {
public void write(OutputStream out) throws IOException, public void write(OutputStream out) throws IOException,
WebApplicationException { WebApplicationException {
try { try {
GenericResultset result = retrieveGenericResultset(rptDB, GenericResultset result = retrieveGenericResultset(name,
name, type, queryParams); type, queryParams);
StringBuffer sb = generateCsvFileBuffer(result); StringBuffer sb = generateCsvFileBuffer(result);
InputStream in = new ByteArrayInputStream(sb.toString() InputStream in = new ByteArrayInputStream(sb.toString()
@@ -126,9 +131,8 @@ public class ReadExtraDataAndReportingServiceImpl implements
} }
@Override @Override
public GenericResultset retrieveGenericResultset(final String rptDB, public GenericResultset retrieveGenericResultset(final String name,
final String name, final String type, final String type, final Map<String, String> queryParams) {
final Map<String, String> queryParams) {
if (name == null) { if (name == null) {
logger.info("Report Name not Found"); logger.info("Report Name not Found");
@@ -154,7 +158,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
String sql; String sql;
try { try {
sql = getSQLtoRun(rptDB, name, type, orgId, queryParams); sql = getSQLtoRun(name, type, orgId, queryParams);
} catch (SQLException e) { } catch (SQLException e) {
logger.info(name + ": Failed in getSQLtoRun"); logger.info(name + ": Failed in getSQLtoRun");
throw new WebApplicationException(Response throw new WebApplicationException(Response
@@ -222,10 +226,14 @@ public class ReadExtraDataAndReportingServiceImpl implements
} }
private String getSQLtoRun(final String rptDB, final String name, private String getSQLtoRun(final String name, final String type,
final String type, final String orgId, final String orgId, final Map<String, String> queryParams)
final Map<String, String> queryParams) throws SQLException { throws SQLException {
String sql = null; String sql = null;
String rptDB = queryParams.get("${rptDB}");
if ((rptDB == null) || rptDB.equals("")) {
rptDB = reportingMetaDataDB;
}
if (type.equals("report")) { if (type.equals("report")) {
sql = getReportSql(rptDB, name); sql = getReportSql(rptDB, name);
@@ -284,7 +292,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
throws SQLException { throws SQLException {
String sql = "select report_sql as the_sql from " + rptDB String sql = "select report_sql as the_sql from " + rptDB
+ ".stretchy_report where report_name = '" + reportName + "'"; + ".stretchy_report where report_name = '" + reportName + "'";
// logger.info("Report SQL: " + sql); logger.info("Report SQL: " + sql);
return getSql(sql); return getSql(sql);
} }
@@ -294,7 +302,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
String sql = "select parameter_sql as the_sql from " + rptDB String sql = "select parameter_sql as the_sql from " + rptDB
+ ".stretchy_parameter where parameter_name = '" + ".stretchy_parameter where parameter_name = '"
+ parameterName + "'"; + parameterName + "'";
// logger.info("Parameter SQL: " + sql); logger.info("Parameter SQL: " + sql);
return getSql(sql); return getSql(sql);
} }
@@ -92,7 +92,6 @@ public class ReportingApiResource {
MultivaluedMap<String, String> queryParams = uriInfo MultivaluedMap<String, String> queryParams = uriInfo
.getQueryParameters(); .getQueryParameters();
String rptDB = queryParams.getFirst("MRP_rptDB");
String name = queryParams.getFirst("MRP_Name"); String name = queryParams.getFirst("MRP_Name");
String type = queryParams.getFirst("MRP_Type"); String type = queryParams.getFirst("MRP_Type");
String exportCSV = queryParams.getFirst("exportCSV"); String exportCSV = queryParams.getFirst("exportCSV");
@@ -115,12 +114,11 @@ public class ReportingApiResource {
if ((exportCSV == null) || (!(exportCSV.equalsIgnoreCase("true")))) { if ((exportCSV == null) || (!(exportCSV.equalsIgnoreCase("true")))) {
GenericResultset result = this.ReadExtraDataAndReportingService GenericResultset result = this.ReadExtraDataAndReportingService
.retrieveGenericResultset(rptDB, name, type, .retrieveGenericResultset(name, type, extractedQueryParams);
extractedQueryParams);
return makeCORS(Response.ok().entity(result)); return makeCORS(Response.ok().entity(result));
} else { } else {
StreamingOutput result = this.ReadExtraDataAndReportingService StreamingOutput result = this.ReadExtraDataAndReportingService
.retrieveReportCSV(rptDB, name, type, extractedQueryParams); .retrieveReportCSV(name, type, extractedQueryParams);
return makeCORSExport(Response.ok().entity(result), return makeCORSExport(Response.ok().entity(result),
name.replaceAll(" ", "") + ".csv"); name.replaceAll(" ", "") + ".csv");