use of org.hisp.dhis.program.notification.ProgramNotificationInstance in project dhis2-core by dhis2.
the class ProgramRuleEngineTest method testSendRepeatableTemplates.
@Test
void testSendRepeatableTemplates() {
setUpScheduleMessage();
pnt.setSendRepeatable(true);
ProgramInstance programInstance = programInstanceService.getProgramInstance("UID-PS");
List<RuleEffect> ruleEffects = programRuleEngineService.evaluateEnrollmentAndRunEffects(programInstance.getId());
assertEquals(1, ruleEffects.size());
RuleAction ruleAction = ruleEffects.get(0).ruleAction();
assertTrue(ruleAction instanceof RuleActionScheduleMessage);
RuleActionScheduleMessage ruleActionScheduleMessage = (RuleActionScheduleMessage) ruleAction;
assertEquals("PNT-1-SCH", ruleActionScheduleMessage.notification());
assertEquals(scheduledDate, ruleEffects.get(0).data());
List<RuleEffect> ruleEffects2 = programRuleEngineService.evaluateEnrollmentAndRunEffects(programInstance.getId());
assertNotNull(ruleEffects2.get(0));
assertTrue(ruleEffects2.get(0).ruleAction() instanceof RuleActionScheduleMessage);
RuleActionScheduleMessage ruleActionScheduleMessage2 = (RuleActionScheduleMessage) ruleEffects2.get(0).ruleAction();
assertNotNull(programNotificationTemplateStore.getByUid(ruleActionScheduleMessage2.notification()));
List<ProgramNotificationInstance> instances = programNotificationInstanceService.getProgramNotificationInstances(ProgramNotificationInstanceParam.builder().programInstance(programInstance).build());
assertEquals(2, instances.size());
assertEquals(instances.get(0).getProgramNotificationTemplateId(), instances.get(1).getProgramNotificationTemplateId());
ExternalNotificationLogEntry logEntry = notificationLoggingService.getByTemplateUid(pnt.getUid());
assertTrue(logEntry.isAllowMultiple());
}
use of org.hisp.dhis.program.notification.ProgramNotificationInstance in project dhis2-core by dhis2.
the class TrackerSideEffectHandlerServiceTest method testRuleEngineSideEffectHandlerService.
@Test
@Disabled("Needs to be added once rule engine PR is merged")
void testRuleEngineSideEffectHandlerService() throws IOException {
TrackerImportParams trackerImportParams = renderService.fromJson(new ClassPathResource("tracker/enrollment_data_with_program_rule_side_effects.json").getInputStream(), TrackerImportParams.class);
assertEquals(0, trackerImportParams.getEvents().size());
assertEquals(1, trackerImportParams.getTrackedEntities().size());
TrackerImportParams params = TrackerImportParams.builder().events(trackerImportParams.getEvents()).enrollments(trackerImportParams.getEnrollments()).trackedEntities(trackerImportParams.getTrackedEntities()).build();
params.setUserId(ADMIN_USER_UID);
trackerImportService.importTracker(params);
await().atMost(2, TimeUnit.SECONDS).until(() -> manager.getAll(ProgramNotificationInstance.class).size() > 0);
List<ProgramNotificationInstance> instances = manager.getAll(ProgramNotificationInstance.class);
assertFalse(instances.isEmpty());
ProgramNotificationInstance instance = instances.get(0);
assertEquals("FdIeUL4gyoB", instance.getProgramNotificationTemplateSnapshot().getUid());
}
use of org.hisp.dhis.program.notification.ProgramNotificationInstance in project dhis2-core by dhis2.
the class ProgarmNotificationInstanceController method getScheduledMessage.
// -------------------------------------------------------------------------
// GET
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL')")
@GetMapping(produces = { "application/json" })
@ResponseBody
public PagingWrapper<ProgramNotificationInstance> getScheduledMessage(@RequestParam(required = false) String programInstance, @RequestParam(required = false) String programStageInstance, @RequestParam(required = false) Date scheduledAt, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "0") int page, @RequestParam(required = false, defaultValue = "50") int pageSize) {
ProgramNotificationInstanceParam params = ProgramNotificationInstanceParam.builder().programInstance(programInstanceService.getProgramInstance(programInstance)).programStageInstance(programStageInstanceService.getProgramStageInstance(programStageInstance)).skipPaging(skipPaging).page(page).pageSize(pageSize).scheduledAt(scheduledAt).build();
PagingWrapper<ProgramNotificationInstance> instancePagingWrapper = new PagingWrapper<>();
if (!skipPaging) {
long total = programNotificationInstanceService.countProgramNotificationInstances(params);
instancePagingWrapper = instancePagingWrapper.withPager(PagingWrapper.Pager.builder().page(page).pageSize(pageSize).total(total).build());
}
programNotificationInstanceService.validateQueryParameters(params);
List<ProgramNotificationInstance> instances = programNotificationInstanceService.getProgramNotificationInstances(params);
return instancePagingWrapper.withInstances(instances);
}
Aggregations