Send KPI execution results on a schedule
We would like to send the latest KPI execution results by email to all SysUsers
that have READ
permission on that Execution
.
The schedule is fixed and runs every Sunday at 12:00 UTC.
Implementation
Add a new class org.gringlobal.notification.KPINotifications
with:
@Scheduled(...)
@Transactional(readOnly = true)
public void generateLastKPIExecutions() {
for (var execution : executionRepository.listActiveExecutions()) {
notifyLastKPIExecution(execution.getName())
}
}
@Transactional(readOnly = true)
public void notifyLastKPIExecution(String executionName) {
var execution = executionService.load...
var sysUserRecipients = makeRecipientList(execution)
if (sysUserRecipients.isEmpty()) return;
// TODO load last run and generate the message body
// TODO send emails to sysUserRecipients using EmailService
}
Notification recipients
The list of active SysUsers
that will receive the email is based on all SIDs that have READ
permission on the execution. When SID is an active SysGroup
then active members of that group (SysUsers[active=true]
) are added to the list. OAuth clients and web users are ignored.
Notification message
The title of the message is the name of the execution.
The body of the message is generated by loading the last execution run and passing it through TemplateService
to generate the message. The default template kpi-execution-template.mustache
is bundled with server code in src/main/resources/notifications
.
The default template should generate a body similar to how the execution run is displayed in the UI:
KPI {{execution.name}} run {{executionRun.timestamp}}
genus COUNT Aa 33 Abarema 26 Abelmoschus ... Total {{executionRun.total}} View it in GGCE +Link to GGCE UI for this execution