Search in sources :

Example 1 with ProgramRuleStageEvent

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

the class RuleActionSendMessageImplementer method handleSingleEvent.

private void handleSingleEvent(RuleEffect ruleEffect, ProgramStageInstance programStageInstance) {
    ProgramNotificationTemplate template = getNotificationTemplate(ruleEffect.ruleAction());
    if (template == null) {
        return;
    }
    publisher.publishEvent(new ProgramRuleStageEvent(this, template.getId(), programStageInstance));
}
Also used : ProgramRuleStageEvent(org.hisp.dhis.program.notification.event.ProgramRuleStageEvent)

Example 2 with ProgramRuleStageEvent

use of org.hisp.dhis.program.notification.event.ProgramRuleStageEvent 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)

Aggregations

ProgramRuleStageEvent (org.hisp.dhis.program.notification.event.ProgramRuleStageEvent)2 ExternalNotificationLogEntry (org.hisp.dhis.notification.logging.ExternalNotificationLogEntry)1 NotificationValidationResult (org.hisp.dhis.notification.logging.NotificationValidationResult)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1