Search in sources :

Example 1 with CodeList

use of org.hisp.dhis.webapi.webdomain.CodeList in project dhis2-core by dhis2.

the class SystemController method getUuid.

@GetMapping(value = "/uuid", produces = { APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public CodeList getUuid(@RequestParam(required = false, defaultValue = "1") Integer limit, HttpServletResponse response) {
    CodeList codeList = generateCodeList(Math.min(limit, 10000), () -> UUID.randomUUID().toString());
    setNoStore(response);
    return codeList;
}
Also used : CodeList(org.hisp.dhis.webapi.webdomain.CodeList) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with CodeList

use of org.hisp.dhis.webapi.webdomain.CodeList 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

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