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());
}
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()));
}
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();
}
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();
}
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);
}
Aggregations