use of org.hisp.dhis.program.notification.ProgramNotificationInstance in project dhis2-core by dhis2.
the class NotificationTemplateService method createNotificationInstance.
public ProgramNotificationInstance createNotificationInstance(ProgramNotificationTemplate template, Date date) {
ProgramNotificationInstance notificationInstance = new ProgramNotificationInstance();
notificationInstance.setAutoFields();
notificationInstance.setName(template.getName());
notificationInstance.setScheduledAt(date);
notificationInstance.setProgramNotificationTemplateSnapshot(mapper.toProgramNotificationTemplateSnapshot(template));
return notificationInstance;
}
use of org.hisp.dhis.program.notification.ProgramNotificationInstance in project dhis2-core by dhis2.
the class RuleActionScheduleMessageImplementer method handleSingleEvent.
// -------------------------------------------------------------------------
// Supportive Methods
// -------------------------------------------------------------------------
private void handleSingleEvent(RuleEffect ruleEffect, ProgramStageInstance programStageInstance) {
ProgramNotificationTemplate template = getNotificationTemplate(ruleEffect.ruleAction());
if (template == null) {
return;
}
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()));
}
use of org.hisp.dhis.program.notification.ProgramNotificationInstance 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.program.notification.ProgramNotificationInstance 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);
}
use of org.hisp.dhis.program.notification.ProgramNotificationInstance in project dhis2-core by dhis2.
the class ProgramNotificationInstanceServiceTest method testGetProgramNotificationInstance.
@Test
void testGetProgramNotificationInstance() {
programRuleEngineService.evaluateEnrollmentAndRunEffects(programInstance.getId());
List<ProgramNotificationInstance> programNotificationInstances = programNotificationInstanceService.getProgramNotificationInstances(ProgramNotificationInstanceParam.builder().programInstance(programInstance).build());
assertFalse(programNotificationInstances.isEmpty());
assertSame(programInstance, programNotificationInstances.get(0).getProgramInstance());
ProgramNotificationInstanceParam param = ProgramNotificationInstanceParam.builder().programInstance(programInstance).build();
List<ProgramNotificationInstance> instances = programNotificationInstanceService.getProgramNotificationInstances(param);
assertFalse(instances.isEmpty());
}
Aggregations