0

this question is for Spring java. I have a problem with the bunches of If statements: Actually I have two pojos in a service layer.

I get the field from one pojo. If this field contains info, I'll set the response to the other pojom passing through an especific decrypt method.

Original Example:

if (clReq.getIdCliente() != null && clReq.getIdCliente().trim().equals("")) {

entity.setFiId(Integer.valueOf(RijndaelCrypto.decrypt(clReq.getIdCliente(), IV, this.privateKey)));

} else {

throw new ClientesBOException("3-FALTA DATOS REQUERIDOS-ERROR");
}

Example 2: I reduce the main condition in an external method:

if (validaCha(clReq.getIdCliente())) {
entity.setFiId(Integer.valueOf(RijndaelCrypto.decrypt(clReq.getIdCliente(), IV, this.privateKey)));         
}

External Method:

public static final boolean validaCha(String val) throws ClientesBOException {  
    if(StringUtils.isBlank(val)) {
       throw new ClientesBOException("ERROR!, Mandatory data missing");    
    }     
    return true;     
  }

The main problem!! The pojo contains 30 fields. I must validate each field, because the Decryption. Now I have this 30 times, with different attributes.

     if (validaCha(clReq.getIdCliente())) {      
 entity.setFiId(Integer.valueOf(RijndaelCrypto.decrypt(clReq.getIdCliente(), IV, this.privateKey)));         
          }

I´m looking for help. I read about make the condition inside set methods from entity pojo. Use Map. Use patterns. Finally I dont find the light

Thanks!!!!!!

0 Answers0