'save parameters in different entity in java spring boot

I'm here to ask the stackoverflow community for help about a problem I've come across and due to lack of experience I can't get out of the problem. I have a form that contains the following information: enter image description here

In "Cliente" is an example of a form header, and in "parametros" the information that comes randomly.

The business rule is to take this information from the form and save it in different entities (Two actually) that are called Key and Value.

In the key entity, only the information contained in "Key" will be saved, and in the Value entity, it will contain the header information (which in the case "Customer") along with the parameter Value information.

Key Entity public class Chave implements Serializable{

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer chaveId; 
private String identificador;

Entity Value

public class Valor implements Serializable{

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long valorId;
private String valorDescricao;
@ManyToOne
@JoinColumn(name = "chave_id")
private Chave chave;
@ManyToOne
@JoinColumn(name = "atendimento_id")
private Atendimento atendimento;
@ManyToOne
@JoinColumn(name = "cliente_id")
private Cliente cliente;
@ManyToOne
@JoinColumn(name = "prestador_id")
private Prestador prestador;
@JsonFormat(pattern = "HH:mm dd/MM/yyyy")
private LocalDateTime dataCriacao;
@ManyToOne
@JoinColumn(name = "documento_id")
private Documento documento;
@Enumerated(EnumType.STRING)
private Status status;
@ManyToOne
@JoinColumn(name = "sequencia_id")
private Sequencia sequencia;

The method I did to create the form was: for each key and value of the parameter, I would have to save the information in its entities as mentioned above

Form rule to save:

public Formulario createFormulario(Formulario formulario) {
    //sequencia ok
    ChaveRequest chaveRequest = new ChaveRequest();
    ValorRequest valorRequest = new ValorRequest();
    SequenciaRequest sequenciaRequest = new SequenciaRequest();
    Long sequenciaRetorno = sequenciaController.createSequencia(sequenciaRequest);
    System.out.println(sequenciaRetorno);
    //interar parametros
    Map<String, Object> parametros = new HashMap<String, Object>();
    parametros = this.getParametro(formulario.getParametros());
    parametros.forEach((key, value) -> {
        //chave
        chaveRequest.setIdentificador(key);
        Long idChave = chaveController.createChave(chaveRequest);
        //valor
        valorRequest.setValorDescricao((String) value);
        valorRequest.getChave().setChaveId(idChave);
        valorRequest.getAtendimento().setAtendimentoId(formulario.getAtendimento().getAtendimentoId());
        valorRequest.getCliente().setClienteId(formulario.getCliente().getClienteId());
        valorRequest.getPrestador().setPrestadorId(formulario.getPrestador().getPrestadorId());
        valorRequest.getDocumento().setDocumentoId(formulario.getDocumento().getDocumentoId());
        valorRequest.getSequencia().setSequenciaId(sequenciaRetorno);
        valorController.createValor(valorRequest);
    });



enter code here

in the first line in (ValorRequest.setValorDescricao((String) value); it works fine, but after it I'm having a lambda error if it's complicated, please let me know to try to improve the explanation as much as possible.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source