[Help] Jasper reports - separate workspace

6 posts / 0 new
Last post
gayathri
Offline
Joined: 01/12/2010
[Help] Jasper reports - separate workspace

Hi,

   How we do use Jasper reports in a separate workspace ? For example, the use case is to have a separate workspace called Reports, clicking on a title of the report should launch the report ? I was able to integrate Jasper reports tying to a specific entity using the steps described in the forum discussion related to integration of iText with Jspresso. It works great. However, how do we move to a separate module and define security roles on that one ?

 

Thanks

Gayathri

vvandens
Offline
Joined: 05/29/2008
[Help] Jasper reports - separate workspace

Hi Gayathri,

You have to define a dedicated collection module (a non filterable module holding a collection of arbitrary beans). This is done using collectionModule SJS keyword or using a org.jspresso.framework.application.model.BeanCollectionModule spring bean. This collection module has to be initialized at startup in order to be filled with the collection of available reports. Jspresso provides a built-in java bean representing a Jasper report ready to be executed. Its descriptor defined as a singleton org.jspresso.framework.application.printing.model.descriptor.basic.BasicReportDescriptor.INSTANCE and registered in String/SJS under BasicReportDescriptor_INSTANCE. The actual report instances are instances of the org.jspresso.framework.application.printing.model.IReport interface with a basic implementation that is org.jspresso.framework.application.printing.model.basic.BasicReport. So the easiest is to create a collection of BasicReport beans to fill-in the collection module in your startup action. You can also rely on the org.jspresso.framework.application.printing.model.basic.BasicReportFactory factory that is able to create BasicReport instances out of a list of IReportDescriptor. This way, you can externalize the report list definition you want to include in the reporting module.

The only thing you have to do then is to install the built-in reportAction, on the collection module view. When the user clicks it, the action launches the selected report.

Here is the SJS snippet for the overall construct :

 

// The reporting collection module view
table('BasicReportDescriptor_INSTANCE.projected.table') {
actionMap {
actionList('SERVICE') { action(ref:'reportAction') }
}
}

workspace('reporting.workspace',
icon:'reporting-48x48.png',
description:'reporting.workspace.description') {
collectionModule('reporting.module',
description:'reporting.module.description',
icon: 'reporting-48x48.png',
moduleView:'BasicReportDescriptor_INSTANCE.projected.table',
component:'BasicReportDescriptor_INSTANCE',
startup:'reportsStartupAction'
)
}

 

Also note that for your specific need, you could have simply defined a grantedRoles attribute on your report action. This would have installed it only for the listed granted roles.

HTH,

Vincent

gayathri
Offline
Joined: 01/12/2010
[Help] Jasper reports - separate workspace

Hi Vincent,

 

   THanks so much for your response.

   This is definitely difficult for me. I will give this a try and keep you posted.

 

Thanks

Gayathri

gayathri
Offline
Joined: 01/12/2010
[Help] Jasper reports - separate workspace

Hi Vincent,

 

    I tried to grasp what you have mentioned. My understanding is that I need to create a ReportsStartupAction class, whose input will be the list of Reports that I want to define. Is that correct ? If yes, ReportsStartupAction should be derived from which class ? What interface should it implement ?

   Thanks again.

 

Thanks

Gayathri

vvandens
Offline
Joined: 05/29/2008
[Help] Jasper reports - separate workspace

Hi Gayathri,

Here is the code skeleton of such an action (must be injected with the reportFactory built-in bean instance and a list of report descriptors to install) :

public class CreateReportsAction extends BackendAction {

private IReportFactory reportFactory;
private List<IReportDescriptor> reportDescriptors;

/**
* {@inheritDoc}
*/
@Override
public boolean execute(IActionHandler actionHandler,
final Map<String, Object> context) {

BeanCollectionModule reportsModule = (BeanCollectionModule) getModule(context);

List<IReport> reports = new ArrayList<IReport>();

if (reportDescriptors != null) {
for (IReportDescriptor reportDescriptor : reportDescriptors) {
reports.add(reportFactory.createReportInstance(reportDescriptor,
getTranslationProvider(context), getLocale(context)));
}
}
reportsModule.setModuleObjects(reports);
return super.execute(actionHandler, context);
}

/**
* Sets the reportFactory.
*
* @param reportFactory
* the reportFactory to set.
*/
public void setReportFactory(IReportFactory reportFactory) {
this.reportFactory = reportFactory;
}

/**
* Sets the reportDescriptors.
*
* @param reportDescriptors
* the reportDescriptors to set.
*/
public void setReportDescriptors(List<IReportDescriptor> reportDescriptors) {
this.reportDescriptors = reportDescriptors;
}
}

 

Cheers,

Vincent

gayathri
Offline
Joined: 01/12/2010
[Help] Jasper reports - separate workspace

Hi Vincent,

 

   Thanks so much for the code. I will try it and let you know.

 

Thanks

Gayathri