Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Datasource: change source
denislagod
I use BIRT 3.7.2. While designing reports we use XML Datasource connection with XML file.
Using java I need to change source from xml file to data from parameter. Actually in designing time it easy: put in Property Binding:
params["param1"].value
How to do it in run time:
What I found:
Expression expression = new Expression("params['param1'].value", ExpressionType.JAVASCRIPT);
PropertyBinding binding = new PropertyBinding();
binding.setExpressionProperty("FILELIST", expression);
binding.setID(myDatasourceHandle.getID());
designHandle.getModule().getPropertyBindings(myDatasourceHandle.getElement()).add(binding);
It doesnt work. Help me!
Find more posts tagged with
Comments
denislagod
Another words: After designer I have this:
<data-sources>
<oda-data-source extensionID="org.eclipse.datatools.enablement.oda.xml" name="DS1" id="7">
<property name="FILELIST">xmldata1.xml</property>
</oda-data-source>
</data-sources>
I need:
<list-property name="propertyBindings">
<structure>
<property name="name">FILELIST</property>
<property name="id">79</property>
<expression name="value" type="javascript">params["param1"].value</expression>
</structure>
<structure>
<property name="name">ENCODINGLIST</property>
<property name="id">79</property>
</structure>
<structure>
<property name="name">SCHEMAFILELIST</property>
<property name="id">79</property>
</structure>
<structure>
<property name="name">OdaConnProfileName</property>
<property name="id">79</property>
</structure>
<structure>
<property name="name">OdaConnProfileStorePath</property>
<property name="id">79</property>
</structure>
</list-property>
<data-sources>
<oda-data-source extensionID="org.eclipse.datatools.enablement.oda.xml" name="DS1" id="79">
</oda-data-source>
</data-sources>
mwilliams
Ok. So, you need to change the file used in your report based on a parameter. Will the XML files you switch between always have the same structure and same columns? Just switching the file location? Let me know.
denislagod
Yes that will be XML file with the same structure.
Whats more I can read all propertyBindings with getPropertyBibdings();
But when I try to setPropertyBinding(String,Expression) there is an error that such a property there is no in "report".
But now I just want to understand how to set:
<list-property name="propertyBindings">
<structure>
<property name="name">FILELIST</property>
<property name="id">79</property>
<expression name="value" type="javascript">params["param1"].value</expression>
</structure>
</list-property>
denislagod
Please Michael, do you have any suggestions how to solve this?
Maybe using PropertyBindingHandle?
But I didnt find how to add it in report.
mwilliams
Here's an example that uses a parameter and script in the beforeOpen of the dataSource to switch the XML file used. Let me know if this is not what you're trying to do. In the zip attached, you'll find two xml files and a report design. Be sure to change the file location in the dataSource to where you save the xml files.
denislagod
Yes it could help :
<method name="beforeOpen"><![CDATA[
this.setExtensionProperty("FILELIST",params["DataFilePath"].value);]]></method>
But I am still looking for the way of using propertyBinding in java class.
If I can read getPropertyBinding(). should be the way of setting this.
mwilliams
If you have the dataSource handle, you should be able to use something like:
dataSourceHandle.setPropertyBinding("FILELIST","'C:/birt/fileName.xml'");
So, if you have your parameter value, you could use it to build your FILELIST string.
denislagod
Deprecated. instead use setPropertyBinding( String propName, Expression value )
When I used this I got exception :
that such a property there is no in "report".
mwilliams
What is the exact code you used? And can you post the entire error and stack? I'm using BIRT 3.7.2. I'm doing this in the beforeFactory script, but it should essentially be the same, and it works for me.
Yaytay
<blockquote class='ipsBlockquote' data-author="'denislagod'" data-cid="105162" data-time="1340636717" data-date="25 June 2012 - 08:05 AM"><p>
I use BIRT 3.7.2. While designing reports we use XML Datasource connection with XML file.<br />
Using java I need to change source from xml file to data from parameter.<br /></p></blockquote>
<br />
Something to bear in mind is that you may have to put this complicated script into every report.<br />
To avoid confusing our report designers with that complexity I put the datasource replacement functionality into our reporting service.<br />
If you have your own custom reporting application and you will be swapping data sources for a lot of reports do give consideration to moving the logic out of the reports.<br />
It's more work up-front, but less work per report.<br />
<br />
Jim
denislagod
Yes. We have reporting application and our aim to combine some reports into one report. So I copy all slots from reports into result report. Now I need to optimize datasources. I tried to use streams, but found that it allows to use only one stream, but If I have 3 reports with 3 different data its impossible to add them in one map. So I decided to use in propertyBinding the name of XML through report parameter/ In report designer it was easy (I found that BIRT just add porpertyBinding section in report XML). But when I copy datasources from one report to result report that propertyBinding lost and I need to add it myself. When I read getPropertyBindings() I can find all propertyBinding. but try to setPropertyBinding(String, Expression) fails.
denislagod
DesignElementHandle copy1 = elementHandle.copy().getHandle(pageDesignHandle.getDesignHandle().getModule());
this.designHandle.getDataSources().add(copy1);
Expression expression = new Expression("params['param1'].value", ExpressionType.JAVASCRIPT);
copy1.setPropertyBinding('FILELIST', expression);
org.eclipse.birt.report.model.api.elements.SemanticError: The property "FILELIST" in the element "report" is not defined.
at org.eclipse.birt.report.model.api.elements.structures.PropertyBinding.validate(PropertyBinding.java:287)
at org.eclipse.birt.report.model.command.AbstractPropertyCommand.checkItem(AbstractPropertyCommand.java:259)
at org.eclipse.birt.report.model.command.AbstractPropertyCommand.checkItem(AbstractPropertyCommand.java:115)
at org.eclipse.birt.report.model.command.ComplexPropertyCommand.addItem(ComplexPropertyCommand.java:106)
at org.eclipse.birt.report.model.command.ComplexPropertyCommand.addItem(ComplexPropertyCommand.java:165)
at org.eclipse.birt.report.model.api.DesignElementHandle.setPropertyBinding(DesignElementHandle.java:3150)
at org.eclipse.birt.report.model.api.DesignElementHandle.setPropertyBinding(DesignElementHandle.java:3046)
at com.****.reportcenter.bs.report.impl.PageAssemblerImpl.replaceWidget(PageAssemblerImpl.java:440)
at com.****.reportcenter.bs.report.impl.PageAssemblerImpl.findAndReplaceWidgets(PageAssemblerImpl.java:188)
at com.****.reportcenter.bs.report.impl.PageAssemblerImpl.assemblePage(PageAssemblerImpl.java:145)
at com.****.reportcenter.bs.report.impl.PageAssemblerImpl.assembleAndSavePage(PageAssemblerImpl.java:132)
at com.****.reportcenter.bs.report.impl.PackageManagerImpl.prepareTask(PackageManagerImpl.java:174)
at com.****.reportcenter.bs.job.ProcessTaskJob.run(ProcessTaskJob.java:36)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Jul 2, 2012 7:42:48 AM com.****.reportcenter.bs.job.ProcessTaskJob run
SEVERE: Cant process task
com.****.reportcenter.bs.exception.GenerateReportException:
at com.****.reportcenter.bs.report.impl.PageAssemblerImpl.replaceWidget(PageAssemblerImpl.java:497)
at com.****.reportcenter.bs.report.impl.PageAssemblerImpl.findAndReplaceWidgets(PageAssemblerImpl.java:188)
at com.****.reportcenter.bs.report.impl.PageAssemblerImpl.assemblePage(PageAssemblerImpl.java:145)
at com.****.reportcenter.bs.report.impl.PageAssemblerImpl.assembleAndSavePage(PageAssemblerImpl.java:132)
at com.****.reportcenter.bs.report.impl.PackageManagerImpl.prepareTask(PackageManagerImpl.java:174)
at com.****.reportcenter.bs.job.ProcessTaskJob.run(ProcessTaskJob.java:36)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.eclipse.birt.report.model.api.elements.SemanticError: The property "FILELIST" in the element "report" is not defined.
at org.eclipse.birt.report.model.api.elements.structures.PropertyBinding.validate(PropertyBinding.java:287)
at org.eclipse.birt.report.model.command.AbstractPropertyCommand.checkItem(AbstractPropertyCommand.java:259)
at org.eclipse.birt.report.model.command.AbstractPropertyCommand.checkItem(AbstractPropertyCommand.java:115)
at org.eclipse.birt.report.model.command.ComplexPropertyCommand.addItem(ComplexPropertyCommand.java:106)
at org.eclipse.birt.report.model.command.ComplexPropertyCommand.addItem(ComplexPropertyCommand.java:165)
at org.eclipse.birt.report.model.api.DesignElementHandle.setPropertyBinding(DesignElementHandle.java:3150)
at org.eclipse.birt.report.model.api.DesignElementHandle.setPropertyBinding(DesignElementHandle.java:3046)
at com.****.reportcenter.bs.report.impl.PageAssemblerImpl.replaceWidget(PageAssemblerImpl.java:440)
... 8 more