Search in sources :

Example 1 with ImportOptions

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

the class DataValueSetController method postCsvDataValueSet.

@RequestMapping(method = RequestMethod.POST, consumes = "application/csv")
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
public void postCsvDataValueSet(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (importOptions.isAsync()) {
        startAsyncImport(importOptions, ImportDataValueTask.FORMAT_CSV, request, response);
    } else {
        ImportSummary summary = dataValueSetService.saveDataValueSetCsv(request.getInputStream(), importOptions);
        summary.setImportOptions(importOptions);
        response.setContentType(CONTENT_TYPE_XML);
        renderService.toXml(response.getOutputStream(), summary);
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ImportOptions

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

the class CompleteDataSetRegistrationController method postCompleteRegistrationsXml.

// -------------------------------------------------------------------------
// POST
// -------------------------------------------------------------------------
@ApiVersion({ DhisApiVersion.DEFAULT, DhisApiVersion.V26, DhisApiVersion.V27 })
@RequestMapping(method = RequestMethod.POST, consumes = CONTENT_TYPE_XML)
public void postCompleteRegistrationsXml(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (importOptions.isAsync()) {
        asyncImport(importOptions, ImportCompleteDataSetRegistrationsTask.FORMAT_XML, request, response);
    } else {
        response.setContentType(CONTENT_TYPE_XML);
        ImportSummary summary = registrationExchangeService.saveCompleteDataSetRegistrationsXml(request.getInputStream(), importOptions);
        summary.setImportOptions(importOptions);
        renderService.toXml(response.getOutputStream(), summary);
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ImportOptions

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

the class CompleteDataSetRegistrationController method asyncImport.

private void asyncImport(ImportOptions importOptions, String format, HttpServletRequest request, HttpServletResponse response) throws IOException {
    Pair<InputStream, Path> tmpFile = saveTmpFile(request.getInputStream());
    TaskId taskId = new TaskId(TaskCategory.COMPLETE_DATA_SET_REGISTRATION_IMPORT, currentUserService.getCurrentUser());
    scheduler.executeTask(new ImportCompleteDataSetRegistrationsTask(registrationExchangeService, sessionFactory, tmpFile.getLeft(), tmpFile.getRight(), importOptions, format, taskId));
    response.setHeader("Location", ContextUtils.getRootPath(request) + "/system/tasks/" + TaskCategory.COMPLETE_DATA_SET_REGISTRATION_IMPORT);
    response.setStatus(HttpServletResponse.SC_ACCEPTED);
}
Also used : Path(java.nio.file.Path) ImportCompleteDataSetRegistrationsTask(org.hisp.dhis.dxf2.dataset.tasks.ImportCompleteDataSetRegistrationsTask) TaskId(org.hisp.dhis.scheduling.TaskId) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 4 with ImportOptions

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

the class CompleteDataSetRegistrationController method postCompleteRegistrationsJson.

@ApiVersion({ DhisApiVersion.DEFAULT, DhisApiVersion.V26, DhisApiVersion.V27 })
@RequestMapping(method = RequestMethod.POST, consumes = CONTENT_TYPE_JSON)
public void postCompleteRegistrationsJson(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (importOptions.isAsync()) {
        asyncImport(importOptions, ImportCompleteDataSetRegistrationsTask.FORMAT_JSON, request, response);
    } else {
        response.setContentType(CONTENT_TYPE_JSON);
        ImportSummary summary = registrationExchangeService.saveCompleteDataSetRegistrationsJson(request.getInputStream(), importOptions);
        summary.setImportOptions(importOptions);
        renderService.toJson(response.getOutputStream(), summary);
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ImportOptions

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

the class DataValueSetServiceTest method testImportDataValuesWithCategoryOptionComboIdScheme.

@Test
public void testImportDataValuesWithCategoryOptionComboIdScheme() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetCCode.xml").getInputStream();
    ImportOptions options = new ImportOptions().setCategoryOptionComboIdScheme("CODE");
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, options);
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(3, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(0, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) 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