Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Changing the &XML Data Source File dynamically
Changing the &XML Data Source File dynamically [message #652350] Thu, 03 February 2011 11:17 Go to next message
Mike Wulkan is currently offline Mike Wulkan
Messages: 141
Registered: July 2009
Senior Member
I have an XML datasource. In the advanced tab of the datasource's property editor I can see
ODA Data Source
&XML Data Source File

which has the value I specified when I created the datasource.

I would like to be able to set this value from a parameter that I pass in. Ideally I would also like to set the default value of the parameter to what ever the current value is.

I am assuming that the hook should be placed in the "beforeOpen" of the datasource but I don't know the syntax for referencing/setting this field.
Re: Changing the &XML Data Source File dynamically [message #652353 is a reply to message #652350] Thu, 03 February 2011 11:23 Go to previous messageGo to next message
Mike Wulkan is currently offline Mike Wulkan
Messages: 141
Registered: July 2009
Senior Member
On further thought, I'm not sure how this can work as parameters are obviously processed after the datasource is opened since the default values for some of these parameters are taken from the data.

So is it even possible to provide the name of the datasource in the Report Parameters?
Re: Changing the &XML Data Source File dynamically [message #652387 is a reply to message #652353] Thu, 03 February 2011 12:33 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Mike,

You can set any datasource property in the beforeOpen like:
extensionProperties.odaURL = "jdbc:mysql://localhost/mysql";
where odaURL is the property you are interested in changing.
You can use the xml view if you are not sure what the property name is.

But if the datasource is already opened like for the parameter this
approach will not work.

Jason


On 2/3/2011 11:23 AM, Mike Wulkan wrote:
> On further thought, I'm not sure how this can work as parameters are
> obviously processed after the datasource is opened since the default
> values for some of these parameters are taken from the data.
>
> So is it even possible to provide the name of the datasource in the
> Report Parameters?
Re: Changing the &XML Data Source File dynamically [message #918302 is a reply to message #652350] Thu, 20 September 2012 19:15 Go to previous messageGo to next message
Randy Evered is currently offline Randy Evered
Messages: 16
Registered: July 2012
Junior Member
Jason,

I wish to do something similar in that I am using an EMF ODA data source and I want to set the Ecore file name and path before running the report using the integrated Java approach. Is it possible to set the data source property from Java on a ReportEngine or RunAndRenderTask option somehow?

Thanks for your time,
Randy
Re: Changing the &XML Data Source File dynamically [message #919043 is a reply to message #918302] Fri, 21 September 2012 12:20 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Sure. There are several ways this can be done. One way is to add a parameter for the property. Then the property binding expression for the property set it to params["yourparam"].value or use a beforeOpen script like:
this.property = params["yourparam"].value; Then in the run and render task just make sure to set the parameter value like task.setParameterValue("yourparam", "youpropertyvalue"); If you do not want to use a parameter put the value in the appcontext like task.getAppContext().put("yourpropname", "yourpropvalue" ); then in the beforeOpen script use this.property =reportContext.getAppContext().get("yourpropname");

Jason
Re: Changing the &XML Data Source File dynamically [message #919054 is a reply to message #919043] Fri, 21 September 2012 12:37 Go to previous messageGo to next message
Randy Evered is currently offline Randy Evered
Messages: 16
Registered: July 2012
Junior Member
Jason,

That will allow me to choose the data source from within Java (if the Data Source already exists)? Sweet! I am not sure if I was clear what I needed or not (LOL sounds too easy).

What is "property"? Do I need to specify another property name, or a generic "property" will work? I am a bit new to properties and parameters. Although I have been reading about parameters.

Thanks for your help!
Randy

[Updated on: Fri, 21 September 2012 12:39]

Report message to a moderator

Re: Changing the &XML Data Source File dynamically [message #919099 is a reply to message #919054] Fri, 21 September 2012 13:24 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

You can look at the xml view of the report and find the property of the data source/set you want to change. It will have a name like odaURL. This is the property I mean. You will see all the settable properties in the property binding toc entry when you open the data set/source in the designer. You can use code like:
this.setProperty("propertyname", "propertyvalue); if the property does not have a native setter method in the beforeOpen script.

Jason
Re: Changing the &XML Data Source File dynamically [message #919338 is a reply to message #919099] Fri, 21 September 2012 19:03 Go to previous messageGo to next message
Randy Evered is currently offline Randy Evered
Messages: 16
Registered: July 2012
Junior Member
Jason,

Would this work too (on the report side)?

path = reportContext.getAppContext().get( "myParameter" );
this.getDataSource( "Data Source" ).setPrivateDriverProperty( "HOME", path );

If I set myParameter in the appContext in Java, and HOME is the property of the Data Source? They had it in the beforeFactory section.

I am just looking around at DevShare in birt-exchange because I am stuck on EMF ODA queryText problem.

I got it from: http: //www.spudsoft.co.uk/2011/10/lsned43-how-to-have-relative-path-in-a-flat-file-data-source-in-birt/

Thanks,
Randy

[Updated on: Fri, 21 September 2012 19:10]

Report message to a moderator

Re: Changing the &XML Data Source File dynamically [message #922167 is a reply to message #919338] Mon, 24 September 2012 16:05 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

That should work. You could also try:

reportContext.getDesignHandle().findDataSource("data source").setProperty("propertyname", value);

Jason
Re: Changing the &XML Data Source File dynamically [message #924469 is a reply to message #922167] Wed, 26 September 2012 17:59 Go to previous messageGo to next message
Randy Evered is currently offline Randy Evered
Messages: 16
Registered: July 2012
Junior Member
Jason,

I tried the following, thinking that reportContext was my reportDesign:

// create engine configuration, start engine and platform
EngineConfig config = new EngineConfig();
config.setLogConfig(null, Level.ALL);

Platform.startup();
ReportEngine engine = new ReportEngine(config);

// open the report design and create a new run task
IReportRunnable reportDesign = engine.openReportDesign(designFile);
//reportDesign.getDesignHandle().findDataSource("data source").setProperty("propertyname", value);
IRunAndRenderTask runTask = engine.createRunAndRenderTask(reportDesign);

But it doesn't compile that way.

Any ideas?

Thanks again,
Randy
Re: Changing the &XML Data Source File dynamically [message #924520 is a reply to message #924469] Wed, 26 September 2012 19:17 Go to previous messageGo to next message
Randy Evered is currently offline Randy Evered
Messages: 16
Registered: July 2012
Junior Member
Jason,

I made a mistake in the last example. I realize now that that is JavaScript. I tried setting the dataSource parameter in Java, and using this JavaScript in the beforeOpen of the Data Source:

path = reportContext.getAppContext().get("dataSource");
reportContext.getDesignHandle().findDataSource("ExampleEcore").setProperty("resource", path);

Which didn't seem to pass the parameter through to Data Source.

I'll work on it.

Thanks,
Randy
Re: Changing the &XML Data Source File dynamically [message #925383 is a reply to message #924520] Thu, 27 September 2012 13:09 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

If you put this in your JavaScript for the report:
path = reportContext.getAppContext().get("dataSource");
reportContext.getDesignHandle().findDataSource("ExampleEcore").setProperty("resource", path);

in Java you should be putting dataSource in like:
runTask.getAppContext().put("dataSource", "yourdatasource");

Jason
Re: Changing the &XML Data Source File dynamically [message #933173 is a reply to message #925383] Thu, 04 October 2012 16:05 Go to previous messageGo to next message
Randy Evered is currently offline Randy Evered
Messages: 16
Registered: July 2012
Junior Member
I had to put it in the beforeFactory to get it working. But, it does work!!!

Randy
Re: Changing the &XML Data Source File dynamically [message #934152 is a reply to message #933173] Fri, 05 October 2012 14:02 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

What error are you getting? In the beforeFactory add something like the following:

var tst = reportContext.getDesignHandle().findDataSource("ExampleEcore").getProperty("resource");
var path = reportContext.getAppContext().get("dataSource");
importPackage( Packages.java.io );
out = new PrintWriter( new FileWriter( "c:/temp/debugreport.txt", true ) );
out.println( "Prop " + tst + "-- appcontext value " + path);
out.close();

Jason
Previous Topic:How to suppress a detail row based on the values from prev. row?
Next Topic:how to change this prompt for each supported language - birt.viewer.progressbar.prompt
Goto Forum:
  


Current Time: Tue Jul 22 23:44:03 EDT 2014

Powered by FUDForum. Page generated in 0.01865 seconds