I am working on implementing a Scheduled Report Emailer mechanism. I have an entity called “EmailReporter” with attributes “Report” and “Users”. The idea is that, using a scheduled task running with a cron expression, get all instances of EmailReporter, run the associated report, and send it as an email attachment to the specified users.
I have been using this response as a template.
Using this barebones code…
package com.company.deiproductconfig2;
import java.util.concurrent.Callable;
public class ScheduledReportEmailServiceBean implements Callable {
public ScheduledReportEmailServiceBean()
{
}
public Boolean runReports()
{
return true;
}
@Override
public Object call() throws Exception
{
return null;
}
}
…I consistently get this error:
2019-05-01 07:16:00.934 ERROR [ScheduledRunnerThread-1/config-core/admin] com.haulmont.cuba.core.app.scheduling.RunnerBean - Error running ScheduledTask{35739af9-8e3b-21c9-f486-b539a4f0bd35, className=com.company.deiproductconfig2.ScheduledReportEmailServiceBean, singleton=false, cron=0 */2 * * * *}
java.lang.RuntimeException: An error occurred while running method call() of class com.company.deiproductconfig2.ScheduledReportEmailServiceBean.
at com.haulmont.cuba.core.app.scheduling.RunnerBean.executeTask(RunnerBean.java:230) ~[cuba-core-6.9.8.jar:6.9.8]
at com.haulmont.cuba.core.app.scheduling.RunnerBean.lambda$runTask$0(RunnerBean.java:124) ~[cuba-core-6.9.8.jar:6.9.8]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_171]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
Caused by: java.lang.NullPointerException: null
at com.haulmont.cuba.core.app.scheduling.RunnerBean.executeTask(RunnerBean.java:224) ~[cuba-core-6.9.8.jar:6.9.8]
... 6 common frames omitted
The reason I am using the Callable interface instead of a managed bean is because, as I understand it, a managed bean must be part of the core module and unless I am mistaken, the Reports module is part of the GUI module. This is also why my class is currently part of my GUI module: so I can run reports. If I am wrong and a managed bean could work to implement this mechanism I would appreciate guidance on that front as well.