Search in sources :

Example 26 with Enrollments

use of org.hisp.dhis.dxf2.events.enrollment.Enrollments in project dhis2-core by dhis2.

the class EnrollmentController method postEnrollmentXml.

@PostMapping(value = "", consumes = APPLICATION_XML_VALUE, produces = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage postEnrollmentXml(@RequestParam(defaultValue = "CREATE_AND_UPDATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    importOptions.setStrategy(strategy);
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    if (!importOptions.isAsync()) {
        ImportSummaries importSummaries = enrollmentService.addEnrollmentsXml(inputStream, importOptions);
        importSummaries.setImportOptions(importOptions);
        importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete() && (!importOptions.getImportStrategy().isSync() || importSummary.getImportCount().getDeleted() == 0)).forEach(importSummary -> importSummary.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference()));
        if (importSummaries.getImportSummaries().size() == 1) {
            ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
            importSummary.setImportOptions(importOptions);
            if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
                importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED).setLocation("/api/" + "enrollments" + "/" + importSummary.getReference());
            }
        }
        return importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED);
    }
    return startAsyncImport(importOptions, enrollmentService.getEnrollmentsXml(inputStream));
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) APPLICATION_XML_VALUE(org.springframework.http.MediaType.APPLICATION_XML_VALUE) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) PagerUtils(org.hisp.dhis.common.PagerUtils) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImportEnrollmentsTask(org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) ContextService(org.hisp.dhis.webapi.service.ContextService) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) Set(java.util.Set) Collectors(java.util.stream.Collectors) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) EnrollmentCriteria(org.hisp.dhis.webapi.controller.event.webrequest.EnrollmentCriteria) List(java.util.List) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) AsyncTaskExecutor(org.hisp.dhis.common.AsyncTaskExecutor) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RootNode(org.hisp.dhis.node.types.RootNode) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) WebMessageUtils.notFound(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ENROLLMENT_IMPORT(org.hisp.dhis.scheduling.JobType.ENROLLMENT_IMPORT) Controller(org.springframework.stereotype.Controller) StreamUtils(org.hisp.dhis.commons.util.StreamUtils) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) SlimPager(org.hisp.dhis.common.SlimPager) WebMessageUtils.importSummaries(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummaries) EnrollmentCriteriaMapper(org.hisp.dhis.webapi.controller.event.mapper.EnrollmentCriteriaMapper) WebMessageUtils.importSummary(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) WebMessageUtils.jobConfigurationReport(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.jobConfigurationReport) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) IOException(java.io.IOException) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) HttpStatus(org.springframework.http.HttpStatus) CurrentUserService(org.hisp.dhis.user.CurrentUserService) InputStream(java.io.InputStream) TextUtils(org.hisp.dhis.commons.util.TextUtils) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 27 with Enrollments

use of org.hisp.dhis.dxf2.events.enrollment.Enrollments 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)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)18 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)16 List (java.util.List)12 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)12 ArrayList (java.util.ArrayList)11 Lists (com.google.common.collect.Lists)9 Map (java.util.Map)9 Set (java.util.Set)9 Collectors (java.util.stream.Collectors)9 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)9 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)8 ProgramInstanceService (org.hisp.dhis.program.ProgramInstanceService)8 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)8 CurrentUserService (org.hisp.dhis.user.CurrentUserService)8 Program (org.hisp.dhis.program.Program)7 ProgramInstance (org.hisp.dhis.program.ProgramInstance)7 ProgramInstanceQueryParams (org.hisp.dhis.program.ProgramInstanceQueryParams)7 SlimPager (org.hisp.dhis.common.SlimPager)6 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)5 Date (java.util.Date)4