Package org.cyclos.impl.banking
Class DRateTypeHandlerImpl
- java.lang.Object
-
- org.cyclos.impl.AbstractServerComponent
-
- org.cyclos.impl.AbstractNetworkedServerComponent
-
- org.cyclos.impl.BaseNetworkedHandlerImpl
-
- org.cyclos.impl.banking.BaseRateTypeHandlerImpl<Date,R,D>
-
- org.cyclos.impl.banking.TimeBasedRateTypeHandlerImpl<DRateParameters,DRateParametersDTO>
-
- org.cyclos.impl.banking.DRateTypeHandlerImpl
-
- All Implemented Interfaces:
DRateTypeHandler,DRateTypeHandlerTestable,RateTypeHandler<Date,DRateParameters,DRateParametersDTO>,TimeBasedRateTypeHandler<DRateParameters,DRateParametersDTO>
@Component public class DRateTypeHandlerImpl extends TimeBasedRateTypeHandlerImpl<DRateParameters,DRateParametersDTO> implements DRateTypeHandlerTestable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.cyclos.impl.banking.BaseRateTypeHandlerImpl
BaseRateTypeHandlerImpl.RateParametersChangeAction
-
-
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
-
Fields inherited from interface org.cyclos.impl.banking.RateTypeHandler
RATE_SCALE
-
-
Constructor Summary
Constructors Constructor Description DRateTypeHandlerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendToRateParametersHistory(DRateCreationValueForTransferTypeDTO dto, TransferType tt)Appends the DRateCreationValueForTransferType object which is represented by the dto to the transferType.voidapplyMaturityPolicyChangesForFrom(TransferType transferType, BigDecimal amount, RatesData originalRates, FromRatesData result)applies the maturity policy to the result parameter.protected voidassignEntityToCurrency(DRateParameters entity, Currency currency)Assigns the RateParameters entity to the currency, so that the RateParameters entity becomes the new active RateParameters for this currency.protected voidassignValidator(Validator currencyValidator, Validator rateParametersValidator)sets specific checks to the RateParametersValidator, and assigns it as nested Validator to the currencyValidator.protected BigDecimalcalculateRateChange(BigDecimal oldRate, Date oldDate, Date newDate)Defines the business logic of rates developing over time.DatecloseDRateCreationValueForTransferTypeInHistory(TransferType tt)Closes the DRateCreationValueForTransferType by setting the end date to now on its actual version in the Transfertype.voidcomplete(RatesData rates)Completes the ratesData by calculating all missing fields of the rate (aRate, raw rate field).Dateconvert(BigDecimal rate, Date date)Converts the nominal rate (as a BigDecimal) to the raw valueBigDecimalconvert(Date rawRate, Date date)Converts the stored rawRate to the actual rate as a BigDecimal.voidcopy(HasRates source, HasRates destination)Copies the rate field from source to destinationprotected com.querydsl.core.types.PathgetAccountRatesFieldPath()gets the path for the relevant field of the QAccountRates query.protected DRateParametersgetCurrentRateParameters(Currency currency)BigDecimalgetDRateConversionResult(RatedCurrencyAmount<Date> setOfUnits)calculates the conversion result according to the D-rate.DRateCreationValueForTransferTypegetDRateCreationValueForTransferType(Long ttId, Date date)can be used to retrieve a history value of the DRateCreationValue from the TransferType.protected Class<DRateParameters>getEntityClass()gets the RateParameters classDategetNullSafeRawRate(RatedEntity entity, Currency currency, Date date)Gets the rawRate from the entity in a null-safe way.protected List<DRateParameters>getParametersList()protected QRateParametersgetQuery()gets the QXRateParameters.xRateParameters of QueryDSL as a view of itself as the parent type.DRateParametersgetRateParameters(Currency currency)Gets the RateParameters from the Currency by simply calling the getter.DRateParametersDTOgetRateParametersDTO(CurrencyDTO currencyDTO)Gets the RateParametersDTO of the CurrencyDTORateTypegetRateType()Returns the rate type being handledprotected booleanhasEqualProperties(DRateParameters entity, DRateParametersDTO dto)checks if the RateParameters entity has equal property values compared to the dto, in order to determine if it has been updated.protected voidimmediateDisableActions(Currency currency)does immediate disable actions needed when the rate is disabled.voidsetRate(HasRates destination, BigDecimal rate)Sets the rate to the destination objectvoidsetRawRate(RatedEntity destination, Date rawRate)Sets the rawRate to the desitnation object.voidtoEntity(TransferType tt, DRateCreationValueForTransferTypeDTO dto)Sets the DRateCreationValueForTransferType from the dto to the transferType entity.-
Methods inherited from class org.cyclos.impl.banking.TimeBasedRateTypeHandlerImpl
adjustIncomingRawRateInTransfer, convert, convert, getInitValue
-
Methods inherited from class org.cyclos.impl.banking.BaseRateTypeHandlerImpl
applyIncomingTransfer, calculateFromRates, convert, getCreationValue, getEnableDate, getRateParameters, inverseMerge, isEnabled, isVisible, isVisibleToUser, merge, nullAllAccountRates, resolveValidator, toEntity
-
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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cyclos.impl.banking.DRateTypeHandlerTestable
inverseMerge, merge
-
Methods inherited from interface org.cyclos.impl.banking.RateTypeHandler
applyIncomingTransfer, calculateFromRates, getCreationValue, getEnableDate, getRateParameters, isEnabled, isVisible, isVisibleToUser, nullAllAccountRates, resolveValidator, toEntity
-
Methods inherited from interface org.cyclos.impl.banking.TimeBasedRateTypeHandler
convert, convert, getInitValue
-
-
-
-
Method Detail
-
appendToRateParametersHistory
public void appendToRateParametersHistory(DRateCreationValueForTransferTypeDTO dto, TransferType tt)
Appends the DRateCreationValueForTransferType object which is represented by the dto to the transferType. The method does all following (necessary) checks and actions:- Closes the previous DRateCreationValueForTransferType entry of the transferType by setting its endDate to now.
- sets the entity's transfertype to the transfertype param
- sets the startDate of the entity to the same date as the closing date of the previous entity (now plus some millis)
- assigns the entity to the transfertype.
- Specified by:
appendToRateParametersHistoryin interfaceDRateTypeHandlerTestable- Parameters:
dto-tt-
-
applyMaturityPolicyChangesForFrom
public void applyMaturityPolicyChangesForFrom(TransferType transferType, BigDecimal amount, RatesData originalRates, FromRatesData result)
Description copied from interface:DRateTypeHandlerapplies the maturity policy to the result parameter. If the policy is different from MaturityPolicy.ALWAYS, and if there is a positive dRate, then the following is done:- check if no units are created for the transfer because of going deeper into minus. If so an IllegalArgumentException is thrown.
- calculate what higher D-rates will be left to the account after paying with D-rate is zero, and set that as the D-rate to the result.
- set appropriate fields to the result param.
- Specified by:
applyMaturityPolicyChangesForFromin interfaceDRateTypeHandleramount- the transfer amountoriginalRates- - the rates as they were before applying the transfer.result- - the FromRatesData object representing the results for the from account, after applying the transfer.
-
closeDRateCreationValueForTransferTypeInHistory
public Date closeDRateCreationValueForTransferTypeInHistory(TransferType tt)
Closes the DRateCreationValueForTransferType by setting the end date to now on its actual version in the Transfertype. After that, the entity is perisisted. The transfertype's reference to the entity is set to null.- Specified by:
closeDRateCreationValueForTransferTypeInHistoryin interfaceDRateTypeHandlerTestable- Parameters:
tt-- Returns:
- The value of the endDate set (now).
-
complete
public void complete(RatesData rates)
Description copied from interface:RateTypeHandlerCompletes the ratesData by calculating all missing fields of the rate (aRate, raw rate field). If both a rate and its raw value are present, the rate is overwritten with the value belonging to the raw value. So if ARate and EmissionDate are both present, A-rate is set to the value corresponding with EmissionDate.- Specified by:
completein interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>
-
convert
public Date convert(BigDecimal rate, Date date)
Description copied from interface:RateTypeHandlerConverts the nominal rate (as a BigDecimal) to the raw value- Specified by:
convertin interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>- Parameters:
rate- the input rate as a BigDecimaldate- the date at which this rate is valid. If null, current date/time is used.- Returns:
- the raw rate as a java.util.Date.
-
convert
public BigDecimal convert(Date rawRate, Date date)
Converts the stored rawRate to the actual rate as a BigDecimal.
Uses correction for minimal D.- Specified by:
convertin interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>- Overrides:
convertin classTimeBasedRateTypeHandlerImpl<DRateParameters,DRateParametersDTO>- Parameters:
rawRate- the raw rate as a java.util.Datedate- The java.util.Date at which this actual rate is requested. If null, now() is used.- Returns:
- the actual rate on date, as a BigDecimal.
-
copy
public void copy(HasRates source, HasRates destination)
Description copied from interface:RateTypeHandlerCopies the rate field from source to destination- Specified by:
copyin interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>
-
getDRateConversionResult
public BigDecimal getDRateConversionResult(RatedCurrencyAmount<Date> setOfUnits)
calculates the conversion result according to the D-rate.- Specified by:
getDRateConversionResultin interfaceDRateTypeHandlerTestable- Parameters:
setOfUnits- a RatesDTO. Needs to have set:- the currency
- the amount to be converted
- the generalRawRate
- the date
- Returns:
- null if D-rate is not enabled. Otherwise, the sum the member gets from converting the original amount.
-
getDRateCreationValueForTransferType
public DRateCreationValueForTransferType getDRateCreationValueForTransferType(Long ttId, Date date)
Description copied from interface:DRateTypeHandlerTestablecan be used to retrieve a history value of the DRateCreationValue from the TransferType. Not used at present, but it is there for future use (for example, for use of rebuilding the rates from history).- Specified by:
getDRateCreationValueForTransferTypein interfaceDRateTypeHandlerTestable
-
getNullSafeRawRate
public Date getNullSafeRawRate(RatedEntity entity, Currency currency, Date date)
Description copied from interface:RateTypeHandlerGets the rawRate from the entity in a null-safe way. That means: if the raw rate appears to be null, it checks if the rate is enabled, and if so, it gets the init value, if applicable.- Specified by:
getNullSafeRawRatein interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>- Parameters:
entity- the entity from which the raw rate is readcurrency- is only used in case the entity has a null rate. In that case the init value is looked up on the entity.date- is only used in case the entity has a null rate. If null, the present date is used (now).
-
getRateParameters
public DRateParameters getRateParameters(Currency currency)
Description copied from interface:RateTypeHandlerGets the RateParameters from the Currency by simply calling the getter.- Specified by:
getRateParametersin interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>
-
getRateParametersDTO
public DRateParametersDTO getRateParametersDTO(CurrencyDTO currencyDTO)
Description copied from interface:RateTypeHandlerGets the RateParametersDTO of the CurrencyDTO- Specified by:
getRateParametersDTOin interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>
-
getRateType
public RateType getRateType()
Description copied from interface:RateTypeHandlerReturns the rate type being handled- Specified by:
getRateTypein interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>
-
setRate
public void setRate(HasRates destination, BigDecimal rate)
Description copied from interface:RateTypeHandlerSets the rate to the destination object- Specified by:
setRatein interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>
-
setRawRate
public void setRawRate(RatedEntity destination, Date rawRate)
Description copied from interface:RateTypeHandlerSets the rawRate to the desitnation object.- Specified by:
setRawRatein interfaceRateTypeHandler<Date,DRateParameters,DRateParametersDTO>
-
toEntity
public void toEntity(TransferType tt, DRateCreationValueForTransferTypeDTO dto)
Description copied from interface:DRateTypeHandlerSets the DRateCreationValueForTransferType from the dto to the transferType entity. method does the following:- checks if the rate parameters have been changed
- Specified by:
toEntityin interfaceDRateTypeHandler
-
assignEntityToCurrency
protected void assignEntityToCurrency(DRateParameters entity, Currency currency)
Description copied from class:BaseRateTypeHandlerImplAssigns the RateParameters entity to the currency, so that the RateParameters entity becomes the new active RateParameters for this currency. Note that the method only calls the currency's setter. SeeBaseRateTypeHandlerImpl.appendToRateParametersHistory(D,org.cyclos.entities.banking.Currency)for other actions to be taken.- Specified by:
assignEntityToCurrencyin classBaseRateTypeHandlerImpl<Date,DRateParameters,DRateParametersDTO>
-
assignValidator
protected void assignValidator(Validator currencyValidator, Validator rateParametersValidator)
Description copied from class:BaseRateTypeHandlerImplsets specific checks to the RateParametersValidator, and assigns it as nested Validator to the currencyValidator.- Specified by:
assignValidatorin classBaseRateTypeHandlerImpl<Date,DRateParameters,DRateParametersDTO>
-
calculateRateChange
protected BigDecimal calculateRateChange(BigDecimal oldRate, Date oldDate, Date newDate)
Defines the business logic of rates developing over time. Gives the new rate, on basis of the old rate, the old date, and the new date.
Note that there is NO correction for minimalD.
To calculate the rate from the stored emission date, useactualDRate = calculateRateChange(BigDecimal.ZERO, expirationDate, actualDate);
- Specified by:
calculateRateChangein classTimeBasedRateTypeHandlerImpl<DRateParameters,DRateParametersDTO>- Parameters:
oldRate- a BigDecimal representing the old rate.oldDate- the java.util.Date belonging to oldRatenewDate- the java.util.Date for which the new Rate is requested- Returns:
- the new rate belonging to newDate.
-
getAccountRatesFieldPath
protected com.querydsl.core.types.Path getAccountRatesFieldPath()
Description copied from class:BaseRateTypeHandlerImplgets the path for the relevant field of the QAccountRates query. For example, returns for A-rate the QAccountRates.emissionDate field path.- Specified by:
getAccountRatesFieldPathin classBaseRateTypeHandlerImpl<Date,DRateParameters,DRateParametersDTO>- Returns:
-
getCurrentRateParameters
protected DRateParameters getCurrentRateParameters(Currency currency)
- Specified by:
getCurrentRateParametersin classBaseRateTypeHandlerImpl<Date,DRateParameters,DRateParametersDTO>
-
getEntityClass
protected Class<DRateParameters> getEntityClass()
Description copied from class:BaseRateTypeHandlerImplgets the RateParameters class- Specified by:
getEntityClassin classBaseRateTypeHandlerImpl<Date,DRateParameters,DRateParametersDTO>
-
getParametersList
protected List<DRateParameters> getParametersList()
- Specified by:
getParametersListin classBaseRateTypeHandlerImpl<Date,DRateParameters,DRateParametersDTO>
-
getQuery
protected QRateParameters getQuery()
Description copied from class:BaseRateTypeHandlerImplgets the QXRateParameters.xRateParameters of QueryDSL as a view of itself as the parent type. So for A-Rate, it gets QARateParametes.aRateParameters as QRateParameters. This is useful for queries on RateParameters for fields which are general for all rate types.- Specified by:
getQueryin classBaseRateTypeHandlerImpl<Date,DRateParameters,DRateParametersDTO>
-
hasEqualProperties
protected boolean hasEqualProperties(DRateParameters entity, DRateParametersDTO dto)
Description copied from class:BaseRateTypeHandlerImplchecks if the RateParameters entity has equal property values compared to the dto, in order to determine if it has been updated. Supposed to be overridden.- Overrides:
hasEqualPropertiesin classTimeBasedRateTypeHandlerImpl<DRateParameters,DRateParametersDTO>
-
immediateDisableActions
protected void immediateDisableActions(Currency currency)
Description copied from class:BaseRateTypeHandlerImpldoes immediate disable actions needed when the rate is disabled.- Overrides:
immediateDisableActionsin classBaseRateTypeHandlerImpl<Date,DRateParameters,DRateParametersDTO>
-
-