Class BaseRateTypeHandlerImpl<T,​R extends RateParameters,​D extends RateParametersDTO>

    • Constructor Detail

      • BaseRateTypeHandlerImpl

        public BaseRateTypeHandlerImpl()
    • Method Detail

      • applyIncomingTransfer

        public void applyIncomingTransfer​(RatesData accountRates,
                                          Transfer transfer)
        Description copied from interface: RateTypeHandler
        Applies the incoming transfer. Chargebacks are treated as any other normal transfer, just according to the rules as described in the wiki. It does the following:
        * checks if enabled and if not unlimited account
        * gets the incoming rate from the transfer
        * gets the account rate from the accountRates Param
        * merges those two, where the accountRates param's virtualRatedBalance field is the amount of the account
        * sets the new raw rate evolving from this merge to the accountRates parameter.
        * Note that only the raw rate is adapted; the normal (BigDecimal) rate is not updated, because it is not used when persisting it.
        Specified by:
        applyIncomingTransfer in interface RateTypeHandler<T,​R extends RateParameters,​D extends RateParametersDTO>
        Parameters:
        accountRates - a RatesVO with the present rates of the account on which the transfer is received. Also the virtualRatedBalance must be set on this. This parameter will be updated with the new merged rate value.
        transfer - The transfer which should be merged.
      • calculateFromRates

        public void calculateFromRates​(FromRatesData rates,
                                       Account fromAccount,
                                       TransferType transferType,
                                       BigDecimal amount)
        Description copied from interface: RateTypeHandler
        Adapts the from account rates after it has been retrieved from the account, and adapts the fields to specific additional rate rules. The rate balance correction and virtual rated balance are NOT adapted. The following rules are applied:
        • in case of D-rate: if the from account is unlimited and there is a creation value D-rate set on the transferType, this is used as the D-rate.
        • in case of insufficient balance: the total amount is considered to consist of two sets: one set coming from the from account, being the complete balance and having the rates of the from accounts, and another set which is newly created against the rate creation values, and being the transaction amount minus the balance. These sets are merged in order to get the rates to be used for the transfer.
          If there was insufficient balance, the FromRatesData.changedDueToCreation field is set to true.
        Note that there is no check whatsoever if the transferType is accessible for the fromAccount. This is considered the responsibility of the calling method.
        Specified by:
        calculateFromRates in interface RateTypeHandler<T,​R extends RateParameters,​D extends RateParametersDTO>
        Parameters:
        rates - - the rates as retrieved by requesting the rates from the from account, without considering the balance or the transfer type.
      • getEnableDate

        public Date getEnableDate​(Currency currency,
                                  Date requestedDate)
        Description copied from interface: RateTypeHandler
        Gets the earliest date of first enabling the rate. The result is the start of the earliest rate enabling period to which the requestedDate also belongs.
        Example: if A-rate was enabled for two months in 2003, and then disabled, and again enabled in 2012, and the requestedDate falls in the 2012 period, the start of the 2012 period is returned.
        Specified by:
        getEnableDate in interface RateTypeHandler<T,​R extends RateParameters,​D extends RateParametersDTO>
        Parameters:
        currency - - rates are set on this currency
        requestedDate - - the returned date and the requestedDate belong to the same rate enabling period without interrupt. However, rateParameters may have changed during that period.
      • inverseMerge

        public T inverseMerge​(RatedCurrencyAmount<T> previousSetOfUnits,
                              RatedCurrencyAmount<T> transferSetOfUnits,
                              Date date)
        does an inverse merge, that is: when a set of units is distracted from an account, and when the distracted set has a rate different from the account rate, then the remaining sum on the account must do an inverseMerge to calculate the rate of the remainder.
        Parameters:
        previousSetOfUnits -
        transferSetOfUnits -
        date -
        Returns:
        The result of this method is as such, that when the result is merged with the transferSetOfUnits, it gives again the previousSetOfUnits.
      • merge

        public T merge​(RatedCurrencyAmount<T> setOfUnits1,
                       RatedCurrencyAmount<T> setOfUnits2,
                       Date date)
                throws IllegalArgumentException
        Does the actual calculation of the rate from a merge (where a set of units enters an account).
        Parameters:
        setOfUnits1 - a RatesDTO object, which must have set the following fields:
        • currency
        • amount
        • anyRawRate or anyRate, depending on the type T.
        setOfUnits2 - as setOfUnits1.
        date - the date on which the transaction takes place. May be null.
        Returns:
        the new raw rate resulting from the merge. returns null if rate not enabled.
        Throws:
        IllegalArgumentException - if the two sets of units belong to different currencies.
      • adjustIncomingRawRateInTransfer

        protected abstract T adjustIncomingRawRateInTransfer​(T incomingRawRate,
                                                             Transfer transfer)
        adjusts a rate as a result of the transaction. For date based rates, this is meaningless, so the method does nothing. For transfer based rates (I-rate, future C-rate) this method adds 1 to the raw rate of the from account - except when the from-account is unlimited; in that case it does nothing.
        Parameters:
        incomingRawRate - the from account's raw rate
        transfer - this is only relevant for iRate, so in other cases this may as well be null, because it is not used then.
        Returns:
        the incoming rate, but increased by 1 for transfer based rates. For date based rates, it returns just the unchanged input.
      • assignEntityToCurrency

        protected abstract void assignEntityToCurrency​(R entity,
                                                       Currency currency)
        Assigns 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. See appendToRateParametersHistory(D,org.cyclos.entities.banking.Currency) for other actions to be taken.
        Parameters:
        entity -
        currency -
        Throws:
        IllegalArgumentException - - only new entities may be assigned to the currency. An IllegalArgumentException is thrown if the entity has a non-null id.
      • assignValidator

        protected abstract void assignValidator​(Validator currencyValidator,
                                                Validator rateParametersValidator)
        sets specific checks to the RateParametersValidator, and assigns it as nested Validator to the currencyValidator.
      • convert

        protected <C> C convert​(Class<C> toType,
                                Object object)
        quick link to convertionHandler.convert
      • getAccountRatesFieldPath

        protected abstract com.querydsl.core.types.Path getAccountRatesFieldPath()
        gets the path for the relevant field of the QAccountRates query. For example, returns for A-rate the QAccountRates.emissionDate field path.
        Parameters:
        ar -
        Returns:
      • getCurrentRateParameters

        protected abstract R getCurrentRateParameters​(Currency currency)
      • getEntityClass

        protected abstract Class<R> getEntityClass()
        gets the RateParameters class
      • getParametersList

        protected abstract List<R> getParametersList()
      • getQuery

        protected abstract QRateParameters getQuery()
        gets 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.
      • hasEqualProperties

        protected boolean hasEqualProperties​(R entity,
                                             D dto)
        checks 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.
      • immediateDisableActions

        protected void immediateDisableActions​(Currency currency)
        does immediate disable actions needed when the rate is disabled.