package com.napa.pulse.service.impl; import com.napa.pulse.dto.ClientDataDTO; import com.napa.pulse.dto.VinRequestDTO; import com.napa.pulse.dto.VinResponseDTO; import com.napa.pulse.service.interfaces.VinService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @Service public class VinServiceImpl implements VinService { private static final Logger LOGGER = LoggerFactory.getLogger(VinServiceImpl.class); @Value("${nicap.service.url}") private String nicapServiceUrl; @Value("${nicap.application.id}") private String applicationId; @Value("${nicap.store.id}") private String storeId; final RestTemplate restTemplate = new RestTemplate(); @Override public VinResponseDTO getVinInformation(String vin) { ResponseEntity response; try { VinRequestDTO request = new VinRequestDTO(); ClientDataDTO clientData = new ClientDataDTO(); clientData.setCulture("en-us"); clientData.setClientId("1234567890"); clientData.setApplicationId(applicationId); clientData.setStoreId(storeId); request.setClientData(clientData); request.setVin(vin); response = restTemplate.postForEntity(nicapServiceUrl, request, VinResponseDTO.class); if (response.getStatusCode().is2xxSuccessful()) { return response.getBody(); } } catch (Exception e) { LOGGER.error("Invalid respose for NICAP service: ", e); } return null; } }