Class used for running a scheduled report

Could you provide (or direct me to) an example of a class used to generate a report? I want to do this in the most efficient way possible.
Please consider that I have a report “Report” that uses “custom_template.”

This is what I have:

public class RunReport implements java.util.concurrent.Callable{

    @Override
    public Object call() throws Exception {
        return null;
    }

    public RunReport (){
        runReport();
    }

    public void runReport(){
      //What goes here?
    }
}

scheduledTask

Hi,
The following code works well in my application.
Reports are generated and saved by calling the reportService.createAndSaveReport() method. They are available through the Administration ? External Files screen afterwards.
As the method returns FileDescriptor, you are able to perform some operations with the generated file (f.e. send it by email).


public class RunReport implements java.util.concurrent.Callable{

    protected ReportService reportService = AppBeans.get(ReportService.class);

    protected DataManager dataManager = AppBeans.get(DataManager.class);

    @Override
    public Object call() throws Exception {
        return null;
    }

    public RunReport (){
        runReport();
    }

    public void runReport(){
        Map<String,Object> reportParams = new HashMap<>();
        reportParams.put("name", "Emily Bronte");

        LoadContext<Report> lContext = new LoadContext<>(Report.class);
        lContext.setQueryString("select r from report$Report r where r.name like '%Author%'");
        List<Report> reports = dataManager.loadList(lContext);

        for (Report report : reports){
            String reportName = "Report" +"-"+ new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());

            FileDescriptor reportFile = reportService.createAndSaveReport(report, reportParams, reportName);
            ....
        }
    }
}

Also, a report can be generated and sent by email without saving it on disk. How to do it was described here: https://www.cuba-platform.com/discuss/t/sending-attachment-to-the-e-mail#comment-1346.

I apologize. I’m a little lost. What is report$Report in the JPQL query?
Where do these reports go to so I can view them after they are created?

I meant, where in the Cuba-Platform do the reports go, not just in general.

When the reports is enabled in your project, a new table report_report is added to the database. Open the Reports ? Reports in UI and create a report. New report is stored in the table.
If the reportService.createAndSaveReport() method is used to run a report, the generated file is saved to platform FileStorage. It is available for downloading on the the Administration ? External Files screen. Also, you can send it by email or save to disk.
For more information on the FileStorage see the following documentation:
https://doc.cuba-platform.com/manual-6.1/file_storage.html
https://doc.cuba-platform.com/manual-6.1/images_recipe.html

I’ve got a report attaching to an email and being sent by the click of a button on a browse screen, but when I put that method into it’s own class and call it with the scheduler , I get errors.


Caused by: java.lang.NullPointerException: null
at com.haulmont.cuba.core.app.scheduling.RunnerBean.executeTask(RunnerBean.java218) ~[cuba-core-6.2.2jar:6.2.2]
… 6 common frames omitted

Are there any other requirements for the class method (defined at https://doc.cuba-platform.com/manual-6.2/scheduled_tasks_cuba_reg.html) that I don’t know about?

Thanks

schedular error

Solved: I needed to use the class path instead of just the class name in the scheduler.