use of org.hisp.dhis.notification.logging.ExternalNotificationLogEntry in project dhis2-core by dhis2.
the class RuleActionScheduleMessageImplementer method implement.
@Override
@Transactional
public void implement(RuleEffect ruleEffect, ProgramInstance programInstance) {
NotificationValidationResult result = validate(ruleEffect, programInstance);
if (!result.isValid()) {
return;
}
ProgramNotificationTemplate template = result.getTemplate();
String key = generateKey(template, programInstance);
String date = StringUtils.unwrap(ruleEffect.data(), '\'');
if (!isDateValid(date)) {
return;
}
ProgramNotificationInstance notificationInstance = notificationTemplateService.createNotificationInstance(template, date);
notificationInstance.setProgramStageInstance(null);
notificationInstance.setProgramInstance(programInstance);
programNotificationInstanceService.save(notificationInstance);
log.info(String.format(LOG_MESSAGE, template.getUid()));
if (result.getLogEntry() != null) {
return;
}
ExternalNotificationLogEntry entry = createLogEntry(key, template.getUid());
entry.setNotificationTriggeredBy(NotificationTriggerEvent.PROGRAM);
entry.setAllowMultiple(template.isSendRepeatable());
notificationLoggingService.save(entry);
}
use of org.hisp.dhis.notification.logging.ExternalNotificationLogEntry in project dhis2-core by dhis2.
the class ProgramRuleEngineTest method testSendRepeatableTemplates.
@Test
void testSendRepeatableTemplates() {
setUpScheduleMessage();
pnt.setSendRepeatable(true);
ProgramInstance programInstance = programInstanceService.getProgramInstance("UID-PS");
List<RuleEffect> ruleEffects = programRuleEngineService.evaluateEnrollmentAndRunEffects(programInstance.getId());
assertEquals(1, ruleEffects.size());
RuleAction ruleAction = ruleEffects.get(0).ruleAction();
assertTrue(ruleAction instanceof RuleActionScheduleMessage);
RuleActionScheduleMessage ruleActionScheduleMessage = (RuleActionScheduleMessage) ruleAction;
assertEquals("PNT-1-SCH", ruleActionScheduleMessage.notification());
assertEquals(scheduledDate, ruleEffects.get(0).data());
List<RuleEffect> ruleEffects2 = programRuleEngineService.evaluateEnrollmentAndRunEffects(programInstance.getId());
assertNotNull(ruleEffects2.get(0));
assertTrue(ruleEffects2.get(0).ruleAction() instanceof RuleActionScheduleMessage);
RuleActionScheduleMessage ruleActionScheduleMessage2 = (RuleActionScheduleMessage) ruleEffects2.get(0).ruleAction();
assertNotNull(programNotificationTemplateStore.getByUid(ruleActionScheduleMessage2.notification()));
List<ProgramNotificationInstance> instances = programNotificationInstanceService.getProgramNotificationInstances(ProgramNotificationInstanceParam.builder().programInstance(programInstance).build());
assertEquals(2, instances.size());
assertEquals(instances.get(0).getProgramNotificationTemplateId(), instances.get(1).getProgramNotificationTemplateId());
ExternalNotificationLogEntry logEntry = notificationLoggingService.getByTemplateUid(pnt.getUid());
assertTrue(logEntry.isAllowMultiple());
}
Aggregations