Skip to content

Commit adc5e1f

Browse files
committed
Working on #353
1 parent 655cdce commit adc5e1f

28 files changed

+109
-69
lines changed

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/ECBCurrentRateProvider.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import java.util.HashMap;
2828
import java.util.Map;
2929

30+
import static org.javamoney.moneta.convert.ecb.defaults.Defaults.ECB_CURRENT_FALLBACK_PATH;
31+
import static org.javamoney.moneta.convert.ecb.defaults.Defaults.ECB_CURRENT_URL;
32+
3033
/**
3134
* This class implements an {@link javax.money.convert.ExchangeRateProvider} that loads data from
3235
* the European Central Bank data feed (XML). It loads the current exchange
@@ -68,8 +71,8 @@ protected LoadDataInformation getDefaultLoadData() {
6871
.withResourceId(getDataId())
6972
.withUpdatePolicy(LoaderService.UpdatePolicy.SCHEDULED)
7073
.withProperties(props)
71-
.withBackupResource(URI.create("org/javamoney/moneta/convert/ecb/defaults/eurofxref-daily.xml"))
72-
.withResourceLocations(URI.create("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"))
74+
.withBackupResource(URI.create(ECB_CURRENT_FALLBACK_PATH))
75+
.withResourceLocations(URI.create(ECB_CURRENT_URL))
7376
.withStartRemote(true)
7477
.build();
7578
}

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/ECBHistoric90RateProvider.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
2+
* Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -26,6 +26,9 @@
2626
import java.util.HashMap;
2727
import java.util.Map;
2828

29+
import static org.javamoney.moneta.convert.ecb.defaults.Defaults.ECB_HIST90_FALLBACK_PATH;
30+
import static org.javamoney.moneta.convert.ecb.defaults.Defaults.ECB_HIST90_URL;
31+
2932
/**
3033
* <p>
3134
* This class implements an {@link javax.money.convert.ExchangeRateProvider}
@@ -72,8 +75,8 @@ protected LoadDataInformation getDefaultLoadData() {
7275
.withResourceId(getDataId())
7376
.withUpdatePolicy(LoaderService.UpdatePolicy.SCHEDULED)
7477
.withProperties(props)
75-
.withBackupResource(URI.create("org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist-90d.xml"))
76-
.withResourceLocations(URI.create("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml"))
78+
.withBackupResource(URI.create(ECB_HIST90_FALLBACK_PATH))
79+
.withResourceLocations(URI.create(ECB_HIST90_URL))
7780
.withStartRemote(true)
7881
.build();
7982
}

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/ECBHistoricRateProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
2+
* Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -60,7 +60,6 @@ public class ECBHistoricRateProvider extends ECBAbstractRateProvider {
6060
ProviderContextBuilder.of("ECB-HIST", RateType.HISTORIC, RateType.DEFERRED)
6161
.set("providerDescription", "European Central Bank").set("days", 1500).build();
6262

63-
6463
public ECBHistoricRateProvider() {
6564
super(CONTEXT);
6665
}

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/ECBRateReadingHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2+
* Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -51,6 +51,7 @@
5151
* currency="LTL" rate="3.4528"/> ...
5252
*
5353
* @author Anatole Tresch
54+
* @author Werner Keil
5455
* @author otaviojava
5556
*/
5657
class ECBRateReadingHandler extends DefaultHandler {
@@ -124,5 +125,4 @@ void addRate(CurrencyUnit term, LocalDate localDate, Number rate) {
124125
}
125126
rateMap.put(term.getCurrencyCode(), exchangeRate);
126127
}
127-
128128
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.javamoney.moneta.convert.ecb.defaults;
2+
/** This class is necessary to declare the "defaults" package using just for resources */
3+
public final class Defaults {
4+
private Defaults() {}
5+
6+
public static final String ECB_CURRENT_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
7+
public static final String ECB_CURRENT_FALLBACK_PATH = "org/javamoney/moneta/convert/ecb/defaults/eurofxref-daily.xml";
8+
9+
public static final String ECB_HIST90_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml";
10+
11+
public static final String ECB_HIST90_FALLBACK_PATH = "org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist-90d.xml";
12+
13+
}

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/defaults/DummyClass.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

moneta-convert/moneta-convert-imf/src/main/java/org/javamoney/moneta/convert/imf/IMFAbstractRateProvider.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2012, 2018, Anatole Tresch, Werner Keil and others by the @author tag.
2+
Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
33
44
Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
use this file except in compliance with the License. You may obtain a copy of
@@ -51,7 +51,6 @@
5151

5252
abstract class IMFAbstractRateProvider extends AbstractRateProvider implements LoaderListener {
5353

54-
5554
private static final Logger LOG = Logger.getLogger(IMFAbstractRateProvider.class.getName());
5655

5756
static final Comparator<ExchangeRate> COMPARATOR_EXCHANGE_BY_LOCAL_DATE = Comparator.comparing(c -> c.getContext().get(LocalDate.class));
@@ -134,11 +133,11 @@ public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
134133
if (!isAvailable(conversionQuery)) {
135134
return null;
136135
}
137-
CurrencyUnit base = conversionQuery.getBaseCurrency();
138-
CurrencyUnit term = conversionQuery.getCurrency();
139-
LocalDate[] times = getQueryDates(conversionQuery);
140-
ExchangeRate rate1 = getExchangeRate(currencyToSdr.get(base), times);
141-
ExchangeRate rate2 = getExchangeRate(sdrToCurrency.get(term), times);
136+
final CurrencyUnit base = conversionQuery.getBaseCurrency();
137+
final CurrencyUnit term = conversionQuery.getCurrency();
138+
LocalDate[] dates = getQueryDates(conversionQuery);
139+
ExchangeRate rate1 = getExchangeRate(currencyToSdr.get(base), dates);
140+
ExchangeRate rate2 = getExchangeRate(sdrToCurrency.get(term), dates);
142141
if (base.equals(SDR)) {
143142
return rate2;
144143
} else if (term.equals(SDR)) {
@@ -185,8 +184,8 @@ private ExchangeRate getExchangeRate(List<ExchangeRate> rates,final LocalDate[]
185184
return exchangeRateOptional.get();
186185
}
187186
}
188-
String datesOnErros = Stream.of(dates).map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE)).collect(Collectors.joining(","));
189-
throw new MonetaryException("There is not exchange on day " + datesOnErros + " to rate to rate on IFMRateProvider.");
187+
final String datesOnErrors = Stream.of(dates).map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE)).collect(Collectors.joining(","));
188+
throw new MonetaryException("There is not exchange on day " + datesOnErrors + " to rate to rate on IFMRateProvider.");
190189
}
191190
}
192191

@@ -195,5 +194,4 @@ public String toString() {
195194
return getClass().getName() + '{' +
196195
" context: " + context + '}';
197196
}
198-
199197
}

moneta-convert/moneta-convert-imf/src/main/java/org/javamoney/moneta/convert/imf/IMFHistoricalType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2+
Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
33
44
Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
use this file except in compliance with the License. You may obtain a copy of
@@ -18,13 +18,13 @@
1818
import java.time.YearMonth;
1919
import java.util.Objects;
2020

21+
import static org.javamoney.moneta.convert.imf.defaults.Defaults.*;
22+
2123
enum IMFHistoricalType {
22-
SDR_Currency("SDRCV"), Currency_SDR("CVSDR");
24+
SDR_Currency(SCRCV), Currency_SDR(CVSDR);
2325

2426
private final String type;
2527

26-
private static final String HOST = "https://www.imf.org/external/np/fin/data/rms_mth.aspx?SelectDate=%s&reportType=%s&tsvflag=Y";
27-
2828
IMFHistoricalType(String type) {
2929
this.type = type;
3030
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.javamoney.moneta.convert.imf.defaults;
2+
/** This class is necessary to declare the "defaults" package using just for resources */
3+
public final class Defaults {
4+
private Defaults() {}
5+
6+
//public static final String DIGIT_FRACTION = "ecb.digit.fraction"
7+
8+
public static final String HOST = "https://www.imf.org/external/np/fin/data/rms_mth.aspx?SelectDate=%s&reportType=%s&tsvflag=Y";
9+
10+
public static final String CVSDR = "CVSDR";
11+
12+
public static final String SCRCV = "SDRCV";
13+
}

moneta-convert/moneta-convert-imf/src/main/java/org/javamoney/moneta/convert/imf/defaults/DummyClass.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)