wip - pentaho reports
This commit is contained in:
+46
-1
@@ -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.html.HtmlReportUtil;
|
||||
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.ResourceException;
|
||||
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
|
||||
@@ -734,7 +737,9 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
||||
logger.info("outputType: " + outputType);
|
||||
try {
|
||||
res = manager.createDirectly(reportPath, MasterReport.class);
|
||||
MasterReport masterReport = (MasterReport) res.getResource();
|
||||
MasterReport masterReport = (MasterReport) res.getResource();
|
||||
|
||||
addParametersToReport(masterReport, queryParams);
|
||||
|
||||
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
|
||||
.getQueryParameters();
|
||||
|
||||
Map<String, String> reportParams = getReportParams(queryParams);
|
||||
|
||||
String parameterType = queryParams.getFirst("parameterType");
|
||||
if ((parameterType == null)
|
||||
|| (!(parameterType.equalsIgnoreCase("true")))) {
|
||||
@@ -97,7 +95,7 @@ public class ReportsApiResource {
|
||||
return this.readExtraDataAndReportingService
|
||||
.processPentahoRequest(reportName,
|
||||
queryParams.getFirst("output-type"),
|
||||
reportParams);
|
||||
getReportParams(queryParams, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +104,7 @@ public class ReportsApiResource {
|
||||
// JSON
|
||||
GenericResultset result = this.readExtraDataAndReportingService
|
||||
.retrieveGenericResultset(reportName, parameterType,
|
||||
reportParams);
|
||||
getReportParams(queryParams, false));
|
||||
|
||||
String selectedFields = "";
|
||||
String json = this.jsonFormattingService.convertRequest(result,
|
||||
@@ -118,7 +116,7 @@ public class ReportsApiResource {
|
||||
|
||||
// CSV Export
|
||||
StreamingOutput result = this.readExtraDataAndReportingService
|
||||
.retrieveReportCSV(reportName, parameterType, reportParams);
|
||||
.retrieveReportCSV(reportName, parameterType, getReportParams(queryParams, false));
|
||||
return Response
|
||||
.ok()
|
||||
.entity(result)
|
||||
@@ -129,7 +127,7 @@ public class ReportsApiResource {
|
||||
}
|
||||
|
||||
private Map<String, String> getReportParams(
|
||||
MultivaluedMap<String, String> queryParams) {
|
||||
MultivaluedMap<String, String> queryParams, Boolean isPentaho) {
|
||||
|
||||
Map<String, String> reportParams = new HashMap<String, String>();
|
||||
Set<String> keys = queryParams.keySet();
|
||||
@@ -138,7 +136,9 @@ public class ReportsApiResource {
|
||||
for (String k : keys) {
|
||||
|
||||
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);
|
||||
reportParams.put(pKey, pValue);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user