Interface RateTypeHandler<T,​R extends RateParameters,​D extends RateParametersDTO>

  • All Known Subinterfaces:
    ARateTypeHandler, DRateTypeHandler, TimeBasedRateTypeHandler<R,​D>

    public interface RateTypeHandler<T,​R extends RateParameters,​D extends RateParametersDTO>
    Handler for specific rates requests. RateHandlers are only supposed to be called from RateHandlerImpl. Other Services should generally call RateService, which is supposed to delegate specific requests to RateTypeHandler children. The T type-identifyer identifies the type of the raw rate; The R identifies the type of the RateParameters. The D identifies the RateParametersDTO belonging to this.
    • Field Detail

      • RATE_SCALE

        static final int RATE_SCALE
        This scale is used for calculations; it is not used for storage. It is a precision up to millis.
        See Also:
        Constant Field Values
    • Method Detail

      • applyIncomingTransfer

        void applyIncomingTransfer​(RatesData accountRates,
                                   Transfer transfer)
        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.
        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

        void calculateFromRates​(FromRatesData rates,
                                Account fromAccount,
                                TransferType transferType,
                                BigDecimal amount)
        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.
        Parameters:
        rates - - the rates as retrieved by requesting the rates from the from account, without considering the balance or the transfer type.
        fromAccount -
        transferType -
        amount -
      • complete

        void complete​(RatesData rates)
        Completes 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.
      • convert

        T convert​(BigDecimal rate,
                  Date date)
        Converts the nominal rate (as a BigDecimal) to the raw value
        Parameters:
        rate - the input rate as a BigDecimal
        date - 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

        BigDecimal convert​(T rawRate,
                           Date date)
        Converts the stored rawRate to the actual rate as a BigDecimal.
        Parameters:
        rawRate - the raw rate as a java.util.Date
        date - 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

        void copy​(HasRates source,
                  HasRates destination)
        Copies the rate field from source to destination
      • getCreationValue

        BigDecimal getCreationValue​(Currency currency,
                                    Date date)
        Gets the creation value of the rate, that is, the value which is assigned for this rate at unit creation.
        Returns:
        the rate creation value as BigDecimal, but returns null if the rate is not enabled at the given date.
      • getEnableDate

        Date getEnableDate​(Currency currency,
                           Date requestedDate)
        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.
        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.
      • getNullSafeRawRate

        T getNullSafeRawRate​(RatedEntity entity,
                             Currency currency,
                             Date date)
        Gets 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.
        Parameters:
        entity - the entity from which the raw rate is read
        currency - 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

        R getRateParameters​(Currency currency)
        Gets the RateParameters from the Currency by simply calling the getter.
      • getRateParameters

        R getRateParameters​(Currency currency,
                            Date date)
        Gets the RateParameters at a certain time by querying the db. If the rate was not enabled at that time, it returns null.
        Parameters:
        date - if null, present datetime is used.
      • getRateParametersDTO

        D getRateParametersDTO​(CurrencyDTO currencyDTO)
        Gets the RateParametersDTO of the CurrencyDTO
      • getRateType

        RateType getRateType()
        Returns the rate type being handled
      • isEnabled

        boolean isEnabled​(Currency currency,
                          Date date)
        Checks if the rate is enabled on the given date
      • isVisible

        boolean isVisible​(Account account,
                          Date date,
                          RateVisibility visibility)
        Determines if the rate is visible, depending on the visibility param. If the rate is not enabled it is considered not visible, so then it returns false.
      • isVisibleToUser

        boolean isVisibleToUser​(Currency currency,
                                Date date)
        Returns true if the rate is visible to the user on the given date. It is visible if and only if: the rate is enabled the showToUser flag on the params is true.
      • nullAllAccountRates

        long nullAllAccountRates​(Currency currency)
        Sets all rates on all accounts explicitly to null (for the actual rate type belonging to this RateTypeHandler).
        Parameters:
        currency -
      • resolveValidator

        void resolveValidator​(Validator validator,
                              CurrencyDTO dto)
        Resolves the validator for the RateParameters as nested validator for CurrencyDTO.
        Parameters:
        validator - the resolved validator is assigned as nested validator to this parameters.
        dto -
      • setRate

        void setRate​(HasRates destination,
                     BigDecimal rate)
        Sets the rate to the destination object
      • setRawRate

        void setRawRate​(RatedEntity destination,
                        T rawRate)
        Sets the rawRate to the desitnation object.
      • toEntity

        void toEntity​(Currency entity,
                      D dto)
        Sets the rateParameters from the dto to the entity. method does the following:
        • checks if the rate parameters have been changed