WIP tidy up pentaho use
This commit is contained in:
@@ -112,6 +112,27 @@ dependencies {
|
||||
[group: 'ch.qos.logback', name: 'logback-classic', version: '1.0.0'],
|
||||
|
||||
[group: 'mysql', name: 'mysql-connector-java', version: '5.1.18'],
|
||||
|
||||
[name: 'bsf', version: '2.4.0'],
|
||||
[name: 'bsh', version: '1.3.0'],
|
||||
[name: 'itext', version: '2.1.7'],
|
||||
[name: 'libbase', version: '1.2.2'],
|
||||
[name: 'libdocbundle', version: '1.2.3'],
|
||||
[name: 'libfonts', version: '1.2.3'],
|
||||
[name: 'libformat', version: '1.2.4'],
|
||||
[name: 'libformula', version: '1.2.3'],
|
||||
[name: 'libloader', version: '1.2.3'],
|
||||
[name: 'librepository', version: '1.2.3'],
|
||||
[name: 'libserializer', version: '1.2.2'],
|
||||
[name: 'libsparkline', version: '1.2.1'],
|
||||
[name: 'libxml', version: '1.2.2'],
|
||||
[name: 'pentaho-reporting-engine-classic-core', version: '3.8.3-GA'],
|
||||
[name: 'pentaho-reporting-engine-classic-extensions', version: '3.8.3-GA'],
|
||||
[name: 'pentaho-reporting-engine-wizard-core', version: '3.8.3-GA'],
|
||||
[name: 'pentaho-reporting-engine-wizard-xul', version: '3.8.3-GA'],
|
||||
[name: 'poi', version: '3.6'],
|
||||
[name: 'poi-ooxml', version: '3.6'],
|
||||
[name: 'poi-ooxml-schemas', version: '3.6'],
|
||||
)
|
||||
|
||||
testCompile 'junit:junit:4.10',
|
||||
|
||||
+2
@@ -23,4 +23,6 @@ public interface ReadExtraDataAndReportingService {
|
||||
|
||||
void updateExtraData(String type, String set, Long id,
|
||||
Map<String, String> queryParams);
|
||||
|
||||
String getReportType(String reportName);
|
||||
}
|
||||
+46
@@ -23,6 +23,7 @@ import org.mifosng.platform.api.data.ResultsetDataRow;
|
||||
import org.mifosng.platform.exceptions.AdditionalFieldsNotFoundException;
|
||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||
import org.mifosng.platform.exceptions.ReportNotFoundException;
|
||||
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -40,6 +41,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
||||
|
||||
@Autowired
|
||||
public ReadExtraDataAndReportingServiceImpl(final DataSource dataSource) {
|
||||
ClassicEngineBoot.getInstance().start();
|
||||
try {
|
||||
this.dataSource = dataSource;
|
||||
Connection db_connection = dataSource.getConnection();
|
||||
@@ -653,4 +655,48 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
||||
}
|
||||
return saveSql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReportType(String reportName) {
|
||||
String sql = "SELECT ifnull(report_type,'') as report_type FROM `stretchy_report` where report_name = '"
|
||||
+ reportName + "'";
|
||||
String reportType = "";
|
||||
logger.info("get reportType: " + sql);
|
||||
|
||||
try {
|
||||
Connection db_connection = dataSource.getConnection();
|
||||
Statement db_statement = db_connection.createStatement();
|
||||
ResultSet rs = db_statement.executeQuery(sql);
|
||||
|
||||
if (rs.next()) {
|
||||
reportType = rs.getString("report_type");
|
||||
} else {
|
||||
dbClose(db_statement, db_connection);
|
||||
throw new ReportNotFoundException(sql);
|
||||
}
|
||||
dbClose(db_statement, db_connection);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.sql.error",
|
||||
e.getMessage(), "Report Name: " + reportName + " Sql: "
|
||||
+ sql);
|
||||
}
|
||||
|
||||
return reportType;
|
||||
}
|
||||
|
||||
private void dbClose(Statement db_statement, Connection db_connection) {
|
||||
try {
|
||||
if (db_statement != null) {
|
||||
db_statement.close();
|
||||
db_statement = null;
|
||||
}
|
||||
if (db_connection != null) {
|
||||
db_connection.close();
|
||||
db_connection = null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.sql.error",
|
||||
e.getMessage(), "Error closing database connection");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.mifosng.platform.api;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -19,6 +21,15 @@ import javax.ws.rs.core.UriInfo;
|
||||
import org.mifosng.platform.ReadExtraDataAndReportingService;
|
||||
import org.mifosng.platform.api.data.GenericResultset;
|
||||
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
||||
import org.pentaho.reporting.engine.classic.core.MasterReport;
|
||||
import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
|
||||
import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfReportUtil;
|
||||
import org.pentaho.reporting.engine.classic.core.modules.output.table.csv.CSVReportUtil;
|
||||
import org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlReportUtil;
|
||||
import org.pentaho.reporting.engine.classic.core.modules.output.table.xls.ExcelReportUtil;
|
||||
import org.pentaho.reporting.libraries.resourceloader.Resource;
|
||||
import org.pentaho.reporting.libraries.resourceloader.ResourceException;
|
||||
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -37,7 +48,7 @@ public class ReportingApiResource {
|
||||
private String filterName = "myFilter";
|
||||
|
||||
@Autowired
|
||||
private ReadExtraDataAndReportingService ReadExtraDataAndReportingService;
|
||||
private ReadExtraDataAndReportingService readExtraDataAndReportingService;
|
||||
|
||||
@Autowired
|
||||
private ApiJSONFormattingService jsonFormattingService;
|
||||
@@ -54,7 +65,7 @@ public class ReportingApiResource {
|
||||
String exportCSV = queryParams.getFirst("exportCSV");
|
||||
|
||||
if ((exportCSV == null) || (!(exportCSV.equalsIgnoreCase("true")))) {
|
||||
GenericResultset result = this.ReadExtraDataAndReportingService
|
||||
GenericResultset result = this.readExtraDataAndReportingService
|
||||
.retrieveGenericResultset(".", ".", extractedQueryParams);
|
||||
String selectedFields = "";
|
||||
String json = this.jsonFormattingService.convertRequest(result,
|
||||
@@ -63,7 +74,7 @@ public class ReportingApiResource {
|
||||
return Response.ok().entity(json).build();
|
||||
}
|
||||
|
||||
StreamingOutput result = this.ReadExtraDataAndReportingService
|
||||
StreamingOutput result = this.readExtraDataAndReportingService
|
||||
.retrieveReportCSV(".", ".", extractedQueryParams);
|
||||
|
||||
return Response
|
||||
@@ -76,7 +87,8 @@ public class ReportingApiResource {
|
||||
@GET
|
||||
@Path("{reportName}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload" })
|
||||
@Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload",
|
||||
"application/vnd.ms-excel", "application/pdf", "text/html" })
|
||||
public Response retrieveReport(
|
||||
@PathParam("reportName") final String reportName,
|
||||
@Context UriInfo uriInfo) {
|
||||
@@ -90,7 +102,6 @@ public class ReportingApiResource {
|
||||
} else {
|
||||
parameterType = "parameter";
|
||||
}
|
||||
String exportCSV = queryParams.getFirst("exportCSV");
|
||||
|
||||
Map<String, String> extractedQueryParams = new HashMap<String, String>();
|
||||
|
||||
@@ -107,8 +118,89 @@ public class ReportingApiResource {
|
||||
}
|
||||
logger.info("BEGINNING REQUEST FOR: " + reportName);
|
||||
|
||||
if (this.readExtraDataAndReportingService.getReportType(reportName)
|
||||
.equalsIgnoreCase("Pentaho")) {
|
||||
|
||||
String reportPath = "C:\\dev\\apache-tomcat-7.0.25\\webapps\\ROOT\\PentahoReports\\"
|
||||
+ reportName + ".prpt";
|
||||
// String reportPath =
|
||||
// "/var/lib/tomcat6/webapps/ROOT/PentahoReports/"
|
||||
// + reportName + ".prpt";
|
||||
logger.info("Report path: " + reportPath);
|
||||
|
||||
// load report definition
|
||||
ResourceManager manager = new ResourceManager();
|
||||
manager.registerDefaults();
|
||||
Resource res;
|
||||
|
||||
String outputType = queryParams.getFirst("output-type");
|
||||
logger.info("outputType: " + outputType);
|
||||
try {
|
||||
res = manager.createDirectly(reportPath, MasterReport.class);
|
||||
MasterReport masterReport = (MasterReport) res.getResource();
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
if ("PDF".equalsIgnoreCase(outputType)) {
|
||||
logger.info("PDF: " + outputType);
|
||||
PdfReportUtil.createPDF(masterReport, baos);
|
||||
return Response.ok().entity(baos.toByteArray())
|
||||
.type("application/pdf").build();
|
||||
/*
|
||||
* .header("Content-Disposition", "attachment;filename=" +
|
||||
* reportName.replaceAll(" ", "") + ".pdf").build();
|
||||
*/
|
||||
}
|
||||
|
||||
if ("XLS".equalsIgnoreCase(outputType)) {
|
||||
logger.info("XLS: " + outputType);
|
||||
ExcelReportUtil.createXLS(masterReport, baos);
|
||||
return Response
|
||||
.ok()
|
||||
.entity(baos.toByteArray())
|
||||
.type("application/vnd.ms-excel")
|
||||
.header("Content-Disposition",
|
||||
"attachment;filename="
|
||||
+ reportName.replaceAll(" ", "")
|
||||
+ ".xls").build();
|
||||
}
|
||||
|
||||
if ("CSV".equalsIgnoreCase(outputType)) {
|
||||
logger.info("CSV: " + outputType);
|
||||
|
||||
CSVReportUtil.createCSV(masterReport, baos, "UTF-8");
|
||||
return Response
|
||||
.ok()
|
||||
.entity(baos.toByteArray())
|
||||
.type("application/x-msdownload")
|
||||
.header("Content-Disposition",
|
||||
"attachment;filename="
|
||||
+ reportName.replaceAll(" ", "")
|
||||
+ ".csv").build();
|
||||
}
|
||||
|
||||
if ("HTML".equalsIgnoreCase(outputType)) {
|
||||
logger.info("HTML: " + outputType);
|
||||
|
||||
HtmlReportUtil.createStreamHTML(masterReport, baos);
|
||||
return Response.ok().entity(baos.toByteArray()).build();
|
||||
}
|
||||
} catch (ResourceException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ReportProcessingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
logger.info("No matching Output Type: " + outputType);
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
String exportCSV = queryParams.getFirst("exportCSV");
|
||||
|
||||
if ((exportCSV == null) || (!(exportCSV.equalsIgnoreCase("true")))) {
|
||||
GenericResultset result = this.ReadExtraDataAndReportingService
|
||||
GenericResultset result = this.readExtraDataAndReportingService
|
||||
.retrieveGenericResultset(reportName, parameterType,
|
||||
extractedQueryParams);
|
||||
|
||||
@@ -116,16 +208,18 @@ public class ReportingApiResource {
|
||||
String json = this.jsonFormattingService.convertRequest(result,
|
||||
filterName, allowedFieldList, selectedFields,
|
||||
uriInfo.getQueryParameters());
|
||||
return Response.ok().entity(json).build();
|
||||
return Response.ok().entity(json).type(MediaType.APPLICATION_JSON)
|
||||
.build();
|
||||
}
|
||||
|
||||
StreamingOutput result = this.ReadExtraDataAndReportingService
|
||||
StreamingOutput result = this.readExtraDataAndReportingService
|
||||
.retrieveReportCSV(reportName, parameterType,
|
||||
extractedQueryParams);
|
||||
|
||||
return Response
|
||||
.ok()
|
||||
.entity(result)
|
||||
.type("application/x-msdownload")
|
||||
.header("Content-Disposition",
|
||||
"attachment;filename=" + reportName.replaceAll(" ", "")
|
||||
+ ".csv").build();
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
|
||||
|
||||
// logger.info("fieldList to be processed is: " + fieldList
|
||||
// + " filter type is: " + filterType);
|
||||
|
||||
logger.info("query params: " + queryParams.toString());
|
||||
return convertDataObjectJSON(dataObject, filterName, filterType,
|
||||
fieldList, isTrue(queryParams.getFirst("pretty")));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user