use of org.hisp.dhis.dxf2.csv.CsvImportOptions in project dhis2-core by dhis2.
the class CsvMetadataImportTest method runImport.
private ImportReport runImport(String csvFile, CsvImportClass importClass, Consumer<Metadata> preCondition, Consumer<MetadataImportParams> modifier) throws IOException {
InputStream input = new ClassPathResource(csvFile).getInputStream();
Metadata metadata = csvImportService.fromCsv(input, new CsvImportOptions().setImportClass(importClass).setFirstRowIsHeader(true));
if (preCondition != null) {
preCondition.accept(metadata);
}
MetadataImportParams params = new MetadataImportParams();
params.addMetadata(schemaService.getMetadataSchemas(), metadata);
if (modifier != null) {
modifier.accept(params);
}
return importService.importMetadata(params);
}
use of org.hisp.dhis.dxf2.csv.CsvImportOptions in project dhis2-core by dhis2.
the class CsvMetadataImportIntegrationTest method runImport.
private ImportReport runImport(String csvFile, CsvImportClass importClass, Consumer<Metadata> preCondition, Consumer<MetadataImportParams> modifier) throws IOException {
InputStream input = new ClassPathResource(csvFile).getInputStream();
Metadata metadata = csvImportService.fromCsv(input, new CsvImportOptions().setImportClass(importClass).setFirstRowIsHeader(true));
if (preCondition != null) {
preCondition.accept(metadata);
}
MetadataImportParams params = new MetadataImportParams();
params.addMetadata(schemaService.getMetadataSchemas(), metadata);
if (modifier != null) {
modifier.accept(params);
}
return importService.importMetadata(params);
}
use of org.hisp.dhis.dxf2.csv.CsvImportOptions in project dhis2-core by dhis2.
the class MetadataImportExportController method postCsvMetadata.
@PostMapping(value = "", consumes = "application/csv")
@ResponseBody
public WebMessage postCsvMetadata(HttpServletRequest request) throws IOException {
MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
String classKey = request.getParameter("classKey");
if (StringUtils.isEmpty(classKey) || !CsvImportClass.classExists(classKey)) {
return conflict("Cannot find Csv import class: " + classKey);
}
params.setCsvImportClass(CsvImportClass.valueOf(classKey));
Metadata metadata = csvImportService.fromCsv(request.getInputStream(), new CsvImportOptions().setImportClass(params.getCsvImportClass()).setFirstRowIsHeader(params.isFirstRowIsHeader()));
params.addMetadata(schemaService.getMetadataSchemas(), metadata);
if (params.hasJobId()) {
return startAsyncMetadata(params);
}
ImportReport importReport = metadataImportService.importMetadata(params);
return importReport(importReport).withPlainResponseBefore(DhisApiVersion.V38);
}
use of org.hisp.dhis.dxf2.csv.CsvImportOptions in project dhis2-core by dhis2.
the class CsvImportServiceTest method testImportCategories.
@Test
void testImportCategories() throws IOException {
InputStream in = new ClassPathResource("csv/categories.csv").getInputStream();
Metadata metadata = csvImportService.fromCsv(in, new CsvImportOptions().setImportClass(CsvImportClass.CATEGORY).setFirstRowIsHeader(true));
assertEquals(3, metadata.getCategories().size());
Category gender = metadata.getCategories().get(0);
Category ageGroup = metadata.getCategories().get(1);
Category partner = metadata.getCategories().get(2);
assertEquals("Gender", gender.getName());
assertEquals(DataDimensionType.DISAGGREGATION, gender.getDataDimensionType());
assertEquals("AGEGROUP", ageGroup.getCode());
assertEquals(DataDimensionType.ATTRIBUTE, partner.getDataDimensionType());
}
use of org.hisp.dhis.dxf2.csv.CsvImportOptions in project dhis2-core by dhis2.
the class CsvImportServiceTest method testImportCategoryCombos.
@Test
void testImportCategoryCombos() throws IOException {
InputStream in = new ClassPathResource("csv/category_combos.csv").getInputStream();
Metadata metadata = csvImportService.fromCsv(in, new CsvImportOptions().setImportClass(CsvImportClass.CATEGORY_COMBO).setFirstRowIsHeader(true));
assertEquals(2, metadata.getCategoryCombos().size());
CategoryCombo genderAge = metadata.getCategoryCombos().get(0);
CategoryCombo partner = metadata.getCategoryCombos().get(1);
assertEquals("Gender and Age", genderAge.getName());
assertEquals(DataDimensionType.DISAGGREGATION, genderAge.getDataDimensionType());
assertEquals(DataDimensionType.ATTRIBUTE, partner.getDataDimensionType());
}
Aggregations