$P{REPORT_DATA_SOURCE} returns SortedDataSource instead of original data source?

We use a custom data source multiple times throughout our report.  In order to get the subsets of data from the main datasource that we need for each area of the report, we add methods to our data source that return a custom datasource with the required data.  We then define a datasource expression for each section that gets report data source, casts it as our custom data source class, and then calls the appropriate method to return get the necessary datasource for that section.  this works great to initially fill and render our report, but when we sort any records, we get an error that says "SortedDataSource can not be cast to [our custom data source]". 

Does anyone know a way to guarantee retrieving the original data source? 

Here are some additional general details about our custom data source, to help understand why we are trying to do what we are doing.  The data source calls rest enpoints to retrieve data for which we do not have direct db access.  The data is returned as Json which we deserialize into POJOs.  For a single report, we would prefer not to make multiple rest calls to retrieve the data.   Some of the records contain subordinate records, so we add methods to return the subordinate records as a separate data source for the areas of the report where they are needed.  

gregg.dale_1's picture
Joined: Apr 27 2018 - 9:50am
Last seen: 4 years 9 months ago

To clarify, we use a data source expresion like ((OurCustomDataSource) ${REPORT_DATA_SOURCE}).getSomeSubsetDataSource()

gregg.dale_1 - 5 years 4 months ago

1 Answer:

1. Once sorted, you cannot retrieve your custom data source, unless you clone it and add it to the report as a parameter and get it from there.

Other options might be:

2. Presort your records in your custom datasource and avoid using sortFields

3. Use subreports or dataSet-based components like lists/table and use sortFields there.

narcism's picture
Joined: Nov 22 2010 - 12:39am
Last seen: 1 day 13 hours ago