Search in sources :

Example 1 with PagingWrapper

use of org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper in project dhis2-core by dhis2.

the class ProgramNotificationTemplateController method getProgramNotificationTemplates.

// -------------------------------------------------------------------------
// GET
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL')")
@GetMapping(produces = { "application/json" }, value = "/filter")
@ResponseBody
public PagingWrapper<ProgramNotificationTemplate> getProgramNotificationTemplates(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "0") int page, @RequestParam(required = false, defaultValue = "50") int pageSize) {
    ProgramNotificationTemplateParam params = ProgramNotificationTemplateParam.builder().program(programService.getProgram(program)).programStage(programStageService.getProgramStage(programStage)).skipPaging(skipPaging).page(page).pageSize(pageSize).build();
    PagingWrapper<ProgramNotificationTemplate> templatePagingWrapper = new PagingWrapper<>();
    if (!skipPaging) {
        long total = programNotificationTemplateService.countProgramNotificationTemplates(params);
        templatePagingWrapper = templatePagingWrapper.withPager(PagingWrapper.Pager.builder().page(page).pageSize(pageSize).total(total).build());
    }
    List<ProgramNotificationTemplate> instances = programNotificationTemplateService.getProgramNotificationTemplates(params);
    return templatePagingWrapper.withInstances(instances);
}
Also used : PagingWrapper(org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper) ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) ProgramNotificationTemplateParam(org.hisp.dhis.program.notification.ProgramNotificationTemplateParam) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with PagingWrapper

use of org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper 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)

Example 3 with PagingWrapper

use of org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper in project dhis2-core by dhis2.

the class TrackerEnrollmentsExportController method getInstances.

@GetMapping(produces = APPLICATION_JSON_VALUE)
PagingWrapper<Enrollment> getInstances(TrackerEnrollmentCriteria trackerEnrollmentCriteria) {
    PagingWrapper<Enrollment> enrollmentPagingWrapper = new PagingWrapper<>();
    List<org.hisp.dhis.dxf2.events.enrollment.Enrollment> enrollmentList;
    if (trackerEnrollmentCriteria.getEnrollment() == null) {
        ProgramInstanceQueryParams params = enrollmentCriteriaMapper.getFromUrl(trackerEnrollmentCriteria);
        Enrollments enrollments = enrollmentService.getEnrollments(params);
        if (trackerEnrollmentCriteria.isPagingRequest()) {
            enrollmentPagingWrapper = enrollmentPagingWrapper.withPager(PagingWrapper.Pager.fromLegacy(trackerEnrollmentCriteria, enrollments.getPager()));
        }
        enrollmentList = enrollments.getEnrollments();
    } else {
        Set<String> enrollmentIds = TextUtils.splitToArray(trackerEnrollmentCriteria.getEnrollment(), TextUtils.SEMICOLON);
        enrollmentList = enrollmentIds != null ? enrollmentIds.stream().map(enrollmentService::getEnrollment).collect(Collectors.toList()) : Collections.emptyList();
    }
    return enrollmentPagingWrapper.withInstances(ENROLLMENT_MAPPER.fromCollection(enrollmentList));
}
Also used : PagingWrapper(org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with PagingWrapper

use of org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper in project dhis2-core by dhis2.

the class TrackerEventsExportController method getEvents.

@GetMapping(produces = APPLICATION_JSON_VALUE)
public PagingWrapper<org.hisp.dhis.tracker.domain.Event> getEvents(TrackerEventCriteria eventCriteria, @RequestParam Map<String, String> parameters, HttpServletRequest request) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    EventSearchParams eventSearchParams = requestToSearchParamsMapper.map(eventCriteria);
    if (areAllEnrollmentsInvalid(eventCriteria, eventSearchParams)) {
        return new PagingWrapper<org.hisp.dhis.tracker.domain.Event>().withInstances(Collections.emptyList());
    }
    Events events = eventService.getEvents(eventSearchParams);
    if (hasHref(fields, eventCriteria.getSkipEventId())) {
        events.getEvents().forEach(e -> e.setHref(getUri(e.getEvent(), request)));
    }
    PagingWrapper<org.hisp.dhis.tracker.domain.Event> eventPagingWrapper = new PagingWrapper<>();
    if (eventCriteria.isPagingRequest()) {
        eventPagingWrapper = eventPagingWrapper.withPager(PagingWrapper.Pager.fromLegacy(eventCriteria, events.getPager()));
    }
    return eventPagingWrapper.withInstances(EVENTS_MAPPER.fromCollection(events.getEvents()));
}
Also used : PagingWrapper(org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper) Events(org.hisp.dhis.dxf2.events.event.Events) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Event(org.hisp.dhis.dxf2.events.event.Event) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with PagingWrapper

use of org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper in project dhis2-core by dhis2.

the class TrackerTrackedEntitiesExportController method getInstances.

@GetMapping(produces = APPLICATION_JSON_VALUE)
PagingWrapper<TrackedEntity> getInstances(TrackerTrackedEntityCriteria criteria) {
    List<String> fields = contextService.getFieldsFromRequestOrAll();
    TrackedEntityInstanceQueryParams queryParams = criteriaMapper.map(criteria);
    Collection<TrackedEntity> trackedEntityInstances = TRACKED_ENTITY_MAPPER.fromCollection(trackedEntityInstanceService.getTrackedEntityInstances(queryParams, trackedEntityInstanceSupportService.getTrackedEntityInstanceParams(fields), false, false));
    PagingWrapper<TrackedEntity> trackedEntityInstancePagingWrapper = new PagingWrapper<>();
    if (criteria.isPagingRequest()) {
        Long count = criteria.isTotalPages() ? (long) trackedEntityInstanceService.getTrackedEntityInstanceCount(queryParams, true, true) : null;
        trackedEntityInstancePagingWrapper = trackedEntityInstancePagingWrapper.withPager(PagingWrapper.Pager.builder().page(queryParams.getPageWithDefault()).total(count).pageSize(queryParams.getPageSizeWithDefault()).build());
    }
    return trackedEntityInstancePagingWrapper.withInstances(trackedEntityInstances);
}
Also used : PagingWrapper(org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

PagingWrapper (org.hisp.dhis.webapi.controller.event.webrequest.PagingWrapper)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 Enrollments (org.hisp.dhis.dxf2.events.enrollment.Enrollments)1 Event (org.hisp.dhis.dxf2.events.event.Event)1 EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)1 Events (org.hisp.dhis.dxf2.events.event.Events)1 ProgramInstanceQueryParams (org.hisp.dhis.program.ProgramInstanceQueryParams)1 ProgramNotificationInstance (org.hisp.dhis.program.notification.ProgramNotificationInstance)1 ProgramNotificationInstanceParam (org.hisp.dhis.program.notification.ProgramNotificationInstanceParam)1 ProgramNotificationTemplate (org.hisp.dhis.program.notification.ProgramNotificationTemplate)1 ProgramNotificationTemplateParam (org.hisp.dhis.program.notification.ProgramNotificationTemplateParam)1 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)1 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)1 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)1