Package org.cyclos.impl.banking
Interface RateHandler
-
public interface RateHandlerService interface for rates. This service contains all common rates methods. The methods are not specific for a particular rate, but apply for all rates enabled. Methods particular for specific rates are delegated toRateTypeHandlerand its child classes.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends Transfer>
voidapplyTransfer(T transfer)Applies a transfer, that is: gets the rate from the fromAccount sets those to the transfer gets the rate of the toAccount merges transfer and toAccount Rates persists from rates if changed due to creation persists to account rates.voidcopy(RatedEntity source, RatedEntity destination)copies all rate fields from one RatedEntity to another.voidcopy(HasRates source, HasRates destination)Copies rate fields from one HasRates to another.AccountRatesgetCurrent(Account account)Returns the currentAccountRatesfrom the given accountFromRatesDatagetFromRates(Account fromAccount, TransferType transferType, BigDecimal amount, Date date, RateVisibility visibility)gets the future rates of a from account that will be after the transaction has been applied.RatesDatagetRates(Account account, BigDecimal balance, Date time, RateVisibility visibility)AsgetRates(Account, RateVisibility), but uses a time and a balance as argument.RatesDatagetRates(Account account, RateVisibility visibility)gets the rates of the account on the given date, according to the RateVisibility param.booleanisAnyRateEnabled(Currency currency, Date time)Checks if any rate is enabled on the given date/time and for the given currency.booleanisVisible(Collection<Currency> currencies, Date date)Determines if any of the given currencies have any rate visible to users.voidresetCurrency(Currency entity)Resets the currency entity to its RateParameters.voidresolveValidator(Validator validator, CurrencyDTO dto)gets the nested validator for the currency's rateparameters.voidsetRateParametersToCurrencyDTO(CurrencyDTO result)sets the RateParameters correctly to the currencyDTO, by: gets the specific RateParametersDTO from the CurrencyDTO if it exists, sets theenabledOnFormproperty of the RateParametersDTO to true.voidtoEntity(Currency target, CurrencyDTO dto)sets the RateParameters entities to the Currency entity
-
-
-
Method Detail
-
applyTransfer
<T extends Transfer> void applyTransfer(T transfer) throws FrameworkException
Applies a transfer, that is:- gets the rate from the fromAccount
- sets those to the transfer
- gets the rate of the toAccount
- merges transfer and toAccount Rates
- persists from rates if changed due to creation
- persists to account rates.
- Parameters:
transfer- the transfer to be applied.- Throws:
FrameworkException
-
copy
void copy(HasRates source, HasRates destination) throws FrameworkException
Copies rate fields from one HasRates to another.- Throws:
FrameworkException
-
copy
void copy(RatedEntity source, RatedEntity destination)
copies all rate fields from one RatedEntity to another.
-
getCurrent
AccountRates getCurrent(Account account)
Returns the currentAccountRatesfrom the given account
-
getFromRates
FromRatesData getFromRates(Account fromAccount, TransferType transferType, BigDecimal amount, Date date, RateVisibility visibility)
gets the future rates of a from account that will be after the transaction has been applied. It takes into account:
* null rates are replaced by init values
* if the balance isn't sufficient creation values are applied for the unsufficient part, and the rateBalanceCorrection and virtualRatedBalance are updated. In this case,FromRatesData.changedDueToCreationis set to true. This does NOT happen in case of an unlimited account.
* transfer type defaults are applied if needed.
* maturity policy other than always may result in transfer rates and from account rates that differ from each other. Under normal circumstances from account rates and transfer rates are always equal, but maturity policy other than aALWAYS may enforce a zero D-rate on the transfer, thus leaving the from account with a higher D. This is reflected in the special fields of the FromRatesData.- Parameters:
fromAccount- the account which is the from account of the transfertransferType- the transfertype of the transferamount- the transfer amountdate- the processing date of the transfer; if null, now is used.visibility- the visibility to be applied. This is usually RateVisibility.PARAMS in case the result is to be shown directly to users, or RateVisibility.ALL in case it is further processed in a transfer.
-
getRates
RatesData getRates(Account account, BigDecimal balance, Date time, RateVisibility visibility) throws FrameworkException
AsgetRates(Account, RateVisibility), but uses a time and a balance as argument. This version is typically used to retrieve historical rates, usually from loops where the balance is calculated for each step.- Throws:
FrameworkException
-
getRates
RatesData getRates(Account account, RateVisibility visibility) throws FrameworkException
gets the rates of the account on the given date, according to the RateVisibility param. All fields are updated, also virtualRatedBalance and RateBalanceCorrection. Always returns a non null result, even when no rates available. Fields of rates not visible or not enabled are null.
Uses the present date (now) as date. Internally, it callsgetRates(account, null, DateHelper.now(), visibility).- Parameters:
account- the account. May not be nullvisibility-- Throws:
FrameworkException
-
isAnyRateEnabled
boolean isAnyRateEnabled(Currency currency, Date time) throws FrameworkException
Checks if any rate is enabled on the given date/time and for the given currency.- Returns:
- false if no rate at all is enabled, otherwise true.
- Throws:
FrameworkException
-
isVisible
boolean isVisible(Collection<Currency> currencies, Date date)
Determines if any of the given currencies have any rate visible to users.
-
resetCurrency
void resetCurrency(Currency entity) throws FrameworkException
Resets the currency entity to its RateParameters. This is needed after saving a transient currency.- Throws:
FrameworkException
-
resolveValidator
void resolveValidator(Validator validator, CurrencyDTO dto) throws FrameworkException
gets the nested validator for the currency's rateparameters.- Throws:
FrameworkException
-
setRateParametersToCurrencyDTO
void setRateParametersToCurrencyDTO(CurrencyDTO result) throws FrameworkException
sets the RateParameters correctly to the currencyDTO, by:- gets the specific RateParametersDTO from the CurrencyDTO
- if it exists, sets the
enabledOnFormproperty of the RateParametersDTO to true. This is needed for a correct handling on the currency details form.
- Throws:
FrameworkException
-
toEntity
void toEntity(Currency target, CurrencyDTO dto) throws FrameworkException
sets the RateParameters entities to the Currency entity- Parameters:
target- the Currency entity to which the RateParameters must be setdto- the CurrencyDTO from which the currency was retrieved, and which is used to read the RateParametersDTO- Throws:
FrameworkException
-
-