Search in sources :

Example 1 with CsvGenerator

use of com.fasterxml.jackson.dataformat.csv.CsvGenerator in project dhis2-core by dhis2.

the class SystemController method getUidCsv.

@GetMapping(value = { "/uid", "/id" }, produces = "application/csv")
public void getUidCsv(@RequestParam(required = false, defaultValue = "1") Integer limit, HttpServletResponse response) throws IOException {
    CodeList codeList = generateCodeList(Math.min(limit, 10000), CodeGenerator::generateUid);
    CsvSchema schema = CsvSchema.builder().addColumn("uid").setUseHeader(true).build();
    CsvGenerator csvGenerator = CSV_FACTORY.createGenerator(response.getOutputStream());
    csvGenerator.setSchema(schema);
    for (String code : codeList.getCodes()) {
        csvGenerator.writeStartObject();
        csvGenerator.writeStringField("uid", code);
        csvGenerator.writeEndObject();
    }
    csvGenerator.flush();
}
Also used : CodeList(org.hisp.dhis.webapi.webdomain.CodeList) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) CodeGenerator(org.hisp.dhis.common.CodeGenerator) CsvGenerator(com.fasterxml.jackson.dataformat.csv.CsvGenerator) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

CsvGenerator (com.fasterxml.jackson.dataformat.csv.CsvGenerator)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 CodeGenerator (org.hisp.dhis.common.CodeGenerator)1 CodeList (org.hisp.dhis.webapi.webdomain.CodeList)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1