Home > front end >  Whenever I try to generate a CSV I get a "No enum constant" exception, does anyone have an
Whenever I try to generate a CSV I get a "No enum constant" exception, does anyone have an

Time:12-01

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:

  • 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(";"));
}

`

CodePudding user response:

As the exception says:

There is no enum value "backoffice" in EOrganiacao

  • Related