Search in sources :

Example 1 with ProgramNotificationInstanceParam

use of org.hisp.dhis.program.notification.ProgramNotificationInstanceParam 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());
}
Also used : ProgramNotificationInstanceParam(org.hisp.dhis.program.notification.ProgramNotificationInstanceParam) ProgramNotificationInstance(org.hisp.dhis.program.notification.ProgramNotificationInstance) Test(org.junit.jupiter.api.Test)

Example 2 with ProgramNotificationInstanceParam

use of org.hisp.dhis.program.notification.ProgramNotificationInstanceParam 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)2 ProgramNotificationInstanceParam (org.hisp.dhis.program.notification.ProgramNotificationInstanceParam)2 PagingWrapper (org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper)1 Test (org.junit.jupiter.api.Test)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