Binding connection profile properties
There are two connection profile properties, Connection Profile Store URL and Connection Profile Name, that can be bound to report parameters or expressions and updated when the report is generated.
The next section shows how to bind a parameter to change Connection Profile Store URL.
Binding the Connection Profile Store URL property
The Connection Profile Store URL property is the path and name of the connection profile store file that contains the connection profile used in a report. The report developer can use the property binding feature in the BIRT data source editor to assign a dynamic file path or URL to Connection Profile Store URL property. This can be done at report run time without changing the report design itself. You can create multiple connection profile store files for different purposes and pass them to a report as parameters at run time.
For example, you have two JDBC connection profiles to the same database using different user names and passwords. These profiles are stored in two separate profile store files. At run time, you can select the profile store you want to use to connect to the database.
The Connection Profile Store URL property name is OdaConnProfileStorePath. You can also use the property binding feature to specify a JavaScript expression for the value of OdaConnProfileStorePath. This feature provides the flexibility to define a different root path for different file properties. For example, the JavaScript expression can include a variable to control the root path:
config[ "birt.viewer.working.path" ].substring(0,2) + "../../data/ProfileStore.acconnprofiles"
Alternatively, you can use a reportContext object to pass session information and build the path expression.
Binding a connection profile name to a report parameter
You can also externalize a connection profile name for a data source by binding it to a report parameter. The next example shows how to create a report design that uses a CSV file as a data source, using BIRT Designer Professional. At design time, the report design uses the CSV file in the folder, C:\ConnProfile\Testing. Typically, the design‑time CSV file contains only a few records. In the production environment, the CSV file, which contains more records, is in the folder, C:\ConnProfile\Production. You create two connection profiles, one for the testing database and one for the production database, and pass the name of the connection profile as a parameter at run time. In this way, the report runs as expected in development and production environments.
How to bind the Connection Profile Store URL property to a report parameter
1 In BIRT Designer Professional, create a new BIRT report.
2 In Data Sources, create a new data source and choose Create from a connection profile in the profile store. Choose Next.
3 In Connection Profile, choose New.
4 In Create a Connection Profile Store, select New.
5 In New Connection Profile, choose Flat File Data Source and enter Products‑testing as a profile name.
6 In Description, type Testing database. Choose Next.
7 In New Flat File Data Source Profile, choose Enter File URI. Choose Browse to select the testing database file, in this example, C:\ConnProfile\Testing\csvTestODA.csv.
8 Choose Test Connection to validate the connection, and select Finish.
The Products-testing profile appears in the Create a Connection Profile Store list, as shown in Figure 45‑17.
Figure 45‑17 Create a connection profile for testing
9 In Create a Connection Profile, choose New to create a connection profile for the production database.
10 In New Connection Profile, choose Flat File Data Source and enter Products‑production as a connection profile name.
11 Choose Next.
12 In New Flat File Data Source Profile, enter the file URI:
C:\ConnProfile\Production\csvTestODA.csv.
13 Select Test Connection to validate the connection.
14 Choose Finish.
Products-production appears in Create a Connection Profile Store list.
15 In Select the connection profiles, select Products-testing and Products‑production, as shown in Figure 45‑18.
Figure 45‑18 Creating a relative path connection profile store
16 In Specify a file name, choose Browse.
Create a Connection Profile store appears, showing Resources folder.
17 In Create a Connection Profile Store, choose the root project folder, ConnProfile, as shown in Figure 45‑19.
Figure 45‑19 Specifying a store file name and location
18 Enter ProductsDB as a file name, and choose OK.
19 In Create a Connection Profile Store, choose OK.
Select Connection Profile appears, as shown in Figure 45‑20, prompting you to select a connection profile for the data source.
20 In Connection Profile, select the testing database connection profile, Products‑testing, as shown in Figure 45‑20.
21 Deselect Use the default data source name, and change the data source name to ProductsDB.
22 Choose Next.
Figure 45‑20 Selecting a connection profile
23 Choose Finish. ProductsDB data source appears in Data Explorer.
24 In Data Explorer, create a new data set named Products from the ProductsDB data source.
25 In Select Columns, select all columns by choosing >>, and then choose Finish.
26 In Edit Data Set ‑ Products, choose OK.
27 Add the Products data set to the layout and choose RunView Reportin Web Viewer. In the example, the report displays only six rows of data, as shown in Figure 45‑21.
Figure 45‑21 Previewing the report with testing data
28 Select Layout, and create a new report parameter in Data Explorer.
29 Name the parameter ConnProfileName, as shown in Figure 45‑22.
30 In Prompt text, enter:
Select the connection profile name:
31 Choose OK to create the parameter.
Figure 45‑22 Creating a report parameter
32 In Data Explorer, double-click ProductsDB data source to open the properties.
33 Choose Property Binding, as shown in Figure 45‑23, and enter the expression:
params["ConnProfileName"].value
Alternatively, you can select Fx to use Expression Builder to create the expression.
Figure 45‑23 Binding a connection profile name to a report parameter
Choose OK.
34 Choose RunView Reportin Web Viewer. In Parameters, enter Products‑Production to choose the production database as a data source. The report displays a large set of data, as shown in Figure 45‑24.
Figure 45‑24 Previewing the report with the production data