Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Whenever I try to generate a CSV I get a "No enum constant" exception, does anyone have an idea what it could be?

Error that appears in the picture:enter image description here

From what I noticed the error seems to be in the "toCsv" method.
whenever I use debug it stops at "obterCsv", but I’m not sure why it throws an exception.

My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • Controller:
    `
@GetMapping("exportar-csv")
public void exportCsv(@Validated TratativaFiltros filtros, HttpServletResponse response) {
    service.exportarCsv(response, filtros);
}

`

  • Service:
    `
private List<TratativaResponse> searchForFiltroAndOrder(TratativaFiltros filtros) {
    var sort = SortBuilders.fieldSort("protocolo").order(SortOrder.DESC);
    var predicate = filtros.toElasticPredicate();
    filtrarPorNivelPermissao(predicate, filtros);
    var tratativas = repository.findAll(sort, predicate.build());

    return tratativas.stream()
        .map(tratativa -> TratativaResponse.of(tratativa))
        .collect(Collectors.toList());
}

public void exportarCsv(HttpServletResponse response, TratativaFiltros filtros) {

    CsvUtils.setCsvNoHttpResponse(
        TratativaResponseCsv.getCsv(searchForFiltroAndOrder(filtros)),
        CsvUtils.createFileName("TRATATIVAS"),
        response);
}

`

  • Response:
    `
public static String getCsv(List<TratativaResponse> tratativa) {
    return getCabecalhoCsv()
        .concat(getLinhasCsv(tratativa));
}
@JsonIgnore
public static String getCabecalhoCsv() {
    return "\uFEFF"
        .concat("PROTOCOLO;")
        .concat("\r\n");
}
@JsonIgnore
private static String getLinhasCsv(List<TratativaResponse> tratativa) {
    return !CollectionUtils.isEmpty(tratativa)
        ? tratativa.stream()
        .map(TratativaResponseCsv::of)
        .map(TratativaResponseCsv::obterCsv)
        .collect(Collectors.joining("\n"))
        : "Registros não encontrados.\n";
}
public static TratativaResponseCsv of(TratativaResponse response) {
    var responseCsv = new TratativaResponseCsv();
    BeanUtils.copyProperties(response, responseCsv);
    return responseCsv;
}
@JsonIgnore
public String[] toCsv() {
    return Stream.of(
        protocolo)
        .map(CsvUtils::replaceCaracteres)
        .toArray(String[]::new);
}
@JsonIgnore
public String obterCsv() {
    return Arrays.stream(toCsv()).collect(Collectors.joining(";"));
}

`

>Solution :

As the exception says:

There is no enum value "backoffice" in EOrganiacao

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading