wip - pentaho reports

This commit is contained in:
John Woodlock
2012-07-19 18:23:56 +10:00
parent 55b1392847
commit 98e216b645
2 changed files with 53 additions and 8 deletions
@@ -35,6 +35,9 @@ import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Pdf
import org.pentaho.reporting.engine.classic.core.modules.output.table.csv.CSVReportUtil; 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.html.HtmlReportUtil;
import org.pentaho.reporting.engine.classic.core.modules.output.table.xls.ExcelReportUtil; import org.pentaho.reporting.engine.classic.core.modules.output.table.xls.ExcelReportUtil;
import org.pentaho.reporting.engine.classic.core.parameters.ParameterDefinitionEntry;
import org.pentaho.reporting.engine.classic.core.parameters.ReportParameterDefinition;
import org.pentaho.reporting.engine.classic.core.util.ReportParameterValues;
import org.pentaho.reporting.libraries.resourceloader.Resource; import org.pentaho.reporting.libraries.resourceloader.Resource;
import org.pentaho.reporting.libraries.resourceloader.ResourceException; import org.pentaho.reporting.libraries.resourceloader.ResourceException;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager; import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
@@ -734,7 +737,9 @@ public class ReadExtraDataAndReportingServiceImpl implements
logger.info("outputType: " + outputType); logger.info("outputType: " + outputType);
try { try {
res = manager.createDirectly(reportPath, MasterReport.class); res = manager.createDirectly(reportPath, MasterReport.class);
MasterReport masterReport = (MasterReport) res.getResource(); MasterReport masterReport = (MasterReport) res.getResource();
addParametersToReport(masterReport, queryParams);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -790,4 +795,44 @@ public class ReadExtraDataAndReportingServiceImpl implements
} }
private void addParametersToReport(MasterReport report,
Map<String, String> queryParams) {
try {
ReportParameterValues rptParamValues = report.getParameterValues();
ReportParameterDefinition paramsDefinition = report
.getParameterDefinition();
/*
* only allow integer and string parameter types and assume all
* mandatory - could go more detailed like Pawel did in Mifos later
* and could match incoming and pentaho parameters better...
* currently assuming they come in ok... and if not an error
*/
for (ParameterDefinitionEntry paramDefEntry : paramsDefinition
.getParameterDefinitions()) {
String paramName = paramDefEntry.getName();
String pValue = queryParams.get(paramName);
if (StringUtils.isBlank(pValue))
throw new PlatformDataIntegrityException(
"error.msg.reporting.error", "Pentaho Parameter: "
+ paramName + " - not Provided");
Class<?> clazz = paramDefEntry.getValueType();
logger.info("addParametersToReport(" + paramName + " : "
+ pValue + " : " + clazz.getCanonicalName() + ")");
if (clazz.getCanonicalName().equalsIgnoreCase(
"java.lang.Integer"))
rptParamValues.put(paramName, Integer.parseInt(pValue));
else
rptParamValues.put(paramName, pValue);
}
} catch (Exception e) {
throw new PlatformDataIntegrityException(
"error.msg.reporting.error", e.getMessage());
}
}
} }
@@ -80,8 +80,6 @@ public class ReportsApiResource {
MultivaluedMap<String, String> queryParams = uriInfo MultivaluedMap<String, String> queryParams = uriInfo
.getQueryParameters(); .getQueryParameters();
Map<String, String> reportParams = getReportParams(queryParams);
String parameterType = queryParams.getFirst("parameterType"); String parameterType = queryParams.getFirst("parameterType");
if ((parameterType == null) if ((parameterType == null)
|| (!(parameterType.equalsIgnoreCase("true")))) { || (!(parameterType.equalsIgnoreCase("true")))) {
@@ -97,7 +95,7 @@ public class ReportsApiResource {
return this.readExtraDataAndReportingService return this.readExtraDataAndReportingService
.processPentahoRequest(reportName, .processPentahoRequest(reportName,
queryParams.getFirst("output-type"), queryParams.getFirst("output-type"),
reportParams); getReportParams(queryParams, true));
} }
} }
@@ -106,7 +104,7 @@ public class ReportsApiResource {
// JSON // JSON
GenericResultset result = this.readExtraDataAndReportingService GenericResultset result = this.readExtraDataAndReportingService
.retrieveGenericResultset(reportName, parameterType, .retrieveGenericResultset(reportName, parameterType,
reportParams); getReportParams(queryParams, false));
String selectedFields = ""; String selectedFields = "";
String json = this.jsonFormattingService.convertRequest(result, String json = this.jsonFormattingService.convertRequest(result,
@@ -118,7 +116,7 @@ public class ReportsApiResource {
// CSV Export // CSV Export
StreamingOutput result = this.readExtraDataAndReportingService StreamingOutput result = this.readExtraDataAndReportingService
.retrieveReportCSV(reportName, parameterType, reportParams); .retrieveReportCSV(reportName, parameterType, getReportParams(queryParams, false));
return Response return Response
.ok() .ok()
.entity(result) .entity(result)
@@ -129,7 +127,7 @@ public class ReportsApiResource {
} }
private Map<String, String> getReportParams( private Map<String, String> getReportParams(
MultivaluedMap<String, String> queryParams) { MultivaluedMap<String, String> queryParams, Boolean isPentaho) {
Map<String, String> reportParams = new HashMap<String, String>(); Map<String, String> reportParams = new HashMap<String, String>();
Set<String> keys = queryParams.keySet(); Set<String> keys = queryParams.keySet();
@@ -138,7 +136,9 @@ public class ReportsApiResource {
for (String k : keys) { for (String k : keys) {
if (k.startsWith("R_")) { if (k.startsWith("R_")) {
pKey = "${" + k.substring(2) + "}"; if (isPentaho) pKey = k.substring(2);
else pKey = "${" + k.substring(2) + "}";
pValue = queryParams.get(k).get(0); pValue = queryParams.get(k).get(0);
reportParams.put(pKey, pValue); reportParams.put(pKey, pValue);
} }