Search in sources :

Example 66 with ImportOptions

use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.

the class EventController method putXmlEvent.

// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { "application/xml", "text/xml" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putXmlEvent(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, ImportOptions importOptions) throws IOException, WebMessageException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event updatedEvent = renderService.fromXml(inputStream, Event.class);
    updatedEvent.setEvent(uid);
    ImportSummary importSummary = eventService.updateEvent(updatedEvent, false, importOptions);
    importSummary.setImportOptions(importOptions);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 67 with ImportOptions

use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.

the class EventController method putJsonEvent.

@RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void putJsonEvent(HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, ImportOptions importOptions) throws IOException, WebMessageException {
    if (!programStageInstanceService.programStageInstanceExists(uid)) {
        throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    Event updatedEvent = renderService.fromJson(inputStream, Event.class);
    updatedEvent.setEvent(uid);
    ImportSummary importSummary = eventService.updateEvent(updatedEvent, false, importOptions);
    importSummary.setImportOptions(importOptions);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 68 with ImportOptions

use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.

the class EnrollmentController method postEnrollmentJson.

// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
public void postEnrollmentJson(@RequestParam(defaultValue = "CREATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    importOptions.setStrategy(strategy);
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummaries importSummaries = enrollmentService.addEnrollmentsJson(inputStream, importOptions);
    importSummaries.setImportOptions(importOptions);
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete()).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)) {
            response.setHeader("Location", getResourcePath(request, importSummary));
        }
    }
    response.setStatus(HttpServletResponse.SC_CREATED);
    webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
}
Also used : DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) StreamUtils(org.hisp.dhis.commons.util.StreamUtils) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) WebMessageService(org.hisp.dhis.webapi.service.WebMessageService) ArrayList(java.util.ArrayList) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Map(java.util.Map) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) WebMessageUtils(org.hisp.dhis.dxf2.webmessage.WebMessageUtils) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) ContextService(org.hisp.dhis.webapi.service.ContextService) OrganisationUnitSelectionMode(org.hisp.dhis.common.OrganisationUnitSelectionMode) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) IOException(java.io.IOException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Collectors(java.util.stream.Collectors) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ProgramStatus(org.hisp.dhis.program.ProgramStatus) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) RootNode(org.hisp.dhis.node.types.RootNode) TextUtils(org.hisp.dhis.commons.util.TextUtils) InputStream(java.io.InputStream) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 69 with ImportOptions

use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.

the class AdxController method postXMLDataValueSet.

@RequestMapping(method = RequestMethod.POST, consumes = "application/xml")
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
public void postXMLDataValueSet(ImportOptions importOptions, HttpServletResponse response, InputStream in, Model model) throws IOException {
    ImportSummary importSummary = adxService.saveDataValueSet(in, importOptions, null);
    importSummary.setImportOptions(importOptions);
    log.debug("Data values set saved");
    response.setContentType(CONTENT_TYPE_XML);
    DefaultRenderService.getXmlMapper().writeValue(response.getOutputStream(), importSummary);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 70 with ImportOptions

use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesWithStrictAttributeOptionCombos.

@Test
public void testImportDataValuesWithStrictAttributeOptionCombos() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
    ImportOptions options = new ImportOptions().setStrictAttributeOptionCombos(true);
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, options);
    assertEquals(summary.getConflicts().toString(), 1, summary.getConflicts().size());
    assertEquals(2, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(1, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)51 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)39 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)20 InputStream (java.io.InputStream)19 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)19 ClassPathResource (org.springframework.core.io.ClassPathResource)17 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)16 Test (org.junit.Test)16 DhisSpringTest (org.hisp.dhis.DhisSpringTest)15 ArrayList (java.util.ArrayList)11 Date (java.util.Date)11 IOException (java.io.IOException)10 Event (org.hisp.dhis.dxf2.events.event.Event)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 TaskId (org.hisp.dhis.scheduling.TaskId)9 Program (org.hisp.dhis.program.Program)8 Lists (com.google.common.collect.Lists)7 HashSet (java.util.HashSet)7