Search code examples
jasper-reportsjasperserverjaspersoft-studio

How can Jaspersoft Bean Datasource be deployed in Jasper Server?


Can anyone please help me with the step by step procedures to add a Bean DataSource (collection of beans) in the Jaspersoft Server? Is there a straightforward process of just pushing the jarfile so the server could recognize it?

here are the steps i did (simplified names)

In Studio project

  • Create a Java Bean called Person containing fields and getter/setters

  • Create a simple Java Class which connects to database named com.company.test.PersonFactory, it has a method generator() which returns a List, it uses simple jdbc calls, both classes are in my Jasper project

  • Created a Data Adaptor called testBean and entered com.company.test.PersonFactory as the Factory Class and generator as the static method in the Factory.

  • Create a new jasper report (testReport1) and use the Data Adapter testBean, clicked the Java Bean tab, enter Person as the classname, add all fields, verified data preview, and save

In Repository Explorer

  • Create a new Data Source > Data Source Bean, enter bean1 as name and id

  • At the Bean Name and Bean method page, Select import from Jaspersoft Studio and select testBean, click finish

In Studio project

  • After verifying that data preview in Jaspersoft Studio is working, publish the report in the Jasper Server

  • Select the bean1 datasource and publish

In Jaspersoft Server

run the report testReport1

get the error

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.company.test.PersonFactory' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:575)

org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1111) at

org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:276) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1119) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.BeanReportDataSourceServiceFactory.createService(BeanReportDataSourceServiceFactory.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at ....

Can anyone help me do the simplest steps on how the Beans and Factory would be recognized in the Jaspersoft Server?

Thanks


Solution

  • I solved this issue a week after my initial question. I just wanted to share the answer:

    The jaspersoft Bean DataSource should be accessed through a class which implements ReportDataSourceService.

    Then, it should have a private variable

    private JRBeanCollectionDataSource dataSource;
    

    also, you need to Override 2 methods

    @Override
    public void closeConnection() {
        // TODO Auto-generated method stub
    
    }
    
    @Override
    public void setReportParameterValues(Map parameterMap) {
        parameterMap.put(JRParameter.REPORT_DATA_SOURCE, dataSource);
    
    }
    

    Then from the Jasper server, you need to define the factory class which calls the constructor of the ReportDataSourceService implemented class you created whicle returning a ReportDataSourceService type