Package org.cyclos.impl.banking
Class RateHandlerImpl
- java.lang.Object
-
- org.cyclos.impl.AbstractServerComponent
-
- org.cyclos.impl.AbstractNetworkedServerComponent
-
- org.cyclos.impl.BaseServiceImpl
-
- org.cyclos.impl.banking.RateHandlerImpl
-
- All Implemented Interfaces:
RateHandler,RateHandlerTestable
@Service public class RateHandlerImpl extends BaseServiceImpl implements RateHandlerTestable
Implementation for RateService; common methods used for any rate type go here. Calls for specific rate types are delegated toRateTypeHandlerchildren.
-
-
Field Summary
-
Fields inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
authHandler, conversionHandler, customFieldValueHandler, entityManagerHandler, groupsHandler, productsHandler, restBeanPropertyMapping, userLocatorHandler
-
Fields inherited from class org.cyclos.impl.AbstractServerComponent
accountHandler, configurationHandler, dataTranslationHandler, notificationHandler, profileFieldHandler, transactionHandler, translationHandler
-
-
Constructor Summary
Constructors Constructor Description RateHandlerImpl()
-
Method Summary
All Methods Instance Methods Concrete 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.AccountRatesgetAccountRatesEntity(Account account, Date time)gets the AccountRates entity from the account.DategetEnableDate(Currency currency, Date requestedDate)gets the earliest date of first enabling of any rate type.FromRatesDatagetFromRates(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)AsRateHandler.getRates(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.Set<RateType>getVisibleRates(Account account, Date time, RateVisibility visibility)determines if any rate is visible according to the setting of the visibility parameters.booleanisAnyRateEnabled(Currency currency, Date time)Checks if any rate is enabled on the given date/time and for the given currency.booleanisVisible(Currency currency, Date date)Determines if any rate is to be shown to users.voidpersist(RatedAccountEntity rates, Account account, Date time)protected voidregisterNetworkMappings(NetworkPathRegistry networkPathRegistry)Needs to be overridden by subclasses to register the path up to the networkvoidresetCurrency(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-
Methods inherited from class org.cyclos.impl.BaseServiceImpl
initializeNetworkMappings
-
Methods inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
canManage, checkManagesUser, checkPermission, checkRelatesToUser, checkValue, clearAlreadyValidated, getBaseEntityManagerHandler, getConfiguration, getLoggedBasicUser, getLoggedUser, getProducts, getTranslatedName, getTranslatedValue, hasPermission, hasValue, inSameNetwork, inSameNetworkOrGlobal, isAdmin, isAlreadyValidated, isBroker, isGlobalAdmin, isGlobalAdminInNetwork, isGuest, isLoggedIn, isMember, isMemberOnly, isNetworkAdmin, isOperator, isRelatedToUser, isSystem, isUserManager, isUserManagerOf, message, message, permission, permission, permissionOptionalValue, permissionOptionalValue, setAlreadyValidated, toDate, toDateTime, validate
-
Methods inherited from class org.cyclos.impl.AbstractServerComponent
dataTranslationProxy, dataTranslationProxy, delete, detach, doDataTranslationProxy, find, flush, from, getApplicationContext, getFormatter, getFormatter, getFormatter, getLogger, getRemoteAddress, getSessionData, mailContentBuilder, message, message, persist, processBatch, processBatch, refresh, remove, selectFrom, subQuery, update
-
-
-
-
Method Detail
-
applyTransfer
public <T extends Transfer> void applyTransfer(T transfer)
Description copied from interface:RateHandlerApplies 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.
- Specified by:
applyTransferin interfaceRateHandler- Parameters:
transfer- the transfer to be applied.
-
copy
public void copy(HasRates source, HasRates destination)
Description copied from interface:RateHandlerCopies rate fields from one HasRates to another.- Specified by:
copyin interfaceRateHandler
-
copy
public void copy(RatedEntity source, RatedEntity destination)
Description copied from interface:RateHandlercopies all rate fields from one RatedEntity to another.- Specified by:
copyin interfaceRateHandler
-
getAccountRatesEntity
public AccountRates getAccountRatesEntity(Account account, Date time)
gets the AccountRates entity from the account. if the time parameter is not null, it retrieves the entity from the history (even if date is now). Doesn't correct for the situation that there is no AccountRates entity even while it should be there.- Specified by:
getAccountRatesEntityin interfaceRateHandlerTestable- Parameters:
account-time-- Returns:
-
getEnableDate
public Date getEnableDate(Currency currency, Date requestedDate)
gets the earliest date of first enabling of any rate type. See {@link RateTypeHandler.getEnableDate(Currency, Date)}- Specified by:
getEnableDatein interfaceRateHandlerTestable
-
getFromRates
public FromRatesData getFromRates(Account fromAccount, TransferType transferType, BigDecimal amount, Date date, RateVisibility visibility)
Description copied from interface:RateHandlergets 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.- Specified by:
getFromRatesin interfaceRateHandler- 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
public RatesData getRates(Account account, BigDecimal balance, Date time, RateVisibility visibility)
Description copied from interface:RateHandlerAsRateHandler.getRates(Account, RateVisibility), but uses a time and a balance as argument. This version is typically use to retrieve historical rates, usually from loops where the balance is calculated for each step.- Specified by:
getRatesin interfaceRateHandler- Parameters:
account- the account. May not be nullbalance- the balance at the specified time. If this is null, the balance is retrieved via a call toAccountService#getBalance(Account, Date). Beware however that this method is dangerous, as it is date EXCLUSIVE, and errors may also occur in loops where two consequetive transfers have the same timestamp. In such a case the use of the balance param is recommended.time- - the time at which the rates are requested. IfnullDateHelper.now()is used. In that case, also passing a null balance is recommended strongly.
-
getRates
public RatesData getRates(Account account, RateVisibility visibility)
Description copied from interface:RateHandlergets 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).- Specified by:
getRatesin interfaceRateHandler- Parameters:
account- the account. May not be null
-
getVisibleRates
public Set<RateType> getVisibleRates(Account account, Date time, RateVisibility visibility)
determines if any rate is visible according to the setting of the visibility parameters. If the rate is not enabled, it is of course not visible either.- Specified by:
getVisibleRatesin interfaceRateHandlerTestable
-
isAnyRateEnabled
public boolean isAnyRateEnabled(Currency currency, Date time)
Description copied from interface:RateHandlerChecks if any rate is enabled on the given date/time and for the given currency.- Specified by:
isAnyRateEnabledin interfaceRateHandler- Parameters:
currency- - If null then it checks it for all the currencies available on the network, and will return true if any of those currencies is found with any of the rates enabled.time- - if null checks it for now.- Returns:
- false if no rate at all is enabled, otherwise true.
-
isVisible
public boolean isVisible(Currency currency, Date date)
Description copied from interface:RateHandlerDetermines if any rate is to be shown to users. Checks the following:
* currency must have any rate enabled
* user must be admin, or rateParameters must be have flag showToUser set as true.
This method can be used if no account is known, or even if no currency is known. If the account was known, it would correspond with isVisible(account, date, RateVisibility.PARAM).- Specified by:
isVisiblein interfaceRateHandler- Parameters:
currency- - If null then it checks it for all the currencies available on the network, and will return true if any of those currencies applies.date- - if null checks it for now.- Returns:
- false if no rate at all is visible to the users, otherwise true.
-
persist
public void persist(RatedAccountEntity rates, Account account, Date time)
- Specified by:
persistin interfaceRateHandlerTestable
-
resetCurrency
public void resetCurrency(Currency entity)
Description copied from interface:RateHandlerResets the currency entity to its RateParameters. This is needed after saving a transient currency.- Specified by:
resetCurrencyin interfaceRateHandler
-
resolveValidator
public void resolveValidator(Validator validator, CurrencyDTO dto)
Description copied from interface:RateHandlergets the nested validator for the currency's rateparameters.- Specified by:
resolveValidatorin interfaceRateHandler
-
setRateParametersToCurrencyDTO
public void setRateParametersToCurrencyDTO(CurrencyDTO result)
Description copied from interface:RateHandlersets 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.
- Specified by:
setRateParametersToCurrencyDTOin interfaceRateHandler
-
toEntity
public void toEntity(Currency target, CurrencyDTO dto)
Description copied from interface:RateHandlersets the RateParameters entities to the Currency entity- Specified by:
toEntityin interfaceRateHandler- 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
-
registerNetworkMappings
protected void registerNetworkMappings(NetworkPathRegistry networkPathRegistry)
Description copied from class:BaseServiceImplNeeds to be overridden by subclasses to register the path up to the network- Specified by:
registerNetworkMappingsin classBaseServiceImpl
-
-