Search in sources :

Example 6 with ProgramNotificationInstance

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());
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) ExternalNotificationLogEntry(org.hisp.dhis.notification.logging.ExternalNotificationLogEntry) ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with ProgramNotificationInstance

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());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) ClassPathResource(org.springframework.core.io.ClassPathResource) ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 8 with ProgramNotificationInstance

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);
}
Also used : PagingWrapper(org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper) ProgramNotificationInstanceParam(org.hisp.dhis.program.notification.ProgramNotificationInstanceParam) ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ProgramNotificationInstance (org.hisp.dhis.program.notification.ProgramNotificationInstance)8 ExternalNotificationLogEntry (org.hisp.dhis.notification.logging.ExternalNotificationLogEntry)3 ProgramNotificationTemplate (org.hisp.dhis.program.notification.ProgramNotificationTemplate)3 Test (org.junit.jupiter.api.Test)3 NotificationValidationResult (org.hisp.dhis.notification.logging.NotificationValidationResult)2 ProgramInstance (org.hisp.dhis.program.ProgramInstance)2 ProgramNotificationInstanceParam (org.hisp.dhis.program.notification.ProgramNotificationInstanceParam)2 Transactional (org.springframework.transaction.annotation.Transactional)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)1 ProgramRuleAction (org.hisp.dhis.programrule.ProgramRuleAction)1 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)1 PagingWrapper (org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper)1 Disabled (org.junit.jupiter.api.Disabled)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1