Search in sources :

Example 16 with ProgramNotificationTemplate

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

the class TranslationServiceTest method testNotificationTemplateTranslations.

@Test
void testNotificationTemplateTranslations() {
    ProgramNotificationTemplate template = createProgramNotificationTemplate("", 0, NotificationTrigger.PROGRAM_RULE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE, Calendar.getInstance().getTime());
    manager.save(template);
    Set<Translation> translations = new HashSet<>();
    translations.add(new Translation(locale.getLanguage(), "NAME", "translated Name"));
    translations.add(new Translation(locale.getLanguage(), "SUBJECT_TEMPLATE", "translated SUBJECT TEMPLATE"));
    translations.add(new Translation(locale.getLanguage(), "MESSAGE_TEMPLATE", "translated MESSAGE TEMPLATE"));
    manager.updateTranslations(template, translations);
    template = manager.get(ProgramNotificationTemplate.class, template.getUid());
    assertEquals("translated Name", template.getDisplayName());
    assertEquals("translated SUBJECT TEMPLATE", template.getDisplaySubjectTemplate());
    assertEquals("translated MESSAGE TEMPLATE", template.getDisplayMessageTemplate());
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 17 with ProgramNotificationTemplate

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

the class ProgramNotificationTemplateObjectBundleHook method postProcess.

private void postProcess(ProgramNotificationTemplate template) {
    ProgramNotificationRecipient pnr = template.getNotificationRecipient();
    ValueType valueType = null;
    if (RECIPIENT_TO_VALUETYPE_RESOLVER.containsKey(pnr)) {
        Function<ProgramNotificationTemplate, ValueType> resolver = RECIPIENT_TO_VALUETYPE_RESOLVER.get(pnr);
        valueType = resolver.apply(template);
    }
    template.setDeliveryChannels(CHANNEL_MAPPER.getOrDefault(valueType, Sets.newHashSet()));
}
Also used : ValueType(org.hisp.dhis.common.ValueType) ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) ProgramNotificationRecipient(org.hisp.dhis.program.notification.ProgramNotificationRecipient)

Example 18 with ProgramNotificationTemplate

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

the class NotificationRuleActionImplementerTest method setUpInstances.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void setUpInstances() {
    template = new ProgramNotificationTemplate();
    template.setUid(NOTIFICATION_UID);
    ruleActionSendMessage = new RuleActionSendMessage() {

        @Nonnull
        @Override
        public String notification() {
            return NOTIFICATION_UID;
        }

        @Nonnull
        @Override
        public String data() {
            return null;
        }
    };
    ruleEffectWithActionSendMessage = RuleEffect.create("", ruleActionSendMessage);
    setMandatoryFieldFalse = RuleActionSetMandatoryField.create(MANDATORY_FIELD);
    OrganisationUnit organisationUnitA = createOrganisationUnit('A');
    Program programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programRuleA = createProgramRule('R', programA);
    programRuleA.setProgram(programA);
    programInstance = new ProgramInstance();
    programInstance.setProgram(programA);
    programInstance.setAutoFields();
    ProgramStage programStageA = createProgramStage('S', programA);
    programA.getProgramStages().add(programStageA);
    programStageInstance = new ProgramStageInstance();
    programStageInstance.setProgramStage(programStageA);
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setAutoFields();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) RuleActionSendMessage(org.hisp.dhis.rules.models.RuleActionSendMessage) Nonnull(javax.annotation.Nonnull) ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Mockito.anyString(org.mockito.Mockito.anyString) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 19 with ProgramNotificationTemplate

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

the class NotificationRuleActionImplementer method validate.

@Transactional(readOnly = true)
public NotificationValidationResult validate(RuleEffect ruleEffect, ProgramInstance programInstance) {
    checkNotNull(ruleEffect, "Rule Effect cannot be null");
    checkNotNull(programInstance, "ProgramInstance cannot be null");
    ProgramNotificationTemplate template = getNotificationTemplate(ruleEffect.ruleAction());
    if (template == null) {
        log.warn(String.format("No template found for Program: %s", programInstance.getProgram().getName()));
        return NotificationValidationResult.builder().valid(false).build();
    }
    ExternalNotificationLogEntry logEntry = notificationLoggingService.getByKey(generateKey(template, programInstance));
    // template has already been delivered and repeated delivery not allowed
    if (logEntry != null && !logEntry.isAllowMultiple()) {
        return NotificationValidationResult.builder().valid(false).template(template).logEntry(logEntry).build();
    }
    return NotificationValidationResult.builder().valid(true).template(template).logEntry(logEntry).build();
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) ExternalNotificationLogEntry(org.hisp.dhis.notification.logging.ExternalNotificationLogEntry) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with ProgramNotificationTemplate

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

Aggregations

ProgramNotificationTemplate (org.hisp.dhis.program.notification.ProgramNotificationTemplate)27 ProgramRuleAction (org.hisp.dhis.programrule.ProgramRuleAction)8 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 Test (org.junit.jupiter.api.Test)7 ProgramInstance (org.hisp.dhis.program.ProgramInstance)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 Date (java.util.Date)3 ExternalNotificationLogEntry (org.hisp.dhis.notification.logging.ExternalNotificationLogEntry)3 ProgramNotificationInstance (org.hisp.dhis.program.notification.ProgramNotificationInstance)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2 ValueType (org.hisp.dhis.common.ValueType)2 NotificationValidationResult (org.hisp.dhis.notification.logging.NotificationValidationResult)2 Nonnull (javax.annotation.Nonnull)1 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)1 ErrorReport (org.hisp.dhis.feedback.ErrorReport)1 BaseNotificationMessageRenderer.formatDate (org.hisp.dhis.notification.BaseNotificationMessageRenderer.formatDate)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.program.Program)1