Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 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 53 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 52 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 58 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 45 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 55 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 55 times)
Previous Topic:Multiple values for dynamic parameter
Next Topic:Create my own parameter window?
Goto Forum:
  


Current Time: Mon Nov 24 15:11:44 GMT 2014

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

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