Coder Social home page Coder Social logo

jsr354-ri-bp's Introduction

JSR 354: Money and Currency API

Maven Central CircleCI Coverage Status Stability: Maintenance Join the chat at https://gitter.im/JavaMoney/jsr354-api

JSR 354 provides an API for representing, transporting, and performing comprehensive calculations with Money and Currency. See the home page for more details: http://jcp.org/en/jsr/detail?id=354

This is the API module of JSR 354 licenced under

  • the Apache License Version 2.0 (LICENCE.txt)

See also: http://javamoney.github.io/

Release Notes

  • 1.0 API as defined by JSR 354 Spec.
  • 1.0.1 API as defined by JSR 354 Spec (Fix: building Java 7 API with Java 7)
  • 1.0.2 API as defined by JSR 354 Spec (Fix: built with Java 9) - dont use, use 1.0.3 instead!
  • 1.0.3 API as defined by JSR 354 Spec (Compatible with Java 8, full Java 9 module support)
  • 1.1 API as defined by JSR 354 MR 1.

Built with Maven

jsr354-ri-bp's People

Contributors

acelopezco avatar alexanderyastrebov avatar atsticks avatar heli80 avatar keilw avatar lukasniemeier-zalando avatar mearman avatar sgrimm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsr354-ri-bp's Issues

Discuss future support for backport

I think it is enough to support Java 8 in the future. Java 7 based release is still in place and if somebody like to take it up and maintain it, feel free to do so. If somebody wants to take over this responsibility (and has time end need to do so), I would be very happy.

Historical Exchange Rates

I can't seem to get historical rates to work. I've tried a bunch of variations, but I either get the current exchange rate or this exception:

CurrencyConversionException [base=USD, term=CAD, conversionContext=null]: Cannot convert USD into CAD: All delegate prov iders failed to deliver rate, providers=[org.javamoney.moneta.internal.convert.IdentityRateProvider@3b088d51, org.javamoney.moneta.internal.convert.ECBCurrentRateProvider{ context: ProviderContext (
{rateTypes=[DEFERRED], providerDescription=European Central Bank, days=1, provider=ECB})}, org.javamoney.moneta.internal.convert.IMFRateProvider{ context: ProviderContext (
{rateTypes=[DEFERRED], providerDescription=International Monetary Fond, days=1, provider=IMF})}, org.javamoney.moneta.internal.convert.IMFHistoricRateProvider{ context: ProviderContext (
{rateTypes=[HISTORIC], providerDescription=Historic International Monetary Fond, days=0, provider=IMF-HIST})}, org.javamoney.moneta.internal.convert.ECBHistoricRateProvider{ context: ProviderContext (
{rateTypes=[DEFERRED, HISTORIC], providerDescription=European Central Bank, days=1500, provider=ECB-HIST})}, org.javamoney.moneta.internal.convert.ECBHistoric90RateProvider{ context: ProviderContext (
{rateTypes=[DEFERRED, HISTORIC], providerDescription=European Central Bank (last 90 days), days=90, provider=ECB-HIST90})}], query=ConversionQuery (
{Query.termCurrency=CAD, Query.baseCurrency=USD, java.time.LocalDate=2000-01-01})
	at org.javamoney.moneta.spi.CompoundRateProvider.getExchangeRate(CompoundRateProvider.java:121)
	at com.github.ryanholdren.portfolio.utilities.CurrencyTest.test(CurrencyTest.java:27)
	...

Here is an example of one of my attempts:

import java.time.LocalDate;
import static java.time.Month.JANUARY;
import javax.money.convert.ConversionQuery;
import javax.money.convert.ConversionQueryBuilder;
import javax.money.convert.ExchangeRate;
import javax.money.convert.ExchangeRateProvider;
import static javax.money.convert.MonetaryConversions.getExchangeRateProvider;
import org.junit.Test;
import org.springframework.util.Assert;

public class ExchangeRateTest {
	@Test
	public void test() {
		final ConversionQuery query = ConversionQueryBuilder.of()
			.setBaseCurrency("USD")
			.setTermCurrency("CAD")
			.set(LocalDate.class, LocalDate.of(2000, JANUARY, 1))
			.build();
		final ExchangeRateProvider provider = getExchangeRateProvider(query);
		final ExchangeRate rate = provider.getExchangeRate(query);
		Assert.notNull(rate);
	}
}

CurrencyConversionException using exchange rate providers

See #JavaMoney/jsr354-ri/161 :

I tried to convert a currency using the following piece of code:

final MonetaryAmount inEuro = Money.of(10, "EUR");
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
final MonetaryAmount inDollar = inEuro.with(dollarConversion);
System.out.println(String.format("%s: %s โ‰™ %s", rateProvider, inEuro, inDollar));

The result was the following exception:

Exception in thread "main" CurrencyConversionException [base=EUR, term=null, conversionContext=null]: Cannot convert EUR into null
	at org.javamoney.moneta.spi.AbstractCurrencyConversion.apply(AbstractCurrencyConversion.java:109)
	at org.javamoney.moneta.Money.with(Money.java:377)
	at org.javamoney.moneta.Money.with(Money.java:58)
	at CurrencyConversionDemo.main(CurrencyConversionDemo.java:34)

From my point of view this code should work.

Better align JDK8 and BP version for future updates

There were several minor improvements done in the JDK8 version, which were not ported to the backport version. All trivial changes should be backported, so the codebases overall are better aligned.
Deprecated artifacts of the RI should NOT be introduced in the backport hereby.

Remove deprecated elements

Between Moneta 1.1 and 1.3 there was enough time to switch from deprecated elements to their new equivalent, especially in the Conversion module/package. The old elements shall be removed with 1.4 as part of JSR 354 MR 1.

CurrencyConversionException

MonetaryAmount oneDollar = Monetary.getDefaultAmountFactory().setCurrency("USD")
.setNumber(1).create();

		    CurrencyConversion conversionEUR = MonetaryConversions.getConversion("EUR");

		    MonetaryAmount convertedAmountUSDtoEUR = oneDollar.with(conversionEUR);

Thousand separator (space) not working when parsing

Hello
The french thousand separator is the space character. When you parse a money amount with currency from a string it doesn't work !!

See this test case for example :

@Test
public void testParseKO() {
    MonetaryAmountFormat format = MonetaryFormats
            .getAmountFormat(AmountFormatQueryBuilder.of(Locale.FRANCE)
                    .set(CurrencyStyle.CODE)
                    .build());
    MonetaryAmount amountOk = format.parse("123,01 EUR");
    MonetaryAmount amountKo = format.parse("14 000,12 EUR");
    assertThat(amountOk.getNumber().doubleValueExact()).isEqualTo(123.01); // OK
    assertThat(amountKo.getNumber().doubleValueExact()).isEqualTo(14000.12); // KO
}

Package name wrong

Hi,

We must not use the exact same package name "org.javamoney.moneta" in two places. Though it would sound appealing, but an exact drop-in replacement without at least changing imports just isn't possible.
JSR 310 may have a lot of nasty mistakes (like circular dependencies, redundancies, etc.) but the BP was done properly so far in a
package org.threeten.bp;

310 is an utter mix of API and RI, in fact the API is hidden in its "temporal" sub-package, so we should do the same for API and Implementation. Either:
org.javamoney.bp.impl;
if the repository was something like "javamoney-impl-bp"
or
org.javamoney.moneta.bp;
if we go for "javamoney-moneta-bp" (or just "moneta-bp")

A third option would be
org.javamoney.bp.moneta;

WDYT?

Loading of IMF remote conversion data fails

See #JavaMoney/jsr354-ri/issues/164 :

Loading of IMF conversion data actually fails (class org.javamoney.moneta.internal.loader.LoadableResource): with a default html response of "Request rejected". Interestingly calling the same URL from a browser, e.g. chrome works:

http://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y

As a result the IMF and IMF-HIST rate provider fails to load because the response is a valid input stream, which unfortunately is not parsable to any conversion rates.

I did not check, if the behaviour in the backport is similar.

Project name misleading

While the API equivalent is called "javamoney-api-bp" the term "jsr354-ri" in this one is misleading.
I suggest either calling it "javamoney-impl-bp" (IMPL not RI, as there can only be one RI) or "moneta-bp" (since Moneta is the codename used for the RI, but it's more like "threeten" for JSR-310, we are free to call it "javamoney-moneta-bp" or "moneta-bp" but should not call it "ri-bp")

Loading of IMF conversion data actually fails

See #JavaMoney/jsr354-ri/issues/164 :

Loading of IMF conversion data actually fails (class org.javamoney.moneta.internal.loader.LoadableResource): with a default html response of "Request rejected". Interestingly calling the same URL from a browser, e.g. chrome works:

http://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y

As a result the IMF and IMF-HIST rate provider fails to load because the response is a valid input stream, which unfortunately is not parsable to any conversion rates.

I did not check, if the behaviour in the backport is similar.

Backport unable to parse valid currencies

When testing #46 with other locales also using spaces to separate large numbers, it fails for certain countries/locales the same way, while others show a different problem:

FAILED: testParseDK
javax.money.MonetaryException: Error parsing CurrencyUnit.
	at org.javamoney.moneta.internal.format.CurrencyToken.parse(CurrencyToken.java:226)
	at org.javamoney.moneta.internal.format.DefaultMonetaryAmountFormat.parse(DefaultMonetaryAmountFormat.java:192)
	at org.javamoney.moneta.format.MonetaryFormatsTest.testParseDK(MonetaryFormatsTest.java:39)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
	at org.testng.TestRunner.privateRun(TestRunner.java:746)
	at org.testng.TestRunner.run(TestRunner.java:600)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
	at org.testng.SuiteRunner.run(SuiteRunner.java:268)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1189)
	at org.testng.TestNG.runSuites(TestNG.java:1104)
	at org.testng.TestNG.run(TestNG.java:1076)
	at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: UnknownCurrencyException [currencyCode=]
	at org.javamoney.moneta.spi.base.BaseMonetaryCurrenciesSingletonSpi.getCurrency(BaseMonetaryCurrenciesSingletonSpi.java:53)
	at javax.money.Monetary.getCurrency(Monetary.java:128)
	at org.javamoney.moneta.internal.format.CurrencyToken.parse(CurrencyToken.java:194)

DKK is a perfectly valid currency code and recognized in the Java 8+ Moneta RI.

Error loading javamoney.properties, ignoring jar:file

When adding org.javamoney:moneta:1.3 to the classpath I get the following error on start:

SEVERE: Error loading javamoney.properties, ignoring jar:file:~/.m2/repository/org/javamoney/moneta-bp/1.1/moneta-bp-1.1.jar!/javamoney.properties
java.lang.IllegalStateException: AmbiguousConfiguration detected for 'load.ECBHistoricRateProvider.resource'.

Running with Java 1.8.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.