PDA

View Full Version : Is it possible to read Query from a Report by API



michael.mest
06-29-2010, 07:55 AM
Hi,

is it possible to read the SQL-Query from a *.prpt-File by Pentaho-API?

gutlez
06-29-2010, 11:05 AM
You can extract the data...

prpt can be opened as a ZIP file, and your queries are in a directory called "Datasources" as XML files. The SQL Query is in there.

Taqua
06-29-2010, 12:57 PM
why work with a xml-structure if you can access the datasources directly?

MasterReport#getDataFactory()
SubReport#getDataFactory()

you most likely get a ComboundDataFactory from there (check with instanceof), which is a container containing more datafactories. Seek for the SQLReportDataFactory in there.


To get to the subreports, you most likely have to iterate over the report into the bands to get the subreports that are attached there. Will Gorman's book explains the API - otherwise have a look at the sources, our API is fairly simple.

michael.mest
06-30-2010, 12:45 AM
why work with a xml-structure if you can access the datasources directly?

MasterReport#getDataFactory()
SubReport#getDataFactory()


I think, that's exactly what I would like to do, but I didn't find out yet, how I can build a MasterReport from an existing prpt-File. Is there any example for that?

I found this one: http://forums.pentaho.org/showpost.php?p=239159&postcount=1

And tried to "copy" it.



reportPath = "file:/<pathToPrpt>";
ResourceManager manager = new ResourceManager();
manager.registerDefaults();
Resource res = manager.createDirectly(new URL(reportPath),MasterReport.class);
MasterReport report = (MasterReport) res.getResource();
DataFactory df = report.getDataFactory();
....
But on Line "Resource res = manager.createDirectly(new URL(reportPath),MasterReport.class);" I get an ContentNotRecognizedException.

What does this mean?

Ok, sorry, I solved it by myself now ;-)

Just missed some JAR-Files and forgot to boot the ReportEngine

Taqua
06-30-2010, 03:24 AM
There are samples in the demo and the sdk (while the SDK definitely has the better documented ones). And as said: Will Gormans book goes into all the dirty details of the API - there is no better resource out there to get started.