Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. @Override
  2. public EquiposFactiblesCompraResponse obtenerFactibilidadEquiposCompra(FactibilidadRequest factibilidadRequest) {
  3. EquiposFactiblesCompraResponse response = new EquiposFactiblesCompraResponse();
  4. response.getRespuesta().setCodigo("NOK");
  5. response.getRespuesta().setMensaje("No se obtuvieron los equipos con factibilidad Trade In");
  6. LOG.info("INICIO obtenerFactibilidadEquiposCompra");
  7. try {
  8. HttpHeaders headers = new HttpHeaders();
  9. headers.setContentType(MediaType.APPLICATION_JSON);
  10. HttpEntity<FactibilidadRequest> req = new HttpEntity<>(factibilidadRequest, headers);
  11.  
  12. RestTemplate restTemplate = getRestTemplate();
  13.  
  14. String urlBFF = factibilidadMapper.getUrlBFF("URL_BFF_MOBILE", "ENDPOINT");
  15. LOG.info("pathServidor {} ", urlBFF);
  16. ResponseEntity<ModelosTradeInResponse> resp = restTemplate.exchange(urlBFF + ConstantesCompraInteligente.URL_EQUIPOS_FACTIBLES_COMPRA , HttpMethod.PUT, req, ModelosTradeInResponse.class);
  17. ModelosTradeInResponse modelosTradeInResponse = resp.getBody();
  18. List<ModeloTradeIn> modeloTradeInList = new ArrayList<>();
  19. for (int i = 0; i < modelosTradeInResponse.getEquiposFactibles().size(); i++) {
  20. Integer codNombreGenerico = modelosTradeInResponse.getEquiposFactibles().get(i)
  21. .getCodigoNombreGenerico();
  22. Integer idMarca = modelosTradeInResponse.getEquiposFactibles().get(i)
  23. .getIdMarca();
  24. Integer skuProducto = modelosTradeInResponse.getEquiposFactibles().get(i)
  25. .getSkuProducto();
  26. String tier1 , tier2, tier3;
  27. tier1 = tier2 = tier3 = "";
  28. tier1 = modelosTradeInResponse.getEquiposFactibles().get(i).getTier1();
  29. tier2 = modelosTradeInResponse.getEquiposFactibles().get(i).getTier2();
  30. tier3 = modelosTradeInResponse.getEquiposFactibles().get(i).getTier3();
  31. ModeloTradeIn modeloTradeIn = factibilidadMapper.getModeloTradeIn(codNombreGenerico, idMarca);
  32. List<ColorEquipo> colorEquipos = factibilidadMapper.getCodHexaDecimalBySkuProducto(skuProducto);
  33. if (modeloTradeIn != null) {
  34. boolean modeloExist = false;
  35. if(modeloTradeInList.size() == 0) {
  36. modeloTradeIn.setColores(colorEquipos);
  37. modeloTradeIn.setValorTier1(tier1 == null ? 0 : Integer.parseInt(tier1.substring(1).replace(".","")));
  38. modeloTradeIn.setValorTier2(tier2 == null ? 0 : Integer.parseInt(tier2.substring(1).replace(".","")));
  39. modeloTradeIn.setValorTier3(tier3 == null ? 0 : Integer.parseInt(tier3.substring(1).replace(".","")));
  40. modeloTradeInList.add(modeloTradeIn);
  41. }else {
  42. for(int j = 0; j < modeloTradeInList.size(); j++) {
  43. if(modeloTradeIn.getNombreGenerico().equals(modeloTradeInList.get(j).getNombreGenerico())) {
  44. modeloTradeInList.get(j).getColores().addAll(colorEquipos);
  45. modeloExist = true;
  46. }
  47. }
  48. if(modeloExist) {
  49. modeloTradeIn.setColores(colorEquipos);
  50. modeloTradeIn.setValorTier1(tier1 == null ? 0 : Integer.parseInt(tier1.substring(1).replace(".","")));
  51. modeloTradeIn.setValorTier2(tier2 == null ? 0 : Integer.parseInt(tier2.substring(1).replace(".","")));
  52. modeloTradeIn.setValorTier3(tier3 == null ? 0 : Integer.parseInt(tier3.substring(1).replace(".","")));
  53. modeloTradeInList.add(modeloTradeIn);
  54. }
  55. }
  56. }
  57. }
  58. response.setModelos(modeloTradeInList);
  59. response.getRespuesta().setCodigo(modelosTradeInResponse.getRespuesta().getCodigo());
  60. response.getRespuesta().setMensaje(modelosTradeInResponse.getRespuesta().getMensaje());
  61. LOG.info("response {} ", response.toString());
  62.  
  63. } catch (Exception e) {
  64. LOG.error("[Exception] Error en obtenerFactibilidadEquiposCompra", e);
  65. response.getRespuesta().setCodigo("NOK");
  66. response.getRespuesta().setMensaje("Ha ocurrido un error al consultar los equipos con factibilidad Trade In");
  67. }
  68. LOG.info("FIN obtenerFactibilidadEquiposCompra");
  69. return response;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement