Search in sources :

Example 1 with CsvImportClass

use of org.hisp.dhis.dxf2.csv.CsvImportClass 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);
}
Also used : CsvImportOptions(org.hisp.dhis.dxf2.csv.CsvImportOptions) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 2 with CsvImportClass

use of org.hisp.dhis.dxf2.csv.CsvImportClass 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);
}
Also used : CsvImportOptions(org.hisp.dhis.dxf2.csv.CsvImportOptions) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

InputStream (java.io.InputStream)2 CsvImportOptions (org.hisp.dhis.dxf2.csv.CsvImportOptions)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2