Report Execution History

The Reports add-on provides a mechanism of a report execution history management with the following features:

  1. Save execution history for each report. The system administrator can use the report execution history to find out how often a report is executed, how much processing time is spent on a report, by which user and when a report was run, what errors occurred during the execution.

  2. Clean outdated report execution history.

The report execution history is disabled by default and can be enabled by setting the jmix.reports.historyRecordingEnabled application property to true.

The execution history view is considered administrative and was not added to the main menu. To view the execution history, go to the report list view (the ReportsReports menu item), select some report, and click on the Execution history button.

Execution History Action

You can open execution history in any view using ShowExecutionReportHistoryAction and an associated button or a component context menu item.

io.jmix.reportsflowui.action.ShowExecutionReportHistoryAction - a standard action for displaying the report execution history. It should be defined for a Button or a list component (DataGrid, TreeDataGrid).

Below is an example of using the declarative action for the DataGrid:

<hbox id="buttonsPanel" classNames="buttons-panel">
    <!-- ... -->
    <button id="historyBtn" action="literatureTypesDataGrid.showHistory"/> (1)
</hbox>
<dataGrid id="literatureTypesDataGrid"
          width="100%"
          minHeight="20em"
          dataContainer="literatureTypesDc">
    <actions>
        <!-- ... -->
        <action id="showHistory" type="report_showExecutionReportHistory"/> (2)
    </actions>
</dataGrid>
1 Add a button with report history action.
2 The type attribute defines a specific report_showExecutionReportHistory action type, provided by the framework.

Example of programmatically creating the action together with a button declared in the view XML descriptor:

@ViewComponent
private JmixButton historyBtn;

@Autowired
private Actions actions;

@Subscribe
public void onInit(final InitEvent event) {
    ShowExecutionReportHistoryAction<LiteratureType> action =
            actions.create(ShowExecutionReportHistoryAction.ID);
    historyBtn.setAction(action);
}

When the action is performed, a modal Execution history dialog will open where reports related to the current view will be displayed. After clicking on the Execution History button, the execution history for the selected reports will be displayed.

"Cancelled" flag means that the user launched the report as a background task, and then canceled it.

Execution history is also recorded even for reports which are not yet saved to the database, but launched from the report detail view (by clicking the Run button).

Output Documents

The mechanism provides an ability to save output documents - report results files - in the file storage. This feature consumes a file storage disk space; it is configured separately and is disabled by default. To enable it, define the jmix.reports.saveOutputDocumentsToHistory application property to true:

jmix.reports.saveOutputDocumentsToHistory = true

Now, if you select an item in the execution history table, the Download document button becomes available. Click the button to download a document that is a report result file.

Reports with table output type do not have result files, so the execution history of such reports does not save any output documents.

If you run the report programmatically using the createAndSaveReport() method, it saves another copy of the same result document to the file storage. These two files are put to the file storage independently.

History Cleanup

You can use Quartz Job Scheduler to clean up the report execution history periodically.

  1. Include Quartz add-on in your project as described in the Quartz / Installation section.

  2. Create a job class and call ReportExecutionHistoryRecorder.cleanupHistory():

    @Component("ReportHistoryCleaner")
    public class ReportHistoryCleanJob implements Job {
        @Autowired
        private ReportExecutionHistoryRecorder reportExecutionHistoryRecorder;
    
        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
            reportExecutionHistoryRecorder.cleanupHistory();
        }
    }
  3. In the running application, open the Quartz → Quartz jobs view, and configure a job for the ReportHistoryCleanJob class.

  4. Alternatively, if you want to configure the job at development time, add the following beans to the main application class:

    @Bean
    JobDetail reportHistoryCleanJob() {
        return JobBuilder.newJob()
                .ofType(ReportHistoryCleanJob.class)
                .storeDurably()
                .withIdentity("reportHistoryClean")
                .build();
    }
    
    @Bean
    Trigger reportHistoryCleanTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(reportHistoryCleanJob())
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 1 * * ?")) (1)
                .build();
    }
    1 Schedule for nightly, for example, 0 0 1 * * ?
  5. Set up the report history cleanup configuration properties:

When the report execution history is cleaned up, the associated output document is also deleted from the file storage.