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
@@ -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()