diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index 3c8a0bf..5aac64f 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: BCV Exchange Rate Plugin Bundle-SymbolicName: com.venezuela.bcvrate;singleton:=true -Bundle-Version: 1.0.14 +Bundle-Version: 1.0.15 Bundle-Vendor: Ezerpa Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-ActivationPolicy: lazy diff --git a/src/com/venezuela/bcvrate/service/BCVApiService.java b/src/com/venezuela/bcvrate/service/BCVApiService.java index ac918c2..dd75873 100644 --- a/src/com/venezuela/bcvrate/service/BCVApiService.java +++ b/src/com/venezuela/bcvrate/service/BCVApiService.java @@ -31,8 +31,25 @@ public class BCVApiService { public BCVRateResponse getRateForDateWithFallback(String requestedDate) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar cal = Calendar.getInstance(); + log.info("Buscando tasa para fecha solicitada: " + requestedDate); + + log.info("Intentando scraping BCV website..."); + BCVRateResponse websiteRate = getRateFromBCVWebsite(); + if (websiteRate != null && websiteRate.isValid()) { + String scrapedEffectiveDate = websiteRate.getDate(); + if (!scrapedEffectiveDate.equals(requestedDate)) { + log.info("Scraping BCV: tasa del " + scrapedEffectiveDate + + " aplica para " + requestedDate); + } else { + log.info("Scraping BCV: tasa del " + scrapedEffectiveDate + + " coincide con fecha solicitada"); + } + return new BCVRateResponse(websiteRate.getDollar(), requestedDate, scrapedEffectiveDate); + } + + log.info("Scraping BCV no disponible, buscando en API hacia atras..."); + Calendar cal = Calendar.getInstance(); try { cal.setTime(sdf.parse(requestedDate)); } catch (Exception e) { @@ -55,15 +72,7 @@ public class BCVApiService { cal.add(Calendar.DAY_OF_MONTH, -1); } - log.info("API no tiene tasa para " + requestedDate + ", intentando scraping BCV..."); - BCVRateResponse websiteRate = getRateFromBCVWebsite(); - if (websiteRate != null && websiteRate.isValid()) { - log.info("Tasa obtenida del sitio web BCV: USD=" + websiteRate.getDollar() - + " effective=" + websiteRate.getDate()); - return new BCVRateResponse(websiteRate.getDollar(), requestedDate, websiteRate.getDate()); - } - - log.info("No se encontro tasa en los ultimos " + MAX_DAYS_BACK + " dias para: " + requestedDate); + log.info("No se encontro tasa para: " + requestedDate); return null; }