Is it possible to initiate db with any created in the development phase reports including some templates,
using the Cuba Platform abilities of course?
Hello @razandale ,
for the import you can use the service ‘com.haulmont.cuba.core.app.importexport.EntityImportExportService’:
EntityImportView view= new EntityImportView(Customer.class);
byte[] bytes = IOUtils.toByteArray(resource.getInputStream());
String json = new String(bytes, StandardCharsets.UTF_8);
entityImportExportService.importEntitiesFromJSON(json, view);
You can find more information here.
For reports you use the service ‘com.haulmont.reports.app.service.ReportService’:
byte[] bytes = IOUtils.toByteArray(resource.getInputStream());
EnumSet<ReportImportOption> importOptions = EnumSet.of(ReportImportOption.DO_NOT_IMPORT_ROLES);
reportService.importReportsWithResult(bytes, importOptions);
Many greetings
Andreas
2 Likes
In order to import reports automatically at server start, create a bean and subscribe to the AppContextStartedEvent. In the event handler method, you can check if the database contains any reports and execute the ReportService.importReports()
method mentioned by Andreas.
1 Like
Thank you for you answer! Sorry for mess in my question.
That is exactly what I was looking for. Thank you!
So if I’ve got it right the full sequence is:
- Create reports in the Cuba platform.
- Download the reports as zip files.
- Put zip files some where in the project.
- Create a bean that is subscribed to the AppContextStartedEvent.
- Inside the bean load the reports with
ReportService.importReports()
method mentioned by @Andreas