Jasper(Soft) : Use multiple Oracle-Database datasources for single report - jasper-reports

I have a Jasper server which has a few templates in one of the folders. I also have an application with a button, and when you click the button it will show a list of all the jasper documents from that folder.
Currently a single parameter (an id) is used in all these Jasper reports, which each use their own query based on what they need.
Now I've added a new jasper template, which has to use a different datasource based on a year parameter, in this same folder.
What I could do is just add this year to the parameter list I send to Jasper for every template in this folder, in which case it will use the id for all the existing templates, and the year for this new one.
However, I prefer to not deploy a new version of this application for the sake of an added jasper template, so I'd like to do the following instead:
Use the parameter id with datasource 1 to query for the year I need
Use this year as parameter with datasource 2 to create the query for the actual jasper report template
So my question: Is this possible? Can a single jasper report have multiple oracle-DB connection datasources? And can I then query for the year in one datasource, to use in the other datasource?
EDIT:
Although the duplicated link gave me a good direction, I'm currently again stuck with the same problem.
What I've done is the following:
I've created the main-report which contains nothing more than a sub-report, and has an id parameter (which will be used to query for the field YEAR in datasource_host_main).
I've created a sub-report with the actual text and lists and such based on a query on datasource_host_sub (with a year parameter).
Here is the code for Main:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-04-10T17:05:30 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Main" language="groovy" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="20" bottomMargin="20" uuid="3830f8f8-db92-4043-bcbe-4af8cbc24623">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasource_host_main"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="ireport.jasperserver.url" value="my_jasper_server_host/jasperserver-pro/"/>
<property name="ireport.jasperserver.user" value="superuser|"/>
<property name="ireport.jasperserver.reportUnit" value="/users/user_1/reports/Systeem/Main"/>
<property name="ireport.jasperserver.report.resource" value="/users/user_1/reports/Systeem/Main_files/main.jrxml"/>
<parameter name="id_parameter" class="java.lang.Integer">
<parameterDescription><![CDATA[id_parameter]]></parameterDescription>
<defaultValueExpression><![CDATA[1]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select dataYear
from MY_TABLE
where id = $P{id_parameter}]]>
</queryString>
<field name="dataYear" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="28" splitType="Stretch"/>
</title>
<detail>
<band height="210" splitType="Stretch">
<subreport>
<reportElement x="6" y="10" width="504" height="200" uuid="e130bc4e-f114-4bd1-b408-dc9ce261b18c"/>
<subreportParameter name="dataYear">
<subreportParameterExpression><![CDATA[$F{dataYear}]]></subreportParameterExpression>
</subreportParameter>
<!-- This below doesn't work: I want to connect to a different datasource in the sub-report -->
<connectionExpression><![CDATA[oracle.jdbc.driver.OracleDriver.getConnection("jdbc:oracle:thin:#datasource_host_sub:1234:ab", "USERNAME", "PASSWORD")]]></connectionExpression>
<subreportExpression><![CDATA["subreport.jrxml"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band height="39"/>
</pageFooter>
</jasperReport>
Subreport:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-04-10T16:37:07 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="subreport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="20" bottomMargin="20" uuid="3830f8f8-db92-4043-bcbe-4af8cbc24623">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasource_host_sub"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="ireport.jasperserver.url" value="my_jasper_server_host/jasperserver-pro/"/>
<property name="ireport.jasperserver.user" value="superuser|"/>
<property name="ireport.jasperserver.reportUnit" value="/users/user_1/reports/Systeem/Main"/>
<property name="ireport.jasperserver.report.resource" value="/users/user_1/reports/Systeem/Main_files/subreport.jrxml"/>
<parameter name="dataYear" class="java.lang.Integer">
<parameterDescription><![CDATA[dataYear]]></parameterDescription>
<defaultValueExpression><![CDATA[YEAR( )]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select NOTES
from MY_TABLE
where extract(year from to_date(DATE, 'dd-MM-yy')) = $P{dataYear}]]>
</queryString>
<field name="NOTES" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="140" splitType="Stretch"/>
</title>
<detail>
<band height="60" splitType="Stretch">
<textField>
<reportElement x="0" y="18" width="510" height="30" uuid="ed29caa8-a839-4457-a270-68bfedcfadb8"/>
<textFieldExpression><![CDATA["Test: " + $F{NOTES}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band height="20"/>
</pageFooter>
</jasperReport>
The Main report uses datasource_host_main, and the sub-report uses datasource_host_sub. Because a Jasper report has only one .properties file with one jasperDatasourceUri, I can only define datasource_host_main. But how can I define datasource_host_sub for the sub-report? As you can see in the mainreport code I tried to do something like this:
<connectionExpression><![CDATA[oracle.jdbc.driver.OracleDriver.getConnection("jdbc:oracle:thin:#datasource_host_sub:1234:ab", "USERNAME", "PASSWORD")]]></connectionExpression>
But unfortunately it gives this error:
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: oracle.jdbc.driver.OracleDriver.getConnection("jdbc:oracle:thin#datasource_host_sub:1234:ab", "USERNAME", "PASSWORD")
What should I put here instead to make it work (both are Oracle databases), and is it even possible to do it like this?
As I said in my original question:
Can a single jasper report have multiple oracle-DB connection datasources? And can I then query for the year in one datasource, to use in the other datasource?

In JasperReports Server you can use a different data source/DB connection for a subreport or subdataset by setting the com.jaspersoft.jrs.data.source property as the data source repository path at (sub)report or subdataset level.
In your case, you would have the report unit use a data source that connects to datasource_host_main, and the following property in the subreport JRXML:
<property name="com.jaspersoft.jrs.data.source" value="/datasources/host_sub_datasource"/>
where /datasources/host_sub_datasource is the repository path of a data source resource that connects to datasource_host_sub.
Outside JasperReports Server, the same thing can be achieved with data adapters (which replace JasperReports Server data sources). The property to set is net.sf.jasperreports.data.adapter, and it needs to point to a path/resource/URI for a data adapter XML file.

Related

JasperReports: xsd for custom component not found

I made a new chart type as custom component for JasperReports.
I inserted my custom component into the jrxml but Jaspersoft Studio says it cannot find the xsd:
net.sf.jasperreports.engine.JRRuntimeException: Unknown entity http://jasperreports.sourceforge.net/xsd/blockchart.xsd, not loading.
I checked that the jar file contains blockchart.xsd.
And the schema location is defined in the blockchart_beans.xml:
<bean id="xmlParser" class="net.sf.jasperreports.engine.component.DefaultComponentXmlParser">
<property name="namespace">
<value>http://jasperreports.sourceforge.net/jasperreports/blockchart</value>
</property>
<property name="publicSchemaLocation">
<value>http://jasperreports.sourceforge.net/xsd/blockchart.xsd</value>
</property>
<property name="internalSchemaResource">
<value>de/xyz/jasperreports/blockchart/blockchart.xsd</value>
</property>
<property name="digesterConfigurer">
<bean class="de.xyz.jasperreports.blockchart.BlockChartsDigester"/>
</property>
</bean>
My jrxml:
<componentElement>
<reportElement x="0" y="0" width="800" height="510" uuid="550e8442-e29b-11d4-a716-446655440042" />
<bc:blockChart evaluationTime="Group" evaluationGroup="mygroup"
xmlns:bc="http://jasperreports.sourceforge.net/jasperreports/blockchart"
xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/blockchart http://jasperreports.sourceforge.net/xsd/blockchart.xsd">
<bc:chartSettings customizerClass="de.xyz.jasper.Report1ChartCustomizer">
</bc:blockChart>
</componentElement>
Why does Jaspersoft Studio not find my xsd? Any idea what I could have missed?

Jasper/iReport - Extra long text does not display properly in excel export

I have a field with excessively long text. When I export the jasper report as xls, the row height does not extend to display the entire content.
Althought the text is present in the cell, the row height needs to be manually increased to see the entire content.
I am using Jasper report version 6.10 and have set the following properties
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="net.sf.jasperreports.export.xls.show.gridlines" value="true"/>
<property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="false"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.xls.white.page.background" value="true"/>
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
<property name="net.sf.jasperreports.print.keep.full.text" value="true"/>
<property name="net.sf.jasperreports.export.xls.fit.width" value="1"/>
<property name="net.sf.jasperreports.export.xls.wrap.text" value="true"/>
<property name="net.sf.jasperreports.export.xls.print.page.top.margin" value="40"/>
<property name="net.sf.jasperreports.export.xls.print.page.bottom.margin" value="40"/>
<property name="net.sf.jasperreports.export.xls.print.page.left.margin" value="36"/>
<property name="net.sf.jasperreports.export.xls.print.page.right.margin" value="36"/>
<property name="net.sf.jasperreports.export.xls.freeze.row" value="2"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.page.height" value="false"/>
<property name="net.sf.jasperreports.export.xls.fit.height" value="0"/>
Please suggest how I can fix this issue.
Use following properties in Report Element
<staticText>
<reportElement x="0" y="100" width="100" height="20">
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
</reportElement>
<textElement/>
<text>
<![CDATA[Your Static Text]]>
</text>
</staticText>
Also I'd recommend you to try using net.sf.jasperreports.export.xls.column.width property, which is more useful. Reference: http://jasperreports.sourceforge.net/config.reference.html

Wso2 cant write groups in external LDAP

I am configuring Wso2 with a read write external LDAP.
I am using the SOAP Api provided by Wso2 for managing users n groups.
However when trying to add a user to an internal group everything works fine but when i try to add a user to an external LDAP group i get that the role does not exist. Which is weird cause i can see the roles in Wso2. I even can i add a user to an external group from there but after it is added its not showed as added even it is actually added in the LDAP.
This is the ldap connection configuration
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager">
<Property name="TenantManager">org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager</Property>
<Property name="ConnectionURL">ldaps://some-url:636</Property>
<Property name="ConnectionName">cn=admin,ou=adminGroups,dc=userstore,dc=gk</Property>
<Property name="ConnectionPassword">someAdminPass</Property>
<Property name="AnonymousBind">false</Property>
<Property name="UserSearchBase">ou=users,dc=userstore,dc=gk</Property>
<Property name="UserEntryObjectClass">inetOrgPerson</Property>
<Property name="UserNameAttribute">uid</Property>
<Property name="UserNameSearchFilter">(&(objectClass=posixAccount)(uid=?))</Property>
<Property name="UserNameListFilter">(objectClass=posixAccount)</Property>
<Property name="DisplayNameAttribute"/>
<Property name="ReadGroups">true</Property>
<Property name="WriteGroups">true</Property>
<Property name="GroupSearchBase">ou=groups,dc=userstore,dc=gk</Property>
<Property name="GroupEntryObjectClass">posixGroup</Property>
<Property name="GroupNameAttribute">cn</Property>
<Property name="GroupNameSearchFilter">(&(objectClass=posixGroup)(cn=?))</Property>
<Property name="GroupNameListFilter">(objectClass=posixGroup)</Property>
<Property name="MembershipAttribute">memberOf</Property>
<Property name="BackLinksEnabled">false</Property>
<Property name="UsernameJavaRegEx">someregex stuff</Property>
<Property name="UsernameJavaScriptRegEx">someregex stuff</Property>
<Property name="UsernameJavaRegExViolationErrorMsg">Username pattern policy violated</Property>
<Property name="PasswordJavaRegEx">someregex stuff</Property>
<Property name="PasswordJavaScriptRegEx">someregex stuff</Property>
<Property name="PasswordJavaRegExViolationErrorMsg">Password length should be within 5 to 30 characters</Property>
<Property name="RolenameJavaRegEx">someregex stuff</Property>
<Property name="RolenameJavaScriptRegEx">someregex stuff</Property>
<Property name="SCIMEnabled">true</Property>
<Property name="IsBulkImportSupported">false</Property>
<Property name="EmptyRolesAllowed">true</Property>
<Property name="PasswordHashMethod">PLAIN_TEXT</Property>
<Property name="MultiAttributeSeparator">,</Property>
<Property name="MaxUserNameListLength">100</Property>
<Property name="MaxRoleNameListLength">100</Property>
<Property name="kdcEnabled">false</Property>
<Property name="defaultRealmName">WSO2.ORG</Property>
<Property name="UserRolesCacheEnabled">true</Property>
<Property name="ConnectionPoolingEnabled">false</Property>
<Property name="LDAPConnectionTimeout">5000</Property>
<Property name="ReadTimeout"/>
<Property name="RetryAttempts"/>
</UserStoreManager>
I am using SoapUi to make this call having this request body
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://service.ws.um.carbon.wso2.org">
<soap:Header/>
<soap:Body>
<ser:updateRoleListOfUser>
<!--Optional:-->
<ser:userName>username</ser:userName>
<!--Zero or more repetitions:-->
<ser:deletedRoles>?</ser:deletedRoles>
<!--Zero or more repetitions:-->
<ser:newRoles>Users</ser:newRoles>
</ser:updateRoleListOfUser>
</soap:Body>
</soap:Envelope>
Seems that some configuration has gone wrong.Is there some special configuration needed to to that ?
This was a silly mistake. I am passing <ser:deletedRoles>?</ser:deletedRoles> and that is what actually throws the error saying that group does not exist.
About the part that i say
after it is added its not showed as added even it is actually added in
the LDAP
This has to do with a different setup that i use in my LDAP server. I have created an additional thread for this configuration issue.

how to exclude title band in jasper reports when exported as excel

I have this at top of my jrxml
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="LineChart01" pageWidth="1400" pageHeight="842" columnWidth="1360" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="70d31602-bfb5-4388-9d80-87ea7a72f43d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="NEW_DATAADAPTER.xml"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<property name="removeEmptySpaceBetweenRows" value="true"/>
<property name="removeEmptySpaceBetweenColumns" value="true"/>
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.title" value="title"/>
<!-- more records ... -->
</jasperReport>
How can I exclude the title band? I tried this. In that link question have few properties to hide some bands those didn't work for me.
Is your title band contains subreport? If yes then you need to use this
<property name="net.sf.jasperreports.export.xlsx.exclude.origin.report.(sameValue)" value="Actual Sub Report Name"/>
<property name="net.sf.jasperreports.export.xlsx.exclude.origin.band.(sameValue)" value="detail"/>
You can change xlsx with pdf, csv, xls etc. I have used detail as value in my second property because my subreport contains only detail band. You can change this with your subreport band.

BIRT Report Unable to run

I'm completely new to BIRT, but I'm trying to integrate it into some testing software. I downloaded the all-in-one package from eclipse for BIRT reporting (Windows 7, 64 bit). I've just started on my first report and I can't get the preview tab to display anything nor the web viewer. The only content on my report is a simple label. Is there something I'm doing wrong?
Here's my source xml for the report:
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.23" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 4.3.1.v201309091055 Build <4.3.1.v20130917-1035></property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<styles>
<style name="report" id="4">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab-cell" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab" id="6">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<label id="7">
<text-property name="text">BRIEF PRODUCT TEST REPORT</text-property>
</label>
</body>
</report>
Found the issue, seems like BIRT uses Internet Explorer to render the report and is apparently incompatible with Internet Explorer 11. Downgrading IE solved my problem