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