Search in sources :

Example 1 with NotificationValidationResult

use of org.hisp.dhis.notification.logging.NotificationValidationResult in project dhis2-core by dhis2.

the class RuleActionSendMessageImplementer method implement.

@Override
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);
    publisher.publishEvent(new ProgramRuleEnrollmentEvent(this, template.getId(), programInstance));
    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) ProgramRuleEnrollmentEvent(org.hisp.dhis.program.notification.event.ProgramRuleEnrollmentEvent) ExternalNotificationLogEntry(org.hisp.dhis.notification.logging.ExternalNotificationLogEntry)

Example 2 with NotificationValidationResult

use of org.hisp.dhis.notification.logging.NotificationValidationResult in project dhis2-core by dhis2.

the class RuleActionSendMessageImplementer method implement.

@Override
public void implement(RuleEffect ruleEffect, ProgramStageInstance programStageInstance) {
    checkNotNull(programStageInstance, "ProgramStageInstance cannot be null");
    NotificationValidationResult result = validate(ruleEffect, programStageInstance.getProgramInstance());
    // For program without registration
    if (programStageInstance.getProgramStage().getProgram().isWithoutRegistration()) {
        handleSingleEvent(ruleEffect, programStageInstance);
        return;
    }
    if (!result.isValid()) {
        return;
    }
    ProgramInstance pi = programStageInstance.getProgramInstance();
    ProgramNotificationTemplate template = result.getTemplate();
    String key = generateKey(template, pi);
    publisher.publishEvent(new ProgramRuleStageEvent(this, template.getId(), programStageInstance));
    if (result.getLogEntry() != null) {
        return;
    }
    ExternalNotificationLogEntry entry = createLogEntry(key, template.getUid());
    entry.setNotificationTriggeredBy(NotificationTriggerEvent.PROGRAM_STAGE);
    entry.setAllowMultiple(template.isSendRepeatable());
    notificationLoggingService.save(entry);
}
Also used : NotificationValidationResult(org.hisp.dhis.notification.logging.NotificationValidationResult) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ExternalNotificationLogEntry(org.hisp.dhis.notification.logging.ExternalNotificationLogEntry) ProgramRuleStageEvent(org.hisp.dhis.program.notification.event.ProgramRuleStageEvent)

Example 3 with NotificationValidationResult

use of org.hisp.dhis.notification.logging.NotificationValidationResult in project dhis2-core by dhis2.

the class NotificationRuleActionImplementerTest method test_loggingServiceKey.

@Test
void test_loggingServiceKey() {
    when(templateStore.getByUid(anyString())).thenReturn(template);
    doAnswer(invocationOnMock -> {
        eventType = (ApplicationEvent) invocationOnMock.getArguments()[0];
        return eventType;
    }).when(publisher).publishEvent(any());
    doAnswer(invocationOnMock -> {
        logEntry = (ExternalNotificationLogEntry) invocationOnMock.getArguments()[0];
        return logEntry;
    }).when(loggingService).save(any());
    NotificationValidationResult result = NotificationValidationResult.builder().valid(true).build();
    when(loggingService.getByKey(anyString())).thenReturn(result.getLogEntry());
    String key = template.getUid() + programInstance.getUid();
    implementer.implement(ruleEffectWithActionSendMessage, programInstance);
    assertEquals(key, logEntry.getKey());
}
Also used : NotificationValidationResult(org.hisp.dhis.notification.logging.NotificationValidationResult) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 4 with NotificationValidationResult

use of org.hisp.dhis.notification.logging.NotificationValidationResult in project dhis2-core by dhis2.

the class RuleActionScheduleMessageImplementer method implement.

@Override
@Transactional
public void implement(RuleEffect ruleEffect, ProgramStageInstance programStageInstance) {
    checkNotNull(programStageInstance, "ProgramStageInstance cannot be null");
    NotificationValidationResult result = validate(ruleEffect, programStageInstance.getProgramInstance());
    // For program without registration
    if (programStageInstance.getProgramStage().getProgram().isWithoutRegistration()) {
        handleSingleEvent(ruleEffect, programStageInstance);
        return;
    }
    if (!result.isValid()) {
        return;
    }
    ProgramInstance pi = programStageInstance.getProgramInstance();
    ProgramNotificationTemplate template = result.getTemplate();
    String key = generateKey(template, pi);
    String date = StringUtils.unwrap(ruleEffect.data(), '\'');
    if (!isDateValid(date)) {
        return;
    }
    ProgramNotificationInstance notificationInstance = notificationTemplateService.createNotificationInstance(template, date);
    notificationInstance.setProgramStageInstance(programStageInstance);
    notificationInstance.setProgramInstance(null);
    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_STAGE);
    entry.setAllowMultiple(template.isSendRepeatable());
    notificationLoggingService.save(entry);
}
Also used : NotificationValidationResult(org.hisp.dhis.notification.logging.NotificationValidationResult) ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ExternalNotificationLogEntry(org.hisp.dhis.notification.logging.ExternalNotificationLogEntry) ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with NotificationValidationResult

use of org.hisp.dhis.notification.logging.NotificationValidationResult 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)

Aggregations

NotificationValidationResult (org.hisp.dhis.notification.logging.NotificationValidationResult)5 ExternalNotificationLogEntry (org.hisp.dhis.notification.logging.ExternalNotificationLogEntry)4 ProgramInstance (org.hisp.dhis.program.ProgramInstance)2 ProgramNotificationInstance (org.hisp.dhis.program.notification.ProgramNotificationInstance)2 ProgramNotificationTemplate (org.hisp.dhis.program.notification.ProgramNotificationTemplate)2 Transactional (org.springframework.transaction.annotation.Transactional)2 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 ProgramRuleEnrollmentEvent (org.hisp.dhis.program.notification.event.ProgramRuleEnrollmentEvent)1 ProgramRuleStageEvent (org.hisp.dhis.program.notification.event.ProgramRuleStageEvent)1 Test (org.junit.jupiter.api.Test)1 Mockito.anyString (org.mockito.Mockito.anyString)1