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);
}
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);
}
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));
}
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()));
}
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);
}
Aggregations