2
respostas

Erro no customização converter (The method setContas(ArrayList<Conta>) is undefined for the type Cliente)

public static Cliente toCliente(ClienteEntity clienteEntity) {

        Cliente cliente = new Cliente();
        cliente.setCpf(clienteEntity.getCpf());
        cliente.setId(clienteEntity.getId());
        cliente.setTitular(clienteEntity.getTitular());
        cliente.setContas(new ArrayList<Conta>());

        if(clienteEntity.getContas() != null) {
            for(ContaEntity contaE: clienteEntity.getContas()) {
                Conta conta = new Conta();
                conta.setAgencia(contaE.getAgencia());
                conta.setNumero(contaE.getNumero());
                conta.setDigito(contaE.getDigito());
                conta.setSaldo(contaE.getSaldo());
                cliente.getContas().add(conta);
            }
        }
] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project alura-bytebank-api: Compilation failure: Compilation failure:
[ERROR] /D:/Estudo/Java-Spring-Boot/spring-server/src/main/java/io/swagger/customizacao/converter/ClienteConverter.java:[40,24] cannot find symbol
[ERROR]   symbol:   method setContas(java.util.ArrayList<io.swagger.model.Conta>)
[ERROR]   location: variable cliente of type io.swagger.model.Cliente
[ERROR] /D:/Estudo/Java-Spring-Boot/spring-server/src/main/java/io/swagger/customizacao/converter/ClienteConverter.java:[49,40] cannot find symbol
[ERROR]   symbol:   method getContas()
[ERROR]   location: variable cliente of type io.swagger.model.Cliente
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
2 respostas

Manda o código da classe ClienteConverter e Cliente, por favor.

Cliente converter

public class ClienteConverter {

    private static final int AGENCIA = 8756;

    public static ClienteEntity toClienteEntity(Cliente cliente, String tokenBasicAuth) {

        ClienteEntity clienteEntity = new ClienteEntity();

        clienteEntity.setTitular(cliente.getTitular());
        clienteEntity.setCpf(cliente.getCpf());
        clienteEntity.setPassword(tokenBasicAuth);

        ContaEntity contaEntity = new ContaEntity();
        contaEntity.setAgencia(AGENCIA);
        contaEntity.setDigito(0);
        contaEntity.setSaldo(0d);
        contaEntity.setCliente(clienteEntity);
        clienteEntity.setContas(Arrays.asList(contaEntity));

        return clienteEntity;
    }

    public static Cliente toCliente(ClienteEntity clienteEntity) {

        Cliente cliente = new Cliente();
        cliente.setCpf(clienteEntity.getCpf());
        cliente.setId(clienteEntity.getId());
        cliente.setTitular(clienteEntity.getTitular());
        cliente.setContas(new ArrayList<Conta>());

        if(clienteEntity.getContas() != null) {
            for(ContaEntity contaE: clienteEntity.getContas()) {
                Conta conta = new Conta();
                conta.setAgencia(contaE.getAgencia());
                conta.setNumero(contaE.getNumero());
                conta.setDigito(contaE.getDigito());
                conta.setSaldo(contaE.getSaldo());
                cliente.getContas().add(conta);
            }
        }

        return cliente;
    }
}
package io.swagger.model;


@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-09-30T21:53:54.256Z")

public class Cliente   {
  @JsonProperty("id")
  private Long id = null;

  @JsonProperty("titular")
  private String titular = null;

  @JsonProperty("cpf")
  private String cpf = null;

  @JsonProperty("senha")
  private String senha = null;

  @JsonProperty("conta")
  @Valid
  private List<Conta> conta = null;

  public Cliente id(Long id) {
    this.id = id;
    return this;
  }

  @ApiModelProperty(example = "234", value = "")

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public Cliente titular(String titular) {
    this.titular = titular;
    return this;
  }

  @ApiModelProperty(example = "Karoline de Souza", value = "")


  public String getTitular() {
    return titular;
  }

  public void setTitular(String titular) {
    this.titular = titular;
  }

  public Cliente cpf(String cpf) {
    this.cpf = cpf;
    return this;
  }

  @ApiModelProperty(example = "03834163104", value = "")

@Size(min=11,max=11) 
  public String getCpf() {
    return cpf;
  }

  public void setCpf(String cpf) {
    this.cpf = cpf;
  }

  public Cliente senha(String senha) {
    this.senha = senha;
    return this;
  }

  @ApiModelProperty(example = "senha123", value = "")


  public String getSenha() {
    return senha;
  }

  public void setSenha(String senha) {
    this.senha = senha;
  }

  public Cliente conta(List<Conta> conta) {
    this.conta = conta;
    return this;
  }

  public Cliente addContaItem(Conta contaItem) {
    if (this.conta == null) {
      this.conta = new ArrayList<Conta>();
    }
    this.conta.add(contaItem);
    return this;
  }

  @ApiModelProperty(value = "")

  @Valid

  public List<Conta> getConta() {
    return conta;
  }

  public void setConta(List<Conta> conta) {
    this.conta = conta;
  }


  @Override
  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    Cliente cliente = (Cliente) o;
    return Objects.equals(this.id, cliente.id) &&
        Objects.equals(this.titular, cliente.titular) &&
        Objects.equals(this.cpf, cliente.cpf) &&
        Objects.equals(this.senha, cliente.senha) &&
        Objects.equals(this.conta, cliente.conta);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, titular, cpf, senha, conta);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Cliente {\n");

    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.ap