use of org.hisp.dhis.notification.logging.ExternalNotificationLogEntry in project dhis2-core by dhis2.
the class NotificationRuleActionImplementer method createLogEntry.
protected ExternalNotificationLogEntry createLogEntry(String key, String templateUid) {
ExternalNotificationLogEntry entry = new ExternalNotificationLogEntry();
entry.setLastSentAt(new Date());
entry.setKey(key);
entry.setNotificationTemplateUid(templateUid);
entry.setAllowMultiple(false);
return entry;
}
use of org.hisp.dhis.notification.logging.ExternalNotificationLogEntry 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.ExternalNotificationLogEntry 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.ExternalNotificationLogEntry 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.notification.logging.ExternalNotificationLogEntry 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