Search in sources :

Example 1 with ProgramNotificationInstance

use of org.hisp.dhis.program.notification.ProgramNotificationInstance in project dhis2-core by dhis2.

the class NotificationTemplateService method createNotificationInstance.

public ProgramNotificationInstance createNotificationInstance(ProgramNotificationTemplate template, Date date) {
    ProgramNotificationInstance notificationInstance = new ProgramNotificationInstance();
    notificationInstance.setAutoFields();
    notificationInstance.setName(template.getName());
    notificationInstance.setScheduledAt(date);
    notificationInstance.setProgramNotificationTemplateSnapshot(mapper.toProgramNotificationTemplateSnapshot(template));
    return notificationInstance;
}
Also used : ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance)

Example 2 with ProgramNotificationInstance

use of org.hisp.dhis.program.notification.ProgramNotificationInstance in project dhis2-core by dhis2.

the class RuleActionScheduleMessageImplementer method handleSingleEvent.

// -------------------------------------------------------------------------
// Supportive Methods
// -------------------------------------------------------------------------
private void handleSingleEvent(RuleEffect ruleEffect, ProgramStageInstance programStageInstance) {
    ProgramNotificationTemplate template = getNotificationTemplate(ruleEffect.ruleAction());
    if (template == null) {
        return;
    }
    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()));
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance)

Example 3 with ProgramNotificationInstance

use of org.hisp.dhis.program.notification.ProgramNotificationInstance 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 4 with ProgramNotificationInstance

use of org.hisp.dhis.program.notification.ProgramNotificationInstance 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 5 with ProgramNotificationInstance

use of org.hisp.dhis.program.notification.ProgramNotificationInstance in project dhis2-core by dhis2.

the class ProgramNotificationInstanceServiceTest method testGetProgramNotificationInstance.

@Test
void testGetProgramNotificationInstance() {
    programRuleEngineService.evaluateEnrollmentAndRunEffects(programInstance.getId());
    List<ProgramNotificationInstance> programNotificationInstances = programNotificationInstanceService.getProgramNotificationInstances(ProgramNotificationInstanceParam.builder().programInstance(programInstance).build());
    assertFalse(programNotificationInstances.isEmpty());
    assertSame(programInstance, programNotificationInstances.get(0).getProgramInstance());
    ProgramNotificationInstanceParam param = ProgramNotificationInstanceParam.builder().programInstance(programInstance).build();
    List<ProgramNotificationInstance> instances = programNotificationInstanceService.getProgramNotificationInstances(param);
    assertFalse(instances.isEmpty());
}
Also used : ProgramNotificationInstanceParam(org.hisp.dhis.program.notification.ProgramNotificationInstanceParam) ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance) Test(org.junit.jupiter.api.Test)

Aggregations

ProgramNotificationInstance (org.hisp.dhis.program.notification.ProgramNotificationInstance)8 ExternalNotificationLogEntry (org.hisp.dhis.notification.logging.ExternalNotificationLogEntry)3 ProgramNotificationTemplate (org.hisp.dhis.program.notification.ProgramNotificationTemplate)3 Test (org.junit.jupiter.api.Test)3 NotificationValidationResult (org.hisp.dhis.notification.logging.NotificationValidationResult)2 ProgramInstance (org.hisp.dhis.program.ProgramInstance)2 ProgramNotificationInstanceParam (org.hisp.dhis.program.notification.ProgramNotificationInstanceParam)2 Transactional (org.springframework.transaction.annotation.Transactional)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)1 ProgramRuleAction (org.hisp.dhis.programrule.ProgramRuleAction)1 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)1 PagingWrapper (org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper)1 Disabled (org.junit.jupiter.api.Disabled)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1