format changes

This commit is contained in:
Keith Woodlock
2012-11-30 12:58:51 +00:00
parent 48b3693944
commit d2c751f2eb
3 changed files with 79 additions and 114 deletions
@@ -55,18 +55,10 @@ public class ReportsApiResource {
boolean exportPdf = ApiParameterHelper.exportPdf(uriInfo.getQueryParameters()); boolean exportPdf = ApiParameterHelper.exportPdf(uriInfo.getQueryParameters());
if(exportPdf) if (exportPdf)
{ {
String result = this.readExtraDataAndReportingService String result = this.readExtraDataAndReportingService.retrieveReportPDF(".", ".", extractedQueryParams);
.retrieveReportPDF(".", ".", extractedQueryParams); return Response.ok().entity(result).header("Content-Disposition", "attachment;filename=ReportList.pdf").build();
return Response
.ok()
.entity(result)
.header("Content-Disposition",
"attachment;filename=ReportList.pdf").build();
} }
if (!exportCsv) { if (!exportCsv) {
@@ -109,30 +101,23 @@ public class ReportsApiResource {
parameterTypeValue = "parameter"; parameterTypeValue = "parameter";
} }
// PDF format // PDF format
if(exportPdf) if (exportPdf) {
{
Map<String, String> reportParams = getReportParams(queryParams, false); Map<String, String> reportParams = getReportParams(queryParams, false);
String pdfFileName = this.readExtraDataAndReportingService String pdfFileName = this.readExtraDataAndReportingService.retrieveReportPDF(reportName, parameterTypeValue, reportParams);
.retrieveReportPDF(reportName, parameterTypeValue, reportParams);
File file=new File(pdfFileName); File file = new File(pdfFileName);
ResponseBuilder response=Response.ok(file); ResponseBuilder response = Response.ok(file);
response.header("Content-Disposition", response.header("Content-Disposition", "attachment; filename=\"" + pdfFileName + "\"");
"attachment; filename=\"" response.header("content-Type", "application/pdf");
+pdfFileName+"\"");
response.header("content-Type","application/pdf");
return response.build(); return response.build();
} }
if (!exportCsv) { if (!exportCsv) {
Map<String, String> reportParams = getReportParams(queryParams, false); Map<String, String> reportParams = getReportParams(queryParams, false);
GenericResultsetData result = this.readExtraDataAndReportingService.retrieveGenericResultset(reportName, parameterTypeValue, GenericResultsetData result = this.readExtraDataAndReportingService.retrieveGenericResultset(reportName, parameterTypeValue,
@@ -187,5 +172,4 @@ public class ReportsApiResource {
} }
return reportParams; return reportParams;
} }
} }
@@ -15,8 +15,7 @@ public interface ReadReportingService {
Response processPentahoRequest(String reportName, String outputType, Map<String, String> queryParams); Response processPentahoRequest(String reportName, String outputType, Map<String, String> queryParams);
String retrieveReportPDF(String name, String type,Map<String, String> extractedQueryParams); String retrieveReportPDF(String name, String type, Map<String, String> extractedQueryParams);
String getReportType(String reportName); String getReportType(String reportName);
} }
@@ -143,8 +143,6 @@ public class ReadReportingServiceImpl implements ReadReportingService {
return writer; return writer;
} }
@Override @Override
public GenericResultsetData retrieveGenericResultset(final String name, final String type, final Map<String, String> queryParams) { public GenericResultsetData retrieveGenericResultset(final String name, final String type, final Map<String, String> queryParams) {
@@ -343,22 +341,17 @@ public class ReadReportingServiceImpl implements ReadReportingService {
} }
@Override @Override
public String retrieveReportPDF(final String reportName,final String type, final Map<String, String> queryParams) { public String retrieveReportPDF(final String reportName, final String type, final Map<String, String> queryParams) {
String fileLocation=FileUtils.MIFOSX_BASE_DIR+File.separator+""; String fileLocation = FileUtils.MIFOSX_BASE_DIR + File.separator + "";
if(!new File(fileLocation).isDirectory()) if (!new File(fileLocation).isDirectory()) {
{
new File(fileLocation).mkdirs(); new File(fileLocation).mkdirs();
} }
String genaratePdf=fileLocation+File.separator+reportName+".pdf"; String genaratePdf = fileLocation + File.separator + reportName + ".pdf";
try
{
GenericResultsetData result = retrieveGenericResultset(
reportName, type, queryParams);
try {
GenericResultsetData result = retrieveGenericResultset(reportName, type, queryParams);
List<ResultsetColumnHeader> columnHeaders = result.getColumnHeaders(); List<ResultsetColumnHeader> columnHeaders = result.getColumnHeaders();
List<ResultsetDataRow> data = result.getData(); List<ResultsetDataRow> data = result.getData();
@@ -369,8 +362,7 @@ public String retrieveReportPDF(final String reportName,final String type, final
Document document = new Document(PageSize.B0.rotate()); Document document = new Document(PageSize.B0.rotate());
PdfWriter.getInstance(document, PdfWriter.getInstance(document, new FileOutputStream(new File(fileLocation + reportName + ".pdf")));
new FileOutputStream(new File(fileLocation+reportName+".pdf")));
document.open(); document.open();
PdfPTable table = new PdfPTable(chSize); PdfPTable table = new PdfPTable(chSize);
@@ -394,17 +386,11 @@ public String retrieveReportPDF(final String reportName,final String type, final
currColType = columnHeaders.get(j).getColumnType(); currColType = columnHeaders.get(j).getColumnType();
currVal = row.get(j); currVal = row.get(j);
if (currVal != null) { if (currVal != null) {
if (currColType.equals("DECIMAL") if (currColType.equals("DECIMAL") || currColType.equals("DOUBLE") || currColType.equals("BIGINT")
|| currColType.equals("DOUBLE") || currColType.equals("SMALLINT") || currColType.equals("INT")) {
|| currColType.equals("BIGINT")
|| currColType.equals("SMALLINT")
|| currColType.equals("INT"))
{
table.addCell(currVal.toString()); table.addCell(currVal.toString());
} } else {
else
{
table.addCell(currVal.toString()); table.addCell(currVal.toString());
} }
} }
@@ -415,12 +401,8 @@ public String retrieveReportPDF(final String reportName,final String type, final
document.close(); document.close();
return genaratePdf; return genaratePdf;
} }
catch (Exception e) { catch (Exception e) {
throw new PlatformDataIntegrityException( throw new PlatformDataIntegrityException("error.msg.exception.error", e.getMessage());
"error.msg.exception.error", e.getMessage());
}
} }
} }
}