Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Cannot run report properly while using aggregations
Cannot run report properly while using aggregations [message #898102] Wed, 25 July 2012 19:27 Go to next message
Robert LaDue is currently offline Robert LaDueFriend
Messages: 1
Registered: July 2012
Junior Member
I am trying to use BIRT to take sample inputs of date and numbers and output them to an .xls file along with the average of the numbers.
I have built an .rptdesign file consisting solely of a table containing the following information: A header row with text ("date" + "number"). A detail row with the data (the date and number data). A footer row containing text ("Average"), and an aggregation with the function AVE, and the expression row["Number"].
I have written a java program to run and render the .rptdesign into an .rptdocument file, and subsequently into an .xls file. The issue lies in the fact that whenever the aggregation is present, none of the data is placed into the .rptdocument file when my code is run. The output is only the text fields. The data and aggregation simply disappear.
Manually generating an .rptdocument through the 'run' menu in eclipse works perfectly, and the render turns out fine. This has led me to believe there is something wrong with my code, but I am at a loss for what it could be.

Here is the code in question:
package code;

import org.eclipse.birt.report.engine.api.*;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import java.util.logging.Level;

public class RenderDoc {
	public static void main( String[] args ){
		try {
			runStuff ();
			renderStuff ();
		} catch (EngineException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BirtException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	//Runs report from .rptdesign to .rptdocument
	public static void runStuff () throws BirtException{
		EngineConfig config = new EngineConfig();
		Config(config);
		//TODO why does this error now?
		Platform.startup(config);
		IReportEngineFactory factory = (IReportEngineFactory) Platform
				.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
		IReportEngine engine = factory.createReportEngine(config);
		engine.changeLogLevel( Level.WARNING );
		IReportRunnable design = engine.openReportDesign("C:\\Users\\Rob\\workspace\\renderDocument\\stock.rptdesign"); 
				
		//Create task to run the report - use the task to execute the report and save to disk.
		IRunTask task = engine.createRunTask(design);
							
		//run the report and destroy the engine
		task.run("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
		task.close();

	  	engine.destroy();
	}
	//Renders report from .rptdocument to .xls
	public static void renderStuff () throws BirtException{
		IReportDocument document = null;
		EngineConfig config = new EngineConfig();
		Config(config);
		IReportEngineFactory factory = (IReportEngineFactory) Platform
				.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
		IReportEngine engine = factory.createReportEngine(config);
		engine.changeLogLevel( Level.WARNING );
		//ReportEngine engine = new ReportEngine(null);
		  document = engine.openReportDocument("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument"); 
		  EXCELRenderOption options = new EXCELRenderOption();
		  options.setOutputFormat("xls");
		  options.setOutputFileName("C:\\Users\\Rob\\workspace\\renderDocument\\stockInfo.xls");
		  org.eclipse.birt.report.engine.api.IRenderTask task = engine.createRenderTask(document);   
		  task.setRenderOption(options);
		  task.render();
		  	engine.destroy();
		  	Platform.shutdown();
	}
	
	protected static void Config(EngineConfig C)
	{
		C.setEngineHome ("C:\\BIRT\\birt-runtime-4_2_0\\ReportEngine");
		C.setLogConfig("C:\\temp", Level.FINE);
		return;
	}
}
Re: Cannot run report properly while using aggregations [message #898619 is a reply to message #898102] Thu, 26 July 2012 21:56 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Robert,

A couple of things. Unless you are using the 4.2 OSGi runtime do not
set the EngineHome. If you are just adding the runtime jars to the
classpath (POJO runtime) this call will cause issues. Also only startup
the platform once for the lifetime of you app. In webapps generally you
create the engine in a singleton. In a command line app just start it
up when you start and shut it down when you are finished. Can you try
running the code below with the attached rptdesign?

package REAPI;



import java.util.Locale;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.RenderOption;


public class RunThenRenderTaskXls {

public void runReport() throws EngineException
{

IReportEngine engine=null;
EngineConfig config = null;
IReportDocument document = null;
try{
config = new EngineConfig( );
Platform.startup( config );

IReportEngineFactory factory = (IReportEngineFactory) Platform
..createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );


IReportRunnable design = null;
design = engine.openReportDesign("Reports/average.rptdesign");
IRunTask task = engine.createRunTask(design);
task.setLocale(new Locale("en", "US"));
task.run("output/resample/average.rptdocument");
task.close();

document =
engine.openReportDocument("output/resample/average.rptdocument");

EXCELRenderOption options = new EXCELRenderOption();
options.setOutputFormat("xls");
options.setOutputFileName("output/resample/average.xls");
options.setOption(IRenderOption.HTML_PAGINATION, true);

IRenderTask rtask = engine.createRenderTask(document);
rtask.setLocale(new Locale("en", "US"));
rtask.setRenderOption(options);
rtask.render();
rtask.close();
document.close();
engine.destroy();

System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}

}


/**
* @param args
*/
public static void main(String[] args) {
try
{

RunThenRenderTaskXls ex = new RunThenRenderTaskXls( );
ex.runReport();

}
catch ( Exception e )
{
e.printStackTrace();
}
}

}



Jason



On 7/25/2012 3:28 PM, Robert LaDue wrote:
> I am trying to use BIRT to take sample inputs of date and numbers and
> output them to an .xls file along with the average of the numbers.
> I have built an .rptdesign file consisting solely of a table containing
> the following information: A header row with text ("date" + "number"). A
> detail row with the data (the date and number data). A footer row
> containing text ("Average"), and an aggregation with the function AVE,
> and the expression row["Number"].
> I have written a java program to run and render the .rptdesign into an
> .rptdocument file, and subsequently into an .xls file. The issue lies in
> the fact that whenever the aggregation is present, none of the data is
> placed into the .rptdocument file when my code is run. The output is
> only the text fields. The data and aggregation simply disappear.
> Manually generating an .rptdocument through the 'run' menu in eclipse
> works perfectly, and the render turns out fine. This has led me to
> believe there is something wrong with my code, but I am at a loss for
> what it could be.
>
> Here is the code in question:
> package code;
>
> import org.eclipse.birt.report.engine.api.*;
> import org.eclipse.birt.core.exception.BirtException;
> import org.eclipse.birt.core.framework.Platform;
> import java.util.logging.Level;
>
> public class RenderDoc {
> public static void main( String[] args ){
> try {
> runStuff ();
> renderStuff ();
> } catch (EngineException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (BirtException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> //Runs report from .rptdesign to .rptdocument
> public static void runStuff () throws BirtException{
> EngineConfig config = new EngineConfig();
> Config(config);
> //TODO why does this error now?
> Platform.startup(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> IReportRunnable design =
> engine.openReportDesign("C:\\Users\\Rob\\workspace\\renderDocument\\stock.rptdesign");
>
> //Create task to run the report - use the task to execute the
> report and save to disk.
> IRunTask task = engine.createRunTask(design);
>
> //run the report and destroy the engine
>
> task.run("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
>
> task.close();
>
> engine.destroy();
> }
> //Renders report from .rptdocument to .xls
> public static void renderStuff () throws BirtException{
> IReportDocument document = null;
> EngineConfig config = new EngineConfig();
> Config(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> //ReportEngine engine = new ReportEngine(null);
> document =
> engine.openReportDocument("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
> EXCELRenderOption options = new EXCELRenderOption();
> options.setOutputFormat("xls");
>
> options.setOutputFileName("C:\\Users\\Rob\\workspace\\renderDocument\\stockInfo.xls");
>
> org.eclipse.birt.report.engine.api.IRenderTask task =
> engine.createRenderTask(document); task.setRenderOption(options);
> task.render();
> engine.destroy();
> Platform.shutdown();
> }
>
> protected static void Config(EngineConfig C)
> {
> C.setEngineHome ("C:\\BIRT\\birt-runtime-4_2_0\\ReportEngine");
> C.setLogConfig("C:\\temp", Level.FINE);
> return;
> }
> }
>
  • Attachment: average.zip
    (Size: 2.44KB, Downloaded 141 times)
Re: Cannot run report properly while using aggregations [message #898620 is a reply to message #898102] Thu, 26 July 2012 21:56 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Robert,

A couple of things. Unless you are using the 4.2 OSGi runtime do not
set the EngineHome. If you are just adding the runtime jars to the
classpath (POJO runtime) this call will cause issues. Also only startup
the platform once for the lifetime of you app. In webapps generally you
create the engine in a singleton. In a command line app just start it
up when you start and shut it down when you are finished. Can you try
running the code below with the attached rptdesign?

package REAPI;



import java.util.Locale;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.RenderOption;


public class RunThenRenderTaskXls {

public void runReport() throws EngineException
{

IReportEngine engine=null;
EngineConfig config = null;
IReportDocument document = null;
try{
config = new EngineConfig( );
Platform.startup( config );

IReportEngineFactory factory = (IReportEngineFactory) Platform
..createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );


IReportRunnable design = null;
design = engine.openReportDesign("Reports/average.rptdesign");
IRunTask task = engine.createRunTask(design);
task.setLocale(new Locale("en", "US"));
task.run("output/resample/average.rptdocument");
task.close();

document =
engine.openReportDocument("output/resample/average.rptdocument");

EXCELRenderOption options = new EXCELRenderOption();
options.setOutputFormat("xls");
options.setOutputFileName("output/resample/average.xls");
options.setOption(IRenderOption.HTML_PAGINATION, true);

IRenderTask rtask = engine.createRenderTask(document);
rtask.setLocale(new Locale("en", "US"));
rtask.setRenderOption(options);
rtask.render();
rtask.close();
document.close();
engine.destroy();

System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}

}


/**
* @param args
*/
public static void main(String[] args) {
try
{

RunThenRenderTaskXls ex = new RunThenRenderTaskXls( );
ex.runReport();

}
catch ( Exception e )
{
e.printStackTrace();
}
}

}



Jason



On 7/25/2012 3:28 PM, Robert LaDue wrote:
> I am trying to use BIRT to take sample inputs of date and numbers and
> output them to an .xls file along with the average of the numbers.
> I have built an .rptdesign file consisting solely of a table containing
> the following information: A header row with text ("date" + "number"). A
> detail row with the data (the date and number data). A footer row
> containing text ("Average"), and an aggregation with the function AVE,
> and the expression row["Number"].
> I have written a java program to run and render the .rptdesign into an
> .rptdocument file, and subsequently into an .xls file. The issue lies in
> the fact that whenever the aggregation is present, none of the data is
> placed into the .rptdocument file when my code is run. The output is
> only the text fields. The data and aggregation simply disappear.
> Manually generating an .rptdocument through the 'run' menu in eclipse
> works perfectly, and the render turns out fine. This has led me to
> believe there is something wrong with my code, but I am at a loss for
> what it could be.
>
> Here is the code in question:
> package code;
>
> import org.eclipse.birt.report.engine.api.*;
> import org.eclipse.birt.core.exception.BirtException;
> import org.eclipse.birt.core.framework.Platform;
> import java.util.logging.Level;
>
> public class RenderDoc {
> public static void main( String[] args ){
> try {
> runStuff ();
> renderStuff ();
> } catch (EngineException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (BirtException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> //Runs report from .rptdesign to .rptdocument
> public static void runStuff () throws BirtException{
> EngineConfig config = new EngineConfig();
> Config(config);
> //TODO why does this error now?
> Platform.startup(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> IReportRunnable design =
> engine.openReportDesign("C:\\Users\\Rob\\workspace\\renderDocument\\stock.rptdesign");
>
> //Create task to run the report - use the task to execute the
> report and save to disk.
> IRunTask task = engine.createRunTask(design);
>
> //run the report and destroy the engine
>
> task.run("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
>
> task.close();
>
> engine.destroy();
> }
> //Renders report from .rptdocument to .xls
> public static void renderStuff () throws BirtException{
> IReportDocument document = null;
> EngineConfig config = new EngineConfig();
> Config(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> //ReportEngine engine = new ReportEngine(null);
> document =
> engine.openReportDocument("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
> EXCELRenderOption options = new EXCELRenderOption();
> options.setOutputFormat("xls");
>
> options.setOutputFileName("C:\\Users\\Rob\\workspace\\renderDocument\\stockInfo.xls");
>
> org.eclipse.birt.report.engine.api.IRenderTask task =
> engine.createRenderTask(document); task.setRenderOption(options);
> task.render();
> engine.destroy();
> Platform.shutdown();
> }
>
> protected static void Config(EngineConfig C)
> {
> C.setEngineHome ("C:\\BIRT\\birt-runtime-4_2_0\\ReportEngine");
> C.setLogConfig("C:\\temp", Level.FINE);
> return;
> }
> }
>
  • Attachment: average.zip
    (Size: 2.44KB, Downloaded 154 times)
Re: Cannot run report properly while using aggregations [message #898621 is a reply to message #898102] Thu, 26 July 2012 21:56 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Robert,

A couple of things. Unless you are using the 4.2 OSGi runtime do not
set the EngineHome. If you are just adding the runtime jars to the
classpath (POJO runtime) this call will cause issues. Also only startup
the platform once for the lifetime of you app. In webapps generally you
create the engine in a singleton. In a command line app just start it
up when you start and shut it down when you are finished. Can you try
running the code below with the attached rptdesign?

package REAPI;



import java.util.Locale;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.RenderOption;


public class RunThenRenderTaskXls {

public void runReport() throws EngineException
{

IReportEngine engine=null;
EngineConfig config = null;
IReportDocument document = null;
try{
config = new EngineConfig( );
Platform.startup( config );

IReportEngineFactory factory = (IReportEngineFactory) Platform
..createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );


IReportRunnable design = null;
design = engine.openReportDesign("Reports/average.rptdesign");
IRunTask task = engine.createRunTask(design);
task.setLocale(new Locale("en", "US"));
task.run("output/resample/average.rptdocument");
task.close();

document =
engine.openReportDocument("output/resample/average.rptdocument");

EXCELRenderOption options = new EXCELRenderOption();
options.setOutputFormat("xls");
options.setOutputFileName("output/resample/average.xls");
options.setOption(IRenderOption.HTML_PAGINATION, true);

IRenderTask rtask = engine.createRenderTask(document);
rtask.setLocale(new Locale("en", "US"));
rtask.setRenderOption(options);
rtask.render();
rtask.close();
document.close();
engine.destroy();

System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}

}


/**
* @param args
*/
public static void main(String[] args) {
try
{

RunThenRenderTaskXls ex = new RunThenRenderTaskXls( );
ex.runReport();

}
catch ( Exception e )
{
e.printStackTrace();
}
}

}



Jason



On 7/25/2012 3:28 PM, Robert LaDue wrote:
> I am trying to use BIRT to take sample inputs of date and numbers and
> output them to an .xls file along with the average of the numbers.
> I have built an .rptdesign file consisting solely of a table containing
> the following information: A header row with text ("date" + "number"). A
> detail row with the data (the date and number data). A footer row
> containing text ("Average"), and an aggregation with the function AVE,
> and the expression row["Number"].
> I have written a java program to run and render the .rptdesign into an
> .rptdocument file, and subsequently into an .xls file. The issue lies in
> the fact that whenever the aggregation is present, none of the data is
> placed into the .rptdocument file when my code is run. The output is
> only the text fields. The data and aggregation simply disappear.
> Manually generating an .rptdocument through the 'run' menu in eclipse
> works perfectly, and the render turns out fine. This has led me to
> believe there is something wrong with my code, but I am at a loss for
> what it could be.
>
> Here is the code in question:
> package code;
>
> import org.eclipse.birt.report.engine.api.*;
> import org.eclipse.birt.core.exception.BirtException;
> import org.eclipse.birt.core.framework.Platform;
> import java.util.logging.Level;
>
> public class RenderDoc {
> public static void main( String[] args ){
> try {
> runStuff ();
> renderStuff ();
> } catch (EngineException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (BirtException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> //Runs report from .rptdesign to .rptdocument
> public static void runStuff () throws BirtException{
> EngineConfig config = new EngineConfig();
> Config(config);
> //TODO why does this error now?
> Platform.startup(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> IReportRunnable design =
> engine.openReportDesign("C:\\Users\\Rob\\workspace\\renderDocument\\stock.rptdesign");
>
> //Create task to run the report - use the task to execute the
> report and save to disk.
> IRunTask task = engine.createRunTask(design);
>
> //run the report and destroy the engine
>
> task.run("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
>
> task.close();
>
> engine.destroy();
> }
> //Renders report from .rptdocument to .xls
> public static void renderStuff () throws BirtException{
> IReportDocument document = null;
> EngineConfig config = new EngineConfig();
> Config(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> //ReportEngine engine = new ReportEngine(null);
> document =
> engine.openReportDocument("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
> EXCELRenderOption options = new EXCELRenderOption();
> options.setOutputFormat("xls");
>
> options.setOutputFileName("C:\\Users\\Rob\\workspace\\renderDocument\\stockInfo.xls");
>
> org.eclipse.birt.report.engine.api.IRenderTask task =
> engine.createRenderTask(document); task.setRenderOption(options);
> task.render();
> engine.destroy();
> Platform.shutdown();
> }
>
> protected static void Config(EngineConfig C)
> {
> C.setEngineHome ("C:\\BIRT\\birt-runtime-4_2_0\\ReportEngine");
> C.setLogConfig("C:\\temp", Level.FINE);
> return;
> }
> }
>
  • Attachment: average.zip
    (Size: 2.44KB, Downloaded 142 times)
Re: Cannot run report properly while using aggregations [message #898623 is a reply to message #898102] Thu, 26 July 2012 21:56 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Robert,

A couple of things. Unless you are using the 4.2 OSGi runtime do not
set the EngineHome. If you are just adding the runtime jars to the
classpath (POJO runtime) this call will cause issues. Also only startup
the platform once for the lifetime of you app. In webapps generally you
create the engine in a singleton. In a command line app just start it
up when you start and shut it down when you are finished. Can you try
running the code below with the attached rptdesign?

package REAPI;



import java.util.Locale;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.RenderOption;


public class RunThenRenderTaskXls {

public void runReport() throws EngineException
{

IReportEngine engine=null;
EngineConfig config = null;
IReportDocument document = null;
try{
config = new EngineConfig( );
Platform.startup( config );

IReportEngineFactory factory = (IReportEngineFactory) Platform
..createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );


IReportRunnable design = null;
design = engine.openReportDesign("Reports/average.rptdesign");
IRunTask task = engine.createRunTask(design);
task.setLocale(new Locale("en", "US"));
task.run("output/resample/average.rptdocument");
task.close();

document =
engine.openReportDocument("output/resample/average.rptdocument");

EXCELRenderOption options = new EXCELRenderOption();
options.setOutputFormat("xls");
options.setOutputFileName("output/resample/average.xls");
options.setOption(IRenderOption.HTML_PAGINATION, true);

IRenderTask rtask = engine.createRenderTask(document);
rtask.setLocale(new Locale("en", "US"));
rtask.setRenderOption(options);
rtask.render();
rtask.close();
document.close();
engine.destroy();

System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}

}


/**
* @param args
*/
public static void main(String[] args) {
try
{

RunThenRenderTaskXls ex = new RunThenRenderTaskXls( );
ex.runReport();

}
catch ( Exception e )
{
e.printStackTrace();
}
}

}



Jason



On 7/25/2012 3:28 PM, Robert LaDue wrote:
> I am trying to use BIRT to take sample inputs of date and numbers and
> output them to an .xls file along with the average of the numbers.
> I have built an .rptdesign file consisting solely of a table containing
> the following information: A header row with text ("date" + "number"). A
> detail row with the data (the date and number data). A footer row
> containing text ("Average"), and an aggregation with the function AVE,
> and the expression row["Number"].
> I have written a java program to run and render the .rptdesign into an
> .rptdocument file, and subsequently into an .xls file. The issue lies in
> the fact that whenever the aggregation is present, none of the data is
> placed into the .rptdocument file when my code is run. The output is
> only the text fields. The data and aggregation simply disappear.
> Manually generating an .rptdocument through the 'run' menu in eclipse
> works perfectly, and the render turns out fine. This has led me to
> believe there is something wrong with my code, but I am at a loss for
> what it could be.
>
> Here is the code in question:
> package code;
>
> import org.eclipse.birt.report.engine.api.*;
> import org.eclipse.birt.core.exception.BirtException;
> import org.eclipse.birt.core.framework.Platform;
> import java.util.logging.Level;
>
> public class RenderDoc {
> public static void main( String[] args ){
> try {
> runStuff ();
> renderStuff ();
> } catch (EngineException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (BirtException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> //Runs report from .rptdesign to .rptdocument
> public static void runStuff () throws BirtException{
> EngineConfig config = new EngineConfig();
> Config(config);
> //TODO why does this error now?
> Platform.startup(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> IReportRunnable design =
> engine.openReportDesign("C:\\Users\\Rob\\workspace\\renderDocument\\stock.rptdesign");
>
> //Create task to run the report - use the task to execute the
> report and save to disk.
> IRunTask task = engine.createRunTask(design);
>
> //run the report and destroy the engine
>
> task.run("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
>
> task.close();
>
> engine.destroy();
> }
> //Renders report from .rptdocument to .xls
> public static void renderStuff () throws BirtException{
> IReportDocument document = null;
> EngineConfig config = new EngineConfig();
> Config(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> //ReportEngine engine = new ReportEngine(null);
> document =
> engine.openReportDocument("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
> EXCELRenderOption options = new EXCELRenderOption();
> options.setOutputFormat("xls");
>
> options.setOutputFileName("C:\\Users\\Rob\\workspace\\renderDocument\\stockInfo.xls");
>
> org.eclipse.birt.report.engine.api.IRenderTask task =
> engine.createRenderTask(document); task.setRenderOption(options);
> task.render();
> engine.destroy();
> Platform.shutdown();
> }
>
> protected static void Config(EngineConfig C)
> {
> C.setEngineHome ("C:\\BIRT\\birt-runtime-4_2_0\\ReportEngine");
> C.setLogConfig("C:\\temp", Level.FINE);
> return;
> }
> }
>
  • Attachment: average.zip
    (Size: 2.44KB, Downloaded 144 times)
Re: Cannot run report properly while using aggregations [message #898624 is a reply to message #898102] Thu, 26 July 2012 21:56 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Robert,

A couple of things. Unless you are using the 4.2 OSGi runtime do not
set the EngineHome. If you are just adding the runtime jars to the
classpath (POJO runtime) this call will cause issues. Also only startup
the platform once for the lifetime of you app. In webapps generally you
create the engine in a singleton. In a command line app just start it
up when you start and shut it down when you are finished. Can you try
running the code below with the attached rptdesign?

package REAPI;



import java.util.Locale;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.RenderOption;


public class RunThenRenderTaskXls {

public void runReport() throws EngineException
{

IReportEngine engine=null;
EngineConfig config = null;
IReportDocument document = null;
try{
config = new EngineConfig( );
Platform.startup( config );

IReportEngineFactory factory = (IReportEngineFactory) Platform
..createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );


IReportRunnable design = null;
design = engine.openReportDesign("Reports/average.rptdesign");
IRunTask task = engine.createRunTask(design);
task.setLocale(new Locale("en", "US"));
task.run("output/resample/average.rptdocument");
task.close();

document =
engine.openReportDocument("output/resample/average.rptdocument");

EXCELRenderOption options = new EXCELRenderOption();
options.setOutputFormat("xls");
options.setOutputFileName("output/resample/average.xls");
options.setOption(IRenderOption.HTML_PAGINATION, true);

IRenderTask rtask = engine.createRenderTask(document);
rtask.setLocale(new Locale("en", "US"));
rtask.setRenderOption(options);
rtask.render();
rtask.close();
document.close();
engine.destroy();

System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}

}


/**
* @param args
*/
public static void main(String[] args) {
try
{

RunThenRenderTaskXls ex = new RunThenRenderTaskXls( );
ex.runReport();

}
catch ( Exception e )
{
e.printStackTrace();
}
}

}



Jason



On 7/25/2012 3:28 PM, Robert LaDue wrote:
> I am trying to use BIRT to take sample inputs of date and numbers and
> output them to an .xls file along with the average of the numbers.
> I have built an .rptdesign file consisting solely of a table containing
> the following information: A header row with text ("date" + "number"). A
> detail row with the data (the date and number data). A footer row
> containing text ("Average"), and an aggregation with the function AVE,
> and the expression row["Number"].
> I have written a java program to run and render the .rptdesign into an
> .rptdocument file, and subsequently into an .xls file. The issue lies in
> the fact that whenever the aggregation is present, none of the data is
> placed into the .rptdocument file when my code is run. The output is
> only the text fields. The data and aggregation simply disappear.
> Manually generating an .rptdocument through the 'run' menu in eclipse
> works perfectly, and the render turns out fine. This has led me to
> believe there is something wrong with my code, but I am at a loss for
> what it could be.
>
> Here is the code in question:
> package code;
>
> import org.eclipse.birt.report.engine.api.*;
> import org.eclipse.birt.core.exception.BirtException;
> import org.eclipse.birt.core.framework.Platform;
> import java.util.logging.Level;
>
> public class RenderDoc {
> public static void main( String[] args ){
> try {
> runStuff ();
> renderStuff ();
> } catch (EngineException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (BirtException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> //Runs report from .rptdesign to .rptdocument
> public static void runStuff () throws BirtException{
> EngineConfig config = new EngineConfig();
> Config(config);
> //TODO why does this error now?
> Platform.startup(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> IReportRunnable design =
> engine.openReportDesign("C:\\Users\\Rob\\workspace\\renderDocument\\stock.rptdesign");
>
> //Create task to run the report - use the task to execute the
> report and save to disk.
> IRunTask task = engine.createRunTask(design);
>
> //run the report and destroy the engine
>
> task.run("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
>
> task.close();
>
> engine.destroy();
> }
> //Renders report from .rptdocument to .xls
> public static void renderStuff () throws BirtException{
> IReportDocument document = null;
> EngineConfig config = new EngineConfig();
> Config(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> //ReportEngine engine = new ReportEngine(null);
> document =
> engine.openReportDocument("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
> EXCELRenderOption options = new EXCELRenderOption();
> options.setOutputFormat("xls");
>
> options.setOutputFileName("C:\\Users\\Rob\\workspace\\renderDocument\\stockInfo.xls");
>
> org.eclipse.birt.report.engine.api.IRenderTask task =
> engine.createRenderTask(document); task.setRenderOption(options);
> task.render();
> engine.destroy();
> Platform.shutdown();
> }
>
> protected static void Config(EngineConfig C)
> {
> C.setEngineHome ("C:\\BIRT\\birt-runtime-4_2_0\\ReportEngine");
> C.setLogConfig("C:\\temp", Level.FINE);
> return;
> }
> }
>
  • Attachment: average.zip
    (Size: 2.44KB, Downloaded 198 times)
Re: Cannot run report properly while using aggregations [message #898625 is a reply to message #898102] Thu, 26 July 2012 21:56 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Robert,

A couple of things. Unless you are using the 4.2 OSGi runtime do not
set the EngineHome. If you are just adding the runtime jars to the
classpath (POJO runtime) this call will cause issues. Also only startup
the platform once for the lifetime of you app. In webapps generally you
create the engine in a singleton. In a command line app just start it
up when you start and shut it down when you are finished. Can you try
running the code below with the attached rptdesign?

package REAPI;



import java.util.Locale;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.RenderOption;


public class RunThenRenderTaskXls {

public void runReport() throws EngineException
{

IReportEngine engine=null;
EngineConfig config = null;
IReportDocument document = null;
try{
config = new EngineConfig( );
Platform.startup( config );

IReportEngineFactory factory = (IReportEngineFactory) Platform
..createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );


IReportRunnable design = null;
design = engine.openReportDesign("Reports/average.rptdesign");
IRunTask task = engine.createRunTask(design);
task.setLocale(new Locale("en", "US"));
task.run("output/resample/average.rptdocument");
task.close();

document =
engine.openReportDocument("output/resample/average.rptdocument");

EXCELRenderOption options = new EXCELRenderOption();
options.setOutputFormat("xls");
options.setOutputFileName("output/resample/average.xls");
options.setOption(IRenderOption.HTML_PAGINATION, true);

IRenderTask rtask = engine.createRenderTask(document);
rtask.setLocale(new Locale("en", "US"));
rtask.setRenderOption(options);
rtask.render();
rtask.close();
document.close();
engine.destroy();

System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}

}


/**
* @param args
*/
public static void main(String[] args) {
try
{

RunThenRenderTaskXls ex = new RunThenRenderTaskXls( );
ex.runReport();

}
catch ( Exception e )
{
e.printStackTrace();
}
}

}



Jason



On 7/25/2012 3:28 PM, Robert LaDue wrote:
> I am trying to use BIRT to take sample inputs of date and numbers and
> output them to an .xls file along with the average of the numbers.
> I have built an .rptdesign file consisting solely of a table containing
> the following information: A header row with text ("date" + "number"). A
> detail row with the data (the date and number data). A footer row
> containing text ("Average"), and an aggregation with the function AVE,
> and the expression row["Number"].
> I have written a java program to run and render the .rptdesign into an
> .rptdocument file, and subsequently into an .xls file. The issue lies in
> the fact that whenever the aggregation is present, none of the data is
> placed into the .rptdocument file when my code is run. The output is
> only the text fields. The data and aggregation simply disappear.
> Manually generating an .rptdocument through the 'run' menu in eclipse
> works perfectly, and the render turns out fine. This has led me to
> believe there is something wrong with my code, but I am at a loss for
> what it could be.
>
> Here is the code in question:
> package code;
>
> import org.eclipse.birt.report.engine.api.*;
> import org.eclipse.birt.core.exception.BirtException;
> import org.eclipse.birt.core.framework.Platform;
> import java.util.logging.Level;
>
> public class RenderDoc {
> public static void main( String[] args ){
> try {
> runStuff ();
> renderStuff ();
> } catch (EngineException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (BirtException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> //Runs report from .rptdesign to .rptdocument
> public static void runStuff () throws BirtException{
> EngineConfig config = new EngineConfig();
> Config(config);
> //TODO why does this error now?
> Platform.startup(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> IReportRunnable design =
> engine.openReportDesign("C:\\Users\\Rob\\workspace\\renderDocument\\stock.rptdesign");
>
> //Create task to run the report - use the task to execute the
> report and save to disk.
> IRunTask task = engine.createRunTask(design);
>
> //run the report and destroy the engine
>
> task.run("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
>
> task.close();
>
> engine.destroy();
> }
> //Renders report from .rptdocument to .xls
> public static void renderStuff () throws BirtException{
> IReportDocument document = null;
> EngineConfig config = new EngineConfig();
> Config(config);
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> //ReportEngine engine = new ReportEngine(null);
> document =
> engine.openReportDocument("C:\\Users\\Rob\\workspace\\renderDocument\\outputTest.rptdocument");
> EXCELRenderOption options = new EXCELRenderOption();
> options.setOutputFormat("xls");
>
> options.setOutputFileName("C:\\Users\\Rob\\workspace\\renderDocument\\stockInfo.xls");
>
> org.eclipse.birt.report.engine.api.IRenderTask task =
> engine.createRenderTask(document); task.setRenderOption(options);
> task.render();
> engine.destroy();
> Platform.shutdown();
> }
>
> protected static void Config(EngineConfig C)
> {
> C.setEngineHome ("C:\\BIRT\\birt-runtime-4_2_0\\ReportEngine");
> C.setLogConfig("C:\\temp", Level.FINE);
> return;
> }
> }
>
  • Attachment: average.zip
    (Size: 2.44KB, Downloaded 145 times)
Previous Topic:Multiple values for dynamic parameter
Next Topic:Create my own parameter window?
Goto Forum:
  


Current Time: Thu Apr 25 10:59:59 GMT 2024

Powered by FUDForum. Page generated in 0.04119 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top