<p>Hi all,</p>
<p> </p>
<p>I'm embedding BIRT runtime (4.4.2) using maven in my Liferay portlet and use the POJO data source. I've created a jar with a mock data object (Relation) and data set (RelatonDataset) to get some results when desiging the report, which works, data is showing.</p>
<p> </p>
<p>Many thanks to I0co for his article on Life in IDE (<a data-ipb='nomediaparse' href='
http://lifeinide.blogspot.nl/2014/12/birt-with-hibernate-using-pojo-s.html'>http://lifeinide.blogspot.nl/2014/12/birt-with-hibernate-using-pojo-s.html</a>)! </p>
<p> </p>
<p>Now when I pass in the collection of "real" Relation objects during runtime, the report is showing without any errors or warnings but no data is showing (only the labels).</p>
<p> </p>
<p>The class I use to run the report:</p>
<pre class="_prettyXprint">
public class BirtRunner {
private static final Log log = LogFactoryUtil.getLog(BirtRunner.class);
@SuppressWarnings("rawtypes")
private HashMap datasets = new HashMap();
/**
*
@param key The application context key defined in BIRT designer.
*
@param objects {
@link Collection}, {
@link Iterator} or array.
*/
@SuppressWarnings("unchecked")
public void addPojoDataset(String key, Object objects) {
datasets.put(key, objects);
}
public InputStream generatePDFReport(String name) throws Exception {
InputStream is = getClass().getClassLoader().getResourceAsStream(name);
if (is==null)
throw new RuntimeException(String.format("Error load %s report", name));
// init birt
log.info("Initializing BIRT...");
log.info("Datasets size = " + datasets.size());
IReportEngine engine = null;
try {
EngineConfig config = new EngineConfig();
config.setEngineHome(System.getProperty("java.io.tmpdir"));
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine( config );
engine.changeLogLevel(Level.WARNING);
// load report
log.info(String.format("Loading report %s...", name));
IReportRunnable runnable = engine.openReportDesign(is);
// execute report
log.info("Generating report ...");
RenderOption renderOption = null;
renderOption = new PDFRenderOption();
renderOption.setOutputFormat("pdf");
ByteArrayOutputStream out = new ByteArrayOutputStream();
renderOption.setOutputStream(out);
IRunAndRenderTask task = engine.createRunAndRenderTask(runnable);
task.setAppContext(datasets);
task.setRenderOption(renderOption);
task.run();
return new ByteArrayInputStream(out.toByteArray());
} finally {
// stop birt
if (engine!=null) {
log.info("Shutting down BIRT...");
engine.destroy();
Platform.shutdown();
//Bugzilla 351052
RegistryProviderFactory.releaseDefault();
engine = null;
}
}
}
}
</pre>
<p>The code portlet action that calls the BirtRunner (opens the generated PDF).</p>
<pre class="_prettyXprint">
public class RelationPortlet extends MVCPortlet {
private static final Log log = LogFactoryUtil.getLog(RelationPortlet.class);
@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
throws IOException, PortletException {
String reportName = ParamUtil.getString(resourceRequest, "reportName");
resourceResponse.setContentType("application/pdf");
OutputStream out = resourceResponse.getPortletOutputStream();
BirtRunner birtRunner = new BirtRunner();
try {
List<Relation> dataset = RelationLocalServiceUtil.getAll();
birtRunner.addPojoDataset("APP_CONTEXT_KEY_RELATION_DATASET", dataset);
InputStream in = birtRunner.generatePDFReport(reportName);
IOUtils.copy(in, out);
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}
</pre>
<p>I checked the context key in the report in this is ok. The collection of passed objects is a simple list of Relation objects. Also I can't use BIRT runtime version 4.5.0 because it gives me an error about a missing artifact in maven (org.eclipse.birt.runtime:org.eclipse.osgi:jar:3.10.100.v20150529-1857).</p>
<p> </p>
<p>Am I missing something?</p>
<p>Any comment or suggestion will be highly appreciated because I'm struggling for 3 days now to get this working and I'm out of ideas.</p>
<p> </p>
<p>Regards,</p>
<p>Pierre</p>