Setting relative classpath for BIRT POJO Datasource in .rptdesignfile - birt

In the .rptdesign file when the"pojoDataSetClassPath" property is set to an absolute path , the report gets generated successfully.However when it is set to a relative path, the data from the data-source is not passed to the report thus the report has no data in it.
For example:
When i set the property value to the absolute path(C:\jars\Abc.jar) in .rptdesign file, report gets generated successfully.
<property name="pojoDataSetClassPath">C:\jars\Abc.jar;</property>
However when i set the property value to the relative path(./jars/Abc.jar), report does not contain any data.
<property name="pojoDataSetClassPath">./jars/Abc.jar;</property>
Can anyone please suggest a correct way to set the relative classpath , thus helping in picking the right pojodatasources.
Thanks in advance!

Related

Set parameter value programatically while generating QuickSight embedded report URL

I am working on the QuickSight embedded report url generation. I am trying to set the parameter default value programatically using below JAVA code.It is not working.
GetDashboardEmbedUrlRequest req = new GetDashboardEmbedUrlRequest()
.withAwsAccountId(awsAccountId)
.withDashboardId(reportInput.getDashboadId())
.withUserArn(userArn)
.withIdentityType(EmbeddingIdentityType.QUICKSIGHT)
.withSessionLifetimeInMinutes(sessionTimeout);
req.putCustomQueryParameter("CampaignName", "ABC");
req.putCustomQueryParameter("reportDev", "Program");
// get the dashboard URL
String embedUrl = quickSightClient.getDashboardEmbedUrl(req).getEmbedUrl();
LOGGER.info("URL:{}",embedUrl);
In the above code, "CampaingName" is multivalues parameter attached to the dropdown control. It's default value is set to "[All]" while building a report. Parameter "reportDev" is single value parameter with no default value and no control or any thing attached to it. Dummy parameter I introduced for testing.
After running the code, when I copy the url printed in console by logger and run it in the browser, report opens properly but with "CampaignName" and "reportDev" both set as "ALL".
Sample generated ulr is as below
https://xx-xxxx-x.quicksight.aws.amazon.com/embed/xxxxxxxxxxxxxxxxx/dashboards/xxxxxxxxxxxxxxxxxxx?code=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&identityprovider=quicksight&isauthcode=true
Well if I get the dashboard url and pass the parameter in the url to, it worked properly. "CampaignName" is set to "ABC" and "reportDev" set to "Program". According the data in the report also got filtered. Url working corrctly as below.
https://xx-xxxx-1.quicksight.aws.amazon.com/embed/xxxxxxxxxxxx/dashboards/xxxxxxxxxxxxxxx#p.reportEnv=Program&p.CampaignName=ABC
Can anybody please tell me what is missing in my code. I tried below variation as well but no luck.
req.putCustomQueryParameter("p.CampaignName", "ABC");
req.putCustomQueryParameter("p.reportDev", "Program");
Have you tried to drop the p. from the parameter name, eg
req.putCustomQueryParameter("CampaignName", "ABC");
req.putCustomQueryParameter("reportDev", "Program");
I know that worked for the javascript sdk.

Pass a property to CSV Data Set Config filename input

In a JSR223 PreProcessor I define two properties:
props.put("DATAFILE_PATH", "pathtofile");
props.put("ENV", "env_test");
Then in CSV Data Set Config object I use:
Filename : props.get("DATAFILE_PATH")
File encoding : UTF-8
...
However, I'm facing this error:
java.lang.IllegalArgumentException: File props.get("DATAFILE_PATH") must exist and be readable
CSV Data Set Config is Configuration element which is executed before pre processors (or other element)
Execution order
0.Configuration elements
1.Pre-Processors
So you can't update this property using pre processor, only by defining such property before execution as different answers suggesting, using user defined variables or adding property to execution

Accessing property values within filename-generator-expression

We have the following snippet in one of our Spring Batch XML files:
<int-file:outbound-channel-adapter
id="out" directory="c:\test"
filename-generator-expression="headers['msg.number']+'.xml'"
channel="in"/>
We would like to add access a value stored in a property file from within filename-generator-expression
The property can be accessed elsewhere in the XML as follows: attribute="${property.name}"
Th question is, how to access it from within filename-generator-expression.
This is obviously wrong:
filename-generator-expression="${property.name} + headers['msg.number']+'.xml'"
What is the correct solution?
Thanks very much

Spring, property file, empty values

I have configured spring security with a ldap server (but continue reading, it's not a problem if you have no knowledge about it, this is really a spring problem). All runs like a charm. Here is the line I use for that:
<ldap-server ldif="" root="" manager-dn="" manager-password="" url="" id="ldapServer" />
If I fill ldif and root attributes, it will run an embeded server:
<ldap-server ldif="classpath://ldap.ldif" root="dc=springframework,dc=org" manager-dn="" manager-password="" url="" id="ldapServer" />
If I fill other fields, it will run a distant server:
<ldap-server ldif="" root="" manager-dn="dc=admin,dc=springframeworg,dc=org" manager-password="password" url="ldap://myldapserver.com/dc=springframeworg,dc=org" id="ldapServer" />
All this stuff run correctly. Now I want to use Spring mechanism to load such parameters from a property file:
So I replace attribute values like this:
<ldap-server ldif="${ldap.ldif.path}" root="${ldap.ldif.root}" manager-dn="${ldap.server.manager.dn}" manager-password="${ldap.server.manager.password}" url="${ldap.server.url}" id="ldapServer" />
and create a property file with:
ldap.server.url=
ldap.server.manager.dn=
ldap.server.manager.password=
ldap.ldif.path=
ldap.ldif.root=
Now, the funny part of the problem. If I fill the following properties in the file:
ldap.server.url=ldap://myldapserver.com/dc=springframeworg,dc=org
ldap.server.manager.dn=dc=admin,dc=springframeworg,dc=org
ldap.server.manager.password=password
ldap.ldif.path=
ldap.ldif.root=
It runs a distant server as expected.
If I fill the property file like this:
ldap.server.url=
ldap.server.manager.dn=
ldap.server.manager.password=
ldap.ldif.path= classpath:ldap.ldif
ldap.ldif.root= dc=springframeworg,dc=org
It does not run, complaining that the ldap url is missing. But the problem is that if I change the spring configuration from:
<ldap-server ldif="${ldap.ldif.path}" root="${ldap.ldif.root}" manager-dn="${ldap.server.manager.dn}" manager-password="${ldap.server.manager.password}" url="${ldap.server.url}" id="ldapServer" />
to (by just removing the reference to the variable ${ldap.server.url})
<ldap-server ldif="${ldap.ldif.path}" root="${ldap.ldif.root}" manager-dn="${ldap.server.manager.dn}" manager-password="${ldap.server.manager.password}" url="" id="ldapServer" />
It runs !
My thoughs are that spring does not replace the attribute value with the property config one if this one is empty. But I find it strange.
Can you give me some clue to understand that ? And what's the best to do to configure my ldap server via a property file ?
EDIT: this is due to a poor design choice (look at accepted answer), an issue has been opened on jira :
https://jira.springsource.org/browse/SEC-1966
Ok, I think this is a spring security bug.
If I debug and look at the class LdapServerBeanDefinition, there is a method called "parse". Here is an extract:
public BeanDefinition parse(Element elt, ParserContext parserContext) {
String url = elt.getAttribute(ATT_URL);
RootBeanDefinition contextSource;
if (!StringUtils.hasText(url)) {
contextSource = createEmbeddedServer(elt, parserContext);
} else {
contextSource = new RootBeanDefinition();
contextSource.setBeanClassName(CONTEXT_SOURCE_CLASS);
contextSource.getConstructorArgumentValues().addIndexedArgumentValue(0, url);
}
contextSource.setSource(parserContext.extractSource(elt));
String managerDn = elt.getAttribute(ATT_PRINCIPAL);
String managerPassword = elt.getAttribute(ATT_PASSWORD);
if (StringUtils.hasText(managerDn)) {
if(!StringUtils.hasText(managerPassword)) {
parserContext.getReaderContext().error("You must specify the " + ATT_PASSWORD +
" if you supply a " + managerDn, elt);
}
contextSource.getPropertyValues().addPropertyValue("userDn", managerDn);
contextSource.getPropertyValues().addPropertyValue("password", managerPassword);
}
...
}
If I debug here, all variables (url, managerDn, managerPassword...) are not replaced by the value specified in the property file. And so, url has the value ${ldap.server.url}, managerDn has the value ${ldap.server.manager.dn} and so on.
The method parse creates a bean, a context source that will be used further. And when this bean will be used, place holders will be replaced.
Here, we got the bug. The parse method check if url is empty or not. The problem is that url is not empty here because it has the value ${ldap.server.url}. So, the parse method creates a context source as a distant server.
When the created source will be used, it will replace the ${ldap.server.url} by empty value (like specified in the property file). And....... Bug !
I don't know really how to solve this for the moment, but I now understand why it bugs ;)
I cannot explain it, but I think you can fix your problem using defaulting syntax, available since Spring 3.0.0.RC1 (see).
In the chageg log you can read: PropertyPlaceholderConfigurer supports "${myKey:myDefaultValue}" defaulting syntax
Anyway, I think that the problem is because "" is valid value, but no value in the property file don't.
I think that url="" works because url attribute is of type xs:token in spring-security XSD and empty string is converted to null (xs:token is removing any leading or trailing spaces, so "" can be recognized as no value). Maybe the value of ${ldap.server.url} is resolved as empty string and that is why you've got an error.
You can try use Spring profiles to define different configurations of ldap server (see Spring Team Blog for details about profiles)
I believe there is an issue here while using place holders. The following will most probably solve the problem:
Create a class which extends PropertyPlaceHolderConfigurer and override its method convertPropertyValue()
in the method you can return the property as empty string if you find anything other than a string which is of type LDAP url i.e. ldap://myldapserver.com/dc=springframeworg,dc=org
Also you need to configure your new specialization of class PropertyPlaceHolderConfigurer in the context file.
Hope this helps.
You can define empty String in the application.properties file as following:
com.core.estimation.stopwords=\ \

BIRT: Specifying XML Datasource file as parameter does not work

Using BIRT designer 3.7.1, it's easy enough to define a report for an XML file data source; however, the input file name is written into the .rptdesign file as constant value, initially. Nice for the start, but useless in real life. What I want is start the BIRT ReportEngine via the genReport.bat script, specifying the name of the XML data source file as parameter. That should be trivial, but it is surprisingly difficult...
What I found out is this: Instead of defining the XML data source file as a constant in the report definition you can use params["datasource"].value, which will be replaced by the parameter value at runtime. Also, in BIRT Designer you can define the Report Parameter (datasource) and give it a default value, say "file://d:/sample.xml".
Yet, it doesn't work. This is the result of my Preview attempt in Designer:
Cannot open the connection for the driver: org.eclipse.datatools.enablement.oda.xml.
org.eclipse.datatools.connectivity.oda.OdaException: The xml source file cannot be found or the URL is malformed.
ReportEngine, started with 'genReport.bat -p "datasource=file://d:/sample.xml" xx.rptdesign' says nearly the same.
Of course, I have made sure that the XML file exists, and tried different spellings of the file URL. So, what's wrong?
What I found out is this: Instead of defining the XML data source file as a constant in the report definition you can use params["datasource"].value, which will be replaced by the parameter value at runtime.
No, it won't - at least, if you specify the value of &XML Data Source File as params["datasource"].value (instead of a valid XML file path) at design time then you will get an error when attempting to run the report. This is because it is trying to use the literal string params["datasource"].value for the file path, rather than the value of params["datasource"].value.
Instead, you need to use an event handler script - specifically, a beforeOpen script.
To do this:
Left-click on your data source in the Data Explorer.
In the main Report Design pane, click on the Script tab (instead of the Layout tab). A blank beforeOpen script should be visible.
Copy and paste the following code into the script:
this.setExtensionProperty("FILELIST", params["datasource"].value);
If you now run the report, you should find that the value of the parameter datasource is used for the XML file location.
You can find out more about parameter-driven XML data sources on BIRT Exchange.
Since this is an old thread but still usefull, i ll add some info :
In the edit datasource, add some url to have sample data to create your dataset
Create your dataset
Then remove url as shown
add some script

Resources