Search in sources :

Example 26 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValuesXmlWithAttributePreheatCacheTrue.

@Test
public void testImportDataValuesXmlWithAttributePreheatCacheTrue() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetBAttribute.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setPreheatCache(true).setIdScheme(IdScheme.ATTR_ID_SCHEME_PREFIX + ATTRIBUTE_UID).setDataElementIdScheme(IdScheme.ATTR_ID_SCHEME_PREFIX + ATTRIBUTE_UID).setOrgUnitIdScheme(IdScheme.ATTR_ID_SCHEME_PREFIX + ATTRIBUTE_UID);
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(0, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertImportDataValues(summary);
}
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)

Example 27 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValuesXmlWithCodePreheatCacheTrue.

@Test
public void testImportDataValuesXmlWithCodePreheatCacheTrue() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetBCode.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setPreheatCache(true).setIdScheme("CODE").setDataElementIdScheme("CODE").setOrgUnitIdScheme("CODE");
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(0, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertImportDataValues(summary);
}
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)

Example 28 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValuesXmlDryRun.

@Test
public void testImportDataValuesXmlDryRun() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setDryRun(true).setIdScheme("UID").setDataElementIdScheme("UID").setOrgUnitIdScheme("UID");
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(0, 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)

Example 29 with ImportSummary

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

the class DataValueSetController method postAdxDataValueSet.

@RequestMapping(method = RequestMethod.POST, consumes = CONTENT_TYPE_XML_ADX)
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
public void postAdxDataValueSet(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (importOptions.isAsync()) {
        startAsyncImport(importOptions, ImportDataValueTask.FORMAT_ADX, request, response);
    } else {
        try {
            ImportSummary summary = adxDataService.saveDataValueSet(request.getInputStream(), importOptions, null);
            summary.setImportOptions(importOptions);
            response.setContentType(CONTENT_TYPE_XML);
            renderService.toXml(response.getOutputStream(), summary);
        } catch (Exception ex) {
            log.error("ADX Import error: ", ex);
            throw ex;
        }
    }
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) AdxException(org.hisp.dhis.dxf2.adx.AdxException) IOException(java.io.IOException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with ImportSummary

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

the class DataValueSetController method postDxf2DataValueSet.

// -------------------------------------------------------------------------
// Post
// -------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.POST, consumes = "application/xml")
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
public void postDxf2DataValueSet(ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (importOptions.isAsync()) {
        startAsyncImport(importOptions, ImportDataValueTask.FORMAT_XML, request, response);
    } else {
        ImportSummary summary = dataValueSetService.saveDataValueSet(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)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)102 Test (org.junit.Test)58 DhisSpringTest (org.hisp.dhis.DhisSpringTest)49 ClassPathResource (org.springframework.core.io.ClassPathResource)39 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)22 DataValue (org.hisp.dhis.datavalue.DataValue)18 Event (org.hisp.dhis.dxf2.events.event.Event)17 InputStream (java.io.InputStream)14 Date (java.util.Date)11 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)11 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)11 IOException (java.io.IOException)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)10 DhisTest (org.hisp.dhis.DhisTest)9 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)7 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)7