How do I get the ReportDesign class for some subregister on the server for script based modifications?
Locally I have a report master.jrxml
and some subreport.jrxml
and you can download and process a subreport via ReportDesign design = JRXmlLoader.load( "/local-file-dir/path/to/subreport.jrxml" )
in the Scriptlet code.
On the server, the above upload method (which works in my opinion master.jrxml
) obviously cannot deal with the repo paths, no matter what I tried (mostly net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: ...
)
( subreport.jrxml
loaded as a JRXML file resource - not as a report with invisibly generated folder structures;
subreport-attached.jrxml
loaded as a file share of my master.jrxml report)
- apwop) the absolute path of the repo without the protocol prefix, e.g.
/repo/path/subreport.jrxml
- apwp) the absolute path of the repo with a protocol prefix, e.g.
repo:/repo/path/subreport.jrxml
- rpwop) the relative path of the repo without the protocol prefix, e.g.
subreport-attached.jrxml
- rpwp) the relative path of the repo with a protocol prefix, e.g.
repo:subreport-attached.jrxml
I also tried the following with the aforementioned uri options found elsewhere on the net without success :
-
JRXmlLoader:
JRXmlLoader.load( new DefaultRepositoryService( DefaultJasperReportsContext.getInstance() ).getInputStream( subrepPath )
-
RepositoryUtil:
RepositoryUtil.getInstance( DefaultJasperReportsContext.getInstance() ).getInputStreamFromLocation( subrepPath )
- JasperServerUtil: similar to this I am still testing and will report back (there are problems with Maven jasperserver support so far - another problem I can solve in another question )
- update: it worked: see my answer below
source to share
Woohoo! :) The last approach with com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService
worked like this:
JasperDesign design = JRXmlLoader.load(
( (RepositoryService) StaticApplicationContext.getApplicationContext()
.getBean( "repositoryService" )
)
.getResourceData( JasperServerUtil.getExecutionContext() ,
"repo:/some/where/subreport.jrxml" )
.getDataStream()
Puh! difficult birth.
source to share