Search in sources :

Example 6 with ExternalNotificationLogEntry

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);
}
Also used : NotificationValidationResult(org.hisp.dhis.notification.logging.NotificationValidationResult) ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) ExternalNotificationLogEntry(org.hisp.dhis.notification.logging.ExternalNotificationLogEntry) ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with ExternalNotificationLogEntry

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());
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) ExternalNotificationLogEntry(org.hisp.dhis.notification.logging.ExternalNotificationLogEntry) ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ExternalNotificationLogEntry (org.hisp.dhis.notification.logging.ExternalNotificationLogEntry)7 NotificationValidationResult (org.hisp.dhis.notification.logging.NotificationValidationResult)4 ProgramInstance (org.hisp.dhis.program.ProgramInstance)3 ProgramNotificationInstance (org.hisp.dhis.program.notification.ProgramNotificationInstance)3 ProgramNotificationTemplate (org.hisp.dhis.program.notification.ProgramNotificationTemplate)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Date (java.util.Date)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 ProgramRuleEnrollmentEvent (org.hisp.dhis.program.notification.event.ProgramRuleEnrollmentEvent)1 ProgramRuleStageEvent (org.hisp.dhis.program.notification.event.ProgramRuleStageEvent)1 ProgramRuleAction (org.hisp.dhis.programrule.ProgramRuleAction)1 Test (org.junit.jupiter.api.Test)1